X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firprog.c;h=963ae93e0eaa904b8a5369b226ad6d38c566418a;hb=2da89aec2e7d54d70940cccfa82f74c83e5221eb;hp=f8054bc98fbb7af76f2be967b270f26492db7cc8;hpb=d5270b4f4973d5a88eb48ea66c43e9f518dfd360;p=libfirm diff --git a/ir/ir/irprog.c b/ir/ir/irprog.c index f8054bc98..963ae93e0 100644 --- a/ir/ir/irprog.c +++ b/ir/ir/irprog.c @@ -6,17 +6,27 @@ ** irprog.c: ir representation of a program */ -# include "irprog.h" +#ifdef HAVE_CONFIG_H +# include +#endif + +# include "irprog_t.h" # include "array.h" +# include "obst.h" +# include "typegmod.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,32 +40,89 @@ 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 **/ -type_class *get_glob_type(void) { + + +/* 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 *get_glob_type(void) { assert(irp); - return irp->glob_type; + return irp->glob_type = skip_tid(irp->glob_type); } /* 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?? */ + /* Don't set the skip_tid result so that no double entries are generated. */ + return skip_tid(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