Browse Source

resolved circular dependency between libevm and libevmjit

cl-refactor
Artur Zawłocki 10 years ago
parent
commit
312e05ab49
  1. 1
      exp/CMakeLists.txt
  2. 3
      libethereum/CMakeLists.txt
  3. 4
      libethereum/Executive.cpp
  4. 4
      libethereum/State.cpp
  5. 8
      libethereum/State.h
  6. 4
      libevm/VM.h
  7. 12
      libevm/VMFace.cpp
  8. 6
      libevm/VMFace.h
  9. 1
      libevmjit/VM.cpp
  10. 8
      libevmjit/VM.h
  11. 3
      test/createRandomTest.cpp
  12. 10
      test/vm.cpp

1
exp/CMakeLists.txt

@ -18,6 +18,7 @@ endif()
target_link_libraries(${EXECUTABLE} ${LEVELDB_LS})
if(EVMJIT)
target_link_libraries(${EXECUTABLE} evm)
target_link_libraries(${EXECUTABLE} evmjit)
endif()

3
libethereum/CMakeLists.txt

@ -28,6 +28,9 @@ endif()
target_link_libraries(${EXECUTABLE} ${LEVELDB_LS})
target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS})
target_link_libraries(${EXECUTABLE} gmp)
if (EVMJIT)
target_link_libraries(${EXECUTABLE} evmjit)
endif()
if("${TARGET_PLATFORM}" STREQUAL "w64")
target_link_libraries(${EXECUTABLE} boost_system-mt-s)

4
libethereum/Executive.cpp

@ -118,7 +118,7 @@ bool Executive::call(Address _receiveAddress, Address _senderAddress, u256 _valu
if (m_s.addressHasCode(_receiveAddress))
{
m_vm = VMFace::create(VMFace::Interpreter, _gas).release();
m_vm = VMFactory::create(VMFactory::Interpreter, _gas).release();
bytes const& c = m_s.code(_receiveAddress);
m_ext = new ExtVM(m_s, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &c, m_ms);
}
@ -137,7 +137,7 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g
m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress) + _endowment, Account::ContractConception);
// Execute _init.
m_vm = VMFace::create(VMFace::Interpreter, _gas).release();
m_vm = VMFactory::create(VMFactory::Interpreter, _gas).release();
m_ext = new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_ms);
return _init.empty();
}

4
libethereum/State.cpp

@ -1214,7 +1214,7 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA
}
else if (addressHasCode(_codeAddress))
{
auto vmObj = VMFace::create(getVMKind(), *_gas);
auto vmObj = VMFactory::create(getVMKind(), *_gas);
auto& vm = *vmObj;
ExtVM evm(*this, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &code(_codeAddress), o_ms, _level);
bool revert = false;
@ -1274,7 +1274,7 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
m_cache[newAddress] = Account(balance(newAddress) + _endowment, Account::ContractConception);
// Execute init code.
auto vmObj = VMFace::create(getVMKind(), *_gas);
auto vmObj = VMFactory::create(getVMKind(), *_gas);
auto& vm = *vmObj;
ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level);
bool revert = false;

8
libethereum/State.h

