issue #128 add initial skeleton files
parent
f07efc720d
commit
95779e058c
@ -0,0 +1,16 @@
|
||||
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}" )
|
@ -0,0 +1,90 @@
|
||||
/******************************************************************************
|
||||
* 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
|
||||
|
||||
#ifdef USE_NANOJIT
|
||||
#include "dmr_c.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TODO we probably do not need all the headers
|
||||
// below
|
||||
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lprefix.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "ldebug.h"
|
||||
#include "ldo.h"
|
||||
#include "lfunc.h"
|
||||
#include "lobject.h"
|
||||
#include "lopcodes.h"
|
||||
#include "lstate.h"
|
||||
#include "lstring.h"
|
||||
#include "ltable.h"
|
||||
#include "lvm.h"
|
||||
|
||||
typedef enum {
|
||||
LUA__TNIL = LUA_TNIL,
|
||||
LUA__TBOOLEAN = LUA_TBOOLEAN,
|
||||
LUA__TLIGHTUSERDATA = LUA_TLIGHTUSERDATA,
|
||||
LUA__TNUMBER = LUA_TNUMBER,
|
||||
LUA__TSTRING = ctb(LUA_TSTRING),
|
||||
LUA__TTABLE = ctb(LUA_TTABLE),
|
||||
RAVI__TLTABLE = ctb(LUA_TTABLE),
|
||||
RAVI__TIARRAY = ctb(RAVI_TIARRAY),
|
||||
RAVI__TFARRAY = ctb(RAVI_TFARRAY),
|
||||
LUA__TFUNCTION = ctb(LUA_TFUNCTION),
|
||||
LUA__TUSERDATA = ctb(LUA_TUSERDATA),
|
||||
LUA__TTHREAD = ctb(LUA_TTHREAD),
|
||||
LUA__TLCL = ctb(LUA_TLCL),
|
||||
LUA__TLCF = LUA_TLCF,
|
||||
LUA__TCCL = ctb(LUA_TCCL),
|
||||
LUA__TSHRSTR = ctb(LUA_TSHRSTR),
|
||||
LUA__TLNGSTR = ctb(LUA_TLNGSTR),
|
||||
LUA__TNUMFLT = LUA_TNUMFLT,
|
||||
LUA__TNUMINT = LUA_TNUMINT
|
||||
} lua_typecode_t;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* USE_GCCJIT */
|
||||
|
||||
#endif /* RAVI_RAVI_GCCJIT_H */
|
@ -0,0 +1,291 @@
|
||||
/******************************************************************************
|
||||
* 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 <stddef.h>
|
||||
#include <ravijit.h>
|
||||
#include "ravi_nanojit.h"
|
||||
|
||||
#if 0
|
||||
ravi_gcc_context_t *ravi_jit_new_context(void) {
|
||||
ravi_gcc_context_t *ravi = NULL;
|
||||
gcc_jit_context *gcc_ctx = gcc_jit_context_acquire();
|
||||
if (!gcc_ctx) {
|
||||
fprintf(stderr, "failed to allocate a GCC JIT context\n");
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
ravi = (ravi_gcc_context_t *)calloc(1, sizeof(ravi_gcc_context_t));
|
||||
if (!ravi) {
|
||||
fprintf(stderr, "failed to allocate a Ravi JIT context\n");
|
||||
goto on_error;
|
||||
}
|
||||
ravi->context = gcc_ctx;
|
||||
ravi->auto_ = false;
|
||||
ravi->enabled_ = true;
|
||||
ravi->min_code_size_ = 150;
|
||||
ravi->min_exec_count_ = 50;
|
||||
ravi->opt_level_ = 3;
|
||||
ravi->size_level_ = 0;
|
||||
|
||||
if (!ravi_setup_lua_types(ravi)) {
|
||||
fprintf(stderr, "failed to setup types\n");
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
ravi->parent_result_ = gcc_jit_context_compile(ravi->context);
|
||||
if (gcc_jit_context_get_first_error(ravi->context)) {
|
||||
fprintf(stderr, "aborting due to JIT error: %s\n",
|
||||
gcc_jit_context_get_first_error(ravi->context));
|
||||
abort();
|
||||
}
|
||||
|
||||
return ravi;
|
||||
on_error:
|
||||
if (ravi) {
|
||||
ravi_jit_context_free(ravi);
|
||||
} else if (gcc_ctx) {
|
||||
gcc_jit_context_release(gcc_ctx);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ravi_jit_context_free(ravi_gcc_context_t *ravi) {
|
||||
if (ravi == NULL)
|
||||
return;
|
||||
if (ravi->parent_result_) {
|
||||
gcc_jit_result_release(ravi->parent_result_);
|
||||
ravi->parent_result_ = NULL;
|
||||
}
|
||||
if (ravi->context) {
|
||||
gcc_jit_context_release(ravi->context);
|
||||
ravi->context = NULL;
|
||||
}
|
||||
if (ravi->types) {
|
||||
free(ravi->types);
|
||||
ravi->types = NULL;
|
||||
}
|
||||
free(ravi);
|
||||
}
|
||||
|
||||
ravi_gcc_codegen_t *ravi_jit_new_codegen(ravi_gcc_context_t *ravi) {
|
||||
ravi_gcc_codegen_t *cg = NULL;
|
||||
cg = (ravi_gcc_codegen_t *)calloc(1, sizeof(ravi_gcc_codegen_t));
|
||||
if (cg == NULL) {
|
||||
fprintf(stderr, "error creating a new context: out of memory\n");
|
||||
goto on_error;
|
||||
}
|
||||
cg->id = 1;
|
||||
cg->temp[0] = 0;
|
||||
cg->ravi = ravi;
|
||||
return cg;
|
||||
|
||||
on_error:
|
||||
if (cg)
|
||||
ravi_jit_codegen_free(cg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ravi_jit_codegen_free(ravi_gcc_codegen_t *codegen) {
|
||||
if (codegen == NULL)
|
||||
return;
|
||||
free(codegen);
|
||||
}
|
||||
|
||||
bool ravi_jit_has_errored(ravi_gcc_context_t *ravi) {
|
||||
const char *msg = gcc_jit_context_get_first_error(ravi->context);
|
||||
if (msg) {
|
||||
fprintf(stderr, "JIT error: %s\n", msg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO we probably do not need all the headers
|
||||
// below
|
||||
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lua.h"
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
// 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));
|
||||
//jit->jit = ravi_jit_new_context();
|
||||
//jit->code_generator = ravi_jit_new_codegen(jit->jit);
|
||||
//G->ravi_state = jit;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Free up the JIT State
|
||||
void raviV_close(struct lua_State *L) {
|
||||
global_State *G = G(L);
|
||||
if (G->ravi_state == NULL)
|
||||
return;
|
||||
//ravi_jit_codegen_free(G->ravi_state->code_generator);
|
||||
//ravi_jit_context_free(G->ravi_state->jit);
|
||||
//free(G->ravi_state);
|
||||
}
|
||||
|
||||
// Dump the LLVM IR
|
||||
void raviV_dumpIR(struct lua_State *L, struct Proto *p) {
|
||||
(void)L;
|
||||
(void)p;
|
||||
}
|
||||
|
||||
// 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);
|
||||
//if (!G->ravi_state)
|
||||
return 0;
|
||||
//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_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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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…
Reference in new issue