Browse Source

Using gas provided by test engine and fix for creating fake ExtVMFace.

cl-refactor
Paweł Bylica 11 years ago
parent
commit
f31f3bcfc5
  1. 3
      evmcc/evmcc.cpp
  2. 9
      libevmjit/ExecutionEngine.cpp
  3. 2
      libevmjit/ExecutionEngine.h
  4. 2
      libevmjit/VM.cpp

3
evmcc/evmcc.cpp

@ -112,7 +112,8 @@ int main(int argc, char** argv)
auto engine = eth::jit::ExecutionEngine(); auto engine = eth::jit::ExecutionEngine();
auto module = eth::jit::Compiler().compile({bytecode.data(), bytecode.size()}); auto module = eth::jit::Compiler().compile({bytecode.data(), bytecode.size()});
module->dump(); module->dump();
auto result = engine.run(std::move(module)); u256 gas = 10000;
auto result = engine.run(std::move(module), gas);
return result; return result;
} }

9
libevmjit/ExecutionEngine.cpp

@ -36,7 +36,7 @@ ExecutionEngine::ExecutionEngine()
extern "C" { EXPORT std::jmp_buf* rt_jmpBuf; } extern "C" { EXPORT std::jmp_buf* rt_jmpBuf; }
int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, ExtVMFace* _ext) int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, ExtVMFace* _ext)
{ {
auto module = _module.get(); // Keep ownership of the module in _module auto module = _module.get(); // Keep ownership of the module in _module
@ -83,7 +83,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, ExtVMFace* _ext)
// Create fake ExtVM interface // Create fake ExtVM interface
if (!_ext) if (!_ext)
{ {
auto _ext = new ExtVMFace; _ext = new ExtVMFace;
_ext->myAddress = Address(1122334455667788); _ext->myAddress = Address(1122334455667788);
_ext->caller = Address(0xfacefacefaceface); _ext->caller = Address(0xfacefacefaceface);
_ext->origin = Address(101010101010101010); _ext->origin = Address(101010101010101010);
@ -102,8 +102,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, ExtVMFace* _ext)
} }
// Init runtime // Init runtime
uint64_t gas = 100; Runtime runtime(_gas, *_ext);
Runtime runtime(gas, *_ext);
auto entryFunc = module->getFunction("main"); auto entryFunc = module->getFunction("main");
if (!entryFunc) if (!entryFunc)
@ -124,7 +123,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, ExtVMFace* _ext)
else else
returnCode = static_cast<ReturnCode>(r); returnCode = static_cast<ReturnCode>(r);
gas = static_cast<decltype(gas)>(Runtime::getGas()); _gas = Runtime::getGas();
if (returnCode == ReturnCode::Return) if (returnCode == ReturnCode::Return)
{ {

2
libevmjit/ExecutionEngine.h

@ -18,7 +18,7 @@ class ExecutionEngine
public: public:
ExecutionEngine(); ExecutionEngine();
int run(std::unique_ptr<llvm::Module> module, ExtVMFace* _ext = nullptr); int run(std::unique_ptr<llvm::Module> module, u256& _gas, ExtVMFace* _ext = nullptr);
bytes returnData; bytes returnData;
}; };

2
libevmjit/VM.cpp

@ -19,7 +19,7 @@ bytes VM::go(ExtVMFace& _ext)
module->dump(); module->dump();
ExecutionEngine engine; ExecutionEngine engine;
auto exitCode = engine.run(std::move(module), &_ext); auto exitCode = engine.run(std::move(module), m_gas, &_ext);
switch (exitCode) switch (exitCode)
{ {

Loading…
Cancel
Save