issue #143 Remove NanoJIT backend

pull/167/head
Dibyendu Majumdar 6 years ago
parent 9fa20358b2
commit 55dc69d4c4

@ -11,17 +11,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# By default JIT is OFF
option(LLVM_JIT "Controls whether LLVM JIT compilation will be enabled, default is OFF" OFF)
option(NANO_JIT "Controls whether NanoJIT compilation will be enabled, default is OFF" OFF)
option(STATIC_BUILD "Build static version of Ravi, default is OFF" OFF)
option(EMBEDDED_DMRC "Controls whether the embedded dmrC feature should be enabled, default is OFF" OFF)
option(COMPUTED_GOTO "Controls whether the interpreter switch will use computed gotos on gcc/clang, default is OFF" ON)
option(ASM_VM "Controls whether to use the new VM (not ready yet! so don't turn on)" OFF)
if (LLVM_JIT AND NANO_JIT)
message(FATAL_ERROR
"Both LLVM_JIT and NANO_JIT cannot be set to ON at the same time")
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
@ -45,10 +39,6 @@ if (LLVM_JIT)
add_definitions(-DUSE_LLVM)
endif()
if (NANO_JIT)
set(EMBEDDED_DMRC ON)
endif()
if (EMBEDDED_DMRC)
add_definitions(-DUSE_DMR_C)
endif()
@ -58,12 +48,6 @@ if (COMPUTED_GOTO AND MSVC)
message(WARNING "Computed goto is not available with MSVC")
endif()
if (NANO_JIT)
find_package(NanoJIT REQUIRED)
include_directories(${NANOJITEXTRA_INCLUDE_DIRS})
add_definitions(-DUSE_NANOJIT)
endif()
if (NOT LLVM_JIT)
message(WARNING "LLVM will not be enabled; specify -DLLVM_JIT=ON to enable")
endif()
@ -184,10 +168,7 @@ if (LLVM_JIT)
src/ravi_llvmarith2.cpp src/ravi_llvmtforcall.cpp src/ravi_llvmrest.cpp
src/ravi_llvmluaapi.cpp)
endif ()
if (NANO_JIT)
set(NANO_JIT_SRCS src/ravi_nanojit.c)
endif()
if (NOT LLVM_JIT AND NOT NANO_JIT)
if (NOT LLVM_JIT)
set(NO_JIT_SRCS src/ravi_nojit.c)
endif()
# define the lua core source files
@ -299,18 +280,7 @@ if (EMBEDDED_DMRC)
)
include_directories("${PROJECT_SOURCE_DIR}/dmr_c/llvm-backend")
endif()
if (NANO_JIT)
set(DMR_C_JIT_SRCS
dmr_c/nanojit-backend/sparse-nanojit.c
)
set(DMR_C_JIT_HEADERS
dmr_c/nanojit-backend/dmr_c.h
)
include_directories("${PROJECT_SOURCE_DIR}/dmr_c/nanojit-backend")
endif()
endif()
if (MSVC OR APPLE)
source_group("dmrC Headers" FILES ${DMR_C_HEADERS} ${DMR_C_JIT_HEADERS})
@ -379,9 +349,7 @@ if (NOT STATIC_BUILD)
endif()
if (LLVM_JIT)
set (LIBRAVI_NAME libravillvm)
elseif (NANO_JIT)
set (LIBRAVI_NAME libravinanojit)
set (LIBRAVI_NAME libravillvm)
else()
set (LIBRAVI_NAME libravinojit)
endif()
@ -391,8 +359,7 @@ add_library(${LIBRAVI_NAME} ${LIBRAVI_BUILD_TYPE}
${RAVI_HEADERS}
${LUA_LIB_SRCS}
${LUA_CORE_SRCS}
${LLVM_JIT_SRCS}
${NANO_JIT_SRCS}
${LLVM_JIT_SRCS}
${NO_JIT_SRCS}
${DMR_C_HEADERS}
${DMR_C_SRCS}
@ -407,7 +374,7 @@ if (NOT STATIC_BUILD)
set_target_properties(${LIBRAVI_NAME} PROPERTIES PREFIX "")
endif ()
endif()
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${NANOJITEXTRA_LIBRARIES})
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS})
# Ravi executable
add_executable(ravi src/lua.c)
@ -432,7 +399,7 @@ add_test(TestVM test_vm)
add_test(TestMisc test_misc)
# Build VSCode Debug Adapter for Ravi
if (STATIC_BUILD AND NOT NANO_JIT)
if (STATIC_BUILD)
add_executable(testravidebug vscode-debugger/src/testravidebug.c vscode-debugger/src/json.c vscode-debugger/src/protocol.c)
target_link_libraries(testravidebug ${LIBRAVI_NAME})

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

