From d2d2f9255ebf39fe561de9a2835b3b646bd1e77b Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Wed, 11 Jan 2006 00:24:42 +0000 Subject: [PATCH] implement JIT_OP_JUMP_TABLE in interpreter --- ChangeLog | 8 +++---- jit/jit-interp.c | 14 ++++++++++++ jit/jit-rules-interp.c | 50 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 002eb4c..78c57d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,10 +5,10 @@ * jit/jit-internal.h, jit/jit-function.c, jiy/jit-rules-x86.c: add fixup_absolute_list field to _jit_block struct for fixing up absolute address references to a block. - * include/jit/jit-opcode.h (JIT_OP_JUMP_TABLE), - * jit/jit-rules-x86.sel (JIT_OP_JUMP_TABLE), - * include/jit/jit-insn.h, jit/jit-insn.c (jit_insn_jump_table): - add new opcode. + * include/jit/jit-opcode.h, include/jit/jit-insn.h, jit/jit-insn.c + (jit_insn_jump_table), jit/jit-rules-x86.sel, jit/jit-rules-interp.c + (_jit_gen_insn), jit/jit-interp.c (_jit_run_function): + add JIT_OP_JUMP_TABLE opcode. 2006-01-08 Aleksey Demakov diff --git a/jit/jit-interp.c b/jit/jit-interp.c index 6583877..26becaa 100644 --- a/jit/jit-interp.c +++ b/jit/jit-interp.c @@ -2045,6 +2045,20 @@ restart_tail: } VMBREAK; + VMCASE(JIT_OP_JUMP_TABLE): + { + if(VM_STK_INT0 < VM_NINT_ARG && VM_STK_INT0 >= 0) + { + pc = pc[2 + VM_STK_INT0]; + VM_MODIFY_STACK(1); + } + else + { + VM_MODIFY_PC_AND_STACK(2 + VM_NINT_ARG, 1); + } + } + VMBREAK; + /****************************************************************** * Comparison opcodes. ******************************************************************/ diff --git a/jit/jit-rules-interp.c b/jit/jit-rules-interp.c index 8377d0e..f7e5330 100644 --- a/jit/jit-rules-interp.c +++ b/jit/jit-rules-interp.c @@ -1103,6 +1103,47 @@ void _jit_gen_insn(jit_gencode_t gen, jit_function_t func, } /* Not reached */ + case JIT_OP_JUMP_TABLE: + { + jit_label_t *labels; + jit_nint num_labels; + jit_nint index; + + labels = (jit_label_t *) insn->value1->address; + num_labels = insn->value2->address; + + _jit_regs_spill_all(gen); + _jit_regs_load_to_top(gen, + insn->dest, + (insn->flags & (JIT_INSN_DEST_NEXT_USE | + JIT_INSN_DEST_LIVE)), + 0); + + jit_cache_opcode(&(gen->posn), insn->opcode); + jit_cache_native(&(gen->posn), num_labels); + for(index = 0; index < num_labels; index++) + { + block = jit_block_from_label(func, labels[index]); + if(!block) + { + return; + } + if(block->address) + { + /* We already know the address of the block */ + jit_cache_native(&(gen->posn), block->address); + } + else + { + /* Record this position on the block's fixup list */ + pc = (void **)(gen->posn.ptr); + jit_cache_native(&(gen->posn), block->fixup_absolute_list); + block->fixup_absolute_list = pc; + } + } + } + break; + case JIT_OP_ADDRESS_OF_LABEL: { /* Get the address of a particular label */ @@ -1751,6 +1792,15 @@ void _jit_gen_start_block(jit_gencode_t gen, jit_block_t block) } block->fixup_list = 0; + fixup = (void **)(block->fixup_absolute_list); + while(fixup != 0) + { + next = (void **)(fixup[0]); + fixup[0] = (void *)(jit_nint)((void **)(block->address)); + fixup = next; + } + block->fixup_absolute_list = 0; + /* If this is the exception catcher block, then we need to update the exception cookie for the function to point to here */ if(block->label == block->func->builder->catcher_label && -- 2.47.3