issue #198 WIP add interface to RaviCompiler project

ravi-compiler
Dibyendu Majumdar 4 years ago
parent 40e020916a
commit 34c6b33a2f

@ -12,6 +12,9 @@ option(STATIC_BUILD "Build static version of Ravi, default is OFF" OFF)
option(COMPUTED_GOTO "Controls whether the interpreter switch will use computed gotos on gcc/clang, default is ON" ON) option(COMPUTED_GOTO "Controls whether the interpreter switch will use computed gotos on gcc/clang, default is ON" ON)
option(LTESTS "Controls whether ltests are enabled in Debug mode; note requires Debug build" ON) option(LTESTS "Controls whether ltests are enabled in Debug mode; note requires Debug build" ON)
option(ASAN "Controls whether address sanitizer should be enabled" OFF) option(ASAN "Controls whether address sanitizer should be enabled" OFF)
option(RAVICOMP "Controls whether to link in RaviComp" ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# By default on non-Windows platforms we enable MIR JIT # By default on non-Windows platforms we enable MIR JIT
if (NOT WIN32 if (NOT WIN32
@ -66,6 +69,7 @@ set(C2MIR_SRCS mir/c2mir/c2mir.c)
set(MIR_JIT_SRCS src/ravi_mirjit.c) set(MIR_JIT_SRCS src/ravi_mirjit.c)
set(NO_JIT_SRCS src/ravi_nojit.c) set(NO_JIT_SRCS src/ravi_nojit.c)
set(LUA_CMD_SRCS src/lua.c) set(LUA_CMD_SRCS src/lua.c)
set(RAVICOMP_SRCS src/ravi_complib.c)
file(GLOB RAVI_HEADERS "${PROJECT_SOURCE_DIR}/include/*.h") file(GLOB RAVI_HEADERS "${PROJECT_SOURCE_DIR}/include/*.h")
if (COMPUTED_GOTO AND NOT MSVC) if (COMPUTED_GOTO AND NOT MSVC)
@ -89,7 +93,6 @@ if (ASAN)
endif() endif()
endif() endif()
if (LLVM_JIT) if (LLVM_JIT)
find_package(LLVM REQUIRED CONFIG) find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
@ -133,10 +136,18 @@ else ()
endif () endif ()
endif () endif ()
if (RAVICOMP)
find_package(RaviComp REQUIRED)
set(ADDON_SRCS ${RAVICOMP_SRCS})
set_property(SOURCE ${RAVICOMP_SRCS}
APPEND
PROPERTY INCLUDE_DIRECTORIES ${RAVICOMP_INCLUDE_DIRS})
endif()
# IDE stuff # IDE stuff
if (MSVC OR APPLE) if (MSVC OR APPLE)
source_group("Ravi Headers" FILES ${RAVI_HEADERS}) source_group("Ravi Headers" FILES ${RAVI_HEADERS})
source_group("Ravi Source Files" FILES ${LUA_CORE_SRCS} ${LUA_LIB_SRCS} ${JIT_SRCS}) source_group("Ravi Source Files" FILES ${LUA_CORE_SRCS} ${LUA_LIB_SRCS} ${JIT_SRCS} ${ADDON_SRCS})
endif () endif ()
# Misc setup # Misc setup
@ -208,6 +219,7 @@ if (LLVM_JIT)
message(STATUS "LLVM_LIBS ${LLVM_LIBS}") message(STATUS "LLVM_LIBS ${LLVM_LIBS}")
endif () endif ()
set(LIBRAVI_NAME libravi) set(LIBRAVI_NAME libravi)
#Main library #Main library
@ -215,8 +227,9 @@ add_library(${LIBRAVI_NAME} ${LIBRAVI_BUILD_TYPE}
${RAVI_HEADERS} ${RAVI_HEADERS}
${LUA_LIB_SRCS} ${LUA_LIB_SRCS}
${LUA_CORE_SRCS} ${LUA_CORE_SRCS}
${JIT_SRCS}) ${JIT_SRCS}
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${MIRJIT_LIBRARIES}) ${ADDON_SRCS})
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${MIRJIT_LIBRARIES} ${RAVICOMP_LIBRARIES})
# Main Ravi executable # Main Ravi executable
add_executable(ravi ${LUA_CMD_SRCS}) add_executable(ravi ${LUA_CMD_SRCS})
@ -279,6 +292,13 @@ if (NOT STATIC_BUILD)
else () else ()
set_target_properties(${LIBRAVI_NAME} PROPERTIES PREFIX "") set_target_properties(${LIBRAVI_NAME} PROPERTIES PREFIX "")
endif () endif ()
if (RAVICOMP)
set_property(
TARGET ${LIBRAVI_NAME}
APPEND
PROPERTY COMPILE_DEFINITIONS "USE_RAVICOMP=1")
set(USE_RAVICOMP 1)
endif()
if (APPLE) if (APPLE)
set_property( set_property(
TARGET ${LIBRAVI_NAME} libravinojit_static TARGET ${LIBRAVI_NAME} libravinojit_static

@ -0,0 +1,14 @@
find_path(RAVICOMP_INCLUDE_DIRS ravi_compiler.h
PATHS
c:/Software/ravicomp/include/ravicomp
~/Software/ravicomp/include/ravicomp
NO_DEFAULT_PATH
)
find_library(RAVICOMP_LIBRARIES
NAMES ravicomp
PATHS
c:/Software/ravicomp/lib
~/Software/ravicomp/lib
)

@ -54,8 +54,10 @@ LUAMOD_API int (luaopen_package) (lua_State *L);
#define LUA_RAVILIBNAME "ravi" #define LUA_RAVILIBNAME "ravi"
LUAMOD_API int (raviopen_jit)(lua_State *L); LUAMOD_API int (raviopen_jit)(lua_State *L);
#define LUA_ASTLIBNAME "ast" #define LUA_RAVICOMPLIBNAME "compiler"
LUAMOD_API int (raviopen_ast_library)(lua_State *L); LUAMOD_API int (raviopen_compiler)(lua_State *L);
/* open all previous libraries */ /* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L); LUALIB_API void (luaL_openlibs) (lua_State *L);

@ -5,5 +5,6 @@
#cmakedefine USE_LLVM @USE_LLVM@ #cmakedefine USE_LLVM @USE_LLVM@
#cmakedefine USE_OMRJIT @USE_OMRJIT@ #cmakedefine USE_OMRJIT @USE_OMRJIT@
#cmakedefine USE_MIRJIT @USE_MIRJIT@ #cmakedefine USE_MIRJIT @USE_MIRJIT@
#cmakedefine USE_RAVICOMP @USE_RAVICOMP@
#endif //_REDUKTI_RAVI_CONFIG_H_IN_H #endif //_REDUKTI_RAVI_CONFIG_H_IN_H

@ -54,6 +54,9 @@ static const luaL_Reg loadedlibs[] = {
{LUA_BITLIBNAME, luaopen_bit32}, {LUA_BITLIBNAME, luaopen_bit32},
#endif #endif
{LUAJIT_BITLIBNAME, luaopen_bit }, {LUAJIT_BITLIBNAME, luaopen_bit },
#if defined(USE_RAVICOMP)
{LUA_RAVICOMPLIBNAME, raviopen_compiler },
#endif
{NULL, NULL} {NULL, NULL}
}; };

@ -0,0 +1,75 @@
#include "ravi_api.h"
#define LUA_CORE
#include "lua.h"
#include "lapi.h"
#include "lauxlib.h"
#include "lfunc.h"
#include "lmem.h"
#include "lstring.h"
#include "ltable.h"
struct CompilerContext {
lua_State* L;
Table* h; /* to avoid collection/reuse strings */
};
static Proto* lua_newProto(void* context, Proto* parent) {
struct CompilerContext* ccontext = (struct CompilerContext*)context;
lua_State* L = ccontext->L;
Proto* p = luaF_newproto(L);
if (parent) {
int old_size = parent->sizep;
int new_size = parent->sizep + 1;
luaM_growvector(L, parent->p, old_size, new_size, Proto*, MAXARG_Bx, "functions");
parent->p[parent->sizep++] = p;
// luaC_objbarrier(L, f, clp);
}
return p;
}
/*
** creates a new string and anchors it in scanner's table so that
** it will not be collected until the end of the compilation
** (by that time it should be anchored somewhere)
*/
//TString* create_newstring(lua_State* L, Table *h, const char* str, size_t l) {
// TValue* o; /* entry for 'str' */
// TString* ts = luaS_newlstr(L, str, l); /* create new string */
// setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */
// o = luaH_set(L, h, L->top - 1);
// if (ttisnil(o)) { /* not in use yet? */
// /* boolean value does not need GC barrier;
// table has no metatable, so it does not need to invalidate cache */
// setbvalue(o, 1); /* t[string] = true */
// luaC_checkGC(L);
// }
// else { /* string already present */
// ts = tsvalue(keyfromval(o)); /* re-use value previously stored */
// }
// L->top--; /* remove string from stack */
// return ts;
//}
/* Add a string constant to Proto and return its index */
static int lua_newStringConstant(void *context, Proto* proto, const char* s, unsigned len) {
struct CompilerContext* ccontext = (struct CompilerContext*)context;
lua_State* L = ccontext->L;
Table* h = ccontext->h;
//TString* ts = create_newstring(L, h, s, len);
}
/* Compile the C code for the given proto, and C source */
void lua_compileProto(lua_State* L, Proto* proto, const char* C_src, unsigned len) {
}
static const luaL_Reg ravilib[] = {
{NULL, NULL} };
int (raviopen_compiler)(lua_State *L) {
luaL_newlib(L, ravilib);
return 1;
}
Loading…
Cancel
Save