Browse Source

Handle endianness of MSTORE & MLOAD [#79877740]

cl-refactor
Paweł Bylica 10 years ago
parent
commit
5db2038111
  1. 1
      evmcc/test/mem/mstore1.evm
  2. 6
      evmcc/test/mem/mstore1.lll
  3. 3
      libevmjit/Endianness.cpp
  4. 7
      libevmjit/Endianness.h
  5. 6
      libevmjit/Memory.cpp

1
evmcc/test/mem/mstore1.evm

@ -0,0 +1 @@
6001600054

6
evmcc/test/mem/mstore1.lll

@ -0,0 +1,6 @@
(asm ;; []
1
0
MSTORE ;; [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]
)

3
libevmjit/Endianness.cpp

@ -12,9 +12,10 @@ namespace eth
namespace jit
{
llvm::Value* Endianness::toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word)
llvm::Value* Endianness::bswap(llvm::IRBuilder<>& _builder, llvm::Value* _word)
{
// TODO: Native is Little Endian
assert(_word->getType() == Type::i256);
auto bswap = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::i256);
return _builder.CreateCall(bswap, _word);
}

7
libevmjit/Endianness.h

@ -14,7 +14,12 @@ class Endianness
{
public:
static llvm::Value* toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word);
static llvm::Value* toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswap(_builder, _word); }
static llvm::Value* toNative(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswap(_builder, _word); }
private:
static llvm::Value* bswap(llvm::IRBuilder<>& _builder, llvm::Value* _word);
};
}

6
libevmjit/Memory.cpp

@ -14,6 +14,7 @@
#include "Type.h"
#include "Runtime.h"
#include "GasMeter.h"
#include "Endianness.h"
namespace dev
{
@ -117,12 +118,15 @@ llvm::Function* Memory::createFunc(bool _isStore, llvm::Type* _valueType, GasMet
{
llvm::Value* value = ++func->arg_begin();
value->setName("value");
if (isWord)
value = Endianness::toBE(m_builder, value);
m_builder.CreateStore(value, ptr);
m_builder.CreateRetVoid();
}
else
{
auto ret = m_builder.CreateLoad(ptr);
llvm::Value* ret = m_builder.CreateLoad(ptr);
ret = Endianness::toNative(m_builder, ret);
m_builder.CreateRet(ret);
}

Loading…
Cancel
Save