implement OP_NOT

pull/81/head
Dibyendu Majumdar 9 years ago
parent 38b59ef2ed
commit 31d5e3e333

@ -554,7 +554,8 @@ public:
void emit_refresh_L_top(RaviFunctionDef *def);
// L->top = R(B)
void emit_set_L_top_toreg(RaviFunctionDef *def, llvm::Instruction *base_ptr, int B);
void emit_set_L_top_toreg(RaviFunctionDef *def, llvm::Instruction *base_ptr,
int B);
// Look for Lua bytecodes that are jump targets and allocate
// a BasicBlock for each such target in def->jump_targets.
@ -717,6 +718,9 @@ public:
void emit_SETLIST(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A, int B, int C);
void emit_NOT(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A, int B);
// Emit code for OP_EQ, OP_LT and OP_LE
// The callee parameter should be luaV_equalobj, luaV_lessthan and
// luaV_lessequal
@ -743,11 +747,11 @@ public:
void emit_TESTSET(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A, int B, int C, int j, int jA);
void emit_TFORCALL(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A, int B, int C, int j, int jA);
void emit_TFORCALL(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *proto, int A, int B, int C, int j, int jA);
void emit_TFORLOOP(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A, int j);
void emit_TFORLOOP(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *proto, int A, int j);
private:
RaviJITStateImpl *jitState_;

@ -403,11 +403,24 @@ days = {"Sunday", "Monday", "Tuesday", "Wednesday",
x = function()
local t
for k,v in pairs(days) do
print(k,v)
t = v
end
return t
end
assert(ravi.compile(x))
assert(x() == "Saturday")
print("test 30 OK")
print("test 30 OK")
-- test 31
x = function(a)
return not a
end
y = function(a)
return a
end
assert(ravi.compile(x))
assert(ravi.compile(y))
assert(y(x()))
assert(y(x(false)))
assert(not y(x(true)))
print("test 31 OK")

@ -65,7 +65,7 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_BNOT | NO | R(A) := ~R(B) |
+-------------------------+----------+--------------------------------------------------+
| OP_NOT | NO | R(A) := not R(B) |
| OP_NOT | YES | R(A) := not R(B) |
+-------------------------+----------+--------------------------------------------------+
| OP_LEN | NO | R(A) := length of R(B) |
+-------------------------+----------+--------------------------------------------------+

@ -246,6 +246,7 @@ bool RaviCodeGenerator::canCompile(Proto *p) {
case OP_EQ:
case OP_LT:
case OP_LE:
case OP_NOT:
case OP_TEST:
case OP_TESTSET:
case OP_FORPREP:
@ -658,6 +659,10 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p) {
int j = sbx + pc + 1;
emit_TFORLOOP(&def, L_ci, proto, A, j);
} break;
case OP_NOT: {
int B = GETARG_B(i);
emit_NOT(&def, L_ci, proto, A, B);
} break;
case OP_TEST: {
int B = GETARG_B(i);
int C = GETARG_C(i);

@ -204,6 +204,23 @@ void RaviCodeGenerator::emit_TEST(RaviFunctionDef *def, llvm::Value *L_ci,
def->builder->SetInsertPoint(else_block);
}
void RaviCodeGenerator::emit_NOT(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *proto, int A, int B) {
// case OP_NOT: {
// TValue *rb = RB(i);
// int res = l_isfalse(rb); /* next assignment may change this value */
// setbvalue(ra, res);
// } break;
llvm::Instruction *base_ptr = emit_load_base(def);
// Get pointer to register B
llvm::Value *rb = emit_gep_ra(def, base_ptr, B);
llvm::Value *v = emit_boolean_testfalse(def, rb, false);
llvm::Value *result = def->builder->CreateZExt(v, def->types->C_intT, "i");
llvm::Value *ra = emit_gep_ra(def, base_ptr, A);
emit_store_reg_b(def, result, ra);
emit_store_type(def, ra, LUA_TBOOLEAN);
}
void RaviCodeGenerator::emit_TESTSET(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *proto, int A, int B, int C,
int j, int jA) {
@ -219,9 +236,7 @@ void RaviCodeGenerator::emit_TESTSET(RaviFunctionDef *def, llvm::Value *L_ci,
// } break;
// Load pointer to base
llvm::Instruction *base_ptr = def->builder->CreateLoad(def->Ci_base);
base_ptr->setMetadata(llvm::LLVMContext::MD_tbaa,
def->types->tbaa_luaState_ci_baseT);
llvm::Instruction *base_ptr = emit_load_base(def);
// Get pointer to register B
llvm::Value *rb = emit_gep_ra(def, base_ptr, B);

Loading…
Cancel
Save