From: Adam Szalkowski Date: Tue, 5 Sep 2006 07:24:01 +0000 (+0000) Subject: dirty hack for getting assembler file name X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=ef01dc80e085060439071ceaa90679c04f1cf1a1;p=libfirm dirty hack for getting assembler file name --- diff --git a/ir/be/bemain.c b/ir/be/bemain.c index c952a1717..b1d6adeff 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -9,6 +9,8 @@ #endif #include +#include +#include #ifdef WITH_LIBCORE #include @@ -392,6 +394,8 @@ static void be_main_loop(FILE *file_handle) unsigned num_nodes_b = 0; unsigned num_nodes_a = 0; unsigned num_nodes_r = 0; + char prof_filename[256]; + char path[256]; #ifdef WITH_LIBCORE lc_timer_t *t_prolog = NULL; @@ -427,11 +431,17 @@ static void be_main_loop(FILE *file_handle) /* for debugging, anchors helps */ // dump_all_anchors(1); + /* please FIXME! I'm a dirty hack. */ + snprintf(path, 256, "/proc/self/fd/%d", fileno(file_handle)); + memset(prof_filename, 0, 256); + readlink(path, prof_filename, 250); + strcat(prof_filename, ".prof"); + if(be_options.opt_profile) { - ir_graph *prof_init_irg = be_profile_instrument(); + ir_graph *prof_init_irg = be_profile_instrument(prof_filename); pset_insert_ptr(env.arch_env->constructor_entities, get_irg_entity(prof_init_irg)); } - be_profile_read("test.c.prof"); //FIXME + be_profile_read(prof_filename); /* For all graphs */ for (i = 0, n = get_irp_n_irgs(); i < n; ++i) { diff --git a/ir/be/beprofile.c b/ir/be/beprofile.c index 89a499762..1140a3662 100644 --- a/ir/be/beprofile.c +++ b/ir/be/beprofile.c @@ -174,22 +174,8 @@ gen_initializer_irg(entity * ent_filename, entity * bblock_id, entity * bblock_c ins[2] = new_r_SymConst(irg, start_block, sym, symconst_addr_ent); ins[3] = new_r_Const_long(irg, start_block, mode_Iu, n_blocks); - call = new_r_Call( irg, - bb, //ir_node * block, - get_irg_initial_mem(irg), //ir_node * store, - symconst, //ir_node * callee, - 4, //int arity, - ins, //ir_node ** in, - init_type //ir_type * tp - ); - - ret = new_r_Return ( irg, - bb, //ir_node * block, - new_r_Proj(irg, bb, call, mode_M, pn_Call_M_regular), //ir_node * store, - 0, //int arity, - NULL //ir_node ** in - ); - + call = new_r_Call(irg, bb, get_irg_initial_mem(irg), symconst, 4, ins, init_type); + ret = new_r_Return(irg, bb, new_r_Proj(irg, bb, call, mode_M, pn_Call_M_regular), 0, NULL); mature_immBlock(bb); add_immBlock_pred(get_irg_end_block(irg), ret); @@ -211,14 +197,13 @@ block_id_walker(ir_node * bb, void * data) } ir_graph * -be_profile_instrument(void) +be_profile_instrument(char * filename) { int n, i; unsigned int n_blocks = 0; entity *bblock_id, *bblock_counts, *ent_filename; ir_type *array_type, *integer_type, *string_type, *character_type; tarval **tarval_array, **tarval_string; - char *filename = "test.c"; //FIXME int filename_len = strlen(filename)+1; ident *cur_ident; @@ -230,20 +215,20 @@ be_profile_instrument(void) set_array_bounds_int(array_type, 0, 0, n_blocks); character_type = new_type_primitive(new_id_from_str("__char"), mode_Bs); - string_type = new_type_array(new_id_from_str("__function_name"), 1, character_type); + string_type = new_type_array(new_id_from_str("__filename"), 1, character_type); set_array_bounds_int(string_type, 0, 0, filename_len); - cur_ident = new_id_from_str("__BLOCK_IDS"); + cur_ident = new_id_from_str("__FIRMPROF__BLOCK_IDS"); bblock_id = new_entity(get_glob_type(), cur_ident, array_type); set_entity_ld_ident(bblock_id, cur_ident); set_entity_variability(bblock_id, variability_initialized); - cur_ident = new_id_from_str("__BLOCK_COUNTS"); + cur_ident = new_id_from_str("__FIRMPROF__BLOCK_COUNTS"); bblock_counts = new_entity(get_glob_type(), cur_ident, array_type); set_entity_ld_ident(bblock_counts, cur_ident); set_entity_variability(bblock_counts, variability_initialized); - cur_ident = new_id_from_str("__FUNCTION_NAME"); + cur_ident = new_id_from_str("__FIRMPROF__FILE_NAME"); ent_filename = new_entity(get_glob_type(), cur_ident, string_type); set_entity_ld_ident(ent_filename, cur_ident); set_entity_variability(ent_filename, variability_initialized); diff --git a/ir/be/beprofile.h b/ir/be/beprofile.h index 26636094e..a1cb80dae 100644 --- a/ir/be/beprofile.h +++ b/ir/be/beprofile.h @@ -15,13 +15,15 @@ /** * Instruments irgs with profile code + * @param filename The name of the output file for the profile information * @return The irg doing the profile initialization. */ -ir_graph * be_profile_instrument(void); +ir_graph * be_profile_instrument(char * filename); /** * Reads the corresponding profile info file if it exists and returns a * profile info struct + * @param filename The name of the file containing profile information */ void be_profile_read(char * filename);