Browse Source
The JIT class added, future public EVM JIT library interface. Currently it supports queries about EVM code status.cl-refactor
Paweł Bylica
10 years ago
11 changed files with 172 additions and 32 deletions
@ -0,0 +1,56 @@ |
|||
#pragma once |
|||
|
|||
#include <cstdint> |
|||
#include <functional> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace evmjit |
|||
{ |
|||
|
|||
struct h256 |
|||
{ |
|||
uint64_t words[4]; |
|||
}; |
|||
|
|||
inline bool operator==(h256 _h1, h256 _h2) |
|||
{ |
|||
return _h1.words[0] == _h2.words[0] && |
|||
_h1.words[1] == _h2.words[1] && |
|||
_h1.words[2] == _h2.words[2] && |
|||
_h1.words[3] == _h2.words[3]; |
|||
} |
|||
|
|||
/// Representation of 256-bit value binary compatible with LLVM i256
|
|||
struct i256 |
|||
{ |
|||
uint64_t a = 0; |
|||
uint64_t b = 0; |
|||
uint64_t c = 0; |
|||
uint64_t d = 0; |
|||
|
|||
i256() = default; |
|||
i256(h256 _h) |
|||
{ |
|||
a = _h.words[0]; |
|||
b = _h.words[1]; |
|||
c = _h.words[2]; |
|||
d = _h.words[3]; |
|||
} |
|||
}; |
|||
|
|||
} |
|||
} |
|||
|
|||
namespace std |
|||
{ |
|||
template<> struct hash<dev::evmjit::h256> |
|||
{ |
|||
size_t operator()(dev::evmjit::h256 const& _h) const |
|||
{ |
|||
/// This implementation expects the argument to be a full 256-bit Keccak hash.
|
|||
/// It does nothing more than returning a slice of the input hash.
|
|||
return static_cast<size_t>(_h.words[0]); |
|||
}; |
|||
}; |
|||
} |
@ -0,0 +1,36 @@ |
|||
#pragma once |
|||
|
|||
#include "evmjit/DataTypes.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
namespace jit |
|||
{ |
|||
class ExecutionEngine; |
|||
} |
|||
} |
|||
|
|||
namespace evmjit |
|||
{ |
|||
|
|||
class JIT |
|||
{ |
|||
public: |
|||
|
|||
/// Ask JIT if the EVM code is ready for execution.
|
|||
/// Returns `true` if the EVM code has been compiled and loaded into memory.
|
|||
/// In this case the code can be executed without overhead.
|
|||
/// \param _codeHash The Keccak hash of the EVM code.
|
|||
static bool isCodeReady(h256 _codeHash); |
|||
|
|||
private: |
|||
friend class dev::eth::jit::ExecutionEngine; |
|||
|
|||
static void* getCode(h256 _codeHash); |
|||
static void mapCode(h256 _codeHash, void* _funcAddr); |
|||
}; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,46 @@ |
|||
#include "evmjit/JIT.h" |
|||
|
|||
#include <unordered_map> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace evmjit |
|||
{ |
|||
namespace |
|||
{ |
|||
|
|||
class JITImpl: JIT |
|||
{ |
|||
public: |
|||
std::unordered_map<h256, void*> codeMap; |
|||
|
|||
static JITImpl& instance() |
|||
{ |
|||
static JITImpl s_instance; |
|||
return s_instance; |
|||
} |
|||
}; |
|||
|
|||
} // anonymous namespace
|
|||
|
|||
bool JIT::isCodeReady(h256 _codeHash) |
|||
{ |
|||
return JITImpl::instance().codeMap.count(_codeHash) != 0; |
|||
} |
|||
|
|||
void* JIT::getCode(h256 _codeHash) |
|||
{ |
|||
auto& codeMap = JITImpl::instance().codeMap; |
|||
auto it = codeMap.find(_codeHash); |
|||
if (it != codeMap.end()) |
|||
return it->second; |
|||
return nullptr; |
|||
} |
|||
|
|||
void JIT::mapCode(h256 _codeHash, void* _funcAddr) |
|||
{ |
|||
JITImpl::instance().codeMap.insert(std::make_pair(_codeHash, _funcAddr)); |
|||
} |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue