From 3b627c22228660511c82d8ed317a3c7ecd976412 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sun, 26 Sep 2010 18:48:10 -0700 Subject: [PATCH] Cleanups for running with ORC_CODE=emulate Fix memleak, check for misaligned arrays. --- orc/orccompiler.c | 12 ++++++------ orc/orcexecutor.c | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/orc/orccompiler.c b/orc/orccompiler.c index a07acdc..5e13a0f 100644 --- a/orc/orccompiler.c +++ b/orc/orccompiler.c @@ -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; diff --git a/orc/orcexecutor.c b/orc/orcexecutor.c index 3773575..d635545 100644 --- a/orc/orcexecutor.c +++ b/orc/orcexecutor.c @@ -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