#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;
}
*/
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.
*/
/**
* Initialize the isa interface.
*/
- void *(*init)(FILE *file_handle);
+ void *(*init)(void);
/**
* Free the isa instance.
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.
* @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.
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))
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);
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);
/* 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);
return bad;
}
-static void *firm_init(FILE *unused)
+static void *firm_init(void)
{
static struct obstack obst;
static int inited = 0;
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;
}
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
};