beemit: Provide be_emit_node(), which merges the (almost) identical node emit functio...
authorChristoph Mallon <christoph.mallon@gmx.de>
Thu, 29 Nov 2012 11:22:22 +0000 (12:22 +0100)
committerChristoph Mallon <christoph.mallon@gmx.de>
Thu, 29 Nov 2012 12:57:00 +0000 (13:57 +0100)
ir/be/TEMPLATE/TEMPLATE_emitter.c
ir/be/amd64/amd64_emitter.c
ir/be/arm/arm_emitter.c
ir/be/beemitter.c
ir/be/beemitter.h
ir/be/ia32/ia32_emitter.c
ir/be/sparc/sparc_emitter.c

index 73c9f49..db1fb0c 100644 (file)
@@ -242,23 +242,6 @@ static void TEMPLATE_register_emitters(void)
        be_set_emitter(op_be_Keep, be_emit_nothing);
 }
 
-typedef void (*emit_func_ptr) (const ir_node *);
-
-/**
- * Emits code for a node.
- */
-static void TEMPLATE_emit_node(const ir_node *node)
-{
-       ir_op               *op       = get_irn_op(node);
-
-       if (op->ops.generic) {
-               emit_func_ptr func = (emit_func_ptr) op->ops.generic;
-               (*func) (node);
-       } else {
-               ir_fprintf(stderr, "No emitter for node %+F\n", node);
-       }
-}
-
 /**
  * Walks over the nodes in a block connected by scheduling edges
  * and emits code for each node.
@@ -268,7 +251,7 @@ static void TEMPLATE_emit_block(ir_node *block)
        be_gas_begin_block(block, true);
 
        sched_foreach(block, node) {
-               TEMPLATE_emit_node(node);
+               be_emit_node(node);
        }
 }
 
index 290ad1d..232e70a 100644 (file)
@@ -483,23 +483,6 @@ static void amd64_register_emitters(void)
        be_set_emitter(op_be_Start, be_emit_nothing);
 }
 
-typedef void (*emit_func_ptr) (const ir_node *);
-
-/**
- * Emits code for a node.
- */
-static void amd64_emit_node(const ir_node *node)
-{
-       ir_op               *op       = get_irn_op(node);
-
-       if (op->ops.generic) {
-               emit_func_ptr func = (emit_func_ptr) op->ops.generic;
-               (*func) (node);
-       } else {
-               ir_fprintf(stderr, "No emitter for node %+F\n", node);
-       }
-}
-
 /**
  * Walks over the nodes in a block connected by scheduling edges
  * and emits code for each node.
@@ -514,7 +497,7 @@ static void amd64_gen_block(ir_node *block, void *data)
        be_gas_begin_block(block, true);
 
        sched_foreach(block, node) {
-               amd64_emit_node(node);
+               be_emit_node(node);
        }
 }
 
index 47cb4d8..3ae1574 100644 (file)
@@ -752,23 +752,6 @@ static void arm_register_emitters(void)
        be_set_emitter(op_be_Keep, be_emit_nothing);
 }
 
-/**
- * Emits code for a node.
- */
-static void arm_emit_node(const ir_node *irn)
-{
-       ir_op *op = get_irn_op(irn);
-
-       if (op->ops.generic) {
-               emit_func *emit = (emit_func *)op->ops.generic;
-               be_dwarf_location(get_irn_dbg_info(irn));
-               (*emit)(irn);
-       } else {
-               panic("Error: No emit handler for node %+F (graph %+F)\n",
-                     irn, get_irn_irg(irn));
-       }
-}
-
 /**
  * emit the block label if needed.
  */
@@ -803,7 +786,7 @@ static void arm_gen_block(ir_node *block, ir_node *prev_block)
        arm_emit_block_header(block, prev_block);
        be_dwarf_location(get_irn_dbg_info(block));
        sched_foreach(block, irn) {
-               arm_emit_node(irn);
+               be_emit_node(irn);
        }
 }
 
index 9d03a49..490cc0b 100644 (file)
  */
 #include "config.h"
 
+#include "bedwarf.h"
 #include "beemitter.h"
 #include "be_t.h"
