diff options
author | Christian <c@ethdev.com> | 2015-01-09 07:58:32 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-01-10 01:20:51 +0800 |
commit | fe16922087ef41f157ef8661a9295aa1539796a5 (patch) | |
tree | e11a1111c08a862c72f9de92b2d47f6d81ea3bcd /CompilerUtils.cpp | |
parent | 396f638ce19206144ce32dcf3926fc13fa9a89b7 (diff) | |
download | dexon-solidity-fe16922087ef41f157ef8661a9295aa1539796a5.tar dexon-solidity-fe16922087ef41f157ef8661a9295aa1539796a5.tar.gz dexon-solidity-fe16922087ef41f157ef8661a9295aa1539796a5.tar.bz2 dexon-solidity-fe16922087ef41f157ef8661a9295aa1539796a5.tar.lz dexon-solidity-fe16922087ef41f157ef8661a9295aa1539796a5.tar.xz dexon-solidity-fe16922087ef41f157ef8661a9295aa1539796a5.tar.zst dexon-solidity-fe16922087ef41f157ef8661a9295aa1539796a5.zip |
Padding for ABI types.
Diffstat (limited to 'CompilerUtils.cpp')
-rw-r--r-- | CompilerUtils.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/CompilerUtils.cpp b/CompilerUtils.cpp index a5254b42..3101c1b4 100644 --- a/CompilerUtils.cpp +++ b/CompilerUtils.cpp @@ -33,17 +33,21 @@ namespace solidity const unsigned int CompilerUtils::dataStartOffset = 4; -void CompilerUtils::loadFromMemory(unsigned _offset, unsigned _bytes, bool _leftAligned, bool _fromCalldata) +unsigned CompilerUtils::loadFromMemory(unsigned _offset, unsigned _bytes, bool _leftAligned, + bool _fromCalldata, bool _padToWordBoundaries) { if (_bytes == 0) { m_context << u256(0); - return; + 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) + 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 @@ -54,21 +58,24 @@ void CompilerUtils::loadFromMemory(unsigned _offset, unsigned _bytes, bool _left m_context << u256(_offset) << load << eth::Instruction::DIV; if (_leftAligned) m_context << eth::Instruction::MUL; + return _bytes; } } -void CompilerUtils::storeInMemory(unsigned _offset, unsigned _bytes, bool _leftAligned) +unsigned CompilerUtils::storeInMemory(unsigned _offset, unsigned _bytes, bool _leftAligned, + bool _padToWordBoundaries) { if (_bytes == 0) { m_context << eth::Instruction::POP; - return; + return 0; } solAssert(_bytes <= 32, "Memory store of more than 32 bytes requested."); - if (_bytes != 32 && !_leftAligned) + if (_bytes != 32 && !_leftAligned && !_padToWordBoundaries) // shift the value accordingly before storing m_context << (u256(1) << ((32 - _bytes) * 8)) << eth::Instruction::MUL; m_context << u256(_offset) << eth::Instruction::MSTORE; + return _padToWordBoundaries ? 32 : _bytes; } void CompilerUtils::moveToStackVariable(VariableDeclaration const& _variable) |