Commit 3ae09678 authored by Matthias Braun's avatar Matthias Braun
Browse files

use a 'low-tech' solution for emitting 8- and 16-bit register names. This also...

use a 'low-tech' solution for emitting 8- and 16-bit register names. This also fixes a recently introduced bug in ia32_build_8bit_reg_map_high

[r28168]
parent 888515bf
......@@ -80,7 +80,6 @@
#include "ia32_common_transform.h"
#include "ia32_transform.h"
#include "ia32_emitter.h"
#include "ia32_map_regs.h"
#include "ia32_optimize.h"
#include "ia32_x87.h"
#include "ia32_dbg_stat.h"
......@@ -1458,9 +1457,6 @@ static ia32_isa_t ia32_isa_template = {
5, /* costs for a reload instruction */
false, /* no custom abi handling */
},
NULL, /* 16bit register names */
NULL, /* 8bit register names */
NULL, /* 8bit register names high */
NULL, /* types */
NULL, /* tv_ents */
NULL, /* abstract machine */
......@@ -1537,10 +1533,6 @@ static arch_env_t *ia32_init(FILE *file_handle)
isa->tv_ent = pmap_create();
isa->cpu = ia32_init_machine_description();
ia32_build_16bit_reg_map(isa->regs_16bit);
ia32_build_8bit_reg_map(isa->regs_8bit);
ia32_build_8bit_reg_map_high(isa->regs_8bit_high);
/* enter the ISA object into the intrinsic environment */
intrinsic_env.isa = isa;
......
......@@ -68,10 +68,6 @@ struct ia32_isa_t {
pmap *types; /**< A map of modes to primitivetypes */
pmap *tv_ent; /**< A map of entities that store const tarvals */
const be_machine_t *cpu; /**< the abstract machine */
const char *regs_32bit[N_ia32_gp_REGS]; /**< Contains the 32bits names of the gp registers */
const char *regs_16bit[N_ia32_gp_REGS]; /**< Contains the 16bits names of the gp registers */
const char *regs_8bit[N_ia32_gp_REGS]; /**< Contains the 8bits names of the gp registers */
const char *regs_8bit_high[N_ia32_gp_REGS]; /**< contains the high partof the 8 bit names of the gp registers */
};
/**
......
......@@ -75,7 +75,6 @@
#include "gen_ia32_regalloc_if.h"
#include "ia32_nodes_attr.h"
#include "ia32_new_nodes.h"
#include "ia32_map_regs.h"
#include "ia32_architecture.h"
#include "bearch_ia32_t.h"
......@@ -205,16 +204,17 @@ static char *get_unique_label(char *buf, size_t buflen, const char *prefix)
return buf;
}
/**
* Emit the name of the 8bit low register
*/
static void emit_8bit_register(const arch_register_t *reg)
{
const char *reg_name = arch_register_get_name(reg);
assert(reg->index == REG_GP_EAX || reg->index == REG_GP_EBX
|| reg->index == REG_GP_ECX || reg->index == REG_GP_EDX);
be_emit_char('%');
be_emit_char(reg_name[1]);
be_emit_char(reg_name[1]); /* get the basic name of the register */
be_emit_char('l');
}
......@@ -224,18 +224,20 @@ static void emit_8bit_register(const arch_register_t *reg)
static void emit_8bit_register_high(const arch_register_t *reg)
{
const char *reg_name = arch_register_get_name(reg);
assert(reg->index == REG_GP_EAX || reg->index == REG_GP_EBX
|| reg->index == REG_GP_ECX || reg->index == REG_GP_EDX);
be_emit_char('%');
be_emit_char(reg_name[1]);
be_emit_char(reg_name[1]); /* get the basic name of the register */
be_emit_char('h');
}
static void emit_16bit_register(const arch_register_t *reg)
{
const char *reg_name = ia32_get_mapped_reg_name(isa->regs_16bit, reg);
const char *reg_name = arch_register_get_name(reg);
be_emit_char('%');
be_emit_string(reg_name);
be_emit_string(reg_name+1); /* skip the 'e' prefix of the 32bit names */
}
/**
......@@ -1366,7 +1368,6 @@ static const char* emit_asm_operand(const ir_node *node, const char *s)
const arch_register_t *reg;
const ia32_asm_reg_t *asm_regs = attr->register_map;
const ia32_asm_reg_t *asm_reg;
const char *reg_name;
char c;
char modifier = 0;
int num = -1;
......@@ -1454,21 +1455,19 @@ static const char* emit_asm_operand(const ir_node *node, const char *s)
/* emit it */
if (modifier != 0) {
be_emit_char('%');
switch (modifier) {
case 'b':
reg_name = ia32_get_mapped_reg_name(isa->regs_8bit, reg);
emit_8bit_register(reg);
break;
case 'h':
reg_name = ia32_get_mapped_reg_name(isa->regs_8bit_high, reg);
emit_8bit_register_high(reg);
break;
case 'w':
reg_name = ia32_get_mapped_reg_name(isa->regs_16bit, reg);
emit_16bit_register(reg);
break;
default:
panic("Invalid asm op modifier");
}
be_emit_string(reg_name);
} else {
emit_register(reg, asm_reg->mode);
}
......
......@@ -41,7 +41,6 @@
#include "bearch_ia32_t.h"
#include "ia32_finish.h"
#include "ia32_new_nodes.h"
#include "ia32_map_regs.h"
#include "ia32_common_transform.h"
#include "ia32_transform.h"
#include "ia32_dbg_stat.h"
......
/*
* Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free Software
* Foundation and appearing in the file LICENSE.GPL included in the
* packaging of this file.
*
* Licensees holding valid libFirm Professional Edition licenses may use
* this file in accordance with the libFirm Commercial License.
* Agreement provided with the Software.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/**
* @file
* @brief Register param constraints and some other register handling tools.
* @author Christian Wuerdig
* @version $Id$
*/
#include "config.h"
#include <stdlib.h>
#include "pmap.h"
#include "error.h"
#include "ia32_map_regs.h"
#include "ia32_new_nodes.h"
#include "ia32_architecture.h"
#include "gen_ia32_regalloc_if.h"
#include "bearch_ia32_t.h"
/* this is the order of the assigned registers used for parameter passing */
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(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(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(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(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 name;
}
/*
* Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free Software
* Foundation and appearing in the file LICENSE.GPL included in the
* packaging of this file.
*
* Licensees holding valid libFirm Professional Edition licenses may use
* this file in accordance with the libFirm Commercial License.
* Agreement provided with the Software.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/**
* @file
* @brief Register param constraints and some other register handling tools.
* @author Christian Wuerdig
* @version $Id$
*/
#ifndef FIRM_BE_IA32_IA32_MAP_REGS_H
#define FIRM_BE_IA32_IA32_MAP_REGS_H
#include "irnode.h"
#include "irmode.h"
#include "set.h"
#include "../bearch.h"
#include "bearch_ia32_t.h"
#include "gen_ia32_regalloc_if.h"
/**
* Enters for each general purpose register the corresponding 16bit
* name into a map.
*/
void ia32_build_16bit_reg_map(const char *reg_map[]);
/**
* Enters for each general purpose register the corresponding 8bit
* name into a map.
*/
void ia32_build_8bit_reg_map(const char *reg_map[]);
void ia32_build_8bit_reg_map_high(const char *reg_map[]);
/**
* Returns the corresponding mapped name for a register.
*/
const char *ia32_get_mapped_reg_name(const char *reg_map[], const arch_register_t *reg);
#endif
......@@ -60,7 +60,6 @@
#include "ia32_nodes_attr.h"
#include "ia32_transform.h"
#include "ia32_new_nodes.h"
#include "ia32_map_regs.h"
#include "ia32_dbg_stat.h"
#include "ia32_optimize.h"
#include "ia32_util.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment