diff options
author | Yoichi Hirai <i@yoichihirai.com> | 2016-11-21 23:41:02 +0800 |
---|---|---|
committer | Yoichi Hirai <i@yoichihirai.com> | 2016-11-25 22:44:36 +0800 |
commit | 56d664108614fa8fdf63a02d8f605bf5afcd0837 (patch) | |
tree | 722952459f301d9a4eac8bb73c38fe85d3300195 /libsolidity | |
parent | 5b8a77398608689088938454583d284afd58ab50 (diff) | |
download | dexon-solidity-56d664108614fa8fdf63a02d8f605bf5afcd0837.tar.gz dexon-solidity-56d664108614fa8fdf63a02d8f605bf5afcd0837.tar.zst dexon-solidity-56d664108614fa8fdf63a02d8f605bf5afcd0837.zip |
codegen: cleanup stored values in a more consistent way
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/codegen/LValue.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 933c0419..78854588 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -216,16 +216,14 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _location, bool _move) const { CompilerUtils utils(m_context); + solAssert(m_dataType, ""); + // stack: value storage_key storage_offset if (m_dataType->isValueType()) { solAssert(m_dataType->storageBytes() <= 32, "Invalid storage bytes size."); solAssert(m_dataType->storageBytes() > 0, "Invalid storage bytes size."); - m_context << Instruction::SWAP2; - CompilerUtils(m_context).convertType(*m_dataType, *m_dataType, true); - m_context << Instruction::SWAP2; - if (m_dataType->storageBytes() == 32) { solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size."); @@ -233,10 +231,23 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc m_context << Instruction::POP; if (!_move) m_context << Instruction::DUP2 << Instruction::SWAP1; + + m_context << Instruction::SWAP1; + utils.convertType(_sourceType, _sourceType, true); + utils.convertType(*m_dataType, *m_dataType, true); + m_context << Instruction::SWAP1; + m_context << Instruction::SSTORE; } else { + if (_sourceType.sizeOnStack() == 1) + { + m_context << Instruction::SWAP2; + utils.convertType(_sourceType, _sourceType, true); + m_context << Instruction::SWAP2; + } + // OR the value into the other values in the storage slot m_context << u256(0x100) << Instruction::EXP; // stack: value storage_ref multiplier @@ -269,6 +280,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc { solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size for opaque type."); // remove the higher order bits + utils.convertType(*m_dataType, *m_dataType, true); m_context << (u256(1) << (8 * (32 - m_dataType->storageBytes()))) << Instruction::SWAP1 |