Cleanups for running with ORC_CODE=emulate
authorDavid Schleef <ds@schleef.org>
Mon, 27 Sep 2010 01:48:10 +0000 (18:48 -0700)
committerDavid Schleef <ds@schleef.org>
Mon, 27 Sep 2010 01:52:37 +0000 (18:52 -0700)
Fix memleak, check for misaligned arrays.

orc/orccompiler.c
orc/orcexecutor.c

index a07acdc..5e13a0f 100644 (file)
@@ -208,12 +208,6 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target,
     goto error;
   }
 
-  if (_orc_compiler_flag_emulate) {
-    program->code_exec = (void *)orc_executor_emulate;
-    compiler->result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE;
-    goto error;
-  }
-
   if (target == NULL) {
     ORC_COMPILER_ERROR(compiler, "No target given");
     compiler->result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE;
@@ -320,6 +314,12 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target,
     program->orccode->vars[i].value = compiler->vars[i].value;
   }
 
+  if (_orc_compiler_flag_emulate) {
+    program->code_exec = (void *)orc_executor_emulate;
+    compiler->result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE;
+    goto error;
+  }
+
   orc_compiler_assign_rules (compiler);
   if (compiler->error) goto error;
 
index 3773575..d635545 100644 (file)
@@ -229,6 +229,11 @@ orc_executor_emulate (OrcExecutor *ex)
 
   memset (&opcode_ex, 0, sizeof(opcode_ex));
 
+  if (code == NULL) {
+    ORC_ERROR("attempt to run program that failed to compile");
+    ORC_ASSERT(0);
+  }
+
   if (code->is_2d) {
     m = ORC_EXECUTOR_M(ex);
   } else {
@@ -276,8 +281,16 @@ orc_executor_emulate (OrcExecutor *ex)
       } else if (var->vartype == ORC_VAR_TYPE_TEMP) {
         opcode_ex[j].src_ptrs[k] = tmpspace[insn->src_args[k]];
       } else if (var->vartype == ORC_VAR_TYPE_SRC) {
+        if (((unsigned long)ex->arrays[insn->src_args[k]]) & (var->size - 1)) {
+          ORC_ERROR("Unaligned array for src%d, program %s",
+              (insn->src_args[k]-ORC_VAR_S1), ex->program->name);
+        }
         opcode_ex[j].src_ptrs[k] = ex->arrays[insn->src_args[k]];
       } else if (var->vartype == ORC_VAR_TYPE_DEST) {
+        if (((unsigned long)ex->arrays[insn->src_args[k]]) & (var->size - 1)) {
+          ORC_ERROR("Unaligned array for dest%d, program %s",
+              (insn->src_args[k]-ORC_VAR_D1), ex->program->name);
+        }
         opcode_ex[j].src_ptrs[k] = ex->arrays[insn->src_args[k]];
       }
     }
@@ -292,6 +305,10 @@ orc_executor_emulate (OrcExecutor *ex)
         opcode_ex[j].dest_ptrs[k] =
           &ex->accumulators[insn->dest_args[k] - ORC_VAR_A1];
       } else if (var->vartype == ORC_VAR_TYPE_DEST) {
+        if (((unsigned long)ex->arrays[insn->dest_args[k]]) & (var->size - 1)) {
+          ORC_ERROR("Unaligned array for dest%d, program %s",
+              (insn->dest_args[k]-ORC_VAR_D1), ex->program->name);
+        }
         opcode_ex[j].dest_ptrs[k] = ex->arrays[insn->dest_args[k]];
       }
     }
@@ -346,7 +363,7 @@ orc_executor_emulate (OrcExecutor *ex)
   }
 
   free (opcode_ex);
-  for(i=0;i<ORC_VAR_T15+1;i++){
+  for(i=0;i<ORC_N_COMPILER_VARIABLES;i++){
     if (tmpspace[i]) free (tmpspace[i]);
   }
 }