diff options
author | David Schleef <ds@schleef.org> | 2012-12-03 11:43:14 -0800 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2012-12-03 11:43:14 -0800 |
commit | 8f6080fc9000af04f72290be072ee7a3704d3a2d (patch) | |
tree | 5edc2a76dc3426ad9defe333979c67380b9243a1 | |
parent | 57c3e69e19a0237b1cb97644ad09485c9f81ee2b (diff) |
Make OrcProgram const during compilation
-rw-r--r-- | orc/Makefile.am | 4 | ||||
-rw-r--r-- | orc/orccompiler.c | 76 | ||||
-rw-r--r-- | orc/orccompiler.h | 2 | ||||
-rw-r--r-- | orc/orcerror.c | 13 | ||||
-rw-r--r-- | orc/orcerror.h | 28 | ||||
-rw-r--r-- | orc/orcprogram-c64x-c.c | 10 | ||||
-rw-r--r-- | orc/orcprogram.c | 4 | ||||
-rw-r--r-- | orc/orcprogram.h | 7 | ||||
-rw-r--r-- | orc/orcx86.c | 2 |
9 files changed, 102 insertions, 44 deletions
diff --git a/orc/Makefile.am b/orc/Makefile.am index 9a14dcf..88fdb09 100644 --- a/orc/Makefile.am +++ b/orc/Makefile.am @@ -31,7 +31,8 @@ liborc_@ORC_MAJORMINOR@_la_SOURCES = \ orctest.c \ orcarray.c \ orcrandom.c \ - orcprofile.c + orcprofile.c \ + orcerror.c if ENABLE_BACKEND_SSE liborc_@ORC_MAJORMINOR@_la_SOURCES += orcsse.c orcrules-sse.c orcprogram-sse.c @@ -89,6 +90,7 @@ pkginclude_HEADERS = \ orccpuinsn.h \ orcdebug.h \ orcemulateopcodes.h \ + orcerror.h \ orcexecutor.h \ orcfunctions.h \ orcinstruction.h \ diff --git a/orc/orccompiler.c b/orc/orccompiler.c index f41db23..6c8ecc1 100644 --- a/orc/orccompiler.c +++ b/orc/orccompiler.c @@ -186,6 +186,23 @@ OrcCompileResult orc_program_compile_full (OrcProgram * program, OrcTarget * target, unsigned int flags) { + OrcCode *code; + + code = orc_program_compile_2 (program, target, flags, NULL); + + if (code) { + program->orccode = code; + return ORC_COMPILE_RESULT_OK; + } + + return ORC_COMPILE_RESULT_UNKNOWN_COMPILE; +} + +OrcCode * +orc_program_compile_2 (const OrcProgram * program, OrcTarget * target, + unsigned int flags, OrcError ** error) +{ + OrcCode *code; OrcCompiler *compiler; int i; OrcCompileResult result; @@ -282,32 +299,29 @@ orc_program_compile_full (OrcProgram * program, OrcTarget * target, if (compiler->error) goto error; - program->orccode = orc_code_new (); + code = 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->backup_func = program->backup_func; + code->is_2d = program->is_2d; + code->constant_n = program->constant_n; + code->constant_m = program->constant_m; + code->backup_func = program->backup_func; if (program->backup_func) { - program->orccode->exec = program->backup_func; + code->exec = program->backup_func; } else { - program->orccode->exec = (void *) orc_executor_emulate; + code->exec = (void *) orc_executor_emulate; } - program->orccode->n_insns = compiler->n_insns; - program->orccode->insns = - malloc (sizeof (OrcInstruction) * compiler->n_insns); - memcpy (program->orccode->insns, compiler->insns, + code->n_insns = compiler->n_insns; + code->insns = malloc (sizeof (OrcInstruction) * compiler->n_insns); + memcpy (code->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); + code->vars = malloc (sizeof (OrcCodeVariable) * ORC_N_COMPILER_VARIABLES); + memset (code->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; + code->vars[i].vartype = compiler->vars[i].vartype; + code->vars[i].size = compiler->vars[i].size; + code->vars[i].value = compiler->vars[i].value; } if (program->backup_func && _orc_compiler_flag_backup) { @@ -317,7 +331,7 @@ orc_program_compile_full (OrcProgram * program, OrcTarget * target, } if (_orc_compiler_flag_emulate || target == NULL) { - program->orccode->exec = (void *) orc_executor_emulate; + code->exec = (void *) orc_executor_emulate; orc_compiler_error (compiler, "Compilation disabled, using emulation"); compiler->result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE; goto error; @@ -341,21 +355,21 @@ orc_program_compile_full (OrcProgram * program, OrcTarget * target, goto error; } - program->orccode->code_size = compiler->codeptr - compiler->code; - orc_code_allocate_codemem (program->orccode, program->orccode->code_size); + code->code_size = compiler->codeptr - compiler->code; + orc_code_allocate_codemem (code, code->code_size); - memcpy (program->orccode->code, compiler->code, program->orccode->code_size); + memcpy (code->code, compiler->code, code->code_size); #ifdef VALGRIND_DISCARD_TRANSLATIONS - VALGRIND_DISCARD_TRANSLATIONS (program->orccode->exec, - program->orccode->code_size); + VALGRIND_DISCARD_TRANSLATIONS (code->exec, code->code_size); #endif if (compiler->target->flush_cache) { - compiler->target->flush_cache (program->orccode); + compiler->target->flush_cache (code); } - program->asm_code = compiler->asm_code; + /* FIXME */ + ((OrcProgram *) program)->asm_code = compiler->asm_code; result = compiler->result; for (i = 0; i < compiler->n_dup_vars; i++) { @@ -369,7 +383,7 @@ orc_program_compile_full (OrcProgram * program, OrcTarget * target, free (compiler); ORC_INFO ("finished compiling (success)"); - return result; + return code; error: if (compiler->error_msg) { @@ -380,9 +394,7 @@ error: program->name, compiler->result); } result = compiler->result; - if (program->error_msg) - free (program->error_msg); - program->error_msg = compiler->error_msg; + //program->error_msg = compiler->error_msg; if (result == 0) { result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE; } @@ -400,7 +412,7 @@ error: free (compiler->output_insns); free (compiler); ORC_INFO ("finished compiling (fail)"); - return result; + return NULL; } void @@ -532,7 +544,7 @@ orc_compiler_rewrite_insns (OrcCompiler * compiler) int i; int j; OrcStaticOpcode *opcode; - OrcProgram *program = compiler->program; + const OrcProgram *program = compiler->program; compiler->n_insns = 0; for (j = 0; j < program->n_insns; j++) { diff --git a/orc/orccompiler.h b/orc/orccompiler.h index 73df995..f0ff697 100644 --- a/orc/orccompiler.h +++ b/orc/orccompiler.h @@ -68,7 +68,7 @@ struct _OrcFixup { */ struct _OrcCompiler { /*< private >*/ - OrcProgram *program; + const OrcProgram *program; OrcTarget *target; unsigned int target_flags; diff --git a/orc/orcerror.c b/orc/orcerror.c new file mode 100644 index 0000000..b191f3e --- /dev/null +++ b/orc/orcerror.c @@ -0,0 +1,13 @@ + +#include "config.h" + +#include <orc/orcerror.h> + +void +orc_error_free (OrcError * error) +{ + if (error) { + free (error->message); + free (error); + } +} diff --git a/orc/orcerror.h b/orc/orcerror.h new file mode 100644 index 0000000..2dba616 --- /dev/null +++ b/orc/orcerror.h @@ -0,0 +1,28 @@ + +#ifndef _ORC_ERROR_H_ +#define _ORC_ERROR_H_ + +#include <orc/orcutils.h> +#include <stdlib.h> + +ORC_BEGIN_DECLS + +typedef struct _OrcError OrcError; + +/** + * OrcError: + * + * Structure that holds information about an error that occurs in the + * Orc library. + */ +struct _OrcError { + /*< private >*/ + char *message; +}; + +void orc_error_free (OrcError *error); + +ORC_END_DECLS + +#endif + diff --git a/orc/orcprogram-c64x-c.c b/orc/orcprogram-c64x-c.c index 1e28099..0b539e6 100644 --- a/orc/orcprogram-c64x-c.c +++ b/orc/orcprogram-c64x-c.c @@ -107,7 +107,7 @@ static const char *varnames[] = { static void output_prototype (OrcCompiler * compiler) { - OrcProgram *p = compiler->program; + const OrcProgram *p = compiler->program; OrcVariable *var; int i; int need_comma; @@ -115,7 +115,7 @@ output_prototype (OrcCompiler * compiler) ORC_ASM_CODE (compiler, "%s (", p->name); need_comma = FALSE; for (i = 0; i < 4; i++) { - var = &p->vars[ORC_VAR_D1 + i]; + var = &compiler->vars[ORC_VAR_D1 + i]; if (var->size) { if (need_comma) ORC_ASM_CODE (compiler, ", "); @@ -133,7 +133,7 @@ output_prototype (OrcCompiler * compiler) } } for (i = 0; i < 4; i++) { - var = &p->vars[ORC_VAR_A1 + i]; + var = &compiler->vars[ORC_VAR_A1 + i]; if (var->size) { if (need_comma) ORC_ASM_CODE (compiler, ", "); @@ -148,7 +148,7 @@ output_prototype (OrcCompiler * compiler) } } for (i = 0; i < 8; i++) { - var = &p->vars[ORC_VAR_S1 + i]; + var = &compiler->vars[ORC_VAR_S1 + i]; if (var->size) { if (need_comma) ORC_ASM_CODE (compiler, ", "); @@ -166,7 +166,7 @@ output_prototype (OrcCompiler * compiler) } } for (i = 0; i < 8; i++) { - var = &p->vars[ORC_VAR_P1 + i]; + var = &compiler->vars[ORC_VAR_P1 + i]; if (var->size) { if (need_comma) ORC_ASM_CODE (compiler, ", "); diff --git a/orc/orcprogram.c b/orc/orcprogram.c index ccd1946..b87d766 100644 --- a/orc/orcprogram.c +++ b/orc/orcprogram.c @@ -976,7 +976,7 @@ orc_program_get_error (OrcProgram * program) * Returns: the number of bytes */ int -orc_program_get_max_array_size (OrcProgram * program) +orc_program_get_max_array_size (const OrcProgram * program) { int i; int max; @@ -1003,7 +1003,7 @@ orc_program_get_max_array_size (OrcProgram * program) * Returns: the number of bytes */ int -orc_program_get_max_accumulator_size (OrcProgram * program) +orc_program_get_max_accumulator_size (const OrcProgram * program) { int i; int max; diff --git a/orc/orcprogram.h b/orc/orcprogram.h index 089a66e..bf385e3 100644 --- a/orc/orcprogram.h +++ b/orc/orcprogram.h @@ -10,6 +10,7 @@ #include <orc/orccompiler.h> #include <orc/orctarget.h> #include <orc/orcrule.h> +#include <orc/orcerror.h> ORC_BEGIN_DECLS @@ -98,6 +99,8 @@ void orc_program_append_ds_str (OrcProgram *p, const char *opcode, void orc_program_append_dds_str (OrcProgram *program, const char *name, const char *arg1, const char *arg2, const char *arg3); +OrcCode *orc_program_compile_2 (const OrcProgram *program, OrcTarget *target, + unsigned int flags, OrcError **error); OrcCompileResult orc_program_compile (OrcProgram *p); OrcCompileResult orc_program_compile_for_target (OrcProgram *p, OrcTarget *target); OrcCompileResult orc_program_compile_full (OrcProgram *p, OrcTarget *target, @@ -137,8 +140,8 @@ OrcCode *orc_program_take_code (OrcProgram *program); const char *orc_program_get_asm_code (OrcProgram *program); const char * orc_program_get_error (OrcProgram *program); -int orc_program_get_max_array_size (OrcProgram *program); -int orc_program_get_max_accumulator_size (OrcProgram *program); +int orc_program_get_max_array_size (const OrcProgram *program); +int orc_program_get_max_accumulator_size (const OrcProgram *program); ORC_END_DECLS diff --git a/orc/orcx86.c b/orc/orcx86.c index d8f7e55..99d3674 100644 --- a/orc/orcx86.c +++ b/orc/orcx86.c @@ -563,7 +563,7 @@ orc_x86_assemble_copy (OrcCompiler * compiler) OrcInstruction *insn; int shift = 0; - insn = compiler->program->insns + 0; + insn = compiler->insns + 0; if (strcmp (insn->opcode->name, "copyw") == 0) { shift = 1; |