Allocate memory and count gas for RETURN instruction

[#79942174]
This commit is contained in:
Paweł Bylica 2014-10-13 19:09:42 +02:00
parent 7a89751433
commit f95999c6b3
6 changed files with 19 additions and 1 deletions

View file

@ -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)

View file

@ -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);
}

View file

@ -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));

View file

@ -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);
};

View file

@ -0,0 +1 @@
6001620f4240f2

6
evmcc/lll/return2.lll Normal file
View file

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