fixed some bugs
[libfirm] / ir / be / ia32 / ia32_emitter.c
index f24e922..d795abd 100644 (file)
@@ -116,6 +116,10 @@ char *ia32_emit_am(const ir_node *n) {
        char             *s;
        int               size;
        static struct obstack *obst  = NULL;
+       ir_mode *mode = get_ia32_ls_mode(n);
+
+       if (! is_ia32_Lea(n))
+               assert(mode && "AM node must have ls_mode attribute set.");
 
        if (! obst) {
                obst = xcalloc(1, sizeof(*obst));
@@ -127,6 +131,22 @@ char *ia32_emit_am(const ir_node *n) {
        /* obstack_free with NULL results in an uninitialized obstack */
        obstack_init(obst);
 
+       if (mode) {
+               switch (get_mode_size_bits(mode)) {
+                       case 8:
+                               obstack_printf(obst, "BYTE PTR ");
+                               break;
+                       case 16:
+                               obstack_printf(obst, "WORD PTR ");
+                               break;
+                       case 32:
+                               obstack_printf(obst, "DWORD PTR ");
+                               break;
+                       default:
+                               assert(0 && "unsupported mode size");
+               }
+       }
+
        obstack_printf(obst, "[");
 
        if (am_flav & ia32_B) {
@@ -204,8 +224,6 @@ static const arch_register_t *get_out_reg(const ir_node *irn, int pos) {
        ir_node                *proj;
        const arch_register_t  *reg = NULL;
 
-       assert(get_irn_n_edges(irn) > pos && "Invalid OUT position");
-
        /* 1st case: irn is not of mode_T, so it has only                 */
        /*           one OUT register -> good                             */
        /* 2nd case: irn is of mode_T -> collect all Projs and ask the    */
@@ -234,22 +252,6 @@ static const arch_register_t *get_out_reg(const ir_node *irn, int pos) {
        return reg;
 }
 
-/**
- * Returns the number of the in register at position pos.
- */
-int get_ia32_reg_nr(ir_node *irn, int pos, int in_out) {
-       const arch_register_t *reg;
-
-       if (in_out == 1) {
-               reg = get_in_reg(irn, pos);
-       }
-       else {
-               reg = get_out_reg(irn, pos);
-       }
-
-       return arch_register_get_index(reg);
-}
-
 enum io_direction {
   IN_REG,
   OUT_REG
@@ -266,7 +268,7 @@ static const char *get_ia32_reg_name(ir_node *irn, int pos, enum io_direction in
        }
        else {
                /* destination address mode nodes don't have outputs */
-               if (get_ia32_op_type(irn) == ia32_AddrModeD) {
+               if (is_ia32_irn(irn) && get_ia32_op_type(irn) == ia32_AddrModeD) {
                        return "MEM";
                }
 
@@ -768,8 +770,18 @@ void emit_ia32_CopyB_i(const ir_node *irn, emit_env_t *emit_env) {
 
 void emit_be_Call(const ir_node *irn, emit_env_t *emit_env) {
        FILE *F = emit_env->out;
+       entity *ent = be_Call_get_entity(irn);
+
+       fprintf(F, "\tcall ");
 
-       lc_efprintf(ia32_get_arg_env(), F, "\tcall %3S\t\t\t/* %+F(%+F) (be_Call) */\n", irn, irn, get_irn_n(irn, 2));
+       if (ent) {
+               fprintf(F, "%s", get_entity_name(ent));
+       }
+       else {
+               lc_efprintf(ia32_get_arg_env(), F, "%1D", get_irn_n(irn, be_pos_Call_ptr));
+       }
+
+       ir_fprintf(F, "\t\t\t/* %+F (be_Call) */\n", irn);
 }
 
 void emit_be_IncSP(const ir_node *irn, emit_env_t *emit_env) {
@@ -786,6 +798,23 @@ void emit_be_IncSP(const ir_node *irn, emit_env_t *emit_env) {
        }
 }
 
+void emit_be_SetSP(const ir_node *irn, emit_env_t *emit_env) {
+       FILE *F = emit_env->out;
+
+       lc_efprintf(ia32_get_arg_env(), F, "\tmov %1D,%3S\t\t\t/* restore SP */\n", irn, irn);
+}
+
+void emit_be_Copy(const ir_node *irn, emit_env_t *emit_env) {
+       FILE *F = emit_env->out;
+
+       lc_efprintf(ia32_get_arg_env(), F, "\tmov %1D,%1S\t\t\t/* %+F */\n", irn, irn, irn);
+}
+
+void emit_be_Perm(const ir_node *irn, emit_env_t *emit_env) {
+       FILE *F = emit_env->out;
+
+       lc_efprintf(ia32_get_arg_env(), F, "\txchg %1S, %2S\t\t\t/* %+F(%1A, %2A) */\n", irn, irn, irn);
+}
 
 /***********************************************************************************
  *                  _          __                                             _
@@ -822,6 +851,9 @@ static void ia32_register_emitters(void) {
        /* benode emitter */
        BE_EMIT(Call);
        BE_EMIT(IncSP);
+       BE_EMIT(SetSP);
+       BE_EMIT(Copy);
+       BE_EMIT(Perm);
 
        /* firm emitter */
        EMIT(Jmp);