mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Using ExtVM provided by test engine
This commit is contained in:
parent
f0928f54f3
commit
dfac5a0033
5 changed files with 29 additions and 25 deletions
|
|
@ -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)
|
int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, ExtVMFace* _ext)
|
||||||
{
|
{
|
||||||
auto module = _module.get(); // Keep ownership of the module in _module
|
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();
|
exec->finalizeObject();
|
||||||
|
|
||||||
// Create fake ExtVM interface
|
// Create fake ExtVM interface
|
||||||
auto ext = std::make_unique<ExtVMFace>();
|
if (!_ext)
|
||||||
ext->myAddress = Address(1122334455667788);
|
{
|
||||||
ext->caller = Address(0xfacefacefaceface);
|
auto _ext = new ExtVMFace;
|
||||||
ext->origin = Address(101010101010101010);
|
_ext->myAddress = Address(1122334455667788);
|
||||||
ext->value = 0xabcd;
|
_ext->caller = Address(0xfacefacefaceface);
|
||||||
ext->gasPrice = 1002;
|
_ext->origin = Address(101010101010101010);
|
||||||
ext->previousBlock.hash = u256(1003);
|
_ext->value = 0xabcd;
|
||||||
ext->currentBlock.coinbaseAddress = Address(1004);
|
_ext->gasPrice = 1002;
|
||||||
ext->currentBlock.timestamp = 1005;
|
_ext->previousBlock.hash = u256(1003);
|
||||||
ext->currentBlock.number = 1006;
|
_ext->currentBlock.coinbaseAddress = Address(1004);
|
||||||
ext->currentBlock.difficulty = 1007;
|
_ext->currentBlock.timestamp = 1005;
|
||||||
ext->currentBlock.gasLimit = 1008;
|
_ext->currentBlock.number = 1006;
|
||||||
std::string calldata = "Hello the Beautiful World of Ethereum!";
|
_ext->currentBlock.difficulty = 1007;
|
||||||
ext->data = calldata;
|
_ext->currentBlock.gasLimit = 1008;
|
||||||
unsigned char fakecode[] = {0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf};
|
std::string calldata = "Hello the Beautiful World of Ethereum!";
|
||||||
ext->code = decltype(ext->code)(fakecode, 8);
|
_ext->data = calldata;
|
||||||
|
unsigned char fakecode[] = {0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf};
|
||||||
|
_ext->code = decltype(_ext->code)(fakecode, 8);
|
||||||
|
}
|
||||||
|
|
||||||
// Init runtime
|
// Init runtime
|
||||||
uint64_t gas = 100;
|
uint64_t gas = 100;
|
||||||
Runtime runtime(gas, std::move(ext));
|
Runtime runtime(gas, *_ext);
|
||||||
|
|
||||||
auto entryFunc = module->getFunction("main");
|
auto entryFunc = module->getFunction("main");
|
||||||
if (!entryFunc)
|
if (!entryFunc)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <llvm/IR/Module.h>
|
#include <llvm/IR/Module.h>
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
#include <libdevcore/Common.h>
|
||||||
|
#include <libevm/ExtVMFace.h>
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
@ -17,7 +18,7 @@ class ExecutionEngine
|
||||||
public:
|
public:
|
||||||
ExecutionEngine();
|
ExecutionEngine();
|
||||||
|
|
||||||
int run(std::unique_ptr<llvm::Module> module);
|
int run(std::unique_ptr<llvm::Module> module, ExtVMFace* _ext = nullptr);
|
||||||
|
|
||||||
bytes returnData;
|
bytes returnData;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ extern "C"
|
||||||
EXPORT i256 gas;
|
EXPORT i256 gas;
|
||||||
}
|
}
|
||||||
|
|
||||||
Runtime::Runtime(u256 _gas, std::unique_ptr<ExtVMFace> _ext):
|
Runtime::Runtime(u256 _gas, ExtVMFace& _ext):
|
||||||
m_ext(std::move(_ext))
|
m_ext(_ext)
|
||||||
{
|
{
|
||||||
assert(!g_runtime);
|
assert(!g_runtime);
|
||||||
g_runtime = this;
|
g_runtime = this;
|
||||||
|
|
@ -44,7 +44,7 @@ MemoryImpl& Runtime::getMemory()
|
||||||
|
|
||||||
ExtVMFace& Runtime::getExt()
|
ExtVMFace& Runtime::getExt()
|
||||||
{
|
{
|
||||||
return *g_runtime->m_ext;
|
return g_runtime->m_ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
u256 Runtime::getGas()
|
u256 Runtime::getGas()
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ using MemoryImpl = bytes;
|
||||||
class Runtime
|
class Runtime
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Runtime(u256 _gas, std::unique_ptr<ExtVMFace> _ext);
|
Runtime(u256 _gas, ExtVMFace& _ext);
|
||||||
~Runtime();
|
~Runtime();
|
||||||
|
|
||||||
Runtime(const Runtime&) = delete;
|
Runtime(const Runtime&) = delete;
|
||||||
|
|
@ -41,7 +41,7 @@ public:
|
||||||
private:
|
private:
|
||||||
StackImpl m_stack;
|
StackImpl m_stack;
|
||||||
MemoryImpl m_memory;
|
MemoryImpl m_memory;
|
||||||
std::unique_ptr<ExtVMFace> m_ext;
|
ExtVMFace& m_ext;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ bytes VM::go(ExtVMFace& _ext)
|
||||||
module->dump();
|
module->dump();
|
||||||
|
|
||||||
ExecutionEngine engine;
|
ExecutionEngine engine;
|
||||||
auto exitCode = engine.run(std::move(module));
|
auto exitCode = engine.run(std::move(module), &_ext);
|
||||||
|
|
||||||
switch (exitCode)
|
switch (exitCode)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue