Browse Source

Merge branch 'develop-evmcc' of github.com:imapp-pl/ethereum into develop-evmcc

cl-refactor
artur-zawlocki 10 years ago
parent
commit
02ad3be828
  1. 22
      libevm/ExtVMFace.h
  2. 1
      libevmjit/BasicBlock.cpp
  3. 21
      libevmjit/Compiler.cpp
  4. 24
      libevmjit/Endianness.cpp
  5. 22
      libevmjit/Endianness.h
  6. 2
      windows/LibEvmJit.vcxproj
  7. 6
      windows/LibEvmJit.vcxproj.filters

22
libevm/ExtVMFace.h

@ -57,37 +57,37 @@ public:
ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth);
/// Get the code at the given location in code ROM.
byte getCode(u256 _n) const { return _n < code.size() ? code[(unsigned)_n] : 0; }
virtual byte getCode(u256 _n) const { return _n < code.size() ? code[(unsigned)_n] : 0; }
/// Read storage location.
u256 store(u256) { return 0; }
virtual u256 store(u256) { return 0; }
/// Write a value in storage.
void setStore(u256, u256) {}
virtual void setStore(u256, u256) {}
/// Read address's balance.
u256 balance(Address) { return 0; }
virtual u256 balance(Address) { return 0; }
/// Read address's code.
bytes const& codeAt(Address) { return NullBytes; }
virtual bytes const& codeAt(Address) { return NullBytes; }
/// Subtract amount from account's balance.
void subBalance(u256) {}
virtual void subBalance(u256) {}
/// Determine account's TX count.
u256 txCount(Address) { return 0; }
virtual u256 txCount(Address) { return 0; }
/// Suicide the associated contract and give proceeds to the given address.
void suicide(Address) { suicides.insert(myAddress); }
virtual void suicide(Address) { suicides.insert(myAddress); }
/// Create a new (contract) account.
h160 create(u256, u256*, bytesConstRef, bytesConstRef) { return h160(); }
virtual h160 create(u256, u256*, bytesConstRef, bytesConstRef) { return h160(); }
/// Make a new message call.
bool call(Address, u256, bytesConstRef, u256*, bytesRef, OnOpFunc const&, Address, Address) { return false; }
virtual bool call(Address, u256, bytesConstRef, u256*, bytesRef, OnOpFunc const&, Address, Address) { return false; }
/// Revert any changes made (by any of the other calls).
void revert() {}
virtual void revert() {}
Address myAddress; ///< Address associated with executing code (a contract, or contract-to-be).
Address caller; ///< Address which sent the message (either equal to origin or a contract).

1
libevmjit/BasicBlock.cpp

@ -32,6 +32,7 @@ BasicBlock::BasicBlock(std::string _name, llvm::Function* _mainFunc) :
void BasicBlock::Stack::push(llvm::Value* _value)
{
assert(_value->getType() == Type::i256);
m_backend.push_back(_value);
}

21
libevmjit/Compiler.cpp

@ -15,6 +15,7 @@
#include "Ext.h"
#include "GasMeter.h"
#include "Utils.h"
#include "Endianness.h"
namespace dev
{
@ -420,21 +421,11 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
const auto byteNum = stack.pop();
auto value = stack.pop();
/*
if (byteNum < 32) - use select
{
value <<= byteNum*8
value >>= 31*8
push value
}
else push 0
*/
// TODO: Shifting by 0 gives wrong results as of this bug http://llvm.org/bugs/show_bug.cgi?id=16439
auto shbits = m_builder.CreateShl(byteNum, Constant::get(3));
value = m_builder.CreateShl(value, shbits);
value = m_builder.CreateLShr(value, Constant::get(31 * 8));
//
value = Endianness::toBE(m_builder, value);
auto bytes = m_builder.CreateBitCast(value, llvm::VectorType::get(Type::Byte, 32), "bytes");
auto byte = m_builder.CreateExtractElement(bytes, byteNum, "byte");
value = m_builder.CreateZExt(byte, Type::i256);
auto byteNumValid = m_builder.CreateICmpULT(byteNum, Constant::get(32));
value = m_builder.CreateSelect(byteNumValid, value, Constant::get(0));

24
libevmjit/Endianness.cpp

@ -0,0 +1,24 @@
#include "Endianness.h"
#include <llvm/IR/IntrinsicInst.h>
#include "Type.h"
namespace dev
{
namespace eth
{
namespace jit
{
llvm::Value* Endianness::toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word)
{
// TODO: Native is Little Endian
auto bswap = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::i256);
return _builder.CreateCall(bswap, _word);
}
}
}
}

22
libevmjit/Endianness.h

@ -0,0 +1,22 @@
#pragma once
#include <llvm/IR/IRBuilder.h>
namespace dev
{
namespace eth
{
namespace jit
{
class Endianness
{
public:
static llvm::Value* toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word);
};
}
}
}

2
windows/LibEvmJit.vcxproj

@ -126,6 +126,7 @@
<ClCompile Include="..\libevmjit\BasicBlock.cpp" />
<ClCompile Include="..\libevmjit\Compiler.cpp" />
<ClCompile Include="..\libevmjit\CompilerHelper.cpp" />
<ClCompile Include="..\libevmjit\Endianness.cpp" />
<ClCompile Include="..\libevmjit\ExecutionEngine.cpp" />
<ClCompile Include="..\libevmjit\Ext.cpp" />
<ClCompile Include="..\libevmjit\GasMeter.cpp" />
@ -139,6 +140,7 @@
<ClInclude Include="..\libevmjit\BasicBlock.h" />
<ClInclude Include="..\libevmjit\Compiler.h" />
<ClInclude Include="..\libevmjit\CompilerHelper.h" />
<ClInclude Include="..\libevmjit\Endianness.h" />
<ClInclude Include="..\libevmjit\ExecutionEngine.h" />
<ClInclude Include="..\libevmjit\Ext.h" />
<ClInclude Include="..\libevmjit\GasMeter.h" />

6
windows/LibEvmJit.vcxproj.filters

@ -39,6 +39,9 @@
<ClCompile Include="..\libevmjit\VM.cpp">
<Filter>libevmjit</Filter>
</ClCompile>
<ClCompile Include="..\libevmjit\Endianness.cpp">
<Filter>libevmjit</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\libevmjit\BasicBlock.h">
@ -74,5 +77,8 @@
<ClInclude Include="..\libevmjit\VM.h">
<Filter>libevmjit</Filter>
</ClInclude>
<ClInclude Include="..\libevmjit\Endianness.h">
<Filter>libevmjit</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading…
Cancel
Save