From 512565e326f2ac39c11bba0544da56c48da3f2d8 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 8 Jun 2009 23:46:04 +0200 Subject: [PATCH] Implement TABLESWITCH opcode Signed-off-by: Guennadi Liakhovetski --- src/interp/engine/interp_jem.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/interp/engine/interp_jem.c b/src/interp/engine/interp_jem.c index a9d72e7..a1a509a 100644 --- a/src/interp/engine/interp_jem.c +++ b/src/interp/engine/interp_jem.c @@ -41,6 +41,7 @@ #include #include +#include #include #include "arch/avr32_jem.h" @@ -1585,6 +1586,49 @@ static int opc_iinc(struct intrp_ctx *ctx) return 0; } +static int opc_tableswitch(struct intrp_ctx *ctx) +{ + /* On entry JPC points to "default" */ + int32_t dflt, high, low, *dflt_p; + int32_t idx; + uint32_t target; + uint8_t *tswitch; + int i; + + tswitch = (uint8_t *)(ctx->jem.jpc - 3); + dflt_p = (int32_t *)(ctx->jem.jpc & ~3); + + dflt = __be32_to_cpu(*dflt_p); + low = __be32_to_cpu(*(dflt_p + 1)); + high = __be32_to_cpu(*(dflt_p + 2)); + + ostack_pop_u32(ctx->frame->ostack, ctx->mb->max_stack, ctx->ostack, idx); + + if (idx < low || idx > high) + target = dflt; + else + target = __be32_to_cpu(*(dflt_p + 3 + idx - low)); + +#ifdef JEM_DEBUG + for (i = 0; i <= high - low; i++) { + int32_t *addr = dflt_p + 3 + i; + + if (!(i & 15)) + jam_dprintf("%p:", addr); + jam_dprintf(" 0x%x", *addr); + if ((i & 15) == 15 || i == high - low) + jam_dprintf("\n", addr); + } +#endif + + jam_dprintf("[%s] trap @%p, jpc 0x%x, default 0x%x @ %p, low %d, high %d, idx %d, target 0x%x\n", + __func__, tswitch, ctx->jem.jpc, dflt, dflt_p, low, high, idx, target); + + ctx->jem.jpc = (uint32_t)(tswitch + target); + + return 0; +} + static int opc_athrow(struct intrp_ctx *ctx) { Object *obj; @@ -1677,6 +1721,7 @@ static handler_fn *trap_handler_f[256] = { [OPC_INSTANCEOF] = opc_instanceof, [OPC_ATHROW] = opc_athrow, [OPC_LRETURN] = opc_ldreturn, + [OPC_TABLESWITCH] = opc_tableswitch, }; static handler_fn *exception_handler_f[] = { -- 2.11.4.GIT