From: Michael Beck Date: Thu, 14 May 2009 09:17:29 +0000 (+0000) Subject: - cleaned up irp functions a bit X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=8e274ccd621c6743361fd63fca32630197da3107;hp=90b095a35e6f296c6318356651805a5bf7f96f50;p=libfirm - cleaned up irp functions a bit [r25941] --- diff --git a/include/libfirm/irprog.h b/include/libfirm/irprog.h index 748030a62..38289397a 100644 --- a/include/libfirm/irprog.h +++ b/include/libfirm/irprog.h @@ -65,31 +65,29 @@ typedef enum ir_segment_t { } ir_segment_t; /** - * Datastructure that holds central information about a program - * - * Preliminary documentation ;-) + * Data structure that holds central information about a program + * or a module. + * One irp is created by libFirm on construction, so irp should never be NULL. * * - main_irg: The ir graph that is the entry point to the program. - * (Anything not reachable from here may be optimized away. - * If we want to translate libraries or the like correctly - * we must replace this by a list.) - * - irg: List of all ir graphs in the program. + * (Anything not reachable from here may be optimized away + * if this irp represents a whole program. + * - irg: List of all ir graphs in the program or module. * - type: A list containing all types known to the translated program. * Some types can have several entries in this list (as a result of * using exchange_types()). - * - glob_type: The unique global type that is owner of all global entities. - * + * - glob_type: The unique global type that is owner of all global entities + * of this module. */ typedef struct ir_prog ir_prog; /** - * A variable from where everything in the ir can be accessed. - * This variable contains the irp, the "immediate representation program". + * A variable pointing to the current irp (program or module). * This variable should be considered constant. Moreover, one should use get_irp() * to get access the the irp. * * @note - * Think of the irp as the "handle" of libFirm. + * Think of the irp as the "handle" of a program. */ extern ir_prog *irp; @@ -104,15 +102,20 @@ ir_resources_t irp_resources_reserved(const ir_prog *irp); #endif /** - * Returns the access points from where everything in the ir can be accessed. + * Returns the current irp from where everything in the current module + * can be accessed. * * @see irp */ ir_prog *get_irp(void); -/** Creates a new ir_prog, returns it and sets irp with it. - * Automatically called by init_firm() through init_irprog. */ -ir_prog *new_ir_prog(void); +/** + * Creates a new ir_prog (a module or compilation unit), + * returns it and sets irp with it. + * + * @param module_name the name of this irp (module) + */ +ir_prog *new_ir_prog(const char *name); /** frees all memory used by irp. Types in type list and irgs in irg * list must be freed by hand before. */ @@ -125,13 +128,11 @@ void set_irp_prog_name(ident *name); /** Returns true if the user ever set a program name */ int irp_prog_name_is_set(void); -/** Gets the file name / executable name or the like. - */ -ident *get_irp_prog_ident(void); +/** Gets the name of the current irp. */ +ident *get_irp_ident(void); -/** Gets the file name / executable name or the like. - */ -const char *get_irp_prog_name (void); +/** Gets the name of the current irp. */ +const char *get_irp_name(void); /** Gets the main routine of the compiled program. */ ir_graph *get_irp_main_irg(void); @@ -139,7 +140,7 @@ ir_graph *get_irp_main_irg(void); /** Sets the main routine of the compiled program. */ void set_irp_main_irg(ir_graph *main_irg); -/** Adds irg to the list of ir graphs in irp. */ +/** Adds irg to the list of ir graphs in the current irp. */ void add_irp_irg(ir_graph *irg); /** Removes irg from the list of irgs and @@ -169,7 +170,9 @@ int get_irp_n_allirgs(void); ir_graph *get_irp_allirg(int pos); /** - * returns the type containing the entities for a segment + * Returns the type containing the entities for a segment. + * + * @param segment the segment */ ir_type *get_segment_type(ir_segment_t segment); @@ -225,7 +228,7 @@ ir_op *get_irp_opcode(int pos); void clear_irp_opcodes_generic_func(void); -/** Return the graph for global constants. +/** Return the graph for global constants of the current irp. * * Returns an irgraph that only contains constant expressions for * constant entities. Do not use any access function for this diff --git a/ir/be/becopyopt.c b/ir/be/becopyopt.c index 20f7f4bcd..0f72936f6 100644 --- a/ir/be/becopyopt.c +++ b/ir/be/becopyopt.c @@ -198,7 +198,7 @@ copy_opt_t *new_copy_opt(be_chordal_env_t *chordal_env, cost_fct_t get_costs) co->cls = chordal_env->cls; co->get_costs = get_costs; - s1 = get_irp_prog_name(); + s1 = get_irp_name(); s2 = get_entity_name(get_irg_entity(co->irg)); s3 = chordal_env->cls->name; len = strlen(s1) + strlen(s2) + strlen(s3) + 5; diff --git a/ir/be/becopystat.c b/ir/be/becopystat.c index d2f794c10..c9e691614 100644 --- a/ir/be/becopystat.c +++ b/ir/be/becopystat.c @@ -370,7 +370,7 @@ void copystat_dump(ir_graph *irg) { char buf[1024]; FILE *out; - snprintf(buf, sizeof(buf), "%s__%s", get_irp_prog_name(), get_entity_name(get_irg_entity(irg))); + snprintf(buf, sizeof(buf), "%s__%s", get_irp_name(), get_entity_name(get_irg_entity(irg))); buf[sizeof(buf) - 1] = '\0'; out = be_ffopen(buf, "stat", "wt"); @@ -394,7 +394,7 @@ void copystat_dump_pretty(ir_graph *irg) { char buf[1024]; FILE *out; - snprintf(buf, sizeof(buf), "%s__%s", get_irp_prog_name(), get_entity_name(get_irg_entity(irg))); + snprintf(buf, sizeof(buf), "%s__%s", get_irp_name(), get_entity_name(get_irg_entity(irg))); buf[sizeof(buf) - 1] = '\0'; out = be_ffopen(buf, "pstat", "wt"); diff --git a/ir/ir/irdumptxt.c b/ir/ir/irdumptxt.c index b465aaa37..f41b901ed 100644 --- a/ir/ir/irdumptxt.c +++ b/ir/ir/irdumptxt.c @@ -1384,7 +1384,7 @@ void dump_types_as_text(unsigned verbosity, const char *suffix) { FILE *F, *CSV = NULL; int i, n_types = get_irp_n_types(); - basename = irp_prog_name_is_set() ? get_irp_prog_name() : "TextTypes"; + basename = irp_prog_name_is_set() ? get_irp_name() : "TextTypes"; F = text_open(basename, suffix, "-types", ".txt"); if (verbosity & dump_verbosity_csv) { @@ -1416,7 +1416,7 @@ void dump_globals_as_text(unsigned verbosity, const char *suffix) { ir_type *g = get_glob_type(); int i, n_mems = get_class_n_members(g); - basename = irp_prog_name_is_set() ? get_irp_prog_name() : "TextGlobals"; + basename = irp_prog_name_is_set() ? get_irp_name() : "TextGlobals"; F = text_open (basename, suffix, "-globals", ".txt"); if (verbosity & dump_verbosity_csv) { diff --git a/ir/ir/irprog.c b/ir/ir/irprog.c index 81ba98677..a313ae9d1 100644 --- a/ir/ir/irprog.c +++ b/ir/ir/irprog.c @@ -69,13 +69,16 @@ static ir_prog *new_incomplete_ir_prog(void) return res; } -/** Completes an incomplete irprog. */ -static ir_prog *complete_ir_prog(ir_prog *irp) { +/** + * Completes an incomplete irprog. + * + * @param irp the (yet incomplete) irp + * @param module_name the (module) name for this irp + */ +static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name) { int i; -#define IDENT(s) new_id_from_chars(s, sizeof(s)-1) - - irp->name = IDENT(INITAL_PROG_NAME); + irp->name = new_id_from_str(module_name); irp->segment_types[IR_SEGMENT_GLOBAL] = new_type_class(IDENT("GlobalType")); irp->segment_types[IR_SEGMENT_THREAD_LOCAL] = new_type_struct(IDENT("ThreadLocal")); @@ -108,7 +111,6 @@ static ir_prog *complete_ir_prog(ir_prog *irp) { irp->globals_entity_usage_state = ir_entity_usage_not_computed; return irp; -#undef IDENT } /* initializes ir_prog. Constructs only the basic lists. */ @@ -118,7 +120,7 @@ void init_irprog_1(void) { /* Completes ir_prog. */ void init_irprog_2(void) { - complete_ir_prog(irp); + (void)complete_ir_prog(irp, INITAL_PROG_NAME); } /* Create a new ir prog. Automatically called by init_firm through @@ -359,10 +361,10 @@ void set_irp_prog_name(ident *name) { int irp_prog_name_is_set(void) { return irp->name != new_id_from_str(INITAL_PROG_NAME); } -ident *get_irp_prog_ident(void) { +ident *get_irp_ident(void) { return irp->name; } -const char *get_irp_prog_name(void) { +const char *get_irp_name(void) { return get_id_str(irp->name); }