Alien-LibJIT
view release on metacpan or search on metacpan
libjit/jit/jit-interp.c view on Meta::CPAN
/*
* jit-interp.c - Fallback interpreter implementation.
*
* Copyright (C) 2004 Southern Storm Software, Pty Ltd.
*
* This file is part of the libjit library.
*
* The libjit library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 2.1 of
* the License, or (at your option) any later version.
*
* The libjit library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the libjit library. If not, see
* <http://www.gnu.org/licenses/>.
*/
/*
This file must be compiled with a C++ compiler, because it uses
C++ exceptions to manage JIT exception throws. It is otherwise
straight vanilla ANSI C.
*/
#include "jit-interp.h"
#include "jit-rules.h"
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_ALLOCA_H
#include <alloca.h>
#endif
#ifdef JIT_WIN32_PLATFORM
#include <malloc.h>
#ifndef alloca
#define alloca _alloca
#endif
#endif
#include "jit-setjmp.h"
#if defined(JIT_BACKEND_INTERP)
/*
* Determine what kind of interpreter dispatch to use.
*/
#ifdef HAVE_COMPUTED_GOTO
#if defined(PIC) && defined(HAVE_PIC_COMPUTED_GOTO)
#define JIT_INTERP_TOKEN_PIC 1
#elif defined(PIC)
#define JIT_INTERP_SWITCH 1
#else
#define JIT_INTERP_TOKEN 1
#endif
#else /* !HAVE_COMPUTED_GOTO */
#define JIT_INTERP_SWITCH 1
#endif /* !HAVE_COMPUTED_GOTO */
/*
* Modify the program counter and stack pointer.
*/
#define VM_MODIFY_PC_AND_STACK(pcmod,stkmod) \
do { \
pc += (jit_nint)(int)(pcmod); \
stacktop += (jit_nint)(int)(stkmod); \
} while (0)
#define VM_MODIFY_PC(pcmod) \
do { \
pc += (jit_nint)(int)(pcmod); \
} while (0)
#define VM_MODIFY_STACK(stkmod) \
do { \
stacktop += (jit_nint)(int)(stkmod); \
} while (0)
/*
* Fetch arguments of various types from the instruction stream.
*/
#define VM_NINT_ARG (((jit_nint *)(pc))[1])
#define VM_NINT_ARG2 (((jit_nint *)(pc))[2])
#define VM_NINT_ARG3 (((jit_nint *)(pc))[3])
#define VM_BR_TARGET (pc + VM_NINT_ARG)
/*
* Fetch registers of various types.
*/
#define VM_R0_INT (r0.int_value)
#define VM_R0_UINT (r0.uint_value)
#define VM_R0_LONG (r0.long_value)
#define VM_R0_ULONG (r0.ulong_value)
#define VM_R0_FLOAT32 (r0.float32_value)
#define VM_R0_FLOAT64 (r0.float64_value)
#define VM_R0_NFLOAT (r0.nfloat_value)
#define VM_R0_PTR (r0.ptr_value)
#define VM_R1_INT (r1.int_value)
#define VM_R1_UINT (r1.uint_value)
#define VM_R1_LONG (r1.long_value)
#define VM_R1_ULONG (r1.ulong_value)
#define VM_R1_FLOAT32 (r1.float32_value)
#define VM_R1_FLOAT64 (r1.float64_value)
#define VM_R1_NFLOAT (r1.nfloat_value)
#define VM_R1_PTR (r1.ptr_value)
#define VM_R2_INT (r2.int_value)
#define VM_R2_UINT (r2.uint_value)
#define VM_R2_LONG (r2.long_value)
#define VM_R2_ULONG (r2.ulong_value)
#define VM_R2_FLOAT32 (r2.float32_value)
#define VM_R2_FLOAT64 (r2.float64_value)
#define VM_R2_NFLOAT (r2.nfloat_value)
#define VM_R2_PTR (r2.ptr_value)
#ifdef JIT_NATIVE_INT32
#define VM_R0_NINT VM_RO_INT
#define VM_R0_NUINT VM_RO_UINT
#define VM_R1_NINT VM_R1_INT
#define VM_R1_NUINT VM_R1_UINT
#define VM_R2_NINT VM_R2_INT
#define VM_R2_NUINT VM_R2_UINT
( run in 0.474 second using v1.01-cache-2.11-cpan-8644d7adfcd )