diff options
author | Christian <c@ethdev.com> | 2015-02-15 07:11:51 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-02-17 02:25:27 +0800 |
commit | 1f6e3651362bdcdaa39773156875c36053d5f6be (patch) | |
tree | cf41f43c2b4e46b1859654ad9884e64f89d36015 /CompilerUtils.cpp | |
parent | f7ba85e0ecb6f690d62bcf66e0f0525f2ed97337 (diff) | |
download | dexon-solidity-1f6e3651362bdcdaa39773156875c36053d5f6be.tar dexon-solidity-1f6e3651362bdcdaa39773156875c36053d5f6be.tar.gz dexon-solidity-1f6e3651362bdcdaa39773156875c36053d5f6be.tar.bz2 dexon-solidity-1f6e3651362bdcdaa39773156875c36053d5f6be.tar.lz dexon-solidity-1f6e3651362bdcdaa39773156875c36053d5f6be.tar.xz dexon-solidity-1f6e3651362bdcdaa39773156875c36053d5f6be.tar.zst dexon-solidity-1f6e3651362bdcdaa39773156875c36053d5f6be.zip |
Move code to loadFromMemory.
Diffstat (limited to 'CompilerUtils.cpp')
-rw-r--r-- | CompilerUtils.cpp | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/CompilerUtils.cpp b/CompilerUtils.cpp index dda1736d..6f99dc7c 100644 --- a/CompilerUtils.cpp +++ b/CompilerUtils.cpp @@ -33,33 +33,34 @@ namespace solidity const unsigned int CompilerUtils::dataStartOffset = 4; -unsigned CompilerUtils::loadFromMemory(unsigned _offset, unsigned _bytes, bool _leftAligned, - bool _fromCalldata, bool _padToWordBoundaries) +unsigned CompilerUtils::loadFromMemory(unsigned _offset, Type const& _type, + bool _fromCalldata, bool _padToWordBoundaries) { - if (_bytes == 0) - { + solAssert(_type.getCategory() != Type::Category::ByteArray, "Unable to statically load dynamic type."); + unsigned _encodedSize = _type.getCalldataEncodedSize(); + unsigned numBytes = _padToWordBoundaries ? getPaddedSize(_encodedSize) : _encodedSize; + bool leftAligned = _type.getCategory() == Type::Category::String; + if (numBytes == 0) m_context << u256(0); - return 0; - } - eth::Instruction load = _fromCalldata ? eth::Instruction::CALLDATALOAD : eth::Instruction::MLOAD; - solAssert(_bytes <= 32, "Memory load of more than 32 bytes requested."); - if (_bytes == 32 || _padToWordBoundaries) - { - m_context << u256(_offset) << load; - return 32; - } else { - // load data and add leading or trailing zeros by dividing/multiplying depending on alignment - u256 shiftFactor = u256(1) << ((32 - _bytes) * 8); - m_context << shiftFactor; - if (_leftAligned) - m_context << eth::Instruction::DUP1; - m_context << u256(_offset) << load << eth::Instruction::DIV; - if (_leftAligned) - m_context << eth::Instruction::MUL; - return _bytes; + eth::Instruction load = _fromCalldata ? eth::Instruction::CALLDATALOAD : eth::Instruction::MLOAD; + solAssert(numBytes <= 32, "Static memory load of more than 32 bytes requested."); + if (numBytes == 32) + m_context << u256(_offset) << load; + else + { + // load data and add leading or trailing zeros by dividing/multiplying depending on alignment + u256 shiftFactor = u256(1) << ((32 - numBytes) * 8); + m_context << shiftFactor; + if (leftAligned) + m_context << eth::Instruction::DUP1; + m_context << u256(_offset) << load << eth::Instruction::DIV; + if (leftAligned) + m_context << eth::Instruction::MUL; + } } + return numBytes; } unsigned CompilerUtils::storeInMemory(unsigned _offset, Type const& _type, bool _padToWordBoundaries) |