Change the way entry function is called.

This commit is contained in:
Paweł Bylica 2014-12-16 17:25:14 +01:00
parent 4a9d08d1b0
commit 2e1c90f828

View file

@ -107,41 +107,31 @@ ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeDa
return returnCode; return returnCode;
} }
ReturnCode ExecutionEngine::run(ExecBundle const& _exec, RuntimeData* _data, Env* _env) namespace
{
ReturnCode runEntryFunc(ExecBundle const& _exec, Runtime* _runtime)
{ {
ReturnCode returnCode;
Runtime runtime(_data, _env);
std::vector<llvm::GenericValue> args{{}, llvm::GenericValue(&runtime)};
llvm::GenericValue result;
typedef ReturnCode(*EntryFuncPtr)(int, Runtime*); typedef ReturnCode(*EntryFuncPtr)(int, Runtime*);
auto entryFuncVoidPtr = _exec.engine->getPointerToFunction(_exec.entryFunc); auto entryFuncVoidPtr = _exec.engine->getPointerToFunction(_exec.entryFunc);
auto entryFuncPtr = static_cast<EntryFuncPtr>(entryFuncVoidPtr); auto entryFuncPtr = static_cast<EntryFuncPtr>(entryFuncVoidPtr);
auto r = setjmp(runtime.getJmpBuf()); ReturnCode returnCode{};
if (r == 0) auto sj = setjmp(_runtime->getJmpBuf());
{ if (sj == 0)
returnCode = entryFuncPtr(0, &runtime); returnCode = entryFuncPtr(0, _runtime); // FIXME: Remove int argument
}
else else
returnCode = static_cast<ReturnCode>(r); returnCode = static_cast<ReturnCode>(sj);
return returnCode;
}
}
ReturnCode ExecutionEngine::run(ExecBundle const& _exec, RuntimeData* _data, Env* _env)
{
Runtime runtime(_data, _env);
auto returnCode = runEntryFunc(_exec, &runtime);
if (returnCode == ReturnCode::Return) if (returnCode == ReturnCode::Return)
{ this->returnData = runtime.getReturnData();
returnData = runtime.getReturnData();
auto&& log = clog(JIT);
log << "RETURN [ ";
for (auto it = returnData.begin(), end = returnData.end(); it != end; ++it)
log << std::hex << std::setw(2) << std::setfill('0') << (int)*it << " ";
log << "]";
}
else
clog(JIT) << "RETURN " << (int)returnCode;
return returnCode; return returnCode;
} }