1 /* Copyright (C) 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
6 ** irprog.c: ir representation of a program
12 #define GLOBAL_TYPE_NAME "GlobalType"
14 /* initializes ir_prog. Calles the constructor for an ir_prog. */
15 void init_irprog(void) {
19 /* Create a new ir prog. Automatically called by init_firm through init_irprog. */
20 ir_prog *new_ir_prog (void) {
23 res = (ir_prog *) malloc (sizeof(ir_prog));
26 /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
27 res->graphs = NEW_ARR_F (ir_graph *, 1);
28 res->types = NEW_ARR_F (type *, 1);
29 res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
30 strlen(GLOBAL_TYPE_NAME)));
31 add_irp_type((type *)res->glob_type);
36 /** Functions to access the fields of ir_prog **/
39 /* Access the main routine of the compiled program. */
40 ir_graph *get_irp_main_irg() {
45 void set_irp_main_irg(ir_graph *main_irg) {
47 irp->main_irg = main_irg;
50 type_class *get_glob_type(void) {
52 return irp->glob_type;
55 /* Adds irg to the list of ir graphs in irp. */
56 void add_irp_irg(ir_graph *irg) {
58 assert(irp && irp->graphs);
59 ARR_APP1 (ir_graph *, irp->graphs, irg);
62 int get_irp_n_irgs() {
63 assert (irp && irp->graphs);
64 /* Strangely the first element of the array is NULL. Why?? */
65 return (ARR_LEN((irp)->graphs) - 1);
68 ir_graph *get_irp_irg(int pos){
69 assert (irp && irp->graphs);
70 /* Strangely the first element of the array is NULL. Why?? */
71 return irp->graphs[pos+1];
74 /* Adds type to the list of types in irp. */
75 void add_irp_type(type *typ) {
78 ARR_APP1 (type *, irp->types, typ);
81 int get_irp_new_node_nr() {
83 irp->max_node_nr = irp->max_node_nr + 1;
84 return irp->max_node_nr - 1;