issue #135 setup dispatch table, some build updates and fixes

gccjit-ravi534
Dibyendu Majumdar 7 years ago
parent 592c2f4a47
commit aa02c2e124

@ -145,6 +145,41 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_definitions(-DLUA_USER_H="ltests.h")
endif ()
if (ASM_VM)
add_definitions(-DRAVI_USE_ASMVM)
set ( ASMVM_DEFS ${PROJECT_SOURCE_DIR}/include/ravi_asmvm_defs.h )
if (WIN32 AND NOT CYGWIN)
set(VMMODE peobj)
elseif (APPLE)
set(VMMODE machasm)
else()
set(VMMODE elfasm)
endif()
macro(add_buildvm_target _target _mode)
add_custom_command(OUTPUT ${_target}
COMMAND ${PROJECT_SOURCE_DIR}/vmbuilder/bin/buildvm ARGS -m ${_mode} -o ${_target} ${ARGN}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${PROJECT_SOURCE_DIR}/vmbuilder/bin/buildvm ${ARGN}
)
endmacro(add_buildvm_target)
if ( WIN32 AND NOT CYGWIN )
add_buildvm_target ( ${CMAKE_CURRENT_BINARY_DIR}/ravi_asmvm.obj ${VMMODE} )
set (ASMVM_SRC ${CMAKE_CURRENT_BINARY_DIR}/ravi_asmvm.obj)
else ()
add_buildvm_target ( ${CMAKE_CURRENT_BINARY_DIR}/ravi_asmvm.s ${VMMODE} )
set (ASMVM_SRC ${CMAKE_CURRENT_BINARY_DIR}/ravo_asmvm.s)
endif ()
add_buildvm_target ( ${ASMVM_DEFS} bcdef ${LJLIB_C} )
SET (ASMVM_DEPS
${ASMVM_SRC}
${ASMVM_DEFS}
)
endif()
# define LLVM JIT compiler sources
if (LLVM_JIT)
set(LLVM_JIT_SRCS src/ravi_llvmjit.cpp src/ravi_llvmtypes.cpp
@ -165,16 +200,6 @@ if (NANO_JIT)
set(NANO_JIT_SRCS src/ravi_nanojit.c)
endif()
if (NOT LLVM_JIT AND NOT GCC_JIT AND NOT NANO_JIT)
if (ASM_VM)
if (MSVC)
set(ASMVM_SRCS vmbuilder/src/vm.obj)
else()
set(ASMVM_SRCS vmbuilder/src/vm.s)
endif()
add_definitions(-DUSE_ASMVM)
else()
set(ASMVM_SRCS "")
endif()
set(NO_JIT_SRCS src/ravi_nojit.c)
endif()
# define the lua core source files
@ -387,7 +412,7 @@ add_library(${LIBRAVI_NAME} ${LIBRAVI_BUILD_TYPE}
${DMR_C_HEADERS}
${DMR_C_SRCS}
${DMR_C_JIT_SRCS}
${ASMVM_SRCS}
${ASMVM_DEPS}
)
if (NOT STATIC_BUILD)
if (WIN32)

@ -0,0 +1,4 @@
mkdir asmvm
cd asmvm
cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -DCMAKE_BUILD_TYPE=Debug -DASM_VM=ON -G "Visual Studio 15 Win64" ..
cd ..

@ -28,6 +28,10 @@
#include "ltable.h"
#include "ltm.h"
#ifdef RAVI_USE_ASMVM
#include "ravi_asmvm_defs.h"
#endif
#include "ravijit.h"
#include "ravi_profile.h"
@ -315,6 +319,23 @@ void raviE_default_writestringerror(const char *fmt, const char *p) {
fflush(stderr);
}
#ifdef RAVI_USE_ASMVM
/* Initialize dispatch table used by the ASM VM */
static void dispatch_init(global_State *G) {
uint32_t i;
ASMFunction *disp = G->dispatch;
for (int i = 0; i < NUM_OPCODES; i++) {
/*
Following computes an offset for the assembly routine for the given OpCode.
The offset is relative to the global symbol ravi_vm_asm_begin that is
generated as part of the VMBuilder code generation. All the bytecode
routines are at some offset to this global symbol.
*/
disp[i] = makeasmfunc(ravi_bytecode_offsets[i]);
}
}
#endif
LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
int i;
lua_State *L;
@ -364,6 +385,10 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
close_state(L);
L = NULL;
}
#ifdef RAVI_USE_ASMVM
/* setup dispatch table*/
dispatch_init(g);
#endif
#if RAVI_BYTECODE_PROFILING_ENABLED
raviV_init_profiledata(L);
#endif

@ -61,3 +61,5 @@ set(SRCS
# Buildvm
add_executable ( buildvm ${SRCS} ${HEADERS} ${DASM_T} )
install(TARGETS buildvm
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../bin)

@ -247,17 +247,18 @@ static void emit_bcdef(BuildCtx *ctx) {
fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n");
fprintf(ctx->fp, "/* ravi_bytecode_offsets contains offsets of OpCode implementations */\n");
/* Start of the ASM code. */
fprintf(ctx->fp, "#include <stdint.h>\n\n");
fprintf(ctx->fp, "extern char ravi_vm_asm_begin[];\n\n");
fprintf(ctx->fp, "/* Bytecode offsets are relative to ravi_vm_asm_begin. */\n");
fprintf(ctx->fp, "/* Internal assembler functions. Never call these directly from C. */\n");
fprintf(ctx->fp, "typedef void (*ASMFunction)(void);\n\n");
fprintf(ctx->fp, "#define makeasmfunc(ofs) ((ASMFunction)(ravi_vm_asm_begin + (ofs)))\n\n");
fprintf(ctx->fp, "const uint16_t ravi_bytecode_offsets[] = {\n");
fprintf(ctx->fp, "static const uint16_t ravi_bytecode_offsets[] = {\n");
for (i = 0; i < ctx->SizeofDispatchTable; i++) {
if (i != 0) fprintf(ctx->fp, ",\n");
fprintf(ctx->fp, "%d", ctx->DispatchTableOffsets[i]);
}
fprintf(ctx->fp, "\n}\n");
fprintf(ctx->fp, "\n};\n");
}
/* -- Argument parsing ---------------------------------------------------- */

Loading…
Cancel
Save