start register allocator again, fix typo
[libfirm] / ir / be / TEMPLATE / bearch_TEMPLATE.c
index 9736a9e..08f77cb 100644 (file)
@@ -21,6 +21,7 @@
 #include "../besched_t.h"
 #include "../be.h"
 #include "../beabi.h"
+#include "../bemodule.h"
 
 #include "bearch_TEMPLATE_t.h"
 
@@ -62,7 +63,7 @@ static const arch_register_req_t *TEMPLATE_get_irn_reg_req(const void *self, arc
        const TEMPLATE_register_req_t *irn_req;
        long               node_pos = pos == -1 ? 0 : pos;
        ir_mode           *mode     = get_irn_mode(irn);
-       firm_dbg_module_t *mod      = firm_dbg_register(DEBUG_MODULE);
+       FIRM_DBG_REGISTER(firm_dbg_module_t *mod, DEBUG_MODULE);
 
        if (mode == mode_T || mode == mode_M) {
                DBG((mod, LEVEL_1, "ignoring mode_T, mode_M node %+F\n", irn));
@@ -210,14 +211,22 @@ static entity *TEMPLATE_get_frame_entity(const void *self, const ir_node *irn) {
        return NULL;
 }
 
+static void TEMPLATE_set_frame_entity(const void *self, const ir_node *irn, entity *ent) {
+       /* TODO: set the entity assigned to the frame */
+}
+
 /**
  * This function is called by the generic backend to correct offsets for
  * nodes accessing the stack.
  */
-static void TEMPLATE_set_stack_bias(const void *self, ir_node *irn, int bias) {
+static void TEMPLATE_set_frame_offset(const void *self, ir_node *irn, int offset) {
        /* TODO: correct offset if irn accesses the stack */
 }
 
+static int TEMPLATE_get_sp_bias(const void *self, const ir_node *irn) {
+       return 0;
+}
+
 /* fill register allocator interface */
 
 static const arch_irn_ops_if_t TEMPLATE_irn_ops_if = {
@@ -227,7 +236,13 @@ static const arch_irn_ops_if_t TEMPLATE_irn_ops_if = {
        TEMPLATE_classify,
        TEMPLATE_get_flags,
        TEMPLATE_get_frame_entity,
-       TEMPLATE_set_stack_bias
+       TEMPLATE_set_frame_entity,
+       TEMPLATE_set_frame_offset,
+       TEMPLATE_get_sp_bias,
+       NULL,    /* get_inverse             */
+       NULL,    /* get_op_estimated_cost   */
+       NULL,    /* possible_memory_operand */
+       NULL,    /* perform_memory_operand  */
 };
 
 TEMPLATE_irn_ops_t TEMPLATE_irn_ops = {
@@ -263,10 +278,11 @@ static void TEMPLATE_prepare_graph(void *self) {
 /**
  * Called immediatly before emit phase.
  */
-static void TEMPLATE_finish_irg(ir_graph *irg, TEMPLATE_code_gen_t *cg) {
-       /* TODO: - fix offsets for nodes accessing stack
-                        - ...
-       */
+static void TEMPLATE_finish_irg(void *self) {
+       TEMPLATE_code_gen_t *cg = self;
+       ir_graph            *irg = cg->irg;
+
+       dump_ir_block_graph_sched(irg, "-TEMPLATE-finished");
 }
 
 
@@ -294,15 +310,13 @@ static void TEMPLATE_after_ra(void *self) {
 static void TEMPLATE_emit_and_done(void *self) {
        TEMPLATE_code_gen_t *cg = self;
        ir_graph           *irg = cg->irg;
-       FILE               *out = cg->out;
+       FILE               *out = cg->isa->out;
 
        if (cg->emit_decls) {
-               TEMPLATE_gen_decls(cg->out);
+               TEMPLATE_gen_decls(out);
                cg->emit_decls = 0;
        }
 
-       TEMPLATE_finish_irg(irg, cg);
-       dump_ir_block_graph_sched(irg, "-TEMPLATE-finished");
        TEMPLATE_gen_routine(out, irg, cg);
 
        cur_reg_set = NULL;
@@ -312,7 +326,7 @@ static void TEMPLATE_emit_and_done(void *self) {
        free(self);
 }
 
-static void *TEMPLATE_cg_init(FILE *F, const be_irg_t *birg);
+static void *TEMPLATE_cg_init(const be_irg_t *birg);
 
 static const arch_code_generator_if_t TEMPLATE_code_gen_if = {
        TEMPLATE_cg_init,
@@ -320,23 +334,24 @@ static const arch_code_generator_if_t TEMPLATE_code_gen_if = {
        TEMPLATE_before_sched,   /* before scheduling hook */
        TEMPLATE_before_ra,      /* before register allocation hook */
        TEMPLATE_after_ra,       /* after register allocation hook */
+       TEMPLATE_finish_irg,
        TEMPLATE_emit_and_done
 };
 
 /**
  * Initializes the code generator.
  */
-static void *TEMPLATE_cg_init(FILE *F, const be_irg_t *birg) {
+static void *TEMPLATE_cg_init(const be_irg_t *birg) {
        TEMPLATE_isa_t      *isa = (TEMPLATE_isa_t *)birg->main_env->arch_env->isa;
        TEMPLATE_code_gen_t *cg  = xmalloc(sizeof(*cg));
 
        cg->impl     = &TEMPLATE_code_gen_if;
        cg->irg      = birg->irg;
        cg->reg_set  = new_set(TEMPLATE_cmp_irn_reg_assoc, 1024);
-       cg->mod      = firm_dbg_register("firm.be.TEMPLATE.cg");
-       cg->out      = F;
        cg->arch_env = birg->main_env->arch_env;
+       cg->isa      = isa;
        cg->birg     = birg;
+       FIRM_DBG_REGISTER(cg->mod, "firm.be.TEMPLATE.cg");
 
        isa->num_codegens++;
 
@@ -375,7 +390,7 @@ static TEMPLATE_isa_t TEMPLATE_isa_template = {
 /**
  * Initializes the backend ISA and opens the output file.
  */
-static void *TEMPLATE_init(void) {
+static void *TEMPLATE_init(FILE *outfile) {
        static int inited = 0;
        TEMPLATE_isa_t *isa;
 
@@ -385,6 +400,8 @@ static void *TEMPLATE_init(void) {
        isa = xcalloc(1, sizeof(*isa));
        memcpy(isa, &TEMPLATE_isa_template, sizeof(*isa));
 
+       isa->out = outfile;
+
        TEMPLATE_register_init(isa);
        TEMPLATE_create_opcodes();
 
@@ -489,7 +506,7 @@ void TEMPLATE_get_call_abi(const void *self, ir_type *method_type, be_abi_call_t
                /* be_abi_call_param_reg(abi, i, reg); */
 
                /* default: all parameters on stack */
-               be_abi_call_param_stack(abi, i);
+               be_abi_call_param_stack(abi, i, 4, 0, 0);
        }
 
        /* TODO: set correct return register */
@@ -537,16 +554,44 @@ static const list_sched_selector_t *TEMPLATE_get_list_sched_selector(const void
        return &TEMPLATE_sched_selector;
 }
 
-#ifdef WITH_LIBCORE
-static void TEMPLATE_register_options(lc_opt_entry_t *ent)
+/**
+ * Returns the necessary byte alignment for storing a register of given class.
+ */
+static int TEMPLATE_get_reg_class_alignment(const void *self, const arch_register_class_t *cls) {
+       ir_mode *mode = arch_register_class_mode(cls);
+       return get_mode_size_bytes(mode);
+}
+
+/**
+ * Returns the libFirm configuration parameter for this backend.
+ */
+static const backend_params *TEMPLATE_get_libfirm_params(void) {
+       static arch_dep_params_t ad = {
+               1,  /* allow subs */
+               0,  /* Muls are fast enough on Firm */
+               31, /* shift would be ok */
+               0,  /* no Mulhs */
+               0,  /* no Mulhu */
+               0,  /* no Mulh */
+       };
+       static backend_params p = {
+               NULL,  /* no additional opcodes */
+               NULL,  /* will be set later */
+               0,     /* no dword lowering */
+               NULL,  /* no creator function */
+               NULL,  /* context for create_intrinsic_fkt */
+       };
+
+       p.dep_param = &ad;
+       return &p;
+}
+
+void be_init_arch_TEMPLATE()
 {
 }
-#endif /* WITH_LIBCORE */
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_TEMPLATE);
 
 const arch_isa_if_t TEMPLATE_isa_if = {
-#ifdef WITH_LIBCORE
-       TEMPLATE_register_options,
-#endif
        TEMPLATE_init,
        TEMPLATE_done,
        TEMPLATE_get_n_reg_class,
@@ -556,4 +601,6 @@ const arch_isa_if_t TEMPLATE_isa_if = {
        TEMPLATE_get_irn_handler,
        TEMPLATE_get_code_generator_if,
        TEMPLATE_get_list_sched_selector,
+       TEMPLATE_get_reg_class_alignment,
+    TEMPLATE_get_libfirm_params,
 };