From d6150388370314ab0cd882e16c2b9065a6f707e4 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sun, 5 Apr 2009 16:44:52 -0700 Subject: [PATCH] Check opcode and instruction argument sizes for agreement And fix some mistakes --- orc/orccompiler.c | 35 +++++++++++++++++++++++++++++++++++ tools/orcc.c | 13 +++++++++---- tools/test.orc | 6 +++--- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/orc/orccompiler.c b/orc/orccompiler.c index 6db5493..653d21c 100644 --- a/orc/orccompiler.c +++ b/orc/orccompiler.c @@ -15,6 +15,7 @@ void orc_compiler_rewrite_vars (OrcCompiler *compiler); void orc_compiler_rewrite_vars2 (OrcCompiler *compiler); void orc_compiler_do_regs (OrcCompiler *compiler); int orc_compiler_dup_temporary (OrcCompiler *compiler, int var, int j); +void orc_compiler_check_sizes (OrcCompiler *compiler); int @@ -83,6 +84,9 @@ orc_program_compile_for_target (OrcProgram *program, OrcTarget *target) compiler->target->compiler_init (compiler); + orc_compiler_check_sizes (compiler); + if (compiler->error) goto error; + orc_compiler_assign_rules (compiler); if (compiler->error) goto error; @@ -115,6 +119,36 @@ error: } void +orc_compiler_check_sizes (OrcCompiler *compiler) +{ + int i; + int j; + + for(i=0;in_insns;i++) { + OrcInstruction *insn = compiler->insns + i; + OrcStaticOpcode *opcode = insn->opcode; + + for(j=0;jdest_size[j] == 0) continue; + if (opcode->dest_size[j] != compiler->vars[insn->dest_args[j]].size) { + ORC_PROGRAM_ERROR(compiler, "size mismatch, opcode %s dest %d", + opcode->name, j); + return; + } + } + for(j=0;jsrc_size[j] == 0) continue; + if (opcode->src_size[j] != compiler->vars[insn->src_args[j]].size && + compiler->vars[insn->src_args[j]].vartype != ORC_VAR_TYPE_PARAM) { + ORC_PROGRAM_ERROR(compiler, "size mismatch, opcode %s src %d", + opcode->name, j); + return; + } + } + } +} + +void orc_compiler_assign_rules (OrcCompiler *compiler) { int i; @@ -126,6 +160,7 @@ orc_compiler_assign_rules (OrcCompiler *compiler) if (insn->rule == NULL || insn->rule->emit == NULL) { ORC_PROGRAM_ERROR(compiler, "No rule for: %s", insn->opcode->name); + return; } } } diff --git a/tools/orcc.c b/tools/orcc.c index d18ad11..7541e08 100644 --- a/tools/orcc.c +++ b/tools/orcc.c @@ -23,16 +23,21 @@ main (int argc, char *argv[]) n = orc_parse (code, &programs); -#if 1 +#if 0 for(i=0;iname); orc_test_gcc_compile (programs[i]); } #endif -#if 0 +#if 1 for(i=0;i