Commit 46fb38de authored by Christoph Mallon's avatar Christoph Mallon
Browse files

amd64, ia32: Encode the length of the constraint list in the type instead of...

amd64, ia32: Encode the length of the constraint list in the type instead of relying on matching magic numbers.
parent 1ec988da
...@@ -67,7 +67,7 @@ const x86_clobber_name_t amd64_additional_clobber_names[] = { ...@@ -67,7 +67,7 @@ const x86_clobber_name_t amd64_additional_clobber_names[] = {
}; };
#define GP &amd64_reg_classes[CLASS_amd64_gp] #define GP &amd64_reg_classes[CLASS_amd64_gp]
const x86_asm_constraint_t amd64_asm_constraints[128] = { const x86_asm_constraint_list_t amd64_asm_constraints = {
['A'] = { MATCH_REG, GP, 1 << REG_GP_RAX | 1 << REG_GP_RDX }, ['A'] = { MATCH_REG, GP, 1 << REG_GP_RAX | 1 << REG_GP_RDX },
['D'] = { MATCH_REG, GP, 1 << REG_GP_RDI }, ['D'] = { MATCH_REG, GP, 1 << REG_GP_RDI },
['I'] = { MATCH_IMM, GP, 0 }, ['I'] = { MATCH_IMM, GP, 0 },
...@@ -2090,7 +2090,7 @@ static ir_node *gen_Cond(ir_node *node) ...@@ -2090,7 +2090,7 @@ static ir_node *gen_Cond(ir_node *node)
static ir_node *gen_ASM(ir_node *node) static ir_node *gen_ASM(ir_node *node)
{ {
return x86_match_ASM(node, new_bd_amd64_asm, amd64_additional_clobber_names, return x86_match_ASM(node, new_bd_amd64_asm, amd64_additional_clobber_names,
amd64_asm_constraints); &amd64_asm_constraints);
} }
static ir_node *gen_Proj_ASM(ir_node *node) static ir_node *gen_Proj_ASM(ir_node *node)
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#include "firm_types.h" #include "firm_types.h"
#include "x86_asm.h" #include "x86_asm.h"
extern const x86_clobber_name_t amd64_additional_clobber_names[]; extern const x86_clobber_name_t amd64_additional_clobber_names[];
extern const x86_asm_constraint_t amd64_asm_constraints[128]; extern const x86_asm_constraint_list_t amd64_asm_constraints;
void amd64_init_transform(void); void amd64_init_transform(void);
......
...@@ -815,7 +815,7 @@ static void amd64_init(void) ...@@ -815,7 +815,7 @@ static void amd64_init(void)
amd64_register_init(); amd64_register_init();
amd64_create_opcodes(&amd64_irn_ops); amd64_create_opcodes(&amd64_irn_ops);
amd64_cconv_init(); amd64_cconv_init();
x86_set_be_asm_constraint_support(amd64_asm_constraints); x86_set_be_asm_constraint_support(&amd64_asm_constraints);
} }
const arch_isa_if_t amd64_isa_if = { const arch_isa_if_t amd64_isa_if = {
......
...@@ -1428,7 +1428,7 @@ static void ia32_init(void) ...@@ -1428,7 +1428,7 @@ static void ia32_init(void)
{ {
ia32_setup_cg_config(); ia32_setup_cg_config();
x86_set_be_asm_constraint_support(ia32_asm_constraints); x86_set_be_asm_constraint_support(&ia32_asm_constraints);
ia32_mode_fpcw = new_non_arithmetic_mode("fpcw", 16); ia32_mode_fpcw = new_non_arithmetic_mode("fpcw", 16);
ia32_mode_flags = new_non_arithmetic_mode("flags", 32); ia32_mode_flags = new_non_arithmetic_mode("flags", 32);
......
...@@ -78,7 +78,7 @@ const x86_clobber_name_t ia32_additional_clobber_names[] = { ...@@ -78,7 +78,7 @@ const x86_clobber_name_t ia32_additional_clobber_names[] = {
#define GP &ia32_reg_classes[CLASS_ia32_gp] #define GP &ia32_reg_classes[CLASS_ia32_gp]
#define FP &ia32_reg_classes[CLASS_ia32_fp] #define FP &ia32_reg_classes[CLASS_ia32_fp]
const x86_asm_constraint_t ia32_asm_constraints[128] = { const x86_asm_constraint_list_t ia32_asm_constraints = {
['A'] = { MATCH_REG, GP, 1 << REG_GP_EAX | 1 << REG_GP_EDX }, ['A'] = { MATCH_REG, GP, 1 << REG_GP_EAX | 1 << REG_GP_EDX },
['D'] = { MATCH_REG, GP, 1 << REG_GP_EDI }, ['D'] = { MATCH_REG, GP, 1 << REG_GP_EDI },
['I'] = { MATCH_IMM, GP, 0 }, ['I'] = { MATCH_IMM, GP, 0 },
...@@ -5774,7 +5774,7 @@ static ir_node *gen_ASM(ir_node *node) ...@@ -5774,7 +5774,7 @@ static ir_node *gen_ASM(ir_node *node)
{ {
ir_node *new_node = x86_match_ASM(node, new_bd_ia32_Asm, ir_node *new_node = x86_match_ASM(node, new_bd_ia32_Asm,
ia32_additional_clobber_names, ia32_additional_clobber_names,
ia32_asm_constraints); &ia32_asm_constraints);
SET_IA32_ORIG_NODE(new_node, node); SET_IA32_ORIG_NODE(new_node, node);
return new_node; return new_node;
} }
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "firm_types.h" #include "firm_types.h"
#include "x86_asm.h" #include "x86_asm.h"
extern const x86_clobber_name_t ia32_additional_clobber_names[]; extern const x86_clobber_name_t ia32_additional_clobber_names[];
extern const x86_asm_constraint_t ia32_asm_constraints[128]; extern const x86_asm_constraint_list_t ia32_asm_constraints;
/** /**
* Transform firm nodes to x86 assembler nodes, ie * Transform firm nodes to x86 assembler nodes, ie
......
...@@ -96,7 +96,7 @@ arch_register_t const *x86_parse_clobber(const arch_env_t *arch_env, ...@@ -96,7 +96,7 @@ arch_register_t const *x86_parse_clobber(const arch_env_t *arch_env,
} }
static void parse_asm_constraints(parsed_constraint_t *const constraint, static void parse_asm_constraints(parsed_constraint_t *const constraint,
const x86_asm_constraint_t *constraints, const x86_asm_constraint_list_t *constraints,
ident *const constraint_text, ident *const constraint_text,
bool const is_output) bool const is_output)
{ {
...@@ -159,9 +159,9 @@ static void parse_asm_constraints(parsed_constraint_t *const constraint, ...@@ -159,9 +159,9 @@ static void parse_asm_constraints(parsed_constraint_t *const constraint,
} }
default: default:
if (*c >= 128) if (*c >= ARRAY_SIZE(*constraints))
panic("Unknown asm constraint '%c'", *c); panic("Unknown asm constraint '%c'", *c);
const x86_asm_constraint_t *constraint = &constraints[*c]; const x86_asm_constraint_t *constraint = &(*constraints)[*c];
switch (constraint->kind) { switch (constraint->kind) {
case MATCH_REG: case MATCH_REG:
new_cls = constraint->cls; new_cls = constraint->cls;
...@@ -347,7 +347,7 @@ static void x86_emit_immediate(const x86_imm32_t *immediate) ...@@ -347,7 +347,7 @@ static void x86_emit_immediate(const x86_imm32_t *immediate)
ir_node *x86_match_ASM(const ir_node *node, new_bd_asm_func new_bd_asm, ir_node *x86_match_ASM(const ir_node *node, new_bd_asm_func new_bd_asm,
const x86_clobber_name_t *additional_clobber_names, const x86_clobber_name_t *additional_clobber_names,
const x86_asm_constraint_t *constraints) const x86_asm_constraint_list_t *constraints)
{ {
int const n_inputs = get_ASM_n_inputs(node); int const n_inputs = get_ASM_n_inputs(node);
size_t const n_out_constraints = get_ASM_n_output_constraints(node); size_t const n_out_constraints = get_ASM_n_output_constraints(node);
...@@ -719,10 +719,10 @@ void x86_emit_asm(const ir_node *node, const x86_asm_attr_t *attr, ...@@ -719,10 +719,10 @@ void x86_emit_asm(const ir_node *node, const x86_asm_attr_t *attr,
be_emit_write_line(); be_emit_write_line();
} }
void x86_set_be_asm_constraint_support(const x86_asm_constraint_t *constraints) void x86_set_be_asm_constraint_support(const x86_asm_constraint_list_t *constraints)
{ {
for (unsigned char c = 0; c < 128; ++c) { for (unsigned char c = 0; c < ARRAY_SIZE(*constraints); ++c) {
const x86_asm_constraint_t *constraint = &constraints[c]; const x86_asm_constraint_t *constraint = &(*constraints)[c];
asm_constraint_flags_t flags; asm_constraint_flags_t flags;
switch (constraint->kind) { switch (constraint->kind) {
case MATCH_INVALID: case MATCH_INVALID:
......
...@@ -65,6 +65,8 @@ typedef struct x86_asm_constraint_t { ...@@ -65,6 +65,8 @@ typedef struct x86_asm_constraint_t {
unsigned limited; unsigned limited;
} x86_asm_constraint_t; } x86_asm_constraint_t;
typedef x86_asm_constraint_t x86_asm_constraint_list_t[128];
static inline bool x86_asm_attr_equal(const x86_asm_attr_t *attr0, static inline bool x86_asm_attr_equal(const x86_asm_attr_t *attr0,
const x86_asm_attr_t *attr1) const x86_asm_attr_t *attr1)
{ {
...@@ -86,11 +88,11 @@ typedef ir_node* (*new_bd_asm_func)(dbg_info *dbgi, ir_node *block, int arity, ...@@ -86,11 +88,11 @@ typedef ir_node* (*new_bd_asm_func)(dbg_info *dbgi, ir_node *block, int arity,
ir_node *x86_match_ASM(const ir_node *node, new_bd_asm_func new_bd_asm, ir_node *x86_match_ASM(const ir_node *node, new_bd_asm_func new_bd_asm,
const x86_clobber_name_t *names, const x86_clobber_name_t *names,
const x86_asm_constraint_t *constraints); const x86_asm_constraint_list_t *constraints);
bool x86_match_immediate(x86_imm32_t *immediate, const ir_node *node, bool x86_match_immediate(x86_imm32_t *immediate, const ir_node *node,
char constraint); char constraint);
void x86_set_be_asm_constraint_support(const x86_asm_constraint_t *constraints); void x86_set_be_asm_constraint_support(const x86_asm_constraint_list_t *constraints);
#endif #endif
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