Browse Source

Removing boost dependency from libevmjit

cl-refactor
Paweł Bylica 10 years ago
parent
commit
bf9dbce468
  1. 3
      evmjit/libevmjit-cpp/Env.cpp
  2. 32
      evmjit/libevmjit-cpp/JitVM.cpp
  3. 38
      evmjit/libevmjit-cpp/Utils.h
  4. 21
      evmjit/libevmjit/Arith256.cpp
  5. 1
      evmjit/libevmjit/Common.h
  6. 4
      evmjit/libevmjit/Runtime.cpp
  7. 3
      evmjit/libevmjit/RuntimeData.h
  8. 26
      evmjit/libevmjit/Utils.cpp
  9. 3
      evmjit/libevmjit/Utils.h

3
evmjit/libevmjit-cpp/Env.cpp

@ -3,7 +3,7 @@
#include <libevm/FeeStructure.h>
#include <libevm/ExtVMFace.h>
#include <evmjit/libevmjit/Utils.h>
#include "Utils.h"
extern "C"
{
@ -16,7 +16,6 @@ extern "C"
using namespace dev;
using namespace dev::eth;
using jit::i256;
using jit::eth2llvm;
EXPORT void env_sload(ExtVMFace* _env, i256* _index, i256* o_value)
{

32
evmjit/libevmjit-cpp/JitVM.cpp

@ -2,7 +2,7 @@
#include "JitVM.h"
#include <libevm/VM.h>
#include <evmjit/libevmjit/ExecutionEngine.h>
#include <evmjit/libevmjit/Utils.h>
#include "Utils.h"
namespace dev
{
@ -13,28 +13,28 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
{
using namespace jit;
m_data.set(RuntimeData::Gas, m_gas);
m_data.set(RuntimeData::Address, fromAddress(_ext.myAddress));
m_data.set(RuntimeData::Caller, fromAddress(_ext.caller));
m_data.set(RuntimeData::Origin, fromAddress(_ext.origin));
m_data.set(RuntimeData::CallValue, _ext.value);
m_data.set(RuntimeData::CallDataSize, _ext.data.size());
m_data.set(RuntimeData::GasPrice, _ext.gasPrice);
m_data.set(RuntimeData::CoinBase, fromAddress(_ext.currentBlock.coinbaseAddress));
m_data.set(RuntimeData::TimeStamp, _ext.currentBlock.timestamp);
m_data.set(RuntimeData::Number, _ext.currentBlock.number);
m_data.set(RuntimeData::Difficulty, _ext.currentBlock.difficulty);
m_data.set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit);
m_data.set(RuntimeData::CodeSize, _ext.code.size());
m_data.elems[RuntimeData::Gas] = eth2llvm(m_gas);
m_data.elems[RuntimeData::Address] = eth2llvm(fromAddress(_ext.myAddress));
m_data.elems[RuntimeData::Caller] = eth2llvm(fromAddress(_ext.caller));
m_data.elems[RuntimeData::Origin] = eth2llvm(fromAddress(_ext.origin));
m_data.elems[RuntimeData::CallValue] = eth2llvm(_ext.value);
m_data.elems[RuntimeData::CallDataSize] = eth2llvm(_ext.data.size());
m_data.elems[RuntimeData::GasPrice] = eth2llvm(_ext.gasPrice);
m_data.elems[RuntimeData::CoinBase] = eth2llvm(fromAddress(_ext.currentBlock.coinbaseAddress));
m_data.elems[RuntimeData::TimeStamp] = eth2llvm(_ext.currentBlock.timestamp);
m_data.elems[RuntimeData::Number] = eth2llvm(_ext.currentBlock.number);
m_data.elems[RuntimeData::Difficulty] = eth2llvm(_ext.currentBlock.difficulty);
m_data.elems[RuntimeData::GasLimit] = eth2llvm(_ext.currentBlock.gasLimit);
m_data.elems[RuntimeData::CodeSize] = eth2llvm(_ext.code.size());
m_data.callData = _ext.data.data();
m_data.code = _ext.code.data();
m_data.code = _ext.code.data();
auto env = reinterpret_cast<Env*>(&_ext);
auto exitCode = m_engine.run(_ext.code, &m_data, env);
switch (exitCode)
{
case ReturnCode::Suicide:
_ext.suicide(right160(m_data.get(RuntimeData::SuicideDestAddress)));
_ext.suicide(right160(llvm2eth(m_data.elems[RuntimeData::SuicideDestAddress])));
break;
case ReturnCode::BadJumpDestination:

38
evmjit/libevmjit-cpp/Utils.h

@ -0,0 +1,38 @@
#pragma once
#include <evmjit/libevmjit/Common.h>
namespace dev
{
namespace eth
{
inline u256 llvm2eth(jit::i256 _i)
{
u256 u = 0;
u |= _i.d;
u <<= 64;
u |= _i.c;
u <<= 64;
u |= _i.b;
u <<= 64;
u |= _i.a;
return u;
}
inline jit::i256 eth2llvm(u256 _u)
{
jit::i256 i;
u256 mask = 0xFFFFFFFFFFFFFFFF;
i.a = static_cast<uint64_t>(_u & mask);
_u >>= 64;
i.b = static_cast<uint64_t>(_u & mask);
_u >>= 64;
i.c = static_cast<uint64_t>(_u & mask);
_u >>= 64;
i.d = static_cast<uint64_t>(_u & mask);
return i;
}
}
}

21
evmjit/libevmjit/Arith256.cpp

@ -102,27 +102,6 @@ llvm::Value* Arith256::mulmod(llvm::Value* _arg1, llvm::Value* _arg2, llvm::Valu
namespace
{
using s256 = boost::multiprecision::int256_t;
inline s256 u2s(u256 _u)
{
static const bigint c_end = (bigint)1 << 256;
static const u256 c_send = (u256)1 << 255;
if (_u < c_send)
return (s256)_u;
else
return (s256)-(c_end - _u);
}
inline u256 s2u(s256 _u)
{
static const bigint c_end = (bigint)1 << 256;
if (_u >= 0)
return (u256)_u;
else
return (u256)(c_end + _u);
}
using uint128 = __uint128_t;
// uint128 add(uint128 a, uint128 b) { return a + b; }

1
evmjit/libevmjit/Common.h

@ -35,7 +35,6 @@ enum class ReturnCode
};
/// Representation of 256-bit value binary compatible with LLVM i256
// TODO: Replace with h256
struct i256
{
uint64_t a = 0;

4
evmjit/libevmjit/Runtime.cpp

@ -21,8 +21,8 @@ Runtime::Runtime(RuntimeData* _data, Env* _env) :
bytes_ref Runtime::getReturnData() const
{
// TODO: Handle large indexes
auto offset = static_cast<size_t>(llvm2eth(m_data.elems[RuntimeData::ReturnDataOffset]));
auto size = static_cast<size_t>(llvm2eth(m_data.elems[RuntimeData::ReturnDataSize]));
auto offset = static_cast<size_t>(m_data.elems[RuntimeData::ReturnDataOffset].a);
auto size = static_cast<size_t>(m_data.elems[RuntimeData::ReturnDataSize].a);
assert(offset + size <= m_memory.size() || size == 0);
if (offset + size > m_memory.size())

3
evmjit/libevmjit/RuntimeData.h

@ -38,9 +38,6 @@ struct RuntimeData
i256 elems[_size] = {};
byte const* callData = nullptr;
byte const* code = nullptr;
void set(Index _index, u256 _value) { elems[_index] = eth2llvm(_value); }
u256 get(Index _index) { return llvm2eth(elems[_index]); }
};
/// VM Environment (ExtVM) opaque type

26
evmjit/libevmjit/Utils.cpp

@ -8,32 +8,6 @@ namespace eth
namespace jit
{
u256 llvm2eth(i256 _i)
{
u256 u = 0;
u |= _i.d;
u <<= 64;
u |= _i.c;
u <<= 64;
u |= _i.b;
u <<= 64;
u |= _i.a;
return u;
}
i256 eth2llvm(u256 _u)
{
i256 i;
u256 mask = 0xFFFFFFFFFFFFFFFF;
i.a = static_cast<uint64_t>(_u & mask);
_u >>= 64;
i.b = static_cast<uint64_t>(_u & mask);
_u >>= 64;
i.c = static_cast<uint64_t>(_u & mask);
_u >>= 64;
i.d = static_cast<uint64_t>(_u & mask);
return i;
}
}
}

3
evmjit/libevmjit/Utils.h

@ -14,9 +14,6 @@ struct JIT: public NoteChannel { static const char* name() { return "JIT"; } };
//#define clog(CHANNEL) std::cerr
#define clog(CHANNEL) std::ostream(nullptr)
u256 llvm2eth(i256);
i256 eth2llvm(u256);
}
}
}

Loading…
Cancel
Save