issue #135 wiring stuff together

gccjit-ravi534
Dibyendu Majumdar 7 years ago
parent aa02c2e124
commit 65fc6adc0d

@ -140,12 +140,16 @@ if (APPLE)
endif ()
include_directories("${PROJECT_SOURCE_DIR}/include")
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG")
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND NOT ASM_VM)
# Note that enabling ltests.h messes with global_State and thus interferes with ASM_VM
message(STATUS "Enabling Lua extended test harness 'ltests'")
add_definitions(-DLUA_USER_H="ltests.h")
endif ()
if (ASM_VM)
# For now we switch to static build
# TODO A fix is needed to ensure that in shared library the asm functions are resolved
set(STATIC_BUILD ON)
add_definitions(-DRAVI_USE_ASMVM)
set ( ASMVM_DEFS ${PROJECT_SOURCE_DIR}/include/ravi_asmvm_defs.h )
if (WIN32 AND NOT CYGWIN)
@ -156,6 +160,7 @@ if (ASM_VM)
set(VMMODE elfasm)
endif()
# This macro runs the buildvm command to generate the VM code
macro(add_buildvm_target _target _mode)
add_custom_command(OUTPUT ${_target}
COMMAND ${PROJECT_SOURCE_DIR}/vmbuilder/bin/buildvm ARGS -m ${_mode} -o ${_target} ${ARGN}
@ -164,6 +169,7 @@ if (ASM_VM)
)
endmacro(add_buildvm_target)
# Generate ravi_asmvm.obj / ravi_asmvm.s (obj on Windows)
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)
@ -172,6 +178,7 @@ if (ASM_VM)
set (ASMVM_SRC ${CMAKE_CURRENT_BINARY_DIR}/ravo_asmvm.s)
endif ()
# Generate the ravi_bcdef.h header file
add_buildvm_target ( ${ASMVM_DEFS} bcdef ${LJLIB_C} )
SET (ASMVM_DEPS
@ -470,4 +477,3 @@ install(TARGETS ${LIBRAVI_NAME} ravi ${RAVI_DEBUGGER_TARGET}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)

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

@ -322,15 +322,15 @@ void raviE_default_writestringerror(const char *fmt, const char *p) {
#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++) {
for (uint32_t 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.
*/
/* NOTE: enabling ltests.h modifies the global_State and breaks the assumptions abou the location of the dispatch table */
disp[i] = makeasmfunc(ravi_bytecode_offsets[i]);
}
}
@ -386,7 +386,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
L = NULL;
}
#ifdef RAVI_USE_ASMVM
/* setup dispatch table*/
/* setup dispatch table - this is only used by the new ASM VM - see vmbuilder */
dispatch_init(g);
#endif
#if RAVI_BYTECODE_PROFILING_ENABLED

@ -1268,6 +1268,13 @@ int luaV_execute (lua_State *L) {
newframe: /* reentry point when frame changes (call/return) */
lua_assert(ci == L->ci);
cl = clLvalue(ci->func); /* local reference to function's closure */
#ifdef RAVI_USE_ASMVM
// This is a temporary hack to test the under development ASM VM.
if (cl->p->sizecode == 1) { /* single bytecode means only OP_RETURN */
extern int ravi_luaV_interp(lua_State *L);
return ravi_luaV_interp(L);
}
#endif
k = cl->p->k; /* local reference to function's constant table */
updatemask(L);
base = ci->u.l.base; /* local copy of function's base */

@ -7,21 +7,16 @@
project ( vmbuilder C )
cmake_minimum_required ( VERSION 2.8 )
if ( WIN32 AND NOT CYGWIN )
set ( LJVM_MODE peobj )
elseif ( APPLE )
set ( LJVM_MODE machasm )
list ( APPEND LIBS m )
else ()
set ( LJVM_MODE elfasm )
list ( APPEND LIBS m )
if ( APPLE )
list ( APPEND LIBS m )
elseif ( NOT WIN32 )
list ( APPEND LIBS m )
endif ()
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
## GENERATE VM
# Build minilua
add_executable ( minilua minilua.c )
target_link_libraries ( minilua ${LIBS} )
@ -35,7 +30,7 @@ set ( DASM_T ${CMAKE_CURRENT_SOURCE_DIR}/buildvm_arch.h )
# Windows is ... special
if ( WIN32 )
list ( APPEND DASM_FLAGS -D WIN )
list ( APPEND DASM_FLAGS -D WIN )
endif ()
list ( APPEND DASM_FLAGS -D P64 )
@ -44,13 +39,15 @@ set ( DASM_DASC ${CMAKE_CURRENT_SOURCE_DIR}/vm_x64.dasc )
# Generate buildvm arch header
add_custom_command(OUTPUT ${DASM_T}
COMMAND minilua ${DASM} -MF ${DASM_FLAGS} -o ${DASM_T} ${DASM_DASC}
DEPENDS minilua ${DASM_DASC}
COMMAND minilua ${DASM} -MF ${DASM_FLAGS} -o ${DASM_T} ${DASM_DASC}
DEPENDS minilua ${DASM_DASC}
)
set(HEADERS
../../include/ravi_arch.h
../../include/ravi_def.h)
../../include/ravi_def.h
../dynasm/dasm_proto.h
../dynasm/dasm_x86.h)
set(SRCS
buildvm.c

@ -14,9 +14,19 @@
** It's a one-shot tool -- any effort fixing this would be wasted.
*/
#include "buildvm.h"
#include "lua.h"
#define LUA_CORE
#include "lprefix.h"
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
@ -27,6 +37,11 @@
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lvm.h"
#include "ravi_profile.h"
#include "buildvm.h"
#if defined(_WIN32)
#include <fcntl.h>
#include <io.h>
@ -387,7 +402,6 @@ int main(int argc, char **argv) {
exit(1);
}
fclose(ctx->fp);
return 0;
}

@ -298,7 +298,7 @@ static void build_OP_RETURN(BuildCtx *ctx)
|// RA ecx has A, RB edx has OpCode
|
| mov KBASE, RCa // Save the bytecode into KBASE as we don't need KBASE anymore
| mov PROTO:TMP1, LCL->p // TMP1 = ci->p
| mov PROTO:TMP1, LCL->p // TMP1 = ci->p
| cmp dword PROTO:TMP1->sizep, 0 // Test ci->p->sizep == 0
| jle >1 // Skip call to luaF_close
|
@ -313,6 +313,8 @@ static void build_OP_RETURN(BuildCtx *ctx)
| mov RCa, KBASE
| ins_AB_ // RA = A, RB = B
|
| // temporary hack - return
| mov rax, 0
| restoreregs
| ret
}

Loading…
Cancel
Save