diff options
Diffstat (limited to 'CompilerUtils.cpp')
-rw-r--r-- | CompilerUtils.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/CompilerUtils.cpp b/CompilerUtils.cpp index 826651e6..7f8f72ca 100644 --- a/CompilerUtils.cpp +++ b/CompilerUtils.cpp @@ -33,26 +33,38 @@ namespace solidity const unsigned int CompilerUtils::dataStartOffset = 4; -unsigned CompilerUtils::loadFromMemory(unsigned _offset, Type const& _type, - bool _fromCalldata, bool _padToWordBoundaries) +unsigned CompilerUtils::loadFromMemory( + unsigned _offset, + Type const& _type, + bool _fromCalldata, + bool _padToWordBoundaries +) { solAssert(_type.getCategory() != Type::Category::Array, "Unable to statically load dynamic type."); m_context << u256(_offset); return loadFromMemoryHelper(_type, _fromCalldata, _padToWordBoundaries); } -void CompilerUtils::loadFromMemoryDynamic(Type const& _type, bool _fromCalldata, bool _padToWordBoundaries) +void CompilerUtils::loadFromMemoryDynamic( + Type const& _type, + bool _fromCalldata, + bool _padToWordBoundaries, + bool _keepUpdatedMemoryOffset +) { solAssert(_type.getCategory() != Type::Category::Array, "Arrays not yet implemented."); - m_context << eth::Instruction::DUP1; + if (_keepUpdatedMemoryOffset) + m_context << eth::Instruction::DUP1; unsigned numBytes = loadFromMemoryHelper(_type, _fromCalldata, _padToWordBoundaries); - // update memory counter - for (unsigned i = 0; i < _type.getSizeOnStack(); ++i) - m_context << eth::swapInstruction(1 + i); - m_context << u256(numBytes) << eth::Instruction::ADD; + if (_keepUpdatedMemoryOffset) + { + // update memory counter + for (unsigned i = 0; i < _type.getSizeOnStack(); ++i) + m_context << eth::swapInstruction(1 + i); + m_context << u256(numBytes) << eth::Instruction::ADD; + } } - unsigned CompilerUtils::storeInMemory(unsigned _offset, Type const& _type, bool _padToWordBoundaries) { solAssert(_type.getCategory() != Type::Category::Array, "Unable to statically store dynamic type."); @@ -134,12 +146,11 @@ void CompilerUtils::moveToStackVariable(VariableDeclaration const& _variable) m_context << eth::swapInstruction(stackPosition - size + 1) << eth::Instruction::POP; } -void CompilerUtils::copyToStackTop(unsigned _stackDepth, Type const& _type) +void CompilerUtils::copyToStackTop(unsigned _stackDepth, unsigned _itemSize) { if (_stackDepth > 16) BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Stack too deep.")); - unsigned const size = _type.getSizeOnStack(); - for (unsigned i = 0; i < size; ++i) + for (unsigned i = 0; i < _itemSize; ++i) m_context << eth::dupInstruction(_stackDepth); } |