Browse Source

Using ExtVM provided by test engine

cl-refactor
Paweł Bylica 10 years ago
parent
commit
dfac5a0033
  1. 39
      libevmjit/ExecutionEngine.cpp
  2. 3
      libevmjit/ExecutionEngine.h
  3. 6
      libevmjit/Runtime.cpp
  4. 4
      libevmjit/Runtime.h
  5. 2
      libevmjit/VM.cpp

39
libevmjit/ExecutionEngine.cpp

@ -36,7 +36,7 @@ ExecutionEngine::ExecutionEngine()
extern "C" { EXPORT std::jmp_buf* rt_jmpBuf; }
int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, ExtVMFace* _ext)
{
auto module = _module.get(); // Keep ownership of the module in _module
@ -81,26 +81,29 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
exec->finalizeObject();
// Create fake ExtVM interface
auto ext = std::make_unique<ExtVMFace>();
ext->myAddress = Address(1122334455667788);
ext->caller = Address(0xfacefacefaceface);
ext->origin = Address(101010101010101010);
ext->value = 0xabcd;
ext->gasPrice = 1002;
ext->previousBlock.hash = u256(1003);
ext->currentBlock.coinbaseAddress = Address(1004);
ext->currentBlock.timestamp = 1005;
ext->currentBlock.number = 1006;
ext->currentBlock.difficulty = 1007;
ext->currentBlock.gasLimit = 1008;
std::string calldata = "Hello the Beautiful World of Ethereum!";
ext->data = calldata;
unsigned char fakecode[] = {0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf};
ext->code = decltype(ext->code)(fakecode, 8);
if (!_ext)
{
auto _ext = new ExtVMFace;
_ext->myAddress = Address(1122334455667788);
_ext->caller = Address(0xfacefacefaceface);
_ext->origin = Address(101010101010101010);
_ext->value = 0xabcd;
_ext->gasPrice = 1002;
_ext->previousBlock.hash = u256(1003);
_ext->currentBlock.coinbaseAddress = Address(1004);
_ext->currentBlock.timestamp = 1005;
_ext->currentBlock.number = 1006;
_ext->currentBlock.difficulty = 1007;
_ext->currentBlock.gasLimit = 1008;
std::string calldata = "Hello the Beautiful World of Ethereum!";
_ext->data = calldata;
unsigned char fakecode[] = {0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf};
_ext->code = decltype(_ext->code)(fakecode, 8);
}
// Init runtime
uint64_t gas = 100;
Runtime runtime(gas, std::move(ext));
Runtime runtime(gas, *_ext);
auto entryFunc = module->getFunction("main");
if (!entryFunc)

3
libevmjit/ExecutionEngine.h

@ -4,6 +4,7 @@
#include <llvm/IR/Module.h>
#include <libdevcore/Common.h>
#include <libevm/ExtVMFace.h>
namespace dev
{
@ -17,7 +18,7 @@ class ExecutionEngine
public:
ExecutionEngine();
int run(std::unique_ptr<llvm::Module> module);
int run(std::unique_ptr<llvm::Module> module, ExtVMFace* _ext = nullptr);
bytes returnData;
};

6
libevmjit/Runtime.cpp

@ -19,8 +19,8 @@ extern "C"
EXPORT i256 gas;
}
Runtime::Runtime(u256 _gas, std::unique_ptr<ExtVMFace> _ext):
m_ext(std::move(_ext))
Runtime::Runtime(u256 _gas, ExtVMFace& _ext):
m_ext(_ext)
{
assert(!g_runtime);
g_runtime = this;
@ -44,7 +44,7 @@ MemoryImpl& Runtime::getMemory()
ExtVMFace& Runtime::getExt()
{
return *g_runtime->m_ext;
return g_runtime->m_ext;
}
u256 Runtime::getGas()

4
libevmjit/Runtime.h

@ -27,7 +27,7 @@ using MemoryImpl = bytes;
class Runtime
{
public:
Runtime(u256 _gas, std::unique_ptr<ExtVMFace> _ext);
Runtime(u256 _gas, ExtVMFace& _ext);
~Runtime();
Runtime(const Runtime&) = delete;
@ -41,7 +41,7 @@ public:
private:
StackImpl m_stack;
MemoryImpl m_memory;
std::unique_ptr<ExtVMFace> m_ext;
ExtVMFace& m_ext;
};
}

2
libevmjit/VM.cpp

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

Loading…
Cancel
Save