From: Sebastian Hack Date: Mon, 9 Jan 2006 15:47:41 +0000 (+0000) Subject: Fulfilled Christian's wishes X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=1345e0ae4de685dbb4012d7f66b6a54c3cf1f27b;p=libfirm Fulfilled Christian's wishes --- diff --git a/ir/be/bearch.c b/ir/be/bearch.c index 6d8f38f37..1433d020a 100644 --- a/ir/be/bearch.c +++ b/ir/be/bearch.c @@ -26,10 +26,10 @@ #include "pset.h" #include "entity.h" -arch_env_t *arch_env_init(arch_env_t *env, const arch_isa_if_t *isa_if, FILE *file_handle) +arch_env_t *arch_env_init(arch_env_t *env, const arch_isa_if_t *isa_if) { memset(env, 0, sizeof(*env)); - env->isa = isa_if->init(file_handle); + env->isa = isa_if->init(); return env; } diff --git a/ir/be/bearch.h b/ir/be/bearch.h index 59bcacc11..b8e080689 100644 --- a/ir/be/bearch.h +++ b/ir/be/bearch.h @@ -384,6 +384,16 @@ struct _arch_irn_handler_t { */ struct _arch_code_generator_if_t { + + /** + * Initialzie the code generator. + * @param file The file to dump to. + * @param irg The fucntion to generate code for. + * @param env The archicture environment. + * @return A newly created code generator. + */ + void *(*init)(FILE *file, ir_graph *irg, const arch_env_t *env); + /** * Called, when the graph is being normalized. */ @@ -444,7 +454,7 @@ struct _arch_isa_if_t { /** * Initialize the isa interface. */ - void *(*init)(FILE *file_handle); + void *(*init)(void); /** * Free the isa instance. @@ -473,12 +483,11 @@ struct _arch_isa_if_t { const arch_irn_handler_t *(*get_irn_handler)(const void *self); /** - * Produce a new code generator. + * Get the code generator interface. * @param self The this pointer. - * @param irg The graph for which code shall be generated. - * @return A code generator. + * @return Some code generator interface. */ - arch_code_generator_t *(*make_code_generator)(void *self, ir_graph *irg); + const arch_code_generator_if_t *(*get_code_generator)(void *self); /** * Get the list scheduler to use. @@ -522,7 +531,7 @@ struct _arch_env_t { * @param isa The isa which shall be put into the environment. * @return The environment. */ -extern arch_env_t *arch_env_init(arch_env_t *env, const arch_isa_if_t *isa, FILE *file_handle); +extern arch_env_t *arch_env_init(arch_env_t *env, const arch_isa_if_t *isa); /** * Add a node handler to the environment. diff --git a/ir/be/bemain.c b/ir/be/bemain.c index 9519a37ed..bc4f54ceb 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -163,13 +163,13 @@ void be_init(void) phi_class_init(); } -static be_main_env_t *be_init_env(be_main_env_t *env, FILE *file_handle) +static be_main_env_t *be_init_env(be_main_env_t *env) { obstack_init(&env->obst); env->dbg = firm_dbg_register("be.main"); env->arch_env = obstack_alloc(&env->obst, sizeof(env->arch_env[0])); - arch_env_init(env->arch_env, isa_if, file_handle); + arch_env_init(env->arch_env, isa_if); /* Register the irn handler of the architecture */ if (arch_isa_get_irn_handler(env->arch_env->isa)) @@ -228,7 +228,7 @@ static void be_main_loop(FILE *file_handle) arch_isa_t *isa; be_main_env_t env; - be_init_env(&env, file_handle); + be_init_env(&env); isa = arch_env_get_isa(env.arch_env); @@ -237,6 +237,7 @@ static void be_main_loop(FILE *file_handle) ir_graph *irg = get_irp_irg(i); arch_code_generator_t *cg; + const arch_code_generator_if_t *cg_if; DBG((env.dbg, LEVEL_2, "====> IRG: %F\n", irg)); dump(DUMP_INITIAL, irg, "-begin", dump_ir_block_graph); @@ -244,8 +245,11 @@ static void be_main_loop(FILE *file_handle) /* set the current graph (this is important for several firm functions) */ current_ir_graph = irg; + /* Get the code generator interface. */ + cg_if = isa->impl->get_code_generator(isa); + /* get a code generator for this graph. */ - cg = arch_isa_make_code_generator(isa, irg); + cg = cg_if->init(file_handle, irg, env.arch_env); /* create the code generator and generate code. */ prepare_graph(&env, irg); diff --git a/ir/be/firm/bearch_firm.c b/ir/be/firm/bearch_firm.c index 1ed6eb947..135ad9b7b 100644 --- a/ir/be/firm/bearch_firm.c +++ b/ir/be/firm/bearch_firm.c @@ -120,7 +120,7 @@ static int dump_node_Imm(ir_node *n, FILE *F, dump_reason_t reason) { return bad; } -static void *firm_init(FILE *unused) +static void *firm_init(void) { static struct obstack obst; static int inited = 0; @@ -490,22 +490,30 @@ static void firm_codegen_done(void *self) free(self); } +static void *firm_cg_init(FILE *file_handle, ir_graph *irg, const arch_env_t *env); + static const arch_code_generator_if_t firm_code_gen = { + firm_cg_init, firm_prepare_graph, firm_before_sched, firm_before_ra, firm_codegen_done }; -static arch_code_generator_t *firm_make_code_generator(void *self, ir_graph *irg) +static void *firm_cg_init(FILE *file_handle, ir_graph *irg, const arch_env_t *env) { firm_code_gen_t *cg = malloc(sizeof(*cg)); cg->impl = &firm_code_gen; cg->irg = irg; - return (arch_code_generator_t *) cg; + return cg; } +static const arch_code_generator_if_t *firm_get_code_generator(void *self) +{ + return &firm_code_gen; +} + static const list_sched_selector_t *firm_get_list_sched_selector(const void *self) { return trivial_selector; } @@ -525,6 +533,6 @@ const arch_isa_if_t firm_isa = { firm_get_n_reg_class, firm_get_reg_class, firm_get_irn_handler, - firm_make_code_generator, + firm_get_code_generator, firm_get_list_sched_selector };