From b84cf62d6bd3a9caa8a9a7f1dcd427418170aed9 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 3 Mar 2015 17:55:28 +0100 Subject: Index access for calldata arrays. --- CompilerUtils.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'CompilerUtils.cpp') diff --git a/CompilerUtils.cpp b/CompilerUtils.cpp index 826651e6..acb6412f 100644 --- a/CompilerUtils.cpp +++ b/CompilerUtils.cpp @@ -41,18 +41,22 @@ unsigned CompilerUtils::loadFromMemory(unsigned _offset, Type const& _type, 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 +138,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); } -- cgit v1.2.3