Browse Source

Updating ExecutionEngine interface

cl-refactor
Paweł Bylica 10 years ago
parent
commit
bb6e603568
  1. 24
      libevmjit/ExecutionEngine.cpp
  2. 7
      libevmjit/ExecutionEngine.h

24
libevmjit/ExecutionEngine.cpp

@ -20,9 +20,6 @@
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include <libevm/VM.h>
#include "Runtime.h" #include "Runtime.h"
#include "Memory.h" #include "Memory.h"
#include "Stack.h" #include "Stack.h"
@ -35,11 +32,7 @@ namespace eth
namespace jit namespace jit
{ {
ExecutionEngine::ExecutionEngine() int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeData* _data, Env* _env)
{
}
int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, bool _outputLogs, ExtVMFace& _ext)
{ {
auto module = _module.get(); // Keep ownership of the module in _module auto module = _module.get(); // Keep ownership of the module in _module
@ -73,7 +66,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, bool
auto exec = std::unique_ptr<llvm::ExecutionEngine>(builder.create()); auto exec = std::unique_ptr<llvm::ExecutionEngine>(builder.create());
if (!exec) if (!exec)
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment(errorMsg)); return -1; // FIXME: Handle internal errors
_module.release(); // Successfully created llvm::ExecutionEngine takes ownership of the module _module.release(); // Successfully created llvm::ExecutionEngine takes ownership of the module
auto finalizationStartTime = std::chrono::high_resolution_clock::now(); auto finalizationStartTime = std::chrono::high_resolution_clock::now();
@ -84,11 +77,11 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, bool
auto entryFunc = module->getFunction("main"); auto entryFunc = module->getFunction("main");
if (!entryFunc) if (!entryFunc)
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("main function not found")); return -2; // FIXME: Handle internal errors
ReturnCode returnCode; ReturnCode returnCode;
std::jmp_buf buf; std::jmp_buf buf;
Runtime runtime(_gas, _ext, buf, _outputLogs); Runtime runtime(_data, _env, buf);
auto r = setjmp(buf); auto r = setjmp(buf);
if (r == 0) if (r == 0)
{ {
@ -105,15 +98,12 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, bool
} }
else else
returnCode = static_cast<ReturnCode>(r); returnCode = static_cast<ReturnCode>(r);
// Return remaining gas
_gas = returnCode == ReturnCode::OutOfGas ? 0 : runtime.getGas();
clog(JIT) << "Max stack size: " << Stack::maxStackSize; clog(JIT) << "Max stack size: " << Stack::maxStackSize;
if (returnCode == ReturnCode::Return) if (returnCode == ReturnCode::Return)
{ {
returnData = runtime.getReturnData().toVector(); // TODO: It might be better to place is in Runtime interface returnData = runtime.getReturnData(); // TODO: It might be better to place is in Runtime interface
auto&& log = clog(JIT); auto&& log = clog(JIT);
log << "RETURN [ "; log << "RETURN [ ";
@ -122,7 +112,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, bool
log << "]"; log << "]";
} }
else else
cslog(JIT) << "RETURN " << (int)returnCode; clog(JIT) << "RETURN " << (int)returnCode;
return static_cast<int>(returnCode); return static_cast<int>(returnCode);
} }

7
libevmjit/ExecutionEngine.h

@ -3,8 +3,7 @@
#include <llvm/IR/Module.h> #include <llvm/IR/Module.h>
#include "Common.h" #include "Runtime.h"
//#include <libevm/ExtVMFace.h>
namespace dev namespace dev
{ {
@ -16,9 +15,9 @@ namespace jit
class ExecutionEngine class ExecutionEngine
{ {
public: public:
ExecutionEngine(); // FIXME: constructor? ExecutionEngine();
int run(std::unique_ptr<llvm::Module> module, u256& _gas, bool _outputLogs, ExtVMFace& _ext); int run(std::unique_ptr<llvm::Module> module, RuntimeData* _data, Env* _env);
bytes returnData; bytes returnData;
}; };

Loading…
Cancel
Save