Browse Source

Code migration.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
8e4881bcd0
  1. 12
      evmjit/include/evmjit/DataTypes.h
  2. 6
      evmjit/include/evmjit/JIT.h
  3. 2
      evmjit/libevmjit-cpp/JitVM.h
  4. 1
      evmjit/libevmjit/Arith256.cpp
  5. 4
      evmjit/libevmjit/BasicBlock.h
  6. 3
      evmjit/libevmjit/CMakeLists.txt
  7. 1
      evmjit/libevmjit/Cache.cpp
  8. 37
      evmjit/libevmjit/Common.h
  9. 73
      evmjit/libevmjit/ExecutionContext.h
  10. 41
      evmjit/libevmjit/ExecutionEngine.cpp
  11. 5
      evmjit/libevmjit/ExecutionEngine.h
  12. 1
      evmjit/libevmjit/GasMeter.h
  13. 5
      evmjit/libevmjit/Instruction.cpp
  14. 7
      evmjit/libevmjit/Instruction.h
  15. 46
      evmjit/libevmjit/JIT.cpp
  16. 63
      evmjit/libevmjit/RuntimeData.h
  17. 3
      evmjit/libevmjit/RuntimeManager.h
  18. 3
      evmjit/libevmjit/Type.h
  19. 1
      evmjit/libevmjit/interface.cpp

12
evmjit/include/evmjit/DataTypes.h

@ -3,11 +3,23 @@
#include <cstdint> #include <cstdint>
#include <functional> #include <functional>
#ifdef _MSC_VER
#define EXPORT __declspec(dllexport)
#define _ALLOW_KEYWORD_MACROS
#define noexcept throw()
#else
#define EXPORT
#endif
namespace dev namespace dev
{ {
namespace evmjit namespace evmjit
{ {
using byte = uint8_t;
using bytes_ref = std::tuple<byte const*, size_t>;
using code_iterator = byte const*;
struct h256 struct h256
{ {
uint64_t words[4]; uint64_t words[4];

6
evmjit/include/evmjit/JIT.h

@ -16,12 +16,6 @@ public:
/// In this case the code can be executed without overhead. /// In this case the code can be executed without overhead.
/// \param _codeHash The Keccak hash of the EVM code. /// \param _codeHash The Keccak hash of the EVM code.
static bool isCodeReady(h256 _codeHash); static bool isCodeReady(h256 _codeHash);
private:
friend class ExecutionEngine;
static void* getCode(h256 _codeHash);
static void mapCode(h256 _codeHash, void* _funcAddr);
}; };
} }

2
evmjit/libevmjit-cpp/JitVM.h

@ -17,7 +17,7 @@ private:
friend class VMFactory; friend class VMFactory;
explicit JitVM(u256 _gas = 0) : VMFace(_gas) {} explicit JitVM(u256 _gas = 0) : VMFace(_gas) {}
jit::RuntimeData m_data; evmjit::RuntimeData m_data;
evmjit::ExecutionContext m_context; evmjit::ExecutionContext m_context;
std::unique_ptr<VMFace> m_fallbackVM; ///< VM used in case of input data rejected by JIT std::unique_ptr<VMFace> m_fallbackVM; ///< VM used in case of input data rejected by JIT
}; };

1
evmjit/libevmjit/Arith256.cpp

@ -8,6 +8,7 @@
#include <llvm/IR/IntrinsicInst.h> #include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h" #include "preprocessor/llvm_includes_end.h"
#include "evmjit/DataTypes.h"
#include "Type.h" #include "Type.h"
#include "Endianness.h" #include "Endianness.h"
#include "Utils.h" #include "Utils.h"

4
evmjit/libevmjit/BasicBlock.h

