Browse Source

Load memory data from Array memory

cl-refactor
Paweł Bylica 10 years ago
parent
commit
2293923a64
  1. 11
      libevmjit/Memory.cpp
  2. 2
      libevmjit/Runtime.cpp
  3. 2
      libevmjit/RuntimeManager.cpp
  4. 2
      libevmjit/RuntimeManager.h

11
libevmjit/Memory.cpp

@ -139,7 +139,7 @@ llvm::Function* Memory::createFunc(bool _isStore, llvm::Type* _valueType)
auto memPtr = m_memory.getPtr(mem, m_builder.CreateTrunc(index, Type::Size));
llvm::Value* ret = m_builder.CreateLoad(ptr);
llvm::Value* ret = m_builder.CreateLoad(memPtr);
ret = Endianness::toNative(m_builder, ret);
m_builder.CreateRet(ret);
}
@ -193,9 +193,8 @@ void Memory::storeByte(llvm::Value* _addr, llvm::Value* _word)
llvm::Value* Memory::getData()
{
auto rtPtr = getRuntimeManager().getRuntimePtr();
auto dataPtr = m_builder.CreateStructGEP(rtPtr, 2);
auto data = m_builder.CreateLoad(dataPtr, "data");
auto memPtr = m_builder.CreateBitCast(getRuntimeManager().getMem(), Type::BytePtr->getPointerTo());
auto data = m_builder.CreateLoad(memPtr, "data");
assert(data->getType() == Type::BytePtr);
return data;
}
@ -255,8 +254,10 @@ void Memory::copyBytes(llvm::Value* _srcPtr, llvm::Value* _srcSize, llvm::Value*
auto src = m_builder.CreateGEP(_srcPtr, idx64, "src");
auto dstIdx = m_builder.CreateTrunc(_destMemIdx, Type::Size, "dstIdx"); // Never allow memory index be a type bigger than i64
auto dst = m_builder.CreateGEP(getData(), dstIdx, "dst");
auto dst = m_memory.getPtr(getRuntimeManager().getMem(), dstIdx);
auto dst2 = m_builder.CreateGEP(getData(), dstIdx, "dst2");
m_builder.CreateMemCpy(dst, src, bytesToCopy, 0);
m_builder.CreateMemCpy(dst2, src, bytesToCopy, 0);
}
}

2
libevmjit/Runtime.cpp

@ -19,7 +19,7 @@ bytes_ref Runtime::getReturnData() const
auto data = m_data.callData;
auto size = static_cast<size_t>(m_data.callDataSize);
if (data < m_memory.data() || data >= m_memory.data() + m_memory.size() || size == 0)
if (data < m_memData || data >= m_memData + m_memSize || size == 0)
{
assert(size == 0); // data can be an invalid pointer only if size is 0
m_data.callData = nullptr;

2
libevmjit/RuntimeManager.cpp

@ -158,7 +158,7 @@ void RuntimeManager::set(RuntimeData::Index _index, llvm::Value* _value)
void RuntimeManager::registerReturnData(llvm::Value* _offset, llvm::Value* _size)
{
auto memPtr = getBuilder().CreateStructGEP(getRuntimePtr(), 2);
auto memPtr = m_builder.CreateBitCast(getMem(), Type::BytePtr->getPointerTo());
auto mem = getBuilder().CreateLoad(memPtr, "memory");
auto idx = m_builder.CreateTrunc(_offset, Type::Size, "idx"); // Never allow memory index be a type bigger than i64 // TODO: Report bug & fix to LLVM
auto returnDataPtr = getBuilder().CreateGEP(mem, idx);

2
libevmjit/RuntimeManager.h

@ -35,7 +35,7 @@ public:
llvm::Value* getMem();
void registerReturnData(llvm::Value* _index, llvm::Value* _size);
void registerReturnData(llvm::Value* _index, llvm::Value* _size); // TODO: Move to Memory.
void registerSuicide(llvm::Value* _balanceAddress);
void exit(ReturnCode _returnCode);

Loading…
Cancel
Save