mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +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; }
|
||||
|
||||
|
||||
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;
|
||||
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;
|
||||
_ext->data = calldata;
|
||||
unsigned char fakecode[] = {0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf};
|
||||
ext->code = decltype(ext->code)(fakecode, 8);
|
||||
_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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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…
Reference in a new issue