@ -30,6 +30,7 @@
#include <libethcore/Exceptions.h>
#include <libethcore/BlockInfo.h>
#include <libethcore/ProofOfWork.h>
#include <libethereum/VMFactory.h>
#include <libevm/FeeStructure.h>
#include <libevm/ExtVMFace.h>
#include <libevm/VMFace.h>
@ -39,6 +40,7 @@
#include "TransactionReceipt.h"
#include "Executive.h"
#include "AccountDiff.h"
#include "VMFactory.h"
namespace dev
{
@ -261,10 +263,10 @@ public:
void cleanup(bool _fullCommit);
/// Sets VM kind to be used by the state
void setVMKind(VMFace::Kind _kind) { m_vmKind = _kind; }
void setVMKind(VMFactory::Kind _kind) { m_vmKind = _kind; }
/// Get the kind of VM used by the state
VMFace::Kind getVMKind() const { return m_vmKind; }
VMFactory::Kind getVMKind() const { return m_vmKind; }
private:
/// Undo the changes to the state for committing to mine.
@ -333,7 +335,7 @@ private:
u256 m_blockReward;
VMFace::Kind m_vmKind = VMFace::Interpreter; ///< The kind of VM used by the state
VMFactory::Kind m_vmKind = VMFactory::Interpreter; ///< The kind of VM used by the state
static std::string c_defaultPath;

4
libevm/VM.h

@ -36,6 +36,8 @@ namespace dev
namespace eth
{
class VMFactory;
/**
*/
class VM : public VMFace
@ -53,7 +55,7 @@ public:
u256s const& stack() const { return m_stack; }
private:
friend VMFace;
friend VMFactory;
explicit VM(u256 _gas = 0): VMFace(_gas) {}
template <class Ext>

12
libevm/VMFace.cpp

@ -22,15 +22,7 @@
using namespace dev;
using namespace dev::eth;
std::unique_ptr<VMFace> VMFace::create(VMFace::Kind _kind, u256 _gas)
void VMFace::reset(u256 _gas) noexcept
{
std::unique_ptr<VMFace> vm;
#if ETH_EVMJIT
vm.reset(_kind == Kind::JIT ? static_cast<VMFace*>(new jit::VM) : new VM);
#else
(void) _kind; // suppress unused var warning
vm.reset(new VM);
#endif
vm->reset(_gas);
return vm;
m_gas = _gas;
}

6
libevm/VMFace.h

@ -62,16 +62,12 @@ public:
VMFace(VMFace const&) = delete;
void operator=(VMFace const&) = delete;
virtual void reset(u256 _gas = 0) noexcept { m_gas = _gas; }
virtual void reset(u256 _gas = 0) noexcept;
virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) = 0;
u256 gas() const { return m_gas; }
enum Kind: bool { Interpreter, JIT };
static std::unique_ptr<VMFace> create(Kind, u256 _gas = 0);
protected:
u256 m_gas = 0;
};

1
libevmjit/VM.cpp

@ -2,6 +2,7 @@
#include "VM.h"
#include <libevm/VMFace.h>
#include <libevm/VM.h>
#include "ExecutionEngine.h"
#include "Compiler.h"

8
libevmjit/VM.h

@ -9,6 +9,9 @@ namespace dev
{
namespace eth
{
class VMFactory;
namespace jit
{
@ -16,8 +19,11 @@ class VM: public VMFace
{
virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final;
enum Kind: bool { Interpreter, JIT };
static std::unique_ptr<VMFace> create(Kind, u256 _gas = 0);
private:
friend VMFace;
friend VMFactory;
explicit VM(u256 _gas = 0): VMFace(_gas) {}
bytes m_output;

3
test/createRandomTest.cpp

@ -31,6 +31,7 @@
#include <json_spirit/json_spirit_writer_template.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonData.h>
#include <libethereum/VMFactory.h>
#include <libevmcore/Instruction.h>
#include <libevm/VM.h>
#include "vm.h"
@ -128,7 +129,7 @@ void doMyTests(json_spirit::mValue& v)
assert(o.count("exec") > 0);
auto vmObj = eth::VMFace::create(eth::VMFace::Interpreter);
auto vmObj = eth::VMFactory::create(eth::VMFactory::Interpreter);
auto& vm = *vmObj;
test::FakeExtVM fev;
fev.importEnv(o["env"].get_obj());

10
test/vm.cpp

@ -22,6 +22,7 @@
#include <chrono>
#include <boost/filesystem.hpp>
#include <libethereum/VMFactory.h>
#include "vm.h"
using namespace std;
using namespace json_spirit;
@ -322,8 +323,11 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
auto useJit = false;
for (auto i = 0; i < argc && !useJit; ++i)
useJit |= std::string(argv[i]) == "--jit";
auto vmKind = useJit ? VMFace::JIT : VMFace::Interpreter;
#if ETH_EVMJIT
auto vmKind = useJit ? VMFactory::JIT : VMFactory::Interpreter;
#else
auto vmKind == VMFactory::Interpreter;
#endif
dev::test::FakeExtVM fev;
fev.importEnv(o["env"].get_obj());
@ -339,7 +343,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
fev.code = fev.thisTxCode;
}
auto vm = VMFace::create(vmKind, fev.gas);
auto vm = VMFactory::create(vmKind, fev.gas);
bytes output;
auto startTime = std::chrono::high_resolution_clock::now();

Loading…
Cancel
Save