Skip to content

Commit

Permalink
script to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dibyendu Majumdar committed Aug 7, 2015
1 parent 418b274 commit c51a424
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 17 deletions.
27 changes: 27 additions & 0 deletions lua-5.3.0-tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
LUA=$1
if [ "$LUA" = "" ]
then
echo "Please pass path to Lua"
exit 1
fi

$LUA -e"_U=true" all.lua
if [ $? != 0 ]
then
echo "all.lua interpreted failed"
exit 1
fi

$LUA -e"_U=true; ravi.auto(true,1)" all.lua
if [ $? != 0 ]
then
echo "all.lua compiled failed"
exit 1
fi

$LUA -e"_U=true; ravi.auto(true)" all.lua
if [ $? != 0 ]
then
echo "all.lua part compiled failed"
exit 1
fi
29 changes: 29 additions & 0 deletions ravi-tests/ravi_tests1.ravi
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,35 @@ ravi.compile(y)
assert(y() == 4.2)
print'test params num[],int OK'

-- test 40
function x(t) return t; end
function f()
local tt: integer[] = {1}
local ss: number[] = { 55.5 }
tt = x(tt)
ss = x(ss)
end
assert(ravi.compile(x))
assert(ravi.compile(f))
assert(pcall(f))
function f()
local tt: integer[] = {1}
tt = x({})
end
--ravi.dumplua(f)
print'+'
assert(ravi.compile(f))
assert(not pcall(f))
print'+'
function f()
local tt: integer[] = {1}
local ss: number[] = { 55.5 }
ss = x(tt)
end
print'+'
assert(ravi.compile(f))
assert(not pcall(f))

print("test 40 OK")


69 changes: 69 additions & 0 deletions ravi-tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
LUA=$1
if [ "$LUA" = "" ]
then
echo "Please pass path to Lua"
exit 1
fi

$LUA ravi_tests1.ravi
if [ $? != 0 ]
then
echo "ravi_tests1 failed"
exit 1
fi

$LUA fornum_test1.lua
if [ $? != 0 ]
then
echo "fornum_test1 failed"
exit 1
fi

$LUA fornum_test2.ravi
if [ $? != 0 ]
then
echo "fornum_test2 failed"
exit 1
fi

$LUA fornum_test3.lua
if [ $? != 0 ]
then
echo "fornum_test3 failed"
exit 1
fi

$LUA mandel1.ravi
if [ $? != 0 ]
then
echo "mandel1 failed"
exit 1
fi

$LUA fannkuchen.ravi
if [ $? != 0 ]
then
echo "fannkuchen failed"
exit 1
fi

$LUA matmul1.ravi
if [ $? != 0 ]
then
echo "matmul1 failed"
exit 1
fi

$LUA basics.lua
if [ $? != 0 ]
then
echo "basics failed"
exit 1
fi

$LUA bitwise_tests.lua
if [ $? != 0 ]
then
echo "bitwise failed"
exit 1
fi
54 changes: 37 additions & 17 deletions src/ravi_llvmcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace ravi {

// OP_JMP
void RaviCodeGenerator::emit_JMP(RaviFunctionDef *def, int A, int j, int pc) {
void RaviCodeGenerator::emit_JMP(RaviFunctionDef *def, int A, int sBx, int pc) {

//#define dojump(ci,i,e)
// { int a = GETARG_A(i);
Expand All @@ -34,14 +34,18 @@ void RaviCodeGenerator::emit_JMP(RaviFunctionDef *def, int A, int j, int pc) {
//
// dojump(ci, i, 0);

assert(def->jmp_targets[j].jmp1);
assert(def->jmp_targets[sBx].jmp1);

// If the current block is already terminated we
// need to create a new block
if (def->builder->GetInsertBlock()->getTerminator()) {
llvm::BasicBlock *jmp_block =
llvm::BasicBlock::Create(def->jitState->context(), "jump", def->f);
llvm::BasicBlock::Create(def->jitState->context(), "OP_JMP_bridge", def->f);
def->builder->SetInsertPoint(jmp_block);
}

emit_debug_trace(def, OP_JMP, pc);

// if (a > 0) luaF_close(L, ci->u.l.base + a - 1);
if (A > 0) {
emit_load_base(def);
Expand All @@ -51,25 +55,35 @@ void RaviCodeGenerator::emit_JMP(RaviFunctionDef *def, int A, int j, int pc) {
CreateCall2(def->builder, def->luaF_closeF, def->L, val);
}

def->builder->CreateBr(def->jmp_targets[j].jmp1);
// Do the actual jump
def->builder->CreateBr(def->jmp_targets[sBx].jmp1);

// Start new block
llvm::BasicBlock *block =
llvm::BasicBlock::Create(def->jitState->context(), "postjump", def->f);
llvm::BasicBlock::Create(def->jitState->context(), "OP_JMP_postjmp", def->f);
def->builder->SetInsertPoint(block);
}

// Handle OP_CALL
// Note that Lua assumes that functions called via OP_CALL
// are Lua functions and secondly that once OP_CALL completes the
// current function will continue within the same luaV_execute()
// call. However in a JIT case each JIT function is a different call
// so we need to take care of the behaviour differences between
// OP_CALL and external calls
void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, int A, int B, int C, int pc) {

// int nresults = c - 1;
// if (b != 0)
// L->top = ra + b; /* else previous instruction set top */
// int c = luaD_precall(L, ra, nresults); /* C or JITed function? */
// int c = luaD_precall(L, ra, nresults, 1); /* C or JITed function? */
// if (c) {
// if (c == 1 && nresults >= 0)
// L->top = ci->top; /* adjust results if C function */
// }
// else { /* Lua function */
// luaV_execute(L);
// int b = luaV_execute(L);
// if (b) L->top = ci->top;
// }
emit_debug_trace(def, OP_CALL, pc);
emit_load_base(def);
Expand All @@ -79,33 +93,35 @@ void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, int A, int B, int C, int

// if (b != 0)
if (B != 0) {
// L->top = ra + b; /* else previous instruction set top */
emit_set_L_top_toreg(def, A + B);
//emit_dump_stack(def, "POST L->top = register");
}

//emit_dump_stacktop(def, "JIT OP_CALL before function call");
// luaD_precall() returns following
// 1 - C function called, results to be adjusted
// 2 - JITed Lua function called, no action
// 0 - Run interpreter on Lua function
// 0 - Run interpreter on Lua function, if returns != 0 then update L->top

// int c = luaD_precall(L, ra, nresults); /* C or JITed function? */
// int c = luaD_precall(L, ra, nresults, op_call); /* C or JITed function? */
// The last parameter to luaD_precall() tells it that
// this is an OP_CALL
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *precall_result =
CreateCall4(def->builder, def->luaD_precallF, def->L, ra,
llvm::ConstantInt::get(def->types->C_intT, nresults),
def->types->kInt[1]);

// If luaD_precall() returns 0 then we need to interpret the
// Lua function
llvm::Value *do_Lua_interp =
def->builder->CreateICmpEQ(precall_result, def->types->kInt[0]);

llvm::BasicBlock *then_block = llvm::BasicBlock::Create(
def->jitState->context(), "if.lua.function", def->f);
def->jitState->context(), "OP_CALL_if_Lua_interp_function", def->f);
llvm::BasicBlock *else_block =
llvm::BasicBlock::Create(def->jitState->context(), "if.not.lua.function");
llvm::BasicBlock::Create(def->jitState->context(), "OP_CALL_if_not_Lua_interp_function");
llvm::BasicBlock *end_block =
llvm::BasicBlock::Create(def->jitState->context(), "op_call.done");
llvm::BasicBlock::Create(def->jitState->context(), "OP_CALL_done");
def->builder->CreateCondBr(do_Lua_interp, then_block, else_block);
def->builder->SetInsertPoint(then_block);

Expand All @@ -117,14 +133,18 @@ void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, int A, int B, int C, int
def->builder->CreateICmpNE(b, def->types->kInt[0]);

llvm::BasicBlock *if_b_block = llvm::BasicBlock::Create(
def->jitState->context(), "if.b", def->f);
def->jitState->context(), "OP_CALL_if_need_reset_L_top", def->f);
def->builder->CreateCondBr(b_not_zero, if_b_block, end_block);
def->builder->SetInsertPoint(if_b_block);

// Set L->top = ci->top
emit_refresh_L_top(def, def->ci_val);

// We are done
def->builder->CreateBr(end_block);

// Handle the C or JIT case
// Handle the C function or JIT case
// function already executed by luaD_precall()
def->f->getBasicBlockList().push_back(else_block);
def->builder->SetInsertPoint(else_block);

Expand All @@ -137,7 +157,7 @@ void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, int A, int B, int C, int
def->builder->CreateICmpEQ(precall_result, def->types->kInt[1]);

llvm::BasicBlock *then1_block = llvm::BasicBlock::Create(
def->jitState->context(), "if.C.function", def->f);
def->jitState->context(), "OP_CALL_if_C_function_returned_values", def->f);
def->builder->CreateCondBr(precall_C, then1_block, end_block);
def->builder->SetInsertPoint(then1_block);

Expand Down

0 comments on commit c51a424

Please sign in to comment.