@ -1,4 +0,0 @@
mkdir nanorelease
cd nanorelease
cmake -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=c:\ravi -G "Visual Studio 15 2017 Win64" -DNANO_JIT=ON ..
cd ..

@ -1,16 +0,0 @@
find_path(NANOJITEXTRA_INCLUDE_DIR nanojitextra.h
PATHS
c:/ravi/include/nanojit
~/ravi/include/nanojit
NO_DEFAULT_PATH
)
find_library(NANOJITEXTRA_LIBRARY
NAMES nanojitextra libnanojitextra libnanojitextra.dylib
PATHS
c:/ravi/lib
~/ravi/lib
)
set( NANOJITEXTRA_INCLUDE_DIRS "${NANOJITEXTRA_INCLUDE_DIR}" )
set( NANOJITEXTRA_LIBRARIES "${NANOJITEXTRA_LIBRARY}" )

@ -1,65 +0,0 @@
/******************************************************************************
* Copyright (C) 2015-2017 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
/******************************************************************************
* Copyright (C) 2015-2017 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#ifndef RAVI_NANOJIT_H
#define RAVI_NANOJIT_H
#include <ravi_jitshared.h>
#ifdef USE_NANOJIT
#include "dmr_c.h"
struct ravi_State {
NJXContextRef jit;
unsigned long long id; // counter to generate function names
int verbosity;
};
#ifdef __cplusplus
};
#endif
#endif /* USE_NANOJIT */
#endif /* RAVI_NANOJIT_H */

@ -48,10 +48,6 @@
#define ravi_xstringify(s) ravi_stringify(s)
#define ravi_stringify(s) #s
#define RAVI_OPTION_STRING3 " LLVM-" LLVM_VERSION_STRING " ORC=" ravi_xstringify(USE_ORC_JIT)
#elif USE_GCCJIT
#define RAVI_OPTION_STRING3 " gccjit"
#elif USE_NANOJIT
#define RAVI_OPTION_STRING3 " nanojit"
#else
#define RAVI_OPTION_STRING3 " nojit"
#endif

