Turn while loop into do-while, we know it will be executed at least once.
[libfirm] / ir / be / ia32 / ia32_map_regs.c
index b6c605f..cb09bf1 100644 (file)
 /* this is the order of the assigned registers used for parameter passing */
 
 
-void ia32_build_16bit_reg_map(pmap *reg_map) {
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EAX], "ax");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EBX], "bx");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_ECX], "cx");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EDX], "dx");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_ESI], "si");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EDI], "di");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EBP], "bp");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_ESP], "sp");
+void ia32_build_16bit_reg_map(const char *reg_map[])
+{
+       memset(reg_map, 0, sizeof(reg_map[0]) * N_ia32_gp_REGS);
+       reg_map[REG_GP_EAX] = "ax";
+       reg_map[REG_GP_EBX] = "bx";
+       reg_map[REG_GP_ECX] = "cx";
+       reg_map[REG_GP_EDX] = "dx";
+       reg_map[REG_GP_ESI] = "si";
+       reg_map[REG_GP_EDI] = "di";
+       reg_map[REG_GP_EBP] = "bp";
+       reg_map[REG_GP_ESP] = "sp";
 }
 
-void ia32_build_8bit_reg_map(pmap *reg_map) {
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EAX], "al");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EBX], "bl");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_ECX], "cl");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EDX], "dl");
+void ia32_build_8bit_reg_map(const char *reg_map[])
+{
+       memset(reg_map, 0, sizeof(reg_map[0]) * N_ia32_gp_REGS);
+       reg_map[REG_GP_EAX] = "al";
+       reg_map[REG_GP_EBX] = "bl";
+       reg_map[REG_GP_ECX] = "cl";
+       reg_map[REG_GP_EDX] = "dl";
 }
 
-void ia32_build_8bit_reg_map_high(pmap *reg_map) {
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EAX], "ah");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EBX], "bh");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_ECX], "ch");
-       pmap_insert(reg_map, &ia32_gp_regs[REG_EDX], "dh");
+void ia32_build_8bit_reg_map_high(const char *reg_map[])
+{
+       memset(reg_map, 0, sizeof(reg_map[0]) * N_ia32_gp_REGS);
+       reg_map[REG_GP_EAX], "ah";
+       reg_map[REG_GP_EBX], "bh";
+       reg_map[REG_GP_ECX], "ch";
+       reg_map[REG_GP_EDX], "dh";
 }
 
-const char *ia32_get_mapped_reg_name(pmap *reg_map, const arch_register_t *reg) {
-       pmap_entry *e = pmap_find(reg_map, (void *)reg);
+const char *ia32_get_mapped_reg_name(const char *reg_map[], const arch_register_t *reg)
+{
+       const char *name = reg_map[reg->index];
+       assert(reg->reg_class->index == CLASS_ia32_gp);
 
-       //assert(e && "missing map init?");
-       if (! e) {
+       //assert(name && "missing map init?");
+       if (! name) {
                printf("FIXME: ia32map_regs.c:122: returning fake register name for ia32 with 32 register\n");
                return reg->name;
        }
 
-       return e->value;
+       return name;
 }