Browse Source

Allocate memory and count gas for RETURN instruction

[#79942174]
cl-refactor
Paweł Bylica 10 years ago
parent
commit
f95999c6b3
  1. 2
      evmcc/ExecutionEngine.cpp
  2. 3
      evmcc/Memory.cpp
  3. 5
      evmcc/Type.cpp
  4. 3
      evmcc/Type.h
  5. 1
      evmcc/bytecode/return2.evm
  6. 6
      evmcc/lll/return2.lll

2
evmcc/ExecutionEngine.cpp

@ -102,7 +102,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
auto returnCode = static_cast<ReturnCode>(result.IntVal.getZExtValue());
if (returnCode == ReturnCode::Return)
{
auto&& returnData = Memory::getReturnData();
auto&& returnData = Memory::getReturnData(); // TODO: It might be better to place is in Runtime interface
std::cout << "RETURN [ ";
for (auto it = returnData.begin(), end = returnData.end(); it != end; ++it)

3
evmcc/Memory.cpp

@ -133,6 +133,9 @@ llvm::Value* Memory::getSize()
void Memory::registerReturnData(llvm::Value* _index, llvm::Value* _size)
{
auto lastWord = m_builder.CreateAdd(_index, m_builder.CreateSub(_size, Constant::get(32)), "lastWord");
loadWord(lastWord); // Make sure that memory is allocated and count gas
m_builder.CreateStore(_index, m_returnDataOffset);
m_builder.CreateStore(_size, m_returnDataSize);
}

5
evmcc/Type.cpp

@ -25,6 +25,11 @@ void Type::init(llvm::LLVMContext& _context)
MainReturn = llvm::Type::getInt32Ty(_context);
}
llvm::Constant* Constant::get(uint64_t _n)
{
return llvm::ConstantInt::get(Type::i256, _n);
}
llvm::Constant* Constant::get(ReturnCode _returnCode)
{
return llvm::ConstantInt::get(Type::MainReturn, static_cast<uint64_t>(_returnCode));

3
evmcc/Type.h

@ -38,6 +38,9 @@ enum class ReturnCode
struct Constant
{
/// Returns word-size constant
static llvm::Constant* get(uint64_t _n);
static llvm::Constant* get(ReturnCode _returnCode);
};

1
evmcc/bytecode/return2.evm

@ -0,0 +1 @@
6001620f4240f2

6
evmcc/lll/return2.lll

@ -0,0 +1,6 @@
(asm
1
1000000
RETURN ;; return 1 byte from index 1M
)
Loading…
Cancel
Save