Check opcode and instruction argument sizes for agreement
authorDavid Schleef <ds@schleef.org>
Sun, 5 Apr 2009 23:44:52 +0000 (16:44 -0700)
committerDavid Schleef <ds@schleef.org>
Tue, 7 Apr 2009 03:37:33 +0000 (20:37 -0700)
And fix some mistakes

orc/orccompiler.c
tools/orcc.c
tools/test.orc

index 6db5493..653d21c 100644 (file)
@@ -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;i<compiler->n_insns;i++) {
+    OrcInstruction *insn = compiler->insns + i;
+    OrcStaticOpcode *opcode = insn->opcode;
+
+    for(j=0;j<ORC_STATIC_OPCODE_N_DEST;j++){
+      if (opcode->dest_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;j<ORC_STATIC_OPCODE_N_SRC;j++){
+      if (opcode->src_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;
     }
   }
 }
index d18ad11..7541e08 100644 (file)
@@ -23,16 +23,21 @@ main (int argc, char *argv[])
 
   n = orc_parse (code, &programs);
 
-#if 1
+#if 0
   for(i=0;i<n;i++){
     printf("%s\n", programs[i]->name);
     orc_test_gcc_compile (programs[i]);
   }
 #endif
-#if 0
+#if 1
   for(i=0;i<n;i++){
-    orc_program_compile_for_target (programs[i], orc_target_get_by_name("c"));
-    printf("%s", orc_program_get_asm_code (programs[i]));
+    int ret;
+
+    ret = orc_program_compile_for_target (programs[i],
+        orc_target_get_by_name("neon"));
+    if (ret) {
+      printf("%s", orc_program_get_asm_code (programs[i]));
+    }
   }
 #endif
 
index 60a9937..7e02889 100644 (file)
@@ -90,7 +90,7 @@ mulswl t2, t1, p1
 addl t2, t2, p2
 shll t2, t2, p3
 convlw t1, t2
-addl d1, d1, t1
+addw d1, d1, t1
 
 
 .function orc_mas4_add_s16_1991
@@ -142,8 +142,8 @@ subw d1, s1, s2
 
 
 .function orc_memcpy
-.dest 2 d1
-.source 2 s1
+.dest 1 d1
+.source 1 s1
 
 copyb d1, s1