Change the way entry function is called.

This commit is contained in:
Paweł Bylica 2014-12-16 16:41:52 +01:00
parent 70279f8679
commit 4a9d08d1b0

View file

@ -112,11 +112,19 @@ ReturnCode ExecutionEngine::run(ExecBundle const& _exec, RuntimeData* _data, Env
ReturnCode returnCode; ReturnCode returnCode;
Runtime runtime(_data, _env); Runtime runtime(_data, _env);
std::vector<llvm::GenericValue> args{{}, llvm::GenericValue(&runtime)};
llvm::GenericValue result;
typedef ReturnCode(*EntryFuncPtr)(int, Runtime*);
auto entryFuncVoidPtr = _exec.engine->getPointerToFunction(_exec.entryFunc);
auto entryFuncPtr = static_cast<EntryFuncPtr>(entryFuncVoidPtr);
auto r = setjmp(runtime.getJmpBuf()); auto r = setjmp(runtime.getJmpBuf());
if (r == 0) if (r == 0)
{ {
auto result = _exec.engine->runFunction(_exec.entryFunc, {{}, llvm::GenericValue(&runtime)}); returnCode = entryFuncPtr(0, &runtime);
returnCode = static_cast<ReturnCode>(result.IntVal.getZExtValue());
} }
else else
returnCode = static_cast<ReturnCode>(r); returnCode = static_cast<ReturnCode>(r);