fix bug in fornum for floating point

Dibyendu Majumdar 9 years ago
parent cbf3a6c665
commit 6e617a576a

@ -317,6 +317,8 @@ struct RaviFunctionDef {
llvm::Constant *luaG_runerrorF;
llvm::Constant *luaV_forlimitF;
llvm::Constant *luaV_tonumberF;
llvm::Constant *printfFunc;
llvm::Value *str;
// Jump targets in the function
std::vector<llvm::BasicBlock *> jmp_targets;

@ -130,6 +130,7 @@ RaviCodeGenerator::create_function(llvm::IRBuilder<> &builder,
def->raviF = func.get();
def->types = types;
def->builder = &builder;
def->str = builder.CreateGlobalString("DEBUG %f\n");
return func;
}
@ -160,6 +161,14 @@ void RaviCodeGenerator::emit_extern_declarations(RaviFunctionDef *def) {
def->luaV_tonumberF = def->raviF->addExternFunction(
def->types->luaV_tonumberT, reinterpret_cast<void *>(&luaV_tonumber_),
"luaV_tonumber_");
// Create printf declaration
std::vector<llvm::Type *> args;
args.push_back(def->types->C_pcharT);
// accepts a char*, is vararg, and returns int
llvm::FunctionType *printfType =
llvm::FunctionType::get(def->types->C_intT, args, true);
def->printfFunc =
def->raviF->module()->getOrInsertFunction("printf", printfType);
}
#define RA(i) (base + GETARG_A(i))

@ -202,7 +202,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, llvm::Value *L_ci,
// Already a float - copy to nlimit
llvm::Value *plimit_nvalue_ptr = def->builder->CreateBitCast(
init, def->types->plua_NumberT, "plimit.n.ptr");
plimit, def->types->plua_NumberT, "plimit.n.ptr");
llvm::Instruction *plimit_nvalue_load =
def->builder->CreateLoad(plimit_nvalue_ptr);
plimit_nvalue_load->setMetadata(llvm::LLVMContext::MD_tbaa,
@ -212,6 +212,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, llvm::Value *L_ci,
nlimit_store->setMetadata(llvm::LLVMContext::MD_tbaa,
def->types->tbaa_longlongT);
// Go to the PSTEP section
llvm::BasicBlock *else1_pstep =
llvm::BasicBlock::Create(def->jitState->context(), "if.else.pstep");

@ -161,7 +161,7 @@ void *RaviJITFunctionImpl::compile() {
// Run the FPM on this function
FPM->run(*function_);
module_->dump();
//module_->dump();
// We don't need this anymore
delete FPM;

@ -67,7 +67,7 @@ static int test_luacompexec1(const char *code, int expected)
int main(int argc, const char *argv[])
{
int failures = 0;
failures += test_luacompexec1("local function x(); local j = 0; for i=1,1000000000 do; j = i; end; return j; end; local y = x(); print(y); return y", 1000000000);
failures += test_luacompexec1("local function x(); local j = 0; for i=2.0,6.0,3.0 do; j = i; end; return j; end; local y = x(); print(y); return y", 5);
failures += test_luacompexec1("local function x(); local a=5; return 1004,2; end; local y; y = x(); print(y); return y", 1004);
failures += test_luacompexec1("local function x(); if 1 == 2 then; return 5.0; end; return 1.0; end; local z = x(); print(z); return z", 1);
failures += test_luacompexec1("local function x(y); if y == 1 then; return 1.0; elseif y == 5 then; return 2.0; else; return 3.0; end; end; local z = x(5); print(z); return z", 2);

Loading…
Cancel
Save