@ -2,7 +2,8 @@
#include <vector> #include <vector>
#include "Common.h"
#include "evmjit/DataTypes.h"
#include "Stack.h" #include "Stack.h"
namespace dev namespace dev
@ -13,6 +14,7 @@ namespace jit
{ {
using instr_idx = uint64_t; using instr_idx = uint64_t;
using namespace evmjit;
class BasicBlock class BasicBlock
{ {

3
evmjit/libevmjit/CMakeLists.txt

@ -17,10 +17,9 @@ set(SOURCES
GasMeter.cpp GasMeter.h GasMeter.cpp GasMeter.h
Instruction.cpp Instruction.h Instruction.cpp Instruction.h
interface.cpp interface.h interface.cpp interface.h
JIT.cpp ${EVMJIT_INCLUDE_DIR}/evmjit/JIT.h ${EVMJIT_INCLUDE_DIR}/evmjit/JIT.h
Memory.cpp Memory.h Memory.cpp Memory.h
Optimizer.cpp Optimizer.h Optimizer.cpp Optimizer.h
RuntimeData.h
RuntimeManager.cpp RuntimeManager.h RuntimeManager.cpp RuntimeManager.h
Stack.cpp Stack.h Stack.cpp Stack.h
Type.cpp Type.h Type.cpp Type.h

1
evmjit/libevmjit/Cache.cpp

@ -18,7 +18,6 @@ namespace dev
{ {
namespace evmjit namespace evmjit
{ {
using namespace eth::jit;
namespace namespace
{ {

37
evmjit/libevmjit/Common.h

@ -3,48 +3,13 @@
#include <tuple> #include <tuple>
#include <cstdint> #include <cstdint>
#ifdef _MSC_VER
#define EXPORT __declspec(dllexport)
#define _ALLOW_KEYWORD_MACROS
#define noexcept throw()
#else
#define EXPORT
#endif
namespace dev namespace dev
{ {
namespace eth namespace eth
{ {
namespace jit namespace jit{
{
using byte = uint8_t;
using bytes_ref = std::tuple<byte const*, size_t>;
using code_iterator = byte const*;
enum class ReturnCode
{
// Success codes
Stop = 0,
Return = 1,
Suicide = 2,
// Standard error codes
OutOfGas = -1,
StackUnderflow = -2,
BadJumpDestination = -3,
BadInstruction = -4,
Rejected = -5, ///< Input data (code, gas, block info, etc.) does not meet JIT requirement and execution request has been rejected
// Internal error codes
LLVMConfigError = -101,
LLVMCompileError = -102,
LLVMLinkError = -103,
UnexpectedException = -111,
LinkerWorkaround = -299,
};
#define UNTESTED assert(false) #define UNTESTED assert(false)

73
evmjit/libevmjit/ExecutionContext.h

@ -1,12 +1,81 @@
#pragma once #pragma once
#include "RuntimeData.h" #include "evmjit/DataTypes.h"
namespace dev namespace dev
{ {
namespace evmjit namespace evmjit
{ {
using namespace eth::jit; // FIXME
struct RuntimeData
{
enum Index
{
Gas,
GasPrice,
CallData,
CallDataSize,
Address,
Caller,
Origin,
CallValue,
CoinBase,
Difficulty,
GasLimit,
Number,
Timestamp,
Code,
CodeSize,
SuicideDestAddress = Address, ///< Suicide balance destination address
ReturnData = CallData, ///< Return data pointer (set only in case of RETURN)
ReturnDataSize = CallDataSize, ///< Return data size (set only in case of RETURN)
};
int64_t gas = 0;
int64_t gasPrice = 0;
byte const* callData = nullptr;
uint64_t callDataSize = 0;
i256 address;
i256 caller;
i256 origin;
i256 callValue;
i256 coinBase;
i256 difficulty;
i256 gasLimit;
uint64_t number = 0;
int64_t timestamp = 0;
byte const* code = nullptr;
uint64_t codeSize = 0;
h256 codeHash;
};
/// VM Environment (ExtVM) opaque type
struct Env;
enum class ReturnCode
{
// Success codes
Stop = 0,
Return = 1,
Suicide = 2,
// Standard error codes
OutOfGas = -1,
StackUnderflow = -2,
BadJumpDestination = -3,
BadInstruction = -4,
Rejected = -5, ///< Input data (code, gas, block info, etc.) does not meet JIT requirement and execution request has been rejected
// Internal error codes
LLVMConfigError = -101,
LLVMCompileError = -102,
LLVMLinkError = -103,
UnexpectedException = -111,
LinkerWorkaround = -299,
};
class ExecutionContext class ExecutionContext
{ {

41
evmjit/libevmjit/ExecutionEngine.cpp

@ -32,6 +32,7 @@ namespace dev
{ {
namespace evmjit namespace evmjit
{ {
using namespace eth::jit;
namespace namespace
{ {
@ -53,7 +54,7 @@ std::string hash2str(i256 const& _hash)
return str; return str;
} }
void printVersion() // FIXME: Fix LLVM version parsing void printVersion()
{ {
std::cout << "Ethereum EVM JIT Compiler (http://github.com/ethereum/evmjit):\n" std::cout << "Ethereum EVM JIT Compiler (http://github.com/ethereum/evmjit):\n"
<< " EVMJIT version " << EVMJIT_VERSION << "\n" << " EVMJIT version " << EVMJIT_VERSION << "\n"
@ -124,6 +125,40 @@ std::unique_ptr<llvm::ExecutionEngine> init()
return ee; return ee;
} }
class JITImpl
{
public:
std::unordered_map<h256, void*> codeMap;
static JITImpl& instance()
{
static JITImpl s_instance;
return s_instance;
}
static void* getCode(h256 _codeHash);
static void mapCode(h256 _codeHash, void* _funcAddr);
};
void* JITImpl::getCode(h256 _codeHash)
{
auto& codeMap = JITImpl::instance().codeMap;
auto it = codeMap.find(_codeHash);
if (it != codeMap.end())
return it->second;
return nullptr;
}
void JITImpl::mapCode(h256 _codeHash, void* _funcAddr)
{
JITImpl::instance().codeMap.insert(std::make_pair(_codeHash, _funcAddr));
}
} // anonymous namespace
bool JIT::isCodeReady(h256 _codeHash)
{
return JITImpl::instance().codeMap.count(_codeHash) != 0;
} }
ReturnCode ExecutionEngine::run(ExecutionContext& _context) ReturnCode ExecutionEngine::run(ExecutionContext& _context)
@ -142,7 +177,7 @@ ReturnCode ExecutionEngine::run(ExecutionContext& _context)
auto mainFuncName = hash2str(codeHash); auto mainFuncName = hash2str(codeHash);
// TODO: Remove cast // TODO: Remove cast
auto entryFuncPtr = (EntryFuncPtr) JIT::getCode(codeHash); auto entryFuncPtr = (EntryFuncPtr) JITImpl::getCode(codeHash);
if (!entryFuncPtr) if (!entryFuncPtr)
{ {
auto module = Cache::getObject(mainFuncName); auto module = Cache::getObject(mainFuncName);
@ -168,7 +203,7 @@ ReturnCode ExecutionEngine::run(ExecutionContext& _context)
entryFuncPtr = (EntryFuncPtr)s_ee->getFunctionAddress(mainFuncName); entryFuncPtr = (EntryFuncPtr)s_ee->getFunctionAddress(mainFuncName);
if (!CHECK(entryFuncPtr)) if (!CHECK(entryFuncPtr))
return ReturnCode::LLVMLinkError; return ReturnCode::LLVMLinkError;
JIT::mapCode(codeHash, (void*)entryFuncPtr); // FIXME: Remove cast JITImpl::mapCode(codeHash, (void*)entryFuncPtr); // FIXME: Remove cast
} }
listener->stateChanged(ExecState::Execution); listener->stateChanged(ExecState::Execution);

5
evmjit/libevmjit/ExecutionEngine.h

@ -1,14 +1,13 @@
#pragma once #pragma once
#include "Common.h" #include "evmjit/DataTypes.h"
namespace dev namespace dev
{ {
namespace evmjit namespace evmjit
{ {
class ExecutionContext; class ExecutionContext;
enum class ReturnCode;
using namespace eth::jit;
enum class ExecState enum class ExecState
{ {

1
evmjit/libevmjit/GasMeter.h

@ -10,6 +10,7 @@ namespace eth
namespace jit namespace jit
{ {
class RuntimeManager; class RuntimeManager;
using namespace evmjit;
class GasMeter : public CompilerHelper // TODO: Use RuntimeHelper class GasMeter : public CompilerHelper // TODO: Use RuntimeHelper
{ {

5
evmjit/libevmjit/Instruction.cpp

@ -6,9 +6,7 @@
namespace dev namespace dev
{ {
namespace eth namespace evmjit
{
namespace jit
{ {
llvm::APInt readPushData(code_iterator& _curr, code_iterator _end) llvm::APInt readPushData(code_iterator& _curr, code_iterator _end)
@ -39,4 +37,3 @@ void skipPushData(code_iterator& _curr, code_iterator _end)
} }
} }
}

7
evmjit/libevmjit/Instruction.h

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Common.h" #include "evmjit/DataTypes.h"
namespace llvm namespace llvm
{ {
@ -9,9 +9,7 @@ namespace llvm
namespace dev namespace dev
{ {
namespace eth namespace evmjit
{
namespace jit
{ {
/// Virtual machine bytecode instruction. /// Virtual machine bytecode instruction.
@ -236,4 +234,3 @@ void skipPushData(code_iterator& _curr, code_iterator _end);
} }
} }
}

46
evmjit/libevmjit/JIT.cpp

@ -1,46 +0,0 @@
#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));
}
}
}

63
evmjit/libevmjit/RuntimeData.h

@ -1,63 +0,0 @@
#pragma once
#include "evmjit/DataTypes.h"
#include "Common.h"
namespace dev
{
namespace eth
{
namespace jit
{
using evmjit::i256;
using evmjit::h256;
struct RuntimeData
{
enum Index
{
Gas,
GasPrice,
CallData,
CallDataSize,
Address,
Caller,
Origin,
CallValue,
CoinBase,
Difficulty,
GasLimit,
Number,
Timestamp,
Code,
CodeSize,
SuicideDestAddress = Address, ///< Suicide balance destination address
ReturnData = CallData, ///< Return data pointer (set only in case of RETURN)
ReturnDataSize = CallDataSize, ///< Return data size (set only in case of RETURN)
};
int64_t gas = 0;
int64_t gasPrice = 0;
byte const* callData = nullptr;
uint64_t callDataSize = 0;
i256 address;
i256 caller;
i256 origin;
i256 callValue;
i256 coinBase;
i256 difficulty;
i256 gasLimit;
uint64_t number = 0;
int64_t timestamp = 0;
byte const* code = nullptr;
uint64_t codeSize = 0;
h256 codeHash;
};
/// VM Environment (ExtVM) opaque type
struct Env;
}
}
}

3
evmjit/libevmjit/RuntimeManager.h

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "ExecutionContext.h"
#include "CompilerHelper.h" #include "CompilerHelper.h"
#include "Type.h" #include "Type.h"
#include "RuntimeData.h"
#include "Instruction.h" #include "Instruction.h"
namespace dev namespace dev
@ -11,6 +11,7 @@ namespace eth
{ {
namespace jit namespace jit
{ {
using namespace evmjit;
class Stack; class Stack;
class RuntimeManager: public CompilerHelper class RuntimeManager: public CompilerHelper

3
evmjit/libevmjit/Type.h

@ -6,7 +6,7 @@
#include <llvm/IR/Metadata.h> #include <llvm/IR/Metadata.h>
#include "preprocessor/llvm_includes_end.h" // FIXME: LLVM 3.7: check if needed #include "preprocessor/llvm_includes_end.h" // FIXME: LLVM 3.7: check if needed
#include "Common.h" #include "ExecutionContext.h" // FIXME: crappy dependence
namespace dev namespace dev
{ {
@ -14,6 +14,7 @@ namespace eth
{ {
namespace jit namespace jit
{ {
using namespace evmjit;
struct Type struct Type
{ {

1
evmjit/libevmjit/interface.cpp

@ -3,7 +3,6 @@
extern "C" extern "C"
{ {
using namespace dev::eth::jit;
using namespace dev::evmjit; using namespace dev::evmjit;
EXPORT void* evmjit_create(RuntimeData* _data, Env* _env) noexcept EXPORT void* evmjit_create(RuntimeData* _data, Env* _env) noexcept

Loading…
Cancel
Save