Add 0x prefix for printing ARM IncSP amount in hex.
[libfirm] / ir / be / arm / arm_emitter.c
index 53be018..7405e6d 100644 (file)
 #include "../beblocksched.h"
 #include "../beirg_t.h"
 #include "../begnuas.h"
+#include "../be_dbgout.h"
 
 #include "arm_emitter.h"
+#include "arm_optimize.h"
 #include "gen_arm_emitter.h"
 #include "arm_nodes_attr.h"
 #include "arm_new_nodes.h"
@@ -173,13 +175,11 @@ void arm_emit_dest_register(const ir_node *node, int pos) {
  */
 void arm_emit_offset(const ir_node *node) {
        int offset = 0;
-       ir_op *irn_op = get_irn_op(node);
+       ir_opcode opc = get_irn_opcode(node);
 
-       if (irn_op == op_be_Reload || irn_op == op_be_Spill) {
+       if (opc == beo_Reload || opc == beo_Spill) {
                ir_entity *ent = be_get_frame_entity(node);
                offset = get_entity_offset(ent);
-       } else if (irn_op == op_be_IncSP) {
-               offset = - be_get_IncSP_offset(node);
        } else {
                assert(!"unimplemented arm_emit_offset for this node type");
                panic("unimplemented arm_emit_offset for this node type");
@@ -192,12 +192,13 @@ void arm_emit_offset(const ir_node *node) {
  */
 static void arm_emit_fpa_postfix(const ir_mode *mode) {
        int bits = get_mode_size_bits(mode);
+       char c = 'e';
+
        if (bits == 32)
-               be_emit_char('s');
+               c = 's';
        else if (bits == 64)
-               be_emit_char('d');
-       else
-               be_emit_char('e');
+               c = 'd';
+       be_emit_char(c);
 }
 
 /**
@@ -337,7 +338,7 @@ static ir_node *get_cfop_target_block(const ir_node *irn) {
  */
 static void arm_emit_block_name(const ir_node *block) {
        if (has_Block_label(block)) {
-               be_emit_string(be_gas_label_prefix());
+               be_emit_string(be_gas_block_label_prefix());
                be_emit_irprintf("%lu", get_Block_label(block));
        } else {
                be_emit_cstring(BLOCK_PREFIX);
@@ -712,19 +713,22 @@ static void emit_be_Call(const ir_node *irn) {
 
 /** Emit an IncSP node */
 static void emit_be_IncSP(const ir_node *irn) {
-       int offs = be_get_IncSP_offset(irn);
+       int offs = -be_get_IncSP_offset(irn);
 
        if (offs != 0) {
-               be_emit_cstring("\tadd ");
+               if (offs < 0) {
+                       be_emit_cstring("\tsub ");
+                       offs = -offs;
+               } else {
+                       be_emit_cstring("\tadd ");
+               }
                arm_emit_dest_register(irn, 0);
                be_emit_cstring(", ");
                arm_emit_source_register(irn, 0);
-               be_emit_cstring(", #");
-               arm_emit_offset(irn);
+               be_emit_irprintf(", #0x%X", offs);
        } else {
-               be_emit_cstring("\t/* omitted IncSP(");
-               arm_emit_offset(irn);
-               be_emit_cstring(") */");
+               /* omitted IncSP(0) */
+               return;
        }
        be_emit_finish_line_gas(irn);
 }
@@ -733,11 +737,7 @@ static void emit_be_Copy(const ir_node *irn) {
        ir_mode *mode = get_irn_mode(irn);
 
        if (get_in_reg(irn, 0) == get_out_reg(irn, 0)) {
-               be_emit_cstring("\t/* omitted Copy: ");
-               arm_emit_source_register(irn, 0);
-               be_emit_cstring(" -> ");
-               arm_emit_dest_register(irn, 0);
-               be_emit_finish_line_gas(irn);
+               /* omitted Copy */
                return;
        }
 
@@ -985,40 +985,6 @@ static void arm_register_emitters(void) {
 #undef SILENCE
 }
 
-static const char *last_name = NULL;
-static unsigned last_line = -1;
-static unsigned num = -1;
-
-/**
- * Emit the debug support for node node.
- */
-static void arm_emit_dbg(const ir_node *irn) {
-       dbg_info *db = get_irn_dbg_info(irn);
-       unsigned lineno;
-       const char *fname = ir_retrieve_dbg_info(db, &lineno);
-
-       if (! cg->birg->main_env->options->stabs_debug_support)
-               return;
-
-       if (fname) {
-               if (last_name != fname) {
-                       last_line = -1;
-                       be_dbg_include_begin(cg->birg->main_env->db_handle, fname);
-                       last_name = fname;
-               }
-               if (last_line != lineno) {
-                       char name[64];
-
-                       snprintf(name, sizeof(name), ".LM%u", ++num);
-                       last_line = lineno;
-                       be_dbg_line(cg->birg->main_env->db_handle, lineno, name);
-                       be_emit_string(name);
-                       be_emit_cstring(":\n");
-                       be_emit_write_line();
-               }
-       }
-}
-
 /**
  * Emits code for a node.
  */
@@ -1027,7 +993,7 @@ static void arm_emit_node(const ir_node *irn) {
 
        if (op->ops.generic) {
                emit_func *emit = (emit_func *)op->ops.generic;
-               arm_emit_dbg(irn);
+               be_dbg_set_dbg_info(get_irn_dbg_info(irn));
                (*emit)(irn);
        } else {
                be_emit_cstring("\t/* TODO */");
@@ -1097,7 +1063,7 @@ static void arm_gen_block(ir_node *block, ir_node *prev_block) {
        ir_node *irn;
 
        arm_emit_block_header(block, prev_block);
-       arm_emit_dbg(block);
+       be_dbg_set_dbg_info(get_irn_dbg_info(block));
        sched_foreach(block, irn) {
                arm_emit_node(irn);
        }
@@ -1164,10 +1130,10 @@ void arm_gen_routine(const arm_code_gen_t *arm_cg, ir_graph *irg) {
        ir_node *last_block = NULL;
 
        cg        = arm_cg;
+       isa       = (const arm_isa_t *)cg->arch_env;
        arch_env  = cg->arch_env;
        sym_or_tv = new_set(cmp_sym_or_tv, 8);
 
-
        arm_register_emitters();
 
        /* create the block schedule. For now, we don't need it earlier. */