@ -1,397 +0,0 @@
/******************************************************************************
* Copyright (C) 2015 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#include <ravi_nanojit.h>
#include <ravijit.h>
#include <stddef.h>
#include <assert.h>
// FIXME should be in ravi_State
static int id = 0;
#define LUA_CORE
#include "lauxlib.h"
#include "lobject.h"
#include "lstate.h"
#include "lua.h"
static const char *errortext[] = {
"integer expected",
"number expected",
"integer[] expected",
"number[] expected",
"table expected",
"upvalue of integer type, cannot be set to non integer value",
"upvalue of number type, cannot be set to non number value",
"upvalue of integer[] type, cannot be set to non integer[] value",
"upvalue of number[] type, cannot be set to non number[] value",
"upvalue of table type, cannot be set to non table value",
NULL};
static void raise_error(lua_State *L, int errorcode) {
assert(errorcode >= 0 && errorcode <= Error_upval_needs_table);
luaG_runerror(L, errortext[errorcode]);
}
static bool register_builtin_arg1(NJXContextRef module, const char *name,
void *fp, enum NJXValueKind return_type,
enum NJXValueKind arg1) {
enum NJXValueKind args[1];
args[0] = arg1;
return NJX_register_C_function(module, name, fp, return_type, args, 1);
}
static bool register_builtin_arg2(NJXContextRef module, const char *name,
void *fp, enum NJXValueKind return_type,
enum NJXValueKind arg1,
enum NJXValueKind arg2) {
enum NJXValueKind args[2];
args[0] = arg1;
args[1] = arg2;
return NJX_register_C_function(module, name, fp, return_type, args, 2);
}
static bool register_builtin_arg3(NJXContextRef module, const char *name,
void *fp, enum NJXValueKind return_type,
enum NJXValueKind arg1,
enum NJXValueKind arg2,
enum NJXValueKind arg3) {
enum NJXValueKind args[3];
args[0] = arg1;
args[1] = arg2;
args[2] = arg3;
return NJX_register_C_function(module, name, fp, return_type, args, 3);
}
static bool register_builtin_arg4(NJXContextRef module, const char *name,
void *fp, enum NJXValueKind return_type,
enum NJXValueKind arg1,
enum NJXValueKind arg2,
enum NJXValueKind arg3,
enum NJXValueKind arg4) {
enum NJXValueKind args[4];
args[0] = arg1;
args[1] = arg2;
args[2] = arg3;
args[3] = arg4;
return NJX_register_C_function(module, name, fp, return_type, args, 4);
}
static bool register_builtin_arg5(NJXContextRef module, const char *name,
void *fp, enum NJXValueKind return_type,
enum NJXValueKind arg1,
enum NJXValueKind arg2,
enum NJXValueKind arg3,
enum NJXValueKind arg4,
enum NJXValueKind arg5) {
enum NJXValueKind args[5];
args[0] = arg1;
args[1] = arg2;
args[2] = arg3;
args[3] = arg4;
args[4] = arg5;
return NJX_register_C_function(module, name, fp, return_type, args, 5);
}
// Initialize the JIT State and attach it to the
// Global Lua State
// If a JIT State already exists then this function
// will return -1
int raviV_initjit(struct lua_State *L) {
global_State *G = G(L);
if (G->ravi_state != NULL) return -1;
ravi_State *jit = (ravi_State *)calloc(1, sizeof(ravi_State));
// The parameter true means we will be dumping stuff as we compile
jit->jit = NJX_create_context(false);
//extern void luaF_close (lua_State *L, StkId level);
register_builtin_arg2(jit->jit, "luaF_close", luaF_close, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P);
register_builtin_arg2(jit->jit, "raise_error", raise_error, NJXValueKind_V, NJXValueKind_P, NJXValueKind_I);
//extern int luaV_tonumber_(const TValue *obj, lua_Number *n);
register_builtin_arg2(jit->jit, "luaV_tonumber_", luaV_tonumber_, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P);
//extern int luaV_tointeger(const TValue *obj, lua_Integer *p, int mode);
register_builtin_arg3(jit->jit, "luaV_tointeger", luaV_tointeger, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
//extern int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres);
register_builtin_arg4(jit->jit, "luaD_poscall", luaD_poscall, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
//extern int luaV_equalobj(lua_State *L, const TValue *t1, const TValue *t2);\n"
register_builtin_arg3(jit->jit, "luaV_equalobj", luaV_equalobj, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//extern int luaV_lessthan(lua_State *L, const TValue *l, const TValue *r);\n"
register_builtin_arg3(jit->jit, "luaV_lessthan", luaV_lessthan, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//extern int luaV_lessequal(lua_State *L, const TValue *l, const TValue *r);\n"
register_builtin_arg3(jit->jit, "luaV_lessequal", luaV_lessequal, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//extern int luaV_execute(lua_State *L);
register_builtin_arg1(jit->jit, "luaV_execute", luaV_execute, NJXValueKind_I, NJXValueKind_P);
//extern void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val)
register_builtin_arg4(jit->jit, "luaV_gettable", luaV_gettable, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//extern void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val);
register_builtin_arg4(jit->jit, "luaV_settable", luaV_settable, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//int luaD_precall (lua_State *L, StkId func, int nresults, int op_call);
register_builtin_arg4(jit->jit, "luaD_precall", luaD_precall, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I, NJXValueKind_I);
//extern void raviV_op_newtable(lua_State *L, CallInfo *ci, TValue *ra, int b, int c)
register_builtin_arg5(jit->jit, "raviV_op_newtable", raviV_op_newtable, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I, NJXValueKind_I);
//extern void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, TValue *res);
register_builtin_arg5(jit->jit, "luaO_arith", luaO_arith, NJXValueKind_V, NJXValueKind_P, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//extern void raviV_op_newarrayint(lua_State *L, CallInfo *ci, TValue *ra);
register_builtin_arg3(jit->jit, "raviV_op_newarrayint", raviV_op_newarrayint, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//extern void raviV_op_newarrayfloat(lua_State *L, CallInfo *ci, TValue *ra);
register_builtin_arg3(jit->jit, "raviV_op_newarrayfloat", raviV_op_newarrayfloat, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//LUAI_FUNC void raviV_op_setlist(lua_State *L, CallInfo *ci, TValue *ra, int b, int c);
register_builtin_arg5(jit->jit, "raviV_op_setlist", raviV_op_setlist, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I, NJXValueKind_I);
//LUAI_FUNC void raviV_op_concat(lua_State *L, CallInfo *ci, int a, int b, int c);
register_builtin_arg5(jit->jit, "raviV_op_concat", raviV_op_concat, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I, NJXValueKind_I, NJXValueKind_I);
//LUAI_FUNC void raviV_op_closure(lua_State *L, CallInfo *ci, LClosure *cl, int a, int Bx);
register_builtin_arg5(jit->jit, "raviV_op_closure", raviV_op_closure, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I, NJXValueKind_I);
//LUAI_FUNC void raviV_op_vararg(lua_State *L, CallInfo *ci, LClosure *cl, int a, int b);
register_builtin_arg5(jit->jit, "raviV_op_vararg", raviV_op_vararg, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I, NJXValueKind_I);
// void luaV_objlen (lua_State *L, StkId ra, const TValue *rb)
register_builtin_arg3(jit->jit, "luaV_objlen", luaV_objlen, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P);
//int luaV_forlimit(const TValue *obj, lua_Integer *p, lua_Integer step, int *stopnow);
register_builtin_arg4(jit->jit, "luaV_forlimit", luaV_forlimit, NJXValueKind_I, NJXValueKind_P, NJXValueKind_P, NJXValueKind_Q, NJXValueKind_P);
// void raviV_op_setupval(lua_State *L, LClosure *cl, TValue *ra, int b);
register_builtin_arg4(jit->jit, "raviV_op_setupval", raviV_op_setupval, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
register_builtin_arg4(jit->jit, "raviV_op_setupvali", raviV_op_setupvali, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
register_builtin_arg4(jit->jit, "raviV_op_setupvalf", raviV_op_setupvalf, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
register_builtin_arg4(jit->jit, "raviV_op_setupvalai", raviV_op_setupvalai, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
register_builtin_arg4(jit->jit, "raviV_op_setupvalaf", raviV_op_setupvalaf, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
register_builtin_arg4(jit->jit, "raviV_op_setupvalt", raviV_op_setupvalt, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
//extern void luaD_call (lua_State *L, StkId func, int nResults);
register_builtin_arg3(jit->jit, "luaD_call", luaD_call, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_I);
//"extern void raviH_set_int(lua_State *L, Table *t, lua_Unsigned key, lua_Integer value);\n"
register_builtin_arg4(jit->jit, "raviH_set_int", raviH_set_int, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_Q, NJXValueKind_Q);
//"extern void raviH_set_float(lua_State *L, Table *t, lua_Unsigned key, lua_Number value);\n"
register_builtin_arg4(jit->jit, "raviH_set_float", raviH_set_float, NJXValueKind_V, NJXValueKind_P, NJXValueKind_P, NJXValueKind_Q, NJXValueKind_D);
G->ravi_state = jit;
return 0;
}
// Free up the JIT State
void raviV_close(struct lua_State *L) {
global_State *G = G(L);
if (G->ravi_state == NULL) return;
// All compiled functions will be deleted at this stage
NJX_destroy_context(G->ravi_state->jit);
free(G->ravi_state);
}
// Dump the IR
void raviV_dumpIR(struct lua_State *L, struct Proto *p) {
global_State *G = G(L);
if (G->ravi_state == NULL)
return;
membuff_t buf;
membuff_init(&buf, 4096);
char fname[30];
snprintf(fname, sizeof fname, "jit", G->ravi_state->id++);
ravi_compile_options_t options = { 0 };
options.codegen_type = RAVI_CODEGEN_ALL;
if (raviJ_codegen(L, p, &options, fname, &buf)) {
printf(buf.buf);
}
membuff_free(&buf);
}
// Dump the LLVM ASM
void raviV_dumpASM(struct lua_State *L, struct Proto *p) {
(void)L;
(void)p;
}
void raviV_setminexeccount(lua_State *L, int value) {
global_State *G = G(L);
if (!G->ravi_state) return;
// G->ravi_state->jit->min_exec_count_ = value;
}
int raviV_getminexeccount(lua_State *L) {
global_State *G = G(L);
// if (!G->ravi_state)
return 0;
// return G->ravi_state->jit->min_exec_count_;
}
void raviV_setmincodesize(lua_State *L, int value) {
global_State *G = G(L);
if (!G->ravi_state) return;
// G->ravi_state->jit->min_code_size_ = value;
}
int raviV_getmincodesize(lua_State *L) {
global_State *G = G(L);
// if (!G->ravi_state)
return 0;
// return G->ravi_state->jit->min_code_size_;
}
void raviV_setauto(lua_State *L, int value) {
global_State *G = G(L);
if (!G->ravi_state) return;
// G->ravi_state->jit->auto_ = value;
}
int raviV_getauto(lua_State *L) {
global_State *G = G(L);
// if (!G->ravi_state)
return 0;
// return G->ravi_state->jit->auto_;
}
// Turn on/off the JIT compiler
void raviV_setjitenabled(lua_State *L, int value) {
global_State *G = G(L);
if (!G->ravi_state) return;
// G->ravi_state->jit->enabled_ = value;
}
int raviV_getjitenabled(lua_State *L) {
global_State *G = G(L);
return G->ravi_state != NULL;
// return G->ravi_state->jit->enabled_;
}
void raviV_setoptlevel(lua_State *L, int value) {
global_State *G = G(L);
if (!G->ravi_state) return;
// G->ravi_state->jit->opt_level_ = value;
}
int raviV_getoptlevel(lua_State *L) {
global_State *G = G(L);
// if (!G->ravi_state)
return 0;
// return G->ravi_state->jit->opt_level_;
}
void raviV_setsizelevel(lua_State *L, int value) {
(void)L;
(void)value;
}
int raviV_getsizelevel(lua_State *L) {
(void)L;
return 0;
}
void raviV_setvalidation(lua_State *L, int value) {
(void)L;
(void)value;
}
int raviV_getvalidation(lua_State *L) {
(void)L;
return 0;
}
void raviV_setverbosity(lua_State *L, int value) {
(void)L;
(void)value;
}
int raviV_getverbosity(lua_State *L) {
(void)L;
return 0;
}
void raviV_setgcstep(lua_State *L, int value) {
(void)L;
(void)value;
}
int raviV_getgcstep(lua_State *L) {
(void)L;
return 0;
}
// Turn on/off the JIT compiler
void raviV_settraceenabled(lua_State *L, int value) {
(void)L;
(void)value;
}
int raviV_gettraceenabled(lua_State *L) {
(void)L;
return 0;
}
int raviV_compile_n(struct lua_State *L, struct Proto *p[], int n,
ravi_compile_options_t *options) {
int count = 0;
for (int i = 0; i < n; i++) {
if (raviV_compile(L, p[i], options)) count++;
}
return count > 0;
}
// Compile a Lua function
// If JIT is turned off then compilation is skipped
// Compilation occurs if either auto compilation is ON (subject to some
// thresholds)
// or if a manual compilation request was made
// Returns true if compilation was successful
int raviV_compile(struct lua_State *L, struct Proto *p,
ravi_compile_options_t *options) {
if (p->ravi_jit.jit_status == RAVI_JIT_COMPILED) return true;
else if (p->ravi_jit.jit_status == RAVI_JIT_CANT_COMPILE) return false;
if (options == NULL || !options->manual_request) return false;
if (!raviJ_cancompile(p)) {
p->ravi_jit.jit_status = RAVI_JIT_CANT_COMPILE;
return false;
}
global_State *G = G(L);
if (G->ravi_state == NULL) return false;
NJXContextRef context = G->ravi_state->jit;
if (context == NULL) return false;
membuff_t buf;
membuff_init(&buf, 4096);
char fname[30];
snprintf(fname, sizeof fname, "jit%lld", G->ravi_state->id++);
if (!raviJ_codegen(L, p, options, fname, &buf)) {
membuff_free(&buf);
p->ravi_jit.jit_status = RAVI_JIT_CANT_COMPILE;
return false;
}
int (*fp)(lua_State * L) = NULL;
//printf("%s\n", buf.buf);
#if 1
char *argv[] = {NULL};
if (!dmrC_nanocompile(0, argv, context, buf.buf)) {
printf("%s\n", buf.buf);
p->ravi_jit.jit_status = RAVI_JIT_CANT_COMPILE;
}
else {
fp = NJX_get_function_by_name(context, fname);
if (fp != NULL) {
p->ravi_jit.jit_data = NULL;
p->ravi_jit.jit_function = fp;
p->ravi_jit.jit_status = RAVI_JIT_COMPILED;
}
}
#else
p->ravi_jit.jit_status = RAVI_JIT_CANT_COMPILE;
#endif
membuff_free(&buf);
return fp != NULL;
}
// Free the JIT compiled function
// Note that this is called by the garbage collector
void raviV_freeproto(struct lua_State *L, struct Proto *p) {
(void)L;
(void)p;
}
Loading…
Cancel
Save