From 10f69d7c379375bd9f40bb213b033218fb74363d Mon Sep 17 00:00:00 2001 From: Jorge Zapata Date: Sun, 7 Jan 2024 19:58:14 +0100 Subject: Move the orc_program_compile* to orcprogram.[ch] Part-of: --- orc/orccompiler.c | 64 +-------------------------------------------------- orc/orccompiler.h | 1 + orc/orcprogram.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 63 deletions(-) diff --git a/orc/orccompiler.c b/orc/orccompiler.c index 5223c53..d7ad043 100644 --- a/orc/orccompiler.c +++ b/orc/orccompiler.c @@ -209,54 +209,6 @@ orc_compiler_allocate_register (OrcCompiler *compiler, int data_reg) return 0; } -/** - * orc_program_compile: - * @program: the OrcProgram to compile - * - * Compiles an Orc program for the current CPU. If successful, - * executable code for the program was generated and can be - * executed. - * - * The return value indicates various levels of success or failure. - * Success can be determined by checking for a true value of the - * macro ORC_COMPILE_RESULT_IS_SUCCESSFUL() on the return value. This - * indicates that executable code was generated. If the macro - * ORC_COMPILE_RESULT_IS_FATAL() on the return value evaluates to - * true, then there was a syntactical error in the program. If the - * result is neither successful nor fatal, the program can still be - * emulated. - * - * Returns: an OrcCompileResult - */ -OrcCompileResult -orc_program_compile (OrcProgram *program) -{ - return orc_program_compile_for_target (program, orc_target_get_default ()); -} - -/** - * orc_program_compile_for_target: - * @program: the OrcProgram to compile - * - * Compiles an Orc program for the given target, using the - * default target flags for that target. - * - * Returns: an OrcCompileResult - */ -OrcCompileResult -orc_program_compile_for_target (OrcProgram *program, OrcTarget *target) -{ - unsigned int flags; - - if (target) { - flags = target->get_default_flags (); - } else { - flags = 0; - } - - return orc_program_compile_full (program, target, flags); -} - #if defined(HAVE_CODEMEM_VIRTUALALLOC) static orc_bool _set_virtual_protect (void * mem, size_t size, int code_protect) @@ -285,20 +237,9 @@ _set_virtual_protect (void * mem, size_t size, int code_protect) } #endif -/** - * orc_program_compile_full: - * @program: the OrcProgram to compile - * - * Compiles an Orc program for the given target, using the - * given target flags. - * - * Returns: an OrcCompileResult - */ OrcCompileResult -orc_program_compile_full (OrcProgram *program, OrcTarget *target, - unsigned int flags) +orc_compiler_compile_program (OrcCompiler *compiler, OrcProgram *program, OrcTarget *target, unsigned int flags) { - OrcCompiler *compiler; int i; OrcCompileResult result; const char *error_msg; @@ -321,9 +262,6 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target, program->asm_code = NULL; } - compiler = malloc (sizeof(OrcCompiler)); - memset (compiler, 0, sizeof(OrcCompiler)); - if (program->backup_func) { program->code_exec = program->backup_func; } else { diff --git a/orc/orccompiler.h b/orc/orccompiler.h index a6c301e..8bda6b2 100644 --- a/orc/orccompiler.h +++ b/orc/orccompiler.h @@ -161,6 +161,7 @@ ORC_API void orc_compiler_append_code (OrcCompiler *p, const char *fmt, ...) ORC #ifdef ORC_ENABLE_UNSTABLE_API ORC_API int orc_compiler_flag_check (const char *flag); +ORC_API OrcCompileResult orc_compiler_compile_program (OrcCompiler *compiler, OrcProgram *program, OrcTarget *target, unsigned int flags); /* FIXME: remove, these were never actually exported as public symbols, so unusable */ extern int _orc_compiler_flag_backup; diff --git a/orc/orcprogram.c b/orc/orcprogram.c index 671de4e..b414e8f 100644 --- a/orc/orcprogram.c +++ b/orc/orcprogram.c @@ -1283,3 +1283,71 @@ orc_program_has_float (OrcCompiler *compiler) } return FALSE; } + +/** + * orc_program_compile: + * @program: the OrcProgram to compile + * + * Compiles an Orc program for the current CPU. If successful, + * executable code for the program was generated and can be + * executed. + * + * The return value indicates various levels of success or failure. + * Success can be determined by checking for a true value of the + * macro ORC_COMPILE_RESULT_IS_SUCCESSFUL() on the return value. This + * indicates that executable code was generated. If the macro + * ORC_COMPILE_RESULT_IS_FATAL() on the return value evaluates to + * true, then there was a syntactical error in the program. If the + * result is neither successful nor fatal, the program can still be + * emulated. + * + * Returns: an OrcCompileResult + */ +OrcCompileResult +orc_program_compile (OrcProgram *program) +{ + return orc_program_compile_for_target (program, orc_target_get_default ()); +} + +/** + * orc_program_compile_for_target: + * @program: the OrcProgram to compile + * + * Compiles an Orc program for the given target, using the + * default target flags for that target. + * + * Returns: an OrcCompileResult + */ +OrcCompileResult +orc_program_compile_for_target (OrcProgram *program, OrcTarget *target) +{ + unsigned int flags; + + if (target) { + flags = target->get_default_flags (); + } else { + flags = 0; + } + + return orc_program_compile_full (program, target, flags); +} + +/** + * orc_program_compile_full: + * @program: the OrcProgram to compile + * + * Compiles an Orc program for the given target, using the + * given target flags. + * + * Returns: an OrcCompileResult + */ +OrcCompileResult +orc_program_compile_full (OrcProgram *program, OrcTarget *target, + unsigned int flags) +{ + OrcCompiler *compiler; + + compiler = malloc (sizeof(OrcCompiler)); + memset (compiler, 0, sizeof(OrcCompiler)); + return orc_compiler_compile_program (compiler, program, target, flags); +} -- cgit v1.2.3