mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Move mock of ExtVMFace to evmcc tool
This commit is contained in:
parent
89e6d2f3e6
commit
f7d6554ad6
4 changed files with 23 additions and 25 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
#include <libdevcore/Common.h>
|
#include <libdevcore/Common.h>
|
||||||
#include <libdevcore/CommonIO.h>
|
#include <libdevcore/CommonIO.h>
|
||||||
#include <libevmcore/Instruction.h>
|
#include <libevmcore/Instruction.h>
|
||||||
|
#include <libevm/ExtVMFace.h>
|
||||||
#include <libevmjit/Compiler.h>
|
#include <libevmjit/Compiler.h>
|
||||||
#include <libevmjit/ExecutionEngine.h>
|
#include <libevmjit/ExecutionEngine.h>
|
||||||
|
|
||||||
|
|
@ -172,7 +173,24 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
auto engine = eth::jit::ExecutionEngine();
|
auto engine = eth::jit::ExecutionEngine();
|
||||||
u256 gas = initialGas;
|
u256 gas = initialGas;
|
||||||
auto result = engine.run(std::move(module), gas, options.count("show-logs") > 0, nullptr);
|
|
||||||
|
// Create fake ExtVM interface
|
||||||
|
eth::ExtVMFace ext;
|
||||||
|
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;
|
||||||
|
ext.data = std::string("Hello the Beautiful World of Ethereum!");
|
||||||
|
ext.code = { 0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf };
|
||||||
|
|
||||||
|
auto result = engine.run(std::move(module), gas, options.count("show-logs") > 0, ext);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ ExecutionEngine::ExecutionEngine()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, bool _outputLogs, ExtVMFace* _ext)
|
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
|
||||||
|
|
||||||
|
|
@ -82,33 +82,13 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, bool
|
||||||
clog(JIT) << "Module finalization time: "
|
clog(JIT) << "Module finalization time: "
|
||||||
<< std::chrono::duration_cast<std::chrono::microseconds>(finalizationEndTime - finalizationStartTime).count();
|
<< std::chrono::duration_cast<std::chrono::microseconds>(finalizationEndTime - finalizationStartTime).count();
|
||||||
|
|
||||||
// Create fake ExtVM interface
|
|
||||||
if (!_ext)
|
|
||||||
{
|
|
||||||
_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->code = { 0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf };
|
|
||||||
}
|
|
||||||
|
|
||||||
auto entryFunc = module->getFunction("main");
|
auto entryFunc = module->getFunction("main");
|
||||||
if (!entryFunc)
|
if (!entryFunc)
|
||||||
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("main function not found"));
|
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("main function not found"));
|
||||||
|
|
||||||
ReturnCode returnCode;
|
ReturnCode returnCode;
|
||||||
std::jmp_buf buf;
|
std::jmp_buf buf;
|
||||||
Runtime runtime(_gas, *_ext, buf, _outputLogs);
|
Runtime runtime(_gas, _ext, buf, _outputLogs);
|
||||||
auto r = setjmp(buf);
|
auto r = setjmp(buf);
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class ExecutionEngine
|
||||||
public:
|
public:
|
||||||
ExecutionEngine();
|
ExecutionEngine();
|
||||||
|
|
||||||
int run(std::unique_ptr<llvm::Module> module, u256& _gas, bool _outputLogs, ExtVMFace* _ext);
|
int run(std::unique_ptr<llvm::Module> module, u256& _gas, bool _outputLogs, ExtVMFace& _ext);
|
||||||
|
|
||||||
bytes returnData;
|
bytes returnData;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
|
||||||
auto module = Compiler(defaultOptions).compile(_ext.code);
|
auto module = Compiler(defaultOptions).compile(_ext.code);
|
||||||
|
|
||||||
ExecutionEngine engine;
|
ExecutionEngine engine;
|
||||||
auto exitCode = engine.run(std::move(module), m_gas, false, &_ext);
|
auto exitCode = engine.run(std::move(module), m_gas, false, _ext);
|
||||||
|
|
||||||
switch (static_cast<ReturnCode>(exitCode))
|
switch (static_cast<ReturnCode>(exitCode))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue