issue #163 add DEFER bytecode to LLVM backend

defer
Dibyendu Majumdar 5 years ago
parent 51eeb4e8c2
commit 6f29bc6cd8

@ -161,5 +161,6 @@ LUAI_FUNC void raviV_gettable_i(lua_State *L, const TValue *t, TValue *key, StkI
LUAI_FUNC void raviV_settable_i(lua_State *L, const TValue *t, TValue *key, StkId val);
LUAI_FUNC void raviV_op_totype(lua_State *L, TValue *ra, TValue *rb);
LUAI_FUNC int raviV_check_usertype(lua_State *L, TString *name, const TValue *o);
LUAI_FUNC void raviV_op_defer(lua_State *L, TValue *ra);
#endif

@ -288,6 +288,7 @@ struct LuaLLVMTypes {
llvm::FunctionType *raviV_gettable_iT;
llvm::FunctionType *raviV_settable_iT;
llvm::FunctionType *raviV_op_totypeT;
llvm::FunctionType *raviV_op_deferT;
llvm::FunctionType *raviH_set_intT;
llvm::FunctionType *raviH_set_floatT;
@ -832,6 +833,7 @@ struct RaviFunctionDef {
llvm::Function *raviV_gettable_iF;
llvm::Function *raviV_settable_iF;
llvm::Function *raviV_op_totypeF;
llvm::Function *raviV_op_deferF;
// array setters
llvm::Function *raviH_set_intF;
@ -1369,6 +1371,8 @@ class RaviCodeGenerator {
void emit_BNOT(RaviFunctionDef *def, int A, int B, int pc);
void emit_DEFER(RaviFunctionDef *def, int A, int pc);
void emit_bitwise_shiftl(RaviFunctionDef *def, llvm::Value *ra, int B, lua_Integer y);
private:

File diff suppressed because it is too large Load Diff

@ -170,4 +170,14 @@ void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, int A, int B, int C,
def->f->getBasicBlockList().push_back(end_block);
def->builder->SetInsertPoint(end_block);
}
void RaviCodeGenerator::emit_DEFER(RaviFunctionDef *def, int A, int pc) {
bool traced = emit_debug_trace(def, OP_RAVI_DEFER, pc);
if (!traced)
emit_update_savedpc(def, pc);
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
CreateCall2(def->builder, def->raviV_op_deferF, def->L, ra);
}
}

@ -1202,6 +1202,9 @@ void RaviCodeGenerator::emit_extern_declarations(RaviFunctionDef *def) {
def->raviV_op_totypeF = def->raviF->addExternFunction(
def->types->raviV_op_totypeT, reinterpret_cast<void *>(&raviV_op_totype),
"raviV_op_totype");
def->raviV_op_deferF = def->raviF->addExternFunction(
def->types->raviV_op_totypeT, reinterpret_cast<void *>(&raviV_op_defer),
"raviV_op_defer");
def->ravi_dump_valueF = def->raviF->addExternFunction(
def->types->ravi_dump_valueT, reinterpret_cast<void *>(&ravi_dump_value),
@ -2014,7 +2017,9 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
int B = GETARG_B(i);
emit_UNM(def, A, B, pc);
} break;
case OP_RAVI_DEFER: {
emit_DEFER(def, A, pc);
} break;
default: {
fprintf(stderr, "Unexpected bytecode %d\n", op);
abort();

@ -759,6 +759,10 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
elements.clear();
elements.push_back(plua_StateT);
elements.push_back(pTValueT);
// void raviV_op_defer(lua_State *L, TValue *ra);
raviV_op_deferT = llvm::FunctionType::get(llvm::Type::getVoidTy(context), elements, false);
elements.push_back(pTValueT);
luaV_equalobjT = llvm::FunctionType::get(C_intT, elements, false);

Loading…
Cancel
Save