diff options
author | David Schleef <ds@schleef.org> | 2010-08-24 13:22:24 -0700 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2010-08-24 13:22:24 -0700 |
commit | 9efe6267870dd10b7924aae8492954f190dd5273 (patch) | |
tree | e36270b5699bf7a7d99c41ad19a0f5d1baac54d8 | |
parent | ca536c47aeaec7c2888862ef0ec2b84770b24cec (diff) |
Use OrcCode structure to handle all executable code
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | orc-test/orctest.c | 17 | ||||
-rw-r--r-- | orc/orcarm.c | 6 | ||||
-rw-r--r-- | orc/orcarm.h | 2 | ||||
-rw-r--r-- | orc/orccode.c | 9 | ||||
-rw-r--r-- | orc/orccodemem.c | 36 | ||||
-rw-r--r-- | orc/orccompiler.c | 79 | ||||
-rw-r--r-- | orc/orcexecutor.c | 12 | ||||
-rw-r--r-- | orc/orcpowerpc.c | 12 | ||||
-rw-r--r-- | orc/orcpowerpc.h | 2 | ||||
-rw-r--r-- | orc/orcprogram-altivec.c | 11 | ||||
-rw-r--r-- | orc/orcprogram-arm.c | 8 | ||||
-rw-r--r-- | orc/orcprogram-mmx.c | 5 | ||||
-rw-r--r-- | orc/orcprogram-neon.c | 9 | ||||
-rw-r--r-- | orc/orcprogram-sse.c | 5 | ||||
-rw-r--r-- | orc/orcprogram.c | 28 | ||||
-rw-r--r-- | orc/orcprogram.h | 26 | ||||
-rw-r--r-- | orc/orcx86.c | 2 |
18 files changed, 198 insertions, 73 deletions
diff --git a/configure.ac b/configure.ac index 4bd0ea7..5d5c570 100644 --- a/configure.ac +++ b/configure.ac @@ -81,6 +81,8 @@ if test "$orc_cv_monotonic_clock" = "yes"; then AC_DEFINE(HAVE_MONOTONIC_CLOCK,1,[Defined if we have a monotonic clock]) fi +AC_CHECK_HEADERS([valgrind/valgrind.h]) + AS_COMPILER_FLAG(-Wall, ORC_CFLAGS="$ORC_CFLAGS -Wall") if test "x$ORC_CVS" = "xyes" then diff --git a/orc-test/orctest.c b/orc-test/orctest.c index 2c76d24..c9b873e 100644 --- a/orc-test/orctest.c +++ b/orc-test/orctest.c @@ -81,7 +81,7 @@ orc_test_gcc_compile (OrcProgram *p) fclose (file); file = fopen (dump_filename, "w"); - ret = fwrite(p->code, p->code_size, 1, file); + ret = fwrite(p->orccode->code, p->orccode->code_size, 1, file); fclose (file); #if defined(HAVE_POWERPC) @@ -190,7 +190,7 @@ orc_test_gcc_compile_neon (OrcProgram *p) fclose (file); file = fopen (dump_filename, "w"); - ret = fwrite(p->code, p->code_size, 1, file); + ret = fwrite(p->orccode->code, p->orccode->code_size, 1, file); fclose (file); sprintf (cmd, PREFIX "gcc -march=armv6t2 -mcpu=cortex-a8 -mfpu=neon -Wall " @@ -283,7 +283,7 @@ orc_test_gcc_compile_c64x (OrcProgram *p) fclose (file); file = fopen (dump_filename, "w"); - ret = fwrite(p->code, p->code_size, 1, file); + ret = fwrite(p->orccode->code, p->orccode->code_size, 1, file); fclose (file); sprintf (cmd, C64X_PREFIX "cl6x -mv=6400+ " @@ -521,10 +521,12 @@ orc_test_compare_output_full (OrcProgram *program, int flags) result = orc_program_compile_full (program, target, flags); if (ORC_COMPILE_RESULT_IS_FATAL(result)) { - return ORC_TEST_FAILED; + ret = ORC_TEST_FAILED; + goto out; } if (!ORC_COMPILE_RESULT_IS_SUCCESSFUL(result)) { - return ORC_TEST_INDETERMINATE; + ret = ORC_TEST_INDETERMINATE; + goto out; } } @@ -716,6 +718,9 @@ orc_test_compare_output_full (OrcProgram *program, int flags) orc_executor_free (ex); +out: + orc_program_reset (program); + return ret; } @@ -907,6 +912,7 @@ orc_test_performance_full (OrcProgram *program, int flags, result = orc_program_compile_full (program, target, flags); if (!ORC_COMPILE_RESULT_IS_SUCCESSFUL(result)) { //printf("compile failed\n"); + orc_program_reset (program); return 0; } } @@ -996,6 +1002,7 @@ orc_test_performance_full (OrcProgram *program, int flags, } orc_executor_free (ex); + orc_program_reset (program); return ave/(n*m); } diff --git a/orc/orcarm.c b/orc/orcarm.c index d8452f1..b7b9d90 100644 --- a/orc/orcarm.c +++ b/orc/orcarm.c @@ -174,7 +174,7 @@ orc_arm_emit_align (OrcCompiler *compiler, int align_shift) { int diff; - diff = (compiler->program->code - compiler->codeptr)&((1<<align_shift) - 1); + diff = (compiler->code - compiler->codeptr)&((1<<align_shift) - 1); while (diff) { orc_arm_emit_nop (compiler); diff-=4; @@ -721,10 +721,10 @@ orc_arm_emit_rv (OrcCompiler *p, int op, OrcArmCond cond, } void -orc_arm_flush_cache (OrcCompiler *compiler) +orc_arm_flush_cache (OrcCode *code) { #ifdef HAVE_ARM - __clear_cache (compiler->program->code, compiler->codeptr); + __clear_cache (code->code, code->code + code->code_size); #endif } diff --git a/orc/orcarm.h b/orc/orcarm.h index aa668a6..9d53040 100644 --- a/orc/orcarm.h +++ b/orc/orcarm.h @@ -121,7 +121,7 @@ void orc_arm_emit_rv (OrcCompiler *p, int op, OrcArmCond cond, int Rd, int Rm); void orc_arm_emit_nop (OrcCompiler *compiler); -void orc_arm_flush_cache (OrcCompiler *compiler); +void orc_arm_flush_cache (OrcCode *code); /* ALL cpus */ /* data procesing instructions */ diff --git a/orc/orccode.c b/orc/orccode.c index 2c644ed..ca5946c 100644 --- a/orc/orccode.c +++ b/orc/orccode.c @@ -23,6 +23,15 @@ orc_code_free (OrcCode *code) { if (code->insns) { free (code->insns); + code->insns = NULL; + } + if (code->vars) { + free (code->vars); + code->vars = NULL; + } + if (code->chunk) { + orc_code_chunk_free (code->chunk); + code->chunk = NULL; } free (code); diff --git a/orc/orccodemem.c b/orc/orccodemem.c index f71b1f2..be7a262 100644 --- a/orc/orccodemem.c +++ b/orc/orccodemem.c @@ -25,7 +25,6 @@ #define SIZE 65536 typedef struct _OrcCodeRegion OrcCodeRegion; -typedef struct _OrcCodeChunk OrcCodeChunk; struct _OrcCodeRegion { orc_uint8 *write_ptr; @@ -148,29 +147,44 @@ orc_code_region_get_free_chunk (int size) } void -orc_compiler_allocate_codemem (OrcCompiler *compiler) +orc_code_allocate_codemem (OrcCode *code, int size) { OrcCodeRegion *region; OrcCodeChunk *chunk; - int size = 4096; + int aligned_size = (size + 15) & (~15); - chunk = orc_code_region_get_free_chunk (size); + chunk = orc_code_region_get_free_chunk (aligned_size); region = chunk->region; - if (chunk->size > size) { - orc_code_chunk_split (chunk, size); + if (chunk->size > aligned_size) { + orc_code_chunk_split (chunk, aligned_size); } chunk->used = TRUE; - compiler->program->code = ORC_PTR_OFFSET(region->write_ptr, chunk->offset); - compiler->program->code_exec = ORC_PTR_OFFSET(region->exec_ptr, chunk->offset); - compiler->program->code_size = chunk->size; - compiler->codeptr = ORC_PTR_OFFSET(region->write_ptr, chunk->offset); + code->chunk = chunk; + code->code = ORC_PTR_OFFSET(region->write_ptr, chunk->offset); + code->exec = ORC_PTR_OFFSET(region->exec_ptr, chunk->offset); + code->code_size = size; + //compiler->codeptr = ORC_PTR_OFFSET(region->write_ptr, chunk->offset); } +void +orc_code_chunk_free (OrcCodeChunk *chunk) +{ + if (_orc_compiler_flag_debug) { + /* If debug is turned on, don't free code */ + return; + } - + chunk->used = FALSE; + if (chunk->next && !chunk->next->used) { + orc_code_chunk_merge (chunk); + } + if (chunk->prev && !chunk->prev->used) { + orc_code_chunk_merge (chunk->prev); + } +} #ifdef HAVE_CODEMEM_MMAP void diff --git a/orc/orccompiler.c b/orc/orccompiler.c index d3cecd1..2f6201a 100644 --- a/orc/orccompiler.c +++ b/orc/orccompiler.c @@ -9,6 +9,10 @@ #include <orc/orcprogram.h> #include <orc/orcdebug.h> +#ifdef HAVE_VALGRIND_VALGRIND_H +#include <valgrind/valgrind.h> +#endif + /** * SECTION:orccompiler * @title: OrcCompiler @@ -187,9 +191,9 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target, memset (compiler, 0, sizeof(OrcCompiler)); if (program->backup_func) { - program->code = program->backup_func; + program->code_exec = program->backup_func; } else { - program->code = (void *)orc_executor_emulate; + program->code_exec = (void *)orc_executor_emulate; } compiler->program = program; @@ -253,15 +257,13 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target, orc_compiler_rewrite_insns (compiler); if (compiler->error) goto error; - orc_compiler_assign_rules (compiler); - if (compiler->error) goto error; - orc_compiler_rewrite_vars (compiler); if (compiler->error) goto error; orc_compiler_global_reg_alloc (compiler); orc_compiler_rewrite_vars2 (compiler); + #if 0 { ORC_ERROR("variables"); @@ -290,8 +292,33 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target, if (compiler->error) goto error; + program->orccode = orc_code_new (); + + program->orccode->is_2d = program->is_2d; + program->orccode->constant_n = program->constant_n; + program->orccode->constant_m = program->constant_m; + + program->orccode->n_insns = compiler->n_insns; + program->orccode->insns = malloc(sizeof(OrcInstruction) * compiler->n_insns); + memcpy (program->orccode->insns, compiler->insns, + sizeof(OrcInstruction) * compiler->n_insns); + + program->orccode->vars = malloc (sizeof(OrcCodeVariable) * ORC_N_COMPILER_VARIABLES); + memset (program->orccode->vars, 0, + sizeof(OrcCodeVariable) * ORC_N_COMPILER_VARIABLES); + for(i=0;i<ORC_N_COMPILER_VARIABLES;i++){ + program->orccode->vars[i].vartype = compiler->vars[i].vartype; + program->orccode->vars[i].size = compiler->vars[i].size; + program->orccode->vars[i].value = compiler->vars[i].value; + } + + orc_compiler_assign_rules (compiler); + if (compiler->error) goto error; + ORC_INFO("allocating code memory"); - orc_compiler_allocate_codemem (compiler); + compiler->code = malloc(65536); + compiler->codeptr = compiler->code; + if (compiler->error) goto error; ORC_INFO("compiling for target \"%s\"", compiler->target->name); @@ -301,30 +328,31 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target, goto error; } - program->orccode = orc_code_new (); - program->orccode->exec = program->code_exec; - program->orccode->code = program->code; - program->orccode->code_size = compiler->codeptr - program->code; - program->orccode->is_2d = program->is_2d; - program->orccode->constant_n = program->constant_n; - program->orccode->constant_m = program->constant_m; + orc_code_allocate_codemem (program->orccode, program->orccode->code_size); + program->orccode->code_size = compiler->codeptr - compiler->code; - program->orccode->n_insns = compiler->n_insns; - program->orccode->insns = malloc(sizeof(OrcInstruction) * compiler->n_insns); - memcpy (program->orccode->insns, compiler->insns, - sizeof(OrcInstruction) * compiler->n_insns); + memcpy (program->orccode->code, compiler->code, program->orccode->code_size); - program->orccode->vars = malloc (sizeof(OrcVariable) * ORC_N_COMPILER_VARIABLES); - memcpy (program->orccode->vars, compiler->vars, - sizeof(OrcVariable) * ORC_N_COMPILER_VARIABLES); +#ifdef VALGRIND_DISCARD_TRANSLATIONS + VALGRIND_DISCARD_TRANSLATIONS (program->orccode->exec, + program->orccode->code_size); +#endif + + if (compiler->target->flush_cache) { + compiler->target->flush_cache (program->orccode); + } + + program->code_exec = program->orccode->exec; program->asm_code = compiler->asm_code; - program->code_size = compiler->codeptr - program->code; result = compiler->result; for (i=0;i<compiler->n_dup_vars;i++){ free(compiler->vars[ORC_VAR_T1 + compiler->n_temp_vars + i].name); + compiler->vars[ORC_VAR_T1 + compiler->n_temp_vars + i].name = NULL; } + free (compiler->code); + compiler->code = NULL; free (compiler); ORC_INFO("finished compiling (success)"); @@ -337,11 +365,16 @@ error: if (result == 0) { result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE; } - program->code_exec = program->backup_func; - if (compiler->asm_code) free (compiler->asm_code); + if (compiler->asm_code) { + free (compiler->asm_code); + compiler->asm_code = NULL; + } for (i=0;i<compiler->n_dup_vars;i++){ free(compiler->vars[ORC_VAR_T1 + compiler->n_temp_vars + i].name); + compiler->vars[ORC_VAR_T1 + compiler->n_temp_vars + i].name = NULL; } + free (compiler->code); + compiler->code = NULL; free (compiler); ORC_INFO("finished compiling (fail)"); return result; diff --git a/orc/orcexecutor.c b/orc/orcexecutor.c index 19ba4ba..df2ed94 100644 --- a/orc/orcexecutor.c +++ b/orc/orcexecutor.c @@ -210,7 +210,7 @@ orc_executor_emulate (OrcExecutor *ex) } for(i=0;i<ORC_N_COMPILER_VARIABLES;i++){ - OrcVariable *var = code->vars + i; + OrcCodeVariable *var = code->vars + i; if (var->size) { tmpspace[i] = malloc(ORC_MAX_VAR_SIZE * CHUNK_SIZE); @@ -232,7 +232,7 @@ orc_executor_emulate (OrcExecutor *ex) } for(k=0;k<ORC_STATIC_OPCODE_N_SRC;k++) { - OrcVariable *var = code->vars + insn->src_args[k]; + OrcCodeVariable *var = code->vars + insn->src_args[k]; if (opcode->src_size[k] == 0) continue; if (var->vartype == ORC_VAR_TYPE_CONST) { @@ -254,7 +254,7 @@ orc_executor_emulate (OrcExecutor *ex) } } for(k=0;k<ORC_STATIC_OPCODE_N_DEST;k++) { - OrcVariable *var = code->vars + insn->dest_args[k]; + OrcCodeVariable *var = code->vars + insn->dest_args[k]; if (opcode->dest_size[k] == 0) continue; if (var->vartype == ORC_VAR_TYPE_TEMP) { @@ -281,7 +281,8 @@ orc_executor_emulate (OrcExecutor *ex) opcode = insn->opcode; for(k=0;k<ORC_STATIC_OPCODE_N_SRC;k++) { - OrcVariable *var = code->vars + insn->src_args[k]; + OrcCodeVariable *var = code->vars + insn->src_args[k]; + if (opcode->src_size[k] == 0) continue; if (var->vartype == ORC_VAR_TYPE_SRC) { opcode_ex[j].src_ptrs[k] = @@ -294,7 +295,8 @@ orc_executor_emulate (OrcExecutor *ex) } } for(k=0;k<ORC_STATIC_OPCODE_N_DEST;k++) { - OrcVariable *var = code->vars + insn->dest_args[k]; + OrcCodeVariable *var = code->vars + insn->dest_args[k]; + if (opcode->dest_size[k] == 0) continue; if (var->vartype == ORC_VAR_TYPE_DEST) { opcode_ex[j].dest_ptrs[k] = diff --git a/orc/orcpowerpc.c b/orc/orcpowerpc.c index efbf0ac..616951f 100644 --- a/orc/orcpowerpc.c +++ b/orc/orcpowerpc.c @@ -304,7 +304,7 @@ powerpc_do_fixups (OrcCompiler *compiler) *(unsigned int *)ptr = (insn&0xffff0000) | ((insn + (label-ptr))&0xffff); break; case 1: - *(unsigned int *)ptr = (insn&0xffff0000) | ((insn + (label-compiler->program->code))&0xffff); + *(unsigned int *)ptr = (insn&0xffff0000) | ((insn + (label-compiler->code))&0xffff); break; case 2: *(unsigned int *)ptr = (insn&0xfc000000) | ((insn + (label-ptr))&0x03ffffff); @@ -314,21 +314,21 @@ powerpc_do_fixups (OrcCompiler *compiler) } void -powerpc_flush (OrcCompiler *compiler) +orc_powerpc_flush_cache (OrcCode *code) { #ifdef HAVE_POWERPC unsigned char *ptr; int cache_line_size = 32; int i; - int size = compiler->codeptr - compiler->program->code; + int size = code->code_size; - ptr = compiler->program->code; + ptr = code->code; for (i=0;i<size;i+=cache_line_size) { __asm__ __volatile__ ("dcbst %0,%1" :: "r" (ptr), "r" (i)); } __asm__ __volatile ("sync"); - ptr = compiler->program->code_exec; + ptr = code->exec; for (i=0;i<size;i+=cache_line_size) { __asm__ __volatile__ ("icbi %0,%1" :: "r" (ptr), "r" (i)); } @@ -420,7 +420,7 @@ powerpc_load_constant (OrcCompiler *p, int i, int reg) powerpc_emit_b (p, label_skip); - while ((p->codeptr - p->program->code) & 0xf) { + while ((p->codeptr - p->code) & 0xf) { ORC_ASM_CODE(p," .long 0x00000000\n"); powerpc_emit (p, 0x00000000); } diff --git a/orc/orcpowerpc.h b/orc/orcpowerpc.h index 44b50c9..2075756 100644 --- a/orc/orcpowerpc.h +++ b/orc/orcpowerpc.h @@ -90,7 +90,7 @@ void powerpc_emit_bne (OrcCompiler *compiler, int label); void powerpc_emit_label (OrcCompiler *compiler, int label); void powerpc_add_fixup (OrcCompiler *compiler, int type, unsigned char *ptr, int label); void powerpc_do_fixups (OrcCompiler *compiler); -void powerpc_flush (OrcCompiler *compiler); +void orc_powerpc_flush_cache (OrcCode *code); void powerpc_emit_srawi (OrcCompiler *compiler, int regd, int rega, int shift, int record); diff --git a/orc/orcprogram-altivec.c b/orc/orcprogram-altivec.c index 2f6bd71..e661c11 100644 --- a/orc/orcprogram-altivec.c +++ b/orc/orcprogram-altivec.c @@ -61,7 +61,14 @@ static OrcTarget altivec_target = { ORC_VEC_REG_BASE, orc_compiler_powerpc_get_default_flags, orc_compiler_powerpc_init, - orc_compiler_powerpc_assemble + orc_compiler_powerpc_assemble, + { { 0 } }, + 0, + NULL, + NULL, + NULL, + orc_powerpc_flush_cache + }; void @@ -689,7 +696,5 @@ orc_compiler_powerpc_assemble (OrcCompiler *compiler) powerpc_emit_epilogue (compiler); powerpc_do_fixups (compiler); - - powerpc_flush (compiler); } diff --git a/orc/orcprogram-arm.c b/orc/orcprogram-arm.c index 5980733..f300d9c 100644 --- a/orc/orcprogram-arm.c +++ b/orc/orcprogram-arm.c @@ -91,7 +91,13 @@ static OrcTarget orc_arm_target = { ORC_GP_REG_BASE, orc_compiler_orc_arm_get_default_flags, orc_compiler_orc_arm_init, - orc_compiler_orc_arm_assemble + orc_compiler_orc_arm_assemble, + { { 0 } }, + 0, + NULL, + NULL, + NULL, + orc_arm_flush_cache }; void diff --git a/orc/orcprogram-mmx.c b/orc/orcprogram-mmx.c index b00c67c..1d80297 100644 --- a/orc/orcprogram-mmx.c +++ b/orc/orcprogram-mmx.c @@ -47,7 +47,8 @@ static OrcTarget mmx_target = { 0, NULL, mmx_load_constant, - mmx_get_flag_name + mmx_get_flag_name, + NULL }; @@ -664,7 +665,7 @@ orc_compiler_mmx_assemble (OrcCompiler *compiler) { orc_mmx_emit_loop (compiler, 0, 0); - compiler->codeptr = compiler->program->code; + compiler->codeptr = compiler->code; free (compiler->asm_code); compiler->asm_code = NULL; compiler->asm_code_len = 0; diff --git a/orc/orcprogram-neon.c b/orc/orcprogram-neon.c index 93e648a..27d52d7 100644 --- a/orc/orcprogram-neon.c +++ b/orc/orcprogram-neon.c @@ -96,7 +96,12 @@ static OrcTarget neon_target = { ORC_VEC_REG_BASE, orc_compiler_neon_get_default_flags, orc_compiler_neon_init, - orc_compiler_neon_assemble + orc_compiler_neon_assemble, + { { 0 } }, 0, + NULL, + NULL, + NULL, + orc_arm_flush_cache }; void @@ -700,8 +705,6 @@ orc_compiler_neon_assemble (OrcCompiler *compiler) orc_arm_emit_data (compiler, 0x0f0e0f0e); orc_arm_do_fixups (compiler); - - orc_arm_flush_cache (compiler); } void diff --git a/orc/orcprogram-sse.c b/orc/orcprogram-sse.c index 7e0eb98..46fc2f0 100644 --- a/orc/orcprogram-sse.c +++ b/orc/orcprogram-sse.c @@ -47,7 +47,8 @@ static OrcTarget sse_target = { 0, NULL, sse_load_constant, - sse_get_flag_name + sse_get_flag_name, + NULL }; @@ -664,7 +665,7 @@ orc_compiler_sse_assemble (OrcCompiler *compiler) { orc_sse_emit_loop (compiler, 0, 0); - compiler->codeptr = compiler->program->code; + compiler->codeptr = compiler->code; free (compiler->asm_code); compiler->asm_code = NULL; compiler->asm_code_len = 0; diff --git a/orc/orcprogram.c b/orc/orcprogram.c index 95bfab1..fa3cae3 100644 --- a/orc/orcprogram.c +++ b/orc/orcprogram.c @@ -147,13 +147,18 @@ orc_program_free (OrcProgram *program) { int i; for(i=0;i<ORC_N_VARIABLES;i++){ - if (program->vars[i].name) free (program->vars[i].name); + if (program->vars[i].name) { + free (program->vars[i].name); + program->vars[i].name = NULL; + } } if (program->asm_code) { free (program->asm_code); + program->asm_code = NULL; } if (program->name) { free (program->name); + program->name = NULL; } free (program); } @@ -815,3 +820,24 @@ orc_get_data_cache_sizes (int *level1, int *level2, int *level3) } +void +orc_program_reset (OrcProgram *program) +{ + if (program->orccode) { + orc_code_free (program->orccode); + program->orccode = NULL; + } + if (program->asm_code) { + free(program->asm_code); + program->asm_code = NULL; + } +} + +OrcCode * +orc_program_take_code (OrcProgram *program) +{ + OrcCode *code = program->orccode; + program->orccode = NULL; + return code; +} + diff --git a/orc/orcprogram.h b/orc/orcprogram.h index 0e4e012..13d56ed 100644 --- a/orc/orcprogram.h +++ b/orc/orcprogram.h @@ -19,6 +19,7 @@ typedef struct _OrcConstant OrcConstant; typedef struct _OrcFixup OrcFixup; typedef struct _OrcTarget OrcTarget; typedef struct _OrcCode OrcCode; +typedef struct _OrcCodeChunk OrcCodeChunk; typedef void (*OrcOpcodeEmulateFunc)(OrcOpcodeExecutor *ex, void *user); typedef void (*OrcOpcodeEmulateNFunc)(OrcOpcodeExecutor *ex, int index, int n); @@ -358,9 +359,9 @@ struct _OrcProgram { char *name; char *asm_code; - unsigned char *code; + unsigned char *_unused2; + /* The offset of code_exec in this structure is part of the ABI */ void *code_exec; - int code_size; OrcInstruction insns[ORC_N_INSNS]; @@ -394,6 +395,7 @@ struct _OrcCompiler { int n_temp_vars; int n_dup_vars; + unsigned char *code; unsigned char *codeptr; OrcConstant constants[ORC_N_CONSTANTS]; @@ -517,6 +519,14 @@ struct _OrcExecutorAlt { #define ORC_EXECUTOR_M_INDEX(ex) ((ex)->params[ORC_VAR_A2]) #define ORC_EXECUTOR_TIME(ex) ((ex)->params[ORC_VAR_A3]) +typedef struct _OrcCodeVariable OrcCodeVariable; +struct _OrcCodeVariable { + /*< private >*/ + int vartype; + int size; + int value; +}; + struct _OrcCode { /*< private >*/ OrcCompileResult result; @@ -526,11 +536,12 @@ struct _OrcCode { OrcExecutorFunc exec; unsigned char *code; int code_size; + void *chunk; /* for emulation */ int n_insns; OrcInstruction *insns; - OrcVariable *vars; + OrcCodeVariable *vars; int is_2d; int constant_n; int constant_m; @@ -555,8 +566,9 @@ struct _OrcTarget { const char * (*get_asm_preamble)(void); void (*load_constant)(OrcCompiler *compiler, int reg, int size, int value); const char * (*get_flag_name)(int shift); + void (*flush_cache) (OrcCode *code); - void *_unused[7]; + void *_unused[6]; }; @@ -654,13 +666,15 @@ const char * orc_target_get_flag_name (OrcTarget *target, int shift); int orc_program_allocate_register (OrcProgram *program, int is_data); -void orc_compiler_allocate_codemem (OrcCompiler *compiler); +void orc_code_allocate_codemem (OrcCode *code, int size); int orc_compiler_label_new (OrcCompiler *compiler); int orc_compiler_get_constant (OrcCompiler *compiler, int size, int value); int orc_compiler_get_temp_constant (OrcCompiler *compiler, int size, int value); int orc_compiler_get_temp_reg (OrcCompiler *compiler); int orc_compiler_get_constant_reg (OrcCompiler *compiler); +void orc_program_reset (OrcProgram *program); +OrcCode *orc_program_take_code (OrcProgram *program); const char *orc_program_get_asm_code (OrcProgram *program); const char *orc_target_get_asm_preamble (const char *target); @@ -693,6 +707,8 @@ extern int _orc_data_cache_size_level3; extern int _orc_compiler_flag_backup; extern int _orc_compiler_flag_debug; +void orc_code_chunk_free (OrcCodeChunk *chunk); + #endif #endif diff --git a/orc/orcx86.c b/orc/orcx86.c index ca64bdc..bd4922d 100644 --- a/orc/orcx86.c +++ b/orc/orcx86.c @@ -998,7 +998,7 @@ orc_x86_emit_align (OrcCompiler *compiler) int diff; int align_shift = 4; - diff = (compiler->program->code - compiler->codeptr)&((1<<align_shift) - 1); + diff = (compiler->code - compiler->codeptr)&((1<<align_shift) - 1); while (diff) { ORC_ASM_CODE(compiler," nop\n"); *compiler->codeptr++ = 0x90; |