gccjit-ravi534
Dibyendu Majumdar 8 years ago
parent c6ee38a14e
commit 5a83899351

@ -253,15 +253,16 @@ if (NOT STATIC_BUILD)
endif()
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${GCCJIT_LIBRARIES})
# Ravi executable
add_executable(ravi src/lua.c)
target_link_libraries(ravi ${LIBRAVI_NAME})
#VM test
# Simple VM tests
add_executable(test_vm tests/test_vm.c)
target_link_libraries(test_vm ${LIBRAVI_NAME})
if (LLVM_JIT)
#LLVM playground
# LLVM playground
add_executable(test_llvm tests/test_llvm.cpp)
target_link_libraries(test_llvm ${LIBRAVI_NAME})
endif ()
@ -274,21 +275,8 @@ endif ()
add_test(TestVM test_vm)
add_test(TestMisc test_misc)
# Build VSCode Debug Adapter for Ravi
if (STATIC_BUILD AND NOT GCC_JIT)
#Static library for the debugger
#add_library(libravinojit
# ${RAVI_HEADERS}
# ${LUA_LIB_SRCS}
# ${LUA_CORE_SRCS}
# src/ravi_nojit.c)
#if (WIN32)
# # enable DLL export
# set_target_properties(libravistatic PROPERTIES DEFINE_SYMBOL "LUA_BUILD_AS_DLL")
#else()
# set_target_properties(libravistatic PROPERTIES PREFIX "")
#endif ()
#target_link_libraries(libravistatic ${EXTRA_LIBRARIES})
add_executable(testravidebug vscode-debugger/src/testravidebug.c vscode-debugger/src/json.c vscode-debugger/src/protocol.c)
target_link_libraries(testravidebug ${LIBRAVI_NAME})

@ -308,6 +308,9 @@ OP_RAVI_MOVETAB, /* A B R(A) := R(B), check R(B) is a table */
OP_RAVI_SETUPVALT,/* A B UpValue[B] := to_table(R(A)) */
OP_RAVI_SELF_S,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
/* Following opcodes are specialized for access where the
key is known to be string but the variable may or may not be
a table */
OP_RAVI_GETTABLE_SK, /* A B C R(A) := R(B)[RK(C)], string key */
OP_RAVI_SELF_SK, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
OP_RAVI_SETTABLE_SK,/* A B C R(A)[RK(B)] := RK(C), string key */

@ -136,7 +136,5 @@ LUAI_FUNC void raviV_op_setupvalt(lua_State *L, LClosure *cl, TValue *ra, int b)
LUAI_FUNC void raviV_op_setupval(lua_State *L, LClosure *cl, TValue *ra, int b);
LUAI_FUNC void raviV_op_shl(lua_State *L, TValue *ra, TValue *rb, TValue *rc);
LUAI_FUNC void raviV_op_shr(lua_State *L, TValue *ra, TValue *rb, TValue *rc);
LUAI_FUNC void raviV_finishget(lua_State *L, const TValue *t, TValue *key, StkId val);
#endif

@ -65,21 +65,6 @@
#include <vector>
#include <memory>
//#if 0
//#if defined(LUA_BUILD_AS_DLL)
//#if defined(_WIN32)
//#if defined(RAVI_LIB)
//#define RAVI_API __declspec(dllexport)
//#else
//#define RAVI_API __declspec(dllimport)
//#endif
//#else
//#define RAVI_API extern
//#endif
//#else
//#define RAVI_API extern
//#endif
#endif
#endif

