X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firprog.c;h=f7355f248957d66dbcc2f9f6bc8873aa4328c16f;hb=5f8ddee6b08c8040c0a304a347d65045c1141d52;hp=f8054bc98fbb7af76f2be967b270f26492db7cc8;hpb=d5270b4f4973d5a88eb48ea66c43e9f518dfd360;p=libfirm diff --git a/ir/ir/irprog.c b/ir/ir/irprog.c index f8054bc98..f7355f248 100644 --- a/ir/ir/irprog.c +++ b/ir/ir/irprog.c @@ -6,17 +6,22 @@ ** irprog.c: ir representation of a program */ -# include "irprog.h" +# include "irprog_t.h" # include "array.h" +# include "obst.h" #define GLOBAL_TYPE_NAME "GlobalType" +/* A variable from where everything in the ir can be accessed. */ +ir_prog *irp; + /* initializes ir_prog. Calles the constructor for an ir_prog. */ void init_irprog(void) { new_ir_prog (); } -/* Create a new ir prog. Automatically called by init_firm through init_irprog. */ +/* Create a new ir prog. Automatically called by init_firm through + init_irprog. */ ir_prog *new_ir_prog (void) { ir_prog *res; @@ -30,11 +35,27 @@ ir_prog *new_ir_prog (void) { strlen(GLOBAL_TYPE_NAME))); add_irp_type((type *)res->glob_type); +#ifdef DEBUG_libfirm + res->max_node_nr = 1; +#endif + return res; } - /** Functions to access the fields of ir_prog **/ + + +/* Access the main routine of the compiled program. */ +ir_graph *get_irp_main_irg() { + assert (irp); + return irp->main_irg; +} + +void set_irp_main_irg(ir_graph *main_irg) { + assert (irp); + irp->main_irg = main_irg; +} + type_class *get_glob_type(void) { assert(irp); return irp->glob_type; @@ -43,19 +64,61 @@ type_class *get_glob_type(void) { /* Adds irg to the list of ir graphs in irp. */ void add_irp_irg(ir_graph *irg) { assert (irg != NULL); - assert(irp); + assert(irp && irp->graphs); ARR_APP1 (ir_graph *, irp->graphs, irg); } +int get_irp_n_irgs() { + assert (irp && irp->graphs); + /* Strangely the first element of the array is NULL. Why?? */ + return (ARR_LEN((irp)->graphs) - 1); +} + +ir_graph *get_irp_irg(int pos){ + assert (irp && irp->graphs); + /* Strangely the first element of the array is NULL. Why?? */ + return irp->graphs[pos+1]; +} + +void set_irp_irg(int pos, ir_graph *irg) { + assert (irp && irg); + assert (pos < (ARR_LEN((irp)->graphs) - 1)); + /* Strangely the first element of the array is NULL. Why?? */ + irp->graphs[pos+1] = irg; +} + /* Adds type to the list of types in irp. */ -void add_irp_type(type *typ) { +void add_irp_type(type *typ) { assert (typ != NULL); assert(irp); ARR_APP1 (type *, irp->types, typ); } -int get_irp_new_node_nr() { +int get_irp_n_types (void) { + assert (irp && irp->types); + /* Strangely the first element of the array is NULL. Why?? */ + return (ARR_LEN((irp)->types) - 1); +} + +type *get_irp_type(int pos) { + assert (irp && irp->types); + /* Strangely the first element of the array is NULL. Why?? */ + return irp->types[pos+1]; + +} + +void set_irp_type(int pos, type *typ) { + assert (irp && typ); + assert (pos < (ARR_LEN((irp)->types) - 1)); + /* Strangely the first element of the array is NULL. Why?? */ + irp->types[pos+1] = typ; + +} + +#ifdef DEBUG_libfirm +int get_irp_new_node_nr() { assert(irp); irp->max_node_nr = irp->max_node_nr + 1; return irp->max_node_nr - 1; } +#endif