fix gcc warnings

pull/81/head
dibyendumajumdar 9 years ago
parent 7fc508518e
commit 70e5e6dce5

@ -5,7 +5,10 @@ local function x()
end
return j
end
if ravi then
print('compiling')
assert(ravi.compile(x))
end
x()
local t1 = os.clock()

@ -152,9 +152,9 @@ static bool create_function(ravi_gcc_codegen_t *codegen,
goto on_error;
}
gcc_jit_context_set_bool_option(def->function_context,
GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE, 0);
GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE, 1);
gcc_jit_context_set_int_option(def->function_context,
GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 2);
GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 3);
/* each function is given a unique name - as Lua functions are closures and do
* not really have names */

@ -140,7 +140,7 @@ void RaviCodeGenerator::emit_ARITH(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RB to local nb
auto src = emit_load_reg_n(def, rb);
auto ins = emit_store_local_n(def, src, nb);
emit_store_local_n(def, src, nb);
def->builder->CreateBr(test_rc);
@ -177,7 +177,7 @@ void RaviCodeGenerator::emit_ARITH(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RC to local;
src = emit_load_reg_n(def, rc);
ins = emit_store_local_n(def, src, nc);
emit_store_local_n(def, src, nc);
def->builder->CreateBr(float_op);
@ -322,7 +322,7 @@ void RaviCodeGenerator::emit_MOD(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RB to local nb
auto src = emit_load_reg_n(def, rb);
auto ins = emit_store_local_n(def, src, nb);
emit_store_local_n(def, src, nb);
def->builder->CreateBr(test_rc);
@ -359,7 +359,7 @@ void RaviCodeGenerator::emit_MOD(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RC to local;
src = emit_load_reg_n(def, rc);
ins = emit_store_local_n(def, src, nc);
emit_store_local_n(def, src, nc);
def->builder->CreateBr(float_op);
@ -388,13 +388,13 @@ void RaviCodeGenerator::emit_MOD(RaviFunctionDef *def, llvm::Value *L_ci,
def->builder->SetInsertPoint(mb_lt0_then);
result = def->builder->CreateFAdd(fmod_result, rhs);
ins = emit_store_local_n(def, result, nb);
emit_store_local_n(def, result, nb);
def->builder->CreateBr(mb_lt0_done);
def->f->getBasicBlockList().push_back(mb_lt0_else);
def->builder->SetInsertPoint(mb_lt0_else);
ins = emit_store_local_n(def, fmod_result, nb);
emit_store_local_n(def, fmod_result, nb);
def->builder->CreateBr(mb_lt0_done);
def->f->getBasicBlockList().push_back(mb_lt0_done);
@ -516,7 +516,7 @@ void RaviCodeGenerator::emit_IDIV(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RB to local nb
auto src = emit_load_reg_n(def, rb);
auto ins = emit_store_local_n(def, src, nb);
emit_store_local_n(def, src, nb);
def->builder->CreateBr(test_rc);
@ -553,7 +553,7 @@ void RaviCodeGenerator::emit_IDIV(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RC to local;
src = emit_load_reg_n(def, rc);
ins = emit_store_local_n(def, src, nc);
emit_store_local_n(def, src, nc);
def->builder->CreateBr(float_op);
@ -647,7 +647,7 @@ void RaviCodeGenerator::emit_POW(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RB to local nb
auto src = emit_load_reg_n(def, rb);
auto ins = emit_store_local_n(def, src, nb);
emit_store_local_n(def, src, nb);
def->builder->CreateBr(test_rc);
@ -684,7 +684,7 @@ void RaviCodeGenerator::emit_POW(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RC to local;
src = emit_load_reg_n(def, rc);
ins = emit_store_local_n(def, src, nc);
emit_store_local_n(def, src, nc);
def->builder->CreateBr(float_op);

@ -27,9 +27,9 @@ namespace ravi {
// OP_JMP
void RaviCodeGenerator::emit_JMP(RaviFunctionDef *def, int A, int j) {
//#define dojump(ci,i,e) \
// { int a = GETARG_A(i); \
// if (a > 0) luaF_close(L, ci->u.l.base + a - 1); \
//#define dojump(ci,i,e)
// { int a = GETARG_A(i);
// if (a > 0) luaF_close(L, ci->u.l.base + a - 1);
// ci->u.l.savedpc += GETARG_sBx(i) + e; }
//
// dojump(ci, i, 0);

@ -78,8 +78,7 @@ void RaviCodeGenerator::emit_FORLOOP2(RaviFunctionDef *def, llvm::Value *L_ci,
emit_load_local_n(def, idx_int_ptr);
llvm::Value *new_idx = def->builder->CreateAdd(step_int_value, idx_int_value,
"next.idx", false, true);
llvm::Instruction *idx_store =
emit_store_local_n(def, new_idx, idx_int_ptr);
emit_store_local_n(def, new_idx, idx_int_ptr);
// lua_Integer limit = ivalue(ra + 1);
llvm::Instruction *limit_int_value =
@ -105,7 +104,7 @@ void RaviCodeGenerator::emit_FORLOOP2(RaviFunctionDef *def, llvm::Value *L_ci,
idx_int_value = emit_load_local_n(def, idx_int_ptr);
new_idx = def->builder->CreateAdd(step_int_value, idx_int_value, "next.idx",
false, true);
idx_store = emit_store_local_n(def, new_idx, idx_int_ptr);
emit_store_local_n(def, new_idx, idx_int_ptr);
// lua_Integer limit = ivalue(ra + 1);
limit_int_value = emit_load_local_n(def, limit_int_ptr);
@ -148,7 +147,7 @@ void RaviCodeGenerator::emit_FORLOOP2(RaviFunctionDef *def, llvm::Value *L_ci,
emit_load_local_n(def, idx_double_ptr);
new_idx =
def->builder->CreateFAdd(step_double_value, idx_double_value, "next.idx");
idx_store = emit_store_local_n(def, new_idx, idx_double_ptr);
emit_store_local_n(def, new_idx, idx_double_ptr);
// lua_Number limit = fltvalue(ra + 1);
llvm::Instruction *limit_double_value =
@ -173,7 +172,7 @@ void RaviCodeGenerator::emit_FORLOOP2(RaviFunctionDef *def, llvm::Value *L_ci,
idx_double_value = emit_load_local_n(def, idx_double_ptr);
new_idx =
def->builder->CreateFAdd(step_double_value, idx_double_value, "next.idx");
idx_store = emit_store_local_n(def, new_idx, idx_double_ptr);
emit_store_local_n(def, new_idx, idx_double_ptr);
// lua_Number limit = fltvalue(ra + 1);
limit_double_value = emit_load_local_n(def, limit_double_ptr);

@ -74,13 +74,13 @@ void RaviCodeGenerator::emit_GETTABLE(RaviFunctionDef *def, llvm::Value *L_ci,
void RaviCodeGenerator::emit_GETTABLE_AF(RaviFunctionDef *def,
llvm::Value *L_ci, llvm::Value *proto,
int A, int B, int C) {
//#define raviH_get_float_inline(L, t, key, v) \
//{ unsigned ukey = (unsigned)((key)); \
// lua_Number *data = (lua_Number *)t->ravi_array.data; \
// if (ukey < t->ravi_array.len) {\
// setfltvalue(v, data[ukey]); \
// }else \
// luaG_runerror(L, "array out of bounds"); \
//#define raviH_get_float_inline(L, t, key, v)
//{ unsigned ukey = (unsigned)((key));
// lua_Number *data = (lua_Number *)t->ravi_array.data;
// if (ukey < t->ravi_array.len) {
// setfltvalue(v, data[ukey]);
// }else
// luaG_runerror(L, "array out of bounds");
//}
// TValue *rb = RB(i);
@ -131,13 +131,13 @@ void RaviCodeGenerator::emit_GETTABLE_AI(RaviFunctionDef *def,
llvm::Value *L_ci, llvm::Value *proto,
int A, int B, int C) {
//#define raviH_get_int_inline(L, t, key, v) \
//{ unsigned ukey = (unsigned)((key)); \
// lua_Integer *data = (lua_Integer *)t->ravi_array.data; \
// if (ukey < t->ravi_array.len) {\
// setivalue(v, data[ukey]); \
// } else \
// luaG_runerror(L, "array out of bounds"); \
//#define raviH_get_int_inline(L, t, key, v)
//{ unsigned ukey = (unsigned)((key));
// lua_Integer *data = (lua_Integer *)t->ravi_array.data;
// if (ukey < t->ravi_array.len) {
// setivalue(v, data[ukey]);
// } else
// luaG_runerror(L, "array out of bounds");
//}
// TValue *rb = RB(i);
@ -188,13 +188,13 @@ void RaviCodeGenerator::emit_SETTABLE_AI(RaviFunctionDef *def,
llvm::Value *L_ci, llvm::Value *proto,
int A, int B, int C) {
//#define raviH_set_int_inline(L, t, key, value) \
//{ unsigned ukey = (unsigned)((key)); \
// lua_Integer *data = (lua_Integer *)t->ravi_array.data; \
// if (ukey < t->ravi_array.len) { \
// data[ukey] = value; \
// } else \
// raviH_set_int(L, t, ukey, value); \
//#define raviH_set_int_inline(L, t, key, value)
//{ unsigned ukey = (unsigned)((key));
// lua_Integer *data = (lua_Integer *)t->ravi_array.data;
// if (ukey < t->ravi_array.len) {
// data[ukey] = value;
// } else
// raviH_set_int(L, t, ukey, value);
//}
// Table *t = hvalue(ra);
@ -245,13 +245,13 @@ void RaviCodeGenerator::emit_SETTABLE_AF(RaviFunctionDef *def,
llvm::Value *L_ci, llvm::Value *proto,
int A, int B, int C) {
//#define raviH_set_float_inline(L, t, key, value) \
//{ unsigned ukey = (unsigned)((key)); \
// lua_Number *data = (lua_Number *)t->ravi_array.data; \
// if (ukey < t->ravi_array.len) { \
// data[ukey] = value; \
// } else \
// raviH_set_float(L, t, ukey, value); \
//#define raviH_set_float_inline(L, t, key, value)
//{ unsigned ukey = (unsigned)((key));
// lua_Number *data = (lua_Number *)t->ravi_array.data;
// if (ukey < t->ravi_array.len) {
// data[ukey] = value;
// } else
// raviH_set_float(L, t, ukey, value);
// }
// Table *t = hvalue(ra);

@ -11,141 +11,6 @@
#include "lauxlib.h"
#include "lualib.h"
/*
** LUA_TFUNCTION variants:
** 0 - Lua function
** 1 - light C function
** 2 - regular C function (closure)
*/
/* Variant tags for functions */
#define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */
#define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */
#define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */
/* Variant tags for strings */
#define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */
#define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */
/* Variant tags for numbers */
#define LUA_TNUMFLT (LUA_TNUMBER | (0 << 4)) /* float numbers */
#define LUA_TNUMINT (LUA_TNUMBER | (1 << 4)) /* integer numbers */
/* Bit mark for collectable types */
#define BIT_ISCOLLECTABLE (1 << 6)
/* mark a tag as collectable */
#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
union ValueX {
double n;
long long i;
};
typedef struct {
int lo;
int hi;
} PartsX;
union TypeX {
double d;
PartsX tt;
unsigned char bytes[8];
};
typedef struct {
union ValueX value_;
union TypeX tt_;
} MyValueT;
static void dumpll(uint64_t d)
{
union {
uint64_t d;
unsigned char bytes[8];
} tt;
tt.d = d;
// Litle endian assumed
for (int i = 7; i >= 0; i--) {
printf("%02x", tt.bytes[i]);
}
printf("\n");
}
static void dumpd(double d)
{
union {
double d;
unsigned char bytes[8];
} tt;
tt.d = d;
// Litle endian assumed
for (int i = 7; i >=0 ; i--) {
printf("%02x", tt.bytes[i]);
}
printf("\n");
}
static void dumpvalue(MyValueT* v)
{
// Litle endian assumed
for (int i = 7; i >= 0; i--) {
printf("%02x", v->tt_.bytes[i]);
}
printf("\n");
}
#define QNAN 0x7ffc0000
#define QVAL 0x0000ffff
#define LUA__TNUMFLT (QNAN | LUA_TNUMFLT)
#define LUA__TNUMINT (QNAN | LUA_TNUMINT)
#define LUA__TNUMBER (QNAN | LUA_TNUMINT)
#define LUA__TTABLE (QNAN | ctb(LUA_TTABLE))
static void tryme() {
MyValueT v = { 0 };
//v.tt_.d = 1.0;
//v.tt_.d /= 0;
//dumpvalue(&v);
v.tt_.tt.hi = LUA__TNUMINT;
dumpvalue(&v);
if (isnan(v.tt_.d))
printf("Is NaN set as expected\n");
if ((v.tt_.tt.hi & QNAN) == QNAN)
printf("QNAN set as expected\n");
if ((v.tt_.tt.hi & QVAL) == LUA_TNUMINT)
printf("LUA_TNUMINT set as expected\n");
v.tt_.d = 1.5;
if ((v.tt_.tt.hi & QNAN) != QNAN)
printf("QNAN unset as expected\n");
v.tt_.tt.hi = LUA__TTABLE;
dumpvalue(&v);
if ((v.tt_.tt.hi & QNAN) == QNAN)
printf("QNAN set as expected\n");
if ((v.tt_.tt.hi & QVAL) == ctb(LUA_TTABLE))
printf("LUA_TTABLE set as expected\n");
v.tt_.d = 42;
if ((v.tt_.tt.hi & QNAN) != QNAN)
printf("QNAN unset as expected\n");
}
/* test supplied lua code compiles */
static int test_luacomp1(const char *code)
{
@ -260,9 +125,6 @@ int main()
{
int failures = 0;
//
#if 0
tryme();
#else
failures += test_luacompexec1("function test(); local x: integer = 1; return function (j) x = j; return x; end; end; fn = test(); return fn('55')", 55);
failures += test_luacompexec1("ravi.auto(true); function arrayaccess (); local x: integer[] = {5}; return x[1]; end; assert(ravi.compile(arrayaccess)); return arrayaccess()", 5);
failures += test_luacompexec1("ravi.auto(true); function cannotload (msg, a,b); assert(not a and string.find(b, msg)); end; ravi.compile(cannotload); return 1", 1);
@ -328,6 +190,5 @@ int main()
failures += test_luacomp1("local a=1; if a==0 then; a = 2; else a=3; end;");
failures += test_luacomp1("local f = function(); return; end; local d:number = 5.0; d = f(); return d");
failures += test_luacomp1("local f = function(); return; end; local d = 5.0; d = f(); return d");
#endif
return failures ? 1 : 0;
}

Loading…
Cancel
Save