@ -66,8 +66,6 @@ extern "C" {
#include <iterator>
#include <type_traits>
#define RAVI_API
namespace ravi {
/*
@ -271,7 +269,6 @@ struct LuaLLVMTypes {
llvm::FunctionType *raviV_op_setupvalaiT;
llvm::FunctionType *raviV_op_setupvalafT;
llvm::FunctionType *raviV_op_setupvaltT;
llvm::FunctionType *raviV_finishgetT;
llvm::FunctionType *raviH_set_intT;
llvm::FunctionType *raviH_set_floatT;
@ -358,18 +355,18 @@ struct LuaLLVMTypes {
// via a shared_ptr. This ensures that RaviJITModule gets
// released when no longer referenced.
class RAVI_API RaviJITState;
class RAVI_API RaviJITModule;
class RAVI_API RaviJITFunction;
class RaviJITState;
class RaviJITModule;
class RaviJITFunction;
class RAVI_API RaviJITStateFactory {
class RaviJITStateFactory {
public:
static std::unique_ptr<RaviJITState> newJITState();
};
// A wrapper for LLVM Module
// Maintains a dedicated ExecutionEngine for the module
class RAVI_API RaviJITModule {
class RaviJITModule {
// The Context that owns this module
RaviJITState *owner_;
@ -428,7 +425,7 @@ class RAVI_API RaviJITModule {
// This object is stored in the Lua Proto structure
// and gets destroyed when the Lua function is
// garbage collected
class RAVI_API RaviJITFunction {
class RaviJITFunction {
// The Module in which this function lives
// We hold a shared_ptr to the module so that
// the module will be destroyed when the
@ -482,7 +479,7 @@ class RAVI_API RaviJITFunction {
// Ravi's LLVM JIT State
// All of the JIT information is held here
class RAVI_API RaviJITState {
class RaviJITState {
// The LLVM Context
llvm::LLVMContext *context_;
@ -641,7 +638,6 @@ struct RaviFunctionDef {
llvm::Function *raviV_op_setupvalaiF;
llvm::Function *raviV_op_setupvalafF;
llvm::Function *raviV_op_setupvaltF;
llvm::Function *raviV_finishgetF;
// array setters
llvm::Function *raviH_set_intF;

@ -527,6 +527,7 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
return "for iterator";
}
/* all other instructions can call only through metamethods */
/* Ravi: added GETTABLE_SK and SELF_SK because the call may be through metamethod rather than table */
case OP_SELF: case OP_GETTABUP: case OP_GETTABLE: case OP_RAVI_GETTABLE_SK: case OP_RAVI_SELF_SK:
tm = TM_INDEX;
break;

@ -157,9 +157,9 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"SETUPVALT", /* A B UpValue[B] := to_table(R(A)) */
"SELF_S", /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
// TODO temporary hack to allow existing tests to see old opcode names
"GETTABLE", /* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"SELF", /* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETTABLE", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
"GETTABLE_SK", /* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"SELF_SK", /* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETTABLE_SK", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
NULL
};
@ -627,8 +627,20 @@ static void setnameval(lua_State *L, const char *name, int val) {
static char *buildop2(Proto *p, int pc, char *buff, size_t len) {
int line = getfuncline(p, pc);
snprintf(buff, len, "(%4d) %4d - ", line, pc);
raviP_instruction_to_str(buff + strlen(buff), len - strlen(buff), p->code[pc]);
char tbuf[100];
raviP_instruction_to_str(tbuf, sizeof tbuf, p->code[pc]);
/* This is a temporary hack to output old opcode names to prevent tests from breaking */
if (strncmp(tbuf, luaP_opnames[OP_RAVI_GETTABLE_SK], strlen(luaP_opnames[OP_RAVI_GETTABLE_SK])) == 0 ||
strncmp(tbuf, luaP_opnames[OP_RAVI_SELF_SK], strlen(luaP_opnames[OP_RAVI_SELF_SK])) == 0 ||
strncmp(tbuf, luaP_opnames[OP_RAVI_SETTABLE_SK], strlen(luaP_opnames[OP_RAVI_SETTABLE_SK])) == 0) {
char *cp = strstr(tbuf, "_SK ");
if (cp != NULL) {
cp[0] = ' ';
cp[1] = ' ';
cp[2] = ' ';
}
}
snprintf(buff, len, "(%4d) %4d - %s", line, pc, tbuf);
return buff;
}

@ -610,23 +610,26 @@ const TValue *luaH_getstr (Table *t, TString *key) {
/*
** main search function
*/
const TValue *luaH_get (Table *t, const TValue *key) {
switch (ttype(key)) {
case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));
case LUA_TNUMINT: return luaH_getint(t, ivalue(key));
case LUA_TNIL: return luaO_nilobject;
case LUA_TNUMFLT: {
lua_Integer k;
if (luaV_tointeger(key, &k, 0)) /* index is int? */
return luaH_getint(t, k); /* use specialized version */
/* else... */
} /* FALLTHROUGH */
default:
return getgeneric(t, key);
const TValue *luaH_get(Table *t, const TValue *key) {
int tt = ttype(key);
if (tt == LUA_TSHRSTR)
return luaH_getshortstr(t, tsvalue(key));
else if (tt == LUA_TNUMINT)
return luaH_getint(t, ivalue(key));
else if (tt == LUA_TNIL)
return luaO_nilobject;
else if (tt == LUA_TNUMFLT) {
lua_Integer k;
if (luaV_tointeger(key, &k, 0)) /* index is int? */
return luaH_getint(t, k); /* use specialized version */
/* else... */
return getgeneric(t, key);
} /* FALLTHROUGH */
else {
return getgeneric(t, key);
}
}
/*
** beware: when using this function you probably need to check a GC
** barrier and invalidate the TM cache.

@ -250,7 +250,7 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
luaG_runerror(L, "'__newindex' chain too long; possible loop");
}
static inline void GETTABLE_INLINE(lua_State *L, const TValue *t, TValue *key, StkId val) {
static inline void gettable_inline(lua_State *L, const TValue *t, TValue *key, StkId val) {
if (!ttistable(t) || hvalue(t)->ravi_array.array_type == RAVI_TTABLE) {
const TValue *slot;
if (luaV_fastget(L, t, key, slot, luaH_get)) { setobj2s(L, val, slot); }
@ -269,7 +269,7 @@ static inline void GETTABLE_INLINE(lua_State *L, const TValue *t, TValue *key, S
}
}
static inline void SETTABLE_INLINE(lua_State *L, const TValue *t, TValue *key, StkId val) {
static inline void settable_inline(lua_State *L, const TValue *t, TValue *key, StkId val) {
if (!ttistable(t) || hvalue(t)->ravi_array.array_type == RAVI_TTABLE) {
const TValue *slot;
if (!luaV_fastset(L, t, key, slot, luaH_get, val))
@ -318,7 +318,7 @@ static inline void SETTABLE_INLINE(lua_State *L, const TValue *t, TValue *key, S
** so that JIT code can invoke it
*/
void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
GETTABLE_INLINE(L, t, key, val);
gettable_inline(L, t, key, val);
}
@ -329,7 +329,7 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
** so that JIT code can invoke it
*/
void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
SETTABLE_INLINE(L, t, key, val);
settable_inline(L, t, key, val);
}
@ -941,16 +941,13 @@ int luaV_execute (lua_State *L) {
case OP_GETTABUP: {
TValue *upval = cl->upvals[GETARG_B(i)]->v; /* table */
TValue *rc = RKC(i); /* key */
GETTABLE_INLINE(L, upval, rc, ra);
gettable_inline(L, upval, rc, ra);
Protect((void)0);
} break;
#if 0
case OP_RAVI_GETTABLE_SK:
#endif
case OP_GETTABLE: {
StkId rb = RB(i); /* table */
TValue *rc = RKC(i); /* key */
GETTABLE_INLINE(L, rb, rc, ra);
gettable_inline(L, rb, rc, ra);
Protect((void)0);
} break;
@ -968,7 +965,7 @@ int luaV_execute (lua_State *L) {
TValue *rb = RKB(i);
TValue *t = (op == OP_SETTABUP) ? cl->upvals[GETARG_A(i)]->v : ra;
TValue *rc = RKC(i);
SETTABLE_INLINE(L, t, rb, rc);
settable_inline(L, t, rb, rc);
Protect((void)0);
} break;
@ -1616,21 +1613,20 @@ int luaV_execute (lua_State *L) {
setobj2s(L, ra, v);
}
else {
//Protect(raviV_finishget(L, rb, rc, ra));
Protect(luaV_finishget(L, rb, rc, ra, v));
}
} break;
#if 1
/* This opcode is used when the key is known to be
short string but the variable may or may not be
a table
*/
case OP_RAVI_GETTABLE_SK: {
StkId rb = RB(i); /* variable - may not be a table */
StkId rb = RB(i); /* variable - may not be a table */
lua_assert(ISK(GETARG_C(i)));
TValue *rc = k + INDEXK(GETARG_C(i)); /* we know that the key a short string constant */
/* we know that the key a short string constant */
TValue *rc = k + INDEXK(GETARG_C(i));
if (!ttistable(rb)) {
GETTABLE_INLINE(L, rb, rc, ra);
gettable_inline(L, rb, rc, ra);
Protect((void)0);
}
else {
@ -1644,17 +1640,15 @@ int luaV_execute (lua_State *L) {
}
else {
Protect(luaV_finishget(L, rb, rc, ra, v));
//Protect(raviV_finishget(L, rb, rc, ra));
}
}
break;
}
#endif
case OP_RAVI_SELF_S:
case OP_RAVI_GETTABLE_S: {
/* Following is an inline version of luaH_getstr() - this is
* not ideal as there is code duplication; should be changed to a common
* macro which can be used in bothe places
/* This opcode is used when the key is known to be
short string and the variable is known to be
a table
*/
StkId rb = RB(i);
if (op == OP_RAVI_SELF_S) { setobjs2s(L, ra + 1, rb); }
@ -1664,33 +1658,11 @@ int luaV_execute (lua_State *L) {
TString *key = tsvalue(rc);
lua_assert(key->tt == LUA_TSHRSTR);
Table *h = hvalue(rb);
#if 0
int position = lmod(key->hash, sizenode(h));
Node *n = &h->node[position];
const TValue *v;
for (;;) { /* check whether 'key' is somewhere in the chain */
const TValue *k = gkey(n);
if (ttisshrstring(k) && eqshrstr(tsvalue(k), key)) {
v = gval(n); /* that's it */
break;
}
else {
int nx = gnext(n);
if (nx == 0) {
v = luaO_nilobject;
break;
}
n += nx;
}
}
#else
const TValue *v = luaH_getshortstr(h, key);
#endif
if (!ttisnil(v) || metamethod_absent(h->metatable, TM_INDEX)) {
setobj2s(L, ra, v);
}
else {
//Protect(raviV_finishget(L, rb, rc, ra));
Protect(luaV_finishget(L, rb, rc, ra, v));
}
}
@ -2337,27 +2309,6 @@ void raviV_op_shr(lua_State *L, TValue *ra, TValue *rb, TValue *rc) {
}
}
void raviV_finishget(lua_State *L, const TValue *t, TValue *key, StkId val) {
int loop; /* counter to avoid infinite loops */
const TValue *tm = luaT_gettm(hvalue(t), TM_INDEX, G(L)->tmname[TM_INDEX]);
for (loop = 0; loop < MAXTAGLOOP; loop++) {
if (tm == NULL) { /* no metamethod (from a table)? */
if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
luaG_typeerror(L, t, "index"); /* no metamethod */
}
if (ttisfunction(tm)) { /* metamethod is a function */
luaT_callTM(L, tm, t, key, val, 1); /* call it */
return;
}
t = tm; /* else repeat access over 'tm' */
if (luaV_fastget(L, t, key, tm, luaH_get)) { /* try fast track */
setobj2s(L, val, tm); /* done */
return;
}
/* else repeat */
}
luaG_runerror(L, "gettable chain too long; possible loop");
}
/* }================================================================== */

@ -1165,9 +1165,6 @@ void RaviCodeGenerator::emit_extern_declarations(RaviFunctionDef *def) {
def->raviV_op_setupvaltF = def->raviF->addExternFunction(
def->types->raviV_op_setupvaltT,
reinterpret_cast<void *>(&raviV_op_setupvalt), "raviV_op_setupvalt");
def->raviV_finishgetF = def->raviF->addExternFunction(
def->types->raviV_finishgetT, reinterpret_cast<void *>(&raviV_finishget),
"raviV_finishget");
def->ravi_dump_valueF = def->raviF->addExternFunction(
def->types->ravi_dump_valueT, reinterpret_cast<void *>(&ravi_dump_value),

@ -143,7 +143,7 @@ void RaviCodeGenerator::emit_GETTABLE_I(RaviFunctionDef *def, int A, int B,
// setobj2s(L, ra, v);
//}
//else {
// Protect(raviV_finishget(L, rb, rc, ra));
// Protect(luaV_finishget(L, rb, rc, ra, v));
//}
emit_debug_trace(def, OP_RAVI_GETTABLE_I, pc);
@ -218,7 +218,6 @@ void RaviCodeGenerator::emit_finish_GETTABLE(RaviFunctionDef *def, llvm::Value *
// If value is nil Lua requires that an index event be
// generated - so we fall back on slow path for that
//CreateCall4(def->builder, def->raviV_finishgetF, def->L, rb, rc, ra);
CreateCall5(def->builder, def->luaV_finishgetF, def->L, rb, rc, ra, phi);
def->builder->CreateBr(if_end_block);
@ -248,7 +247,7 @@ void RaviCodeGenerator::emit_common_GETTABLE_S(RaviFunctionDef *def, int A, int
// setobj2s(L, ra, v);
// }
// else {
// Protect(raviV_finishget(L, rb, rc, ra));
// Protect(luaV_finishget(L, rb, rc, ra, v));
// }
// A number of macros are involved above do the

@ -797,9 +797,6 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
// void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val)
luaV_settableT =
llvm::FunctionType::get(llvm::Type::getVoidTy(context), elements, false);
// void raviV_finishget(lua_State *L, const TValue *t, TValue *key, StkId val);
raviV_finishgetT =
llvm::FunctionType::get(llvm::Type::getVoidTy(context), elements, false);
// void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
// StkId val, const TValue *slot);
elements.push_back(pTValueT);

Loading…
Cancel
Save