1 2 #ifndef _ORC_COMPILER_H_ 3 #define _ORC_COMPILER_H_ 4 5 #include <orc/orc.h> 6 #include <orc/orclimits.h> 7 #include <orc/orcexecutor.h> 8 #include <orc/orccode.h> 9 #include <orc/orctarget.h> 10 #include <orc/orcinstruction.h> 11 #include <orc/orcvariable.h> 12 #include <orc/orcconstant.h> 13 14 ORC_BEGIN_DECLS 15 16 typedef struct _OrcFixup OrcFixup; 17 18 19 #define ORC_ENABLE_ASM_CODE 20 #ifdef ORC_ENABLE_ASM_CODE 21 #define ORC_ASM_CODE(compiler,...) orc_compiler_append_code(compiler, __VA_ARGS__) 22 #else 23 #define ORC_ASM_CODE(compiler,...) 24 #endif 25 26 27 #define ORC_COMPILER_ERROR(compiler, ...) do { \ 28 compiler->error = TRUE; \ 29 compiler->result = ORC_COMPILE_RESULT_UNKNOWN_PARSE; \ 30 orc_debug_print(ORC_DEBUG_WARNING, __FILE__, ORC_FUNCTION, __LINE__, __VA_ARGS__); \ 31 } while (0) 32 33 #if 0 34 /* FIXME in orcutils.h since it's needed in orccode.h */ 35 typedef enum { 36 ORC_COMPILE_RESULT_OK = 0, 37 38 ORC_COMPILE_RESULT_UNKNOWN_COMPILE = 0x100, 39 ORC_COMPILE_RESULT_MISSING_RULE = 0x101, 40 41 ORC_COMPILE_RESULT_UNKNOWN_PARSE = 0x200, 42 ORC_COMPILE_RESULT_PARSE = 0x201, 43 ORC_COMPILE_RESULT_VARIABLE = 0x202 44 45 } OrcCompileResult; 46 #endif 47 48 #define ORC_COMPILE_RESULT_IS_SUCCESSFUL(x) ((x) < 0x100) 49 #define ORC_COMPILE_RESULT_IS_FATAL(x) ((x) >= 0x200) 50 51 /** 52 * OrcFixup: 53 * 54 * The OrcFixup structure has no public members 55 */ 56 struct _OrcFixup { 57 /*< private >*/ 58 unsigned char *ptr; 59 int type; 60 int label; 61 }; 62 63 /** 64 * OrcCompiler: 65 * 66 * The OrcCompiler structure has no public members 67 */ 68 struct _OrcCompiler { 69 /*< private >*/ 70 OrcProgram *program; 71 OrcTarget *target; 72 73 unsigned int target_flags; 74 75 OrcInstruction insns[ORC_N_INSNS]; 76 int n_insns; 77 78 OrcVariable vars[ORC_N_COMPILER_VARIABLES]; 79 int n_temp_vars; 80 int n_dup_vars; 81 82 unsigned char *code; 83 unsigned char *codeptr; 84 85 OrcConstant constants[ORC_N_CONSTANTS]; 86 int n_constants; 87 88 OrcFixup fixups[ORC_N_FIXUPS]; 89 int n_fixups; 90 unsigned char *labels[ORC_N_LABELS]; 91 int labels_int[ORC_N_LABELS]; 92 int n_labels; 93 94 int error; 95 char *error_msg; 96 OrcCompileResult result; 97 98 int valid_regs[ORC_N_REGS]; 99 int save_regs[ORC_N_REGS]; 100 int used_regs[ORC_N_REGS]; 101 int alloc_regs[ORC_N_REGS]; 102 103 int loop_shift; 104 int long_jumps; 105 int use_frame_pointer; 106 107 char *asm_code; 108 int asm_code_len; 109 110 int is_64bit; 111 int tmpreg; 112 int tmpreg2; 113 int exec_reg; 114 int gp_tmpreg; 115 116 int insn_index; 117 int unroll_index; 118 int need_mask_regs; 119 int unroll_shift; 120 121 int alloc_loop_counter; 122 int allow_gp_on_stack; 123 int loop_counter; 124 int size_region; 125 int has_iterator_opcode; 126 127 int offset; 128 int min_temp_reg; 129 int max_used_temp_reg; 130 131 int insn_shift; /* used when emitting rules */ 132 int max_var_size; /* size of largest var */ 133 int load_params; 134 135 void *output_insns; 136 int n_output_insns; 137 int n_output_insns_alloc; 138 }; 139 140 141 ORC_API int orc_compiler_label_new (OrcCompiler *compiler); 142 143 ORC_API int orc_compiler_get_constant (OrcCompiler *compiler, int size, int value); 144 145 ORC_API int orc_compiler_get_constant_long (OrcCompiler *compiler, orc_uint32 a, 146 orc_uint32 b, orc_uint32 c, orc_uint32 d); 147 148 ORC_API int orc_compiler_try_get_constant_long (OrcCompiler *compiler, orc_uint32 a, 149 orc_uint32 b, orc_uint32 c, orc_uint32 d); 150 151 ORC_API int orc_compiler_get_temp_constant (OrcCompiler *compiler, int size, int value); 152 153 ORC_API int orc_compiler_get_temp_reg (OrcCompiler *compiler); 154 155 ORC_API int orc_compiler_get_constant_reg (OrcCompiler *compiler); 156 157 ORC_API void orc_compiler_error (OrcCompiler *compiler, const char *fmt, ...); 158 159 ORC_API void orc_compiler_append_code (OrcCompiler *p, const char *fmt, ...) ORC_GNU_PRINTF(2,3); 160 161 #ifdef ORC_ENABLE_UNSTABLE_API 162 163 ORC_API int orc_compiler_flag_check (const char *flag); 164 165 /* FIXME: remove, these were never actually exported as public symbols, so unusable */ 166 extern int _orc_compiler_flag_backup; 167 extern int _orc_compiler_flag_emulate; 168 extern int _orc_compiler_flag_debug; 169 extern int _orc_compiler_flag_randomize; 170 171 #endif 172 173 ORC_END_DECLS 174 175 #endif 176 177