This code is arch-independent, is useful for multiple architectures, so we move it into jit/emit.c.
Signed-off-by: Eduard - Gabriel Munteanu <[email protected]> --- arch/ppc/emit-code.c | 5 -- arch/x86/emit-code_32.c | 110 ++--------------------------------------------- arch/x86/emit-code_64.c | 5 -- include/jit/emit-code.h | 19 ++++++++- jit/emit.c | 89 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 117 deletions(-) diff --git a/arch/ppc/emit-code.c b/arch/ppc/emit-code.c index 5af54c3..ce7fbfc 100644 --- a/arch/ppc/emit-code.c +++ b/arch/ppc/emit-code.c @@ -43,11 +43,6 @@ void emit_epilog(struct buffer *buffer) NOT_IMPLEMENTED } -void emit_body(struct basic_block *bb, struct buffer *buffer) -{ - NOT_IMPLEMENTED -} - void emit_trampoline(struct compilation_unit *cu, void *call_target, struct jit_trampoline *trampoline) { diff --git a/arch/x86/emit-code_32.c b/arch/x86/emit-code_32.c index 27277c9..58c6ec7 100644 --- a/arch/x86/emit-code_32.c +++ b/arch/x86/emit-code_32.c @@ -907,22 +907,7 @@ void emit_unlock_this(struct buffer *buf) __emit_pop_reg(buf, REG_EAX); } -enum emitter_type { - NO_OPERANDS = 1, - SINGLE_OPERAND, - TWO_OPERANDS, - BRANCH, -}; - -struct emitter { - void *emit_fn; - enum emitter_type type; -}; - -#define DECL_EMITTER(_insn_type, _fn, _emitter_type) \ - [_insn_type] = { .emit_fn = _fn, .type = _emitter_type } - -static struct emitter emitters[] = { +struct emitter emitters[] = { DECL_EMITTER(INSN_ADC_IMM_REG, emit_adc_imm_reg, TWO_OPERANDS), DECL_EMITTER(INSN_ADC_REG_REG, emit_adc_reg_reg, TWO_OPERANDS), DECL_EMITTER(INSN_ADC_MEMBASE_REG, emit_adc_membase_reg, TWO_OPERANDS), @@ -980,71 +965,9 @@ static struct emitter emitters[] = { DECL_EMITTER(INSN_XOR_IMM_REG, emit_xor_imm_reg, TWO_OPERANDS), }; -typedef void (*emit_no_operands_fn) (struct buffer *); - -static void emit_no_operands(struct emitter *emitter, struct buffer *buf) -{ - emit_no_operands_fn emit = emitter->emit_fn; - emit(buf); -} - -typedef void (*emit_single_operand_fn) (struct buffer *, struct operand * operand); - -static void emit_single_operand(struct emitter *emitter, struct buffer *buf, struct insn *insn) -{ - emit_single_operand_fn emit = emitter->emit_fn; - emit(buf, &insn->operand); -} - -typedef void (*emit_two_operands_fn) (struct buffer *, struct operand * src, struct operand * dest); - -static void emit_two_operands(struct emitter *emitter, struct buffer *buf, struct insn *insn) -{ - emit_two_operands_fn emit = emitter->emit_fn; - emit(buf, &insn->src, &insn->dest); -} - -typedef void (*emit_branch_fn) (struct buffer *, struct insn *); - -static void emit_branch(struct emitter *emitter, struct buffer *buf, struct insn *insn) -{ - emit_branch_fn emit = emitter->emit_fn; - emit(buf, insn); -} - -static void __emit_insn(struct buffer *buf, struct insn *insn) -{ - struct emitter *emitter; - - emitter = &emitters[insn->type]; - switch (emitter->type) { - case NO_OPERANDS: - emit_no_operands(emitter, buf); - break; - case SINGLE_OPERAND: - emit_single_operand(emitter, buf, insn); - break; - case TWO_OPERANDS: - emit_two_operands(emitter, buf, insn); - break; - case BRANCH: - emit_branch(emitter, buf, insn); - break; - default: - printf("Oops. No emitter for 0x%x.\n", insn->type); - abort(); - }; -} - -static void emit_insn(struct buffer *buf, struct insn *insn) -{ - insn->mach_offset = buffer_offset(buf); - __emit_insn(buf, insn); -} - -static void backpatch_branch_target(struct buffer *buf, - struct insn *insn, - unsigned long target_offset) +void backpatch_branch_target(struct buffer *buf, + struct insn *insn, + unsigned long target_offset) { unsigned long backpatch_offset; long relative_addr; @@ -1058,31 +981,6 @@ static void backpatch_branch_target(struct buffer *buf, write_imm32(buf, backpatch_offset, relative_addr); } -static void backpatch_branches(struct buffer *buf, - struct list_head *to_backpatch, - unsigned long target_offset) -{ - struct insn *this, *next; - - list_for_each_entry_safe(this, next, to_backpatch, branch_list_node) { - backpatch_branch_target(buf, this, target_offset); - list_del(&this->branch_list_node); - } -} - -void emit_body(struct basic_block *bb, struct buffer *buf) -{ - struct insn *insn; - - bb->mach_offset = buffer_offset(buf); - backpatch_branches(buf, &bb->backpatch_insns, bb->mach_offset); - - for_each_insn(insn, &bb->insn_list) { - emit_insn(buf, insn); - } - bb->is_emitted = true; -} - /* * This fixes relative calls generated by EXPR_INVOKE. * diff --git a/arch/x86/emit-code_64.c b/arch/x86/emit-code_64.c index d8d00f4..3799634 100644 --- a/arch/x86/emit-code_64.c +++ b/arch/x86/emit-code_64.c @@ -52,11 +52,6 @@ void emit_branch_rel(struct buffer *buf, unsigned char prefix, abort(); } -void emit_body(struct basic_block *bb, struct buffer *buf) -{ - abort(); -} - void emit_trampoline(struct compilation_unit *cu, void *call_target, struct jit_trampoline *trampoline) { diff --git a/include/jit/emit-code.h b/include/jit/emit-code.h index 3467673..65b4469 100644 --- a/include/jit/emit-code.h +++ b/include/jit/emit-code.h @@ -7,14 +7,31 @@ struct basic_block; struct buffer; struct object; +enum emitter_type { + NO_OPERANDS = 1, + SINGLE_OPERAND, + TWO_OPERANDS, + BRANCH, +}; + +struct emitter { + void *emit_fn; + enum emitter_type type; +}; + +extern struct emitter emitters[]; + +#define DECL_EMITTER(_insn_type, _fn, _emitter_type) \ + [_insn_type] = { .emit_fn = _fn, .type = _emitter_type } + void emit_prolog(struct buffer *, unsigned long); void emit_epilog(struct buffer *); -void emit_body(struct basic_block *, struct buffer *); void emit_trampoline(struct compilation_unit *, void *, struct jit_trampoline *); void emit_unwind(struct buffer *); void emit_lock(struct buffer *, struct object *); void emit_lock_this(struct buffer *); void emit_unlock(struct buffer *, struct object *); void emit_unlock_this(struct buffer *); +void backpatch_branch_target(struct buffer *, struct insn *, unsigned long); #endif /* JATO_EMIT_CODE_H */ diff --git a/jit/emit.c b/jit/emit.c index 4fe3a73..18a426e 100644 --- a/jit/emit.c +++ b/jit/emit.c @@ -17,6 +17,8 @@ #include <jit/emit-code.h> #include <jit/compiler.h> +#include <arch/instruction.h> + #include <errno.h> #include <stdlib.h> #include <string.h> @@ -42,6 +44,93 @@ static struct buffer_operations exec_buf_ops = { .free = generic_buffer_free, }; +typedef void (*emit_no_operands_fn) (struct buffer *); + +static void emit_no_operands(struct emitter *emitter, struct buffer *buf) +{ + emit_no_operands_fn emit = emitter->emit_fn; + emit(buf); +} + +typedef void (*emit_single_operand_fn) (struct buffer *, struct operand * operand); + +static void emit_single_operand(struct emitter *emitter, struct buffer *buf, struct insn *insn) +{ + emit_single_operand_fn emit = emitter->emit_fn; + emit(buf, &insn->operand); +} + +typedef void (*emit_two_operands_fn) (struct buffer *, struct operand * src, struct operand * dest); + +static void emit_two_operands(struct emitter *emitter, struct buffer *buf, struct insn *insn) +{ + emit_two_operands_fn emit = emitter->emit_fn; + emit(buf, &insn->src, &insn->dest); +} + +typedef void (*emit_branch_fn) (struct buffer *, struct insn *); + +static void emit_branch(struct emitter *emitter, struct buffer *buf, struct insn *insn) +{ + emit_branch_fn emit = emitter->emit_fn; + emit(buf, insn); +} + +static void __emit_insn(struct buffer *buf, struct insn *insn) +{ + struct emitter *emitter; + + emitter = &emitters[insn->type]; + switch (emitter->type) { + case NO_OPERANDS: + emit_no_operands(emitter, buf); + break; + case SINGLE_OPERAND: + emit_single_operand(emitter, buf, insn); + break; + case TWO_OPERANDS: + emit_two_operands(emitter, buf, insn); + break; + case BRANCH: + emit_branch(emitter, buf, insn); + break; + default: + printf("Oops. No emitter for 0x%x.\n", insn->type); + abort(); + }; +} + +static void emit_insn(struct buffer *buf, struct insn *insn) +{ + insn->mach_offset = buffer_offset(buf); + __emit_insn(buf, insn); +} + +static void backpatch_branches(struct buffer *buf, + struct list_head *to_backpatch, + unsigned long target_offset) +{ + struct insn *this, *next; + + list_for_each_entry_safe(this, next, to_backpatch, branch_list_node) { + backpatch_branch_target(buf, this, target_offset); + list_del(&this->branch_list_node); + } +} + +static void emit_body(struct basic_block *bb, struct buffer *buf) +{ + struct insn *insn; + + bb->mach_offset = buffer_offset(buf); + backpatch_branches(buf, &bb->backpatch_insns, bb->mach_offset); + + for_each_insn(insn, &bb->insn_list) { + emit_insn(buf, insn); + } + bb->is_emitted = true; +} + int emit_machine_code(struct compilation_unit *cu) { unsigned long frame_size; -- 1.6.0.6 ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Jatovm-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jatovm-devel