+#include "error.h"
 #include "irnode_t.h"
 #include "irprintf.h"
 #include "ident.h"
@@ -113,3 +115,12 @@ void be_emit_nothing(ir_node const *const node)
 {
        (void)node;
 }
+
+void be_emit_node(ir_node const *const node)
+{
+       be_dwarf_location(get_irn_dbg_info(node));
+       ir_op     *const op   = get_irn_op(node);
+       emit_func *const emit = get_generic_function_ptr(emit_func, op);
+       DEBUG_ONLY(if (!emit) panic("no emit handler for node %+F (%+G, graph %+F)\n", node, node, get_irn_irg(node));)
+       emit(node);
+}
index 0b0dcfc..d44dfd3 100644 (file)
@@ -133,4 +133,9 @@ static inline void be_set_emitter(ir_op *const op, emit_func *const func)
 
 void be_emit_nothing(ir_node const *node);
 
+/**
+ * Emit code for a node.
+ */
+void be_emit_node(ir_node const *node);
+
 #endif
index d0ae47c..ac7ea5c 100644 (file)
@@ -1431,8 +1431,6 @@ static void ia32_register_emitters(void)
 #undef IA32_EMIT
 }
 
-typedef void (*emit_func_ptr) (const ir_node *);
-
 /**
  * Assign and emit an exception label if the current instruction can fail.
  */
@@ -1455,8 +1453,6 @@ static void ia32_assign_exc_label(ir_node *node)
  */
 static void ia32_emit_node(ir_node *node)
 {
-       ir_op *op = get_irn_op(node);
-
        DBG((dbg, LEVEL_1, "emitting code for %+F\n", node));
 
        if (is_ia32_irn(node)) {
@@ -1476,15 +1472,8 @@ static void ia32_emit_node(ir_node *node)
                        }
                }
        }
-       if (op->ops.generic) {
-               emit_func_ptr func = (emit_func_ptr) op->ops.generic;
-
-               be_dwarf_location(get_irn_dbg_info(node));
 
-               (*func) (node);
-       } else {
-               panic("no emit handler for node %+F (%+G, graph %+F)\n", node, node, get_irn_irg(node));
-       }
+       be_emit_node(node);
 
        if (sp_relative) {
                int sp_change = arch_get_sp_bias(node);
index 5d3694c..15de55d 100644 (file)
@@ -65,7 +65,6 @@ static ir_heights_t *heights;
 static unsigned     *delay_slot_fillers;
 static pmap         *delay_slots;
 
-static void sparc_emit_node(const ir_node *node);
 static bool emitting_delay_slot;
 
 /**
@@ -741,7 +740,7 @@ static void fill_delay_slot(const ir_node *node)
        if (filler != NULL) {
                assert(!is_no_instruction(filler));
                assert(!emits_multiple_instructions(filler));
-               sparc_emit_node(filler);
+               be_emit_node(filler);
        } else {
                sparc_emitf(NULL, "nop");
        }
@@ -1301,23 +1300,6 @@ static void sparc_register_emitters(void)
        be_set_emitter(op_sparc_Start, be_emit_nothing);
 }
 
-/**
- * Emits code for a node.
- */
-static void sparc_emit_node(const ir_node *node)
-{
-       ir_op *op = get_irn_op(node);
-
-       if (op->ops.generic) {
-               emit_func *func = (emit_func*)op->ops.generic;
-               be_dwarf_location(get_irn_dbg_info(node));
-               (*func) (node);
-       } else {
-               panic("No emit handler for node %+F (graph %+F)\n", node,
-                     get_irn_irg(node));
-       }
-}
-
 static bool block_needs_label(const ir_node *block, const ir_node *sched_prev)
 {
        if (get_Block_entity(block) != NULL)
@@ -1349,7 +1331,7 @@ static void sparc_emit_block(ir_node *block, ir_node *prev)
        sched_foreach(block, node) {
                if (rbitset_is_set(delay_slot_fillers, get_irn_idx(node)))
                        continue;
-               sparc_emit_node(node);
+               be_emit_node(node);
        }
 }