codegen: cleanup stored values in a more consistent way

This commit is contained in:
Yoichi Hirai 2016-11-21 16:41:02 +01:00
parent 5b8a773986
commit 56d6641086
No known key found for this signature in database
GPG Key ID: E7B75D080FCF7992

View File

@ -216,16 +216,14 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const
void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _location, bool _move) const void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _location, bool _move) const
{ {
CompilerUtils utils(m_context); CompilerUtils utils(m_context);
solAssert(m_dataType, "");
// stack: value storage_key storage_offset // stack: value storage_key storage_offset
if (m_dataType->isValueType()) if (m_dataType->isValueType())
{ {
solAssert(m_dataType->storageBytes() <= 32, "Invalid storage bytes size."); solAssert(m_dataType->storageBytes() <= 32, "Invalid storage bytes size.");
solAssert(m_dataType->storageBytes() > 0, "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) if (m_dataType->storageBytes() == 32)
{ {
solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size."); 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; m_context << Instruction::POP;
if (!_move) if (!_move)
m_context << Instruction::DUP2 << Instruction::SWAP1; 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; m_context << Instruction::SSTORE;
} }
else 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 // OR the value into the other values in the storage slot
m_context << u256(0x100) << Instruction::EXP; m_context << u256(0x100) << Instruction::EXP;
// stack: value storage_ref multiplier // 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."); solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size for opaque type.");
// remove the higher order bits // remove the higher order bits
utils.convertType(*m_dataType, *m_dataType, true);
m_context m_context
<< (u256(1) << (8 * (32 - m_dataType->storageBytes()))) << (u256(1) << (8 * (32 - m_dataType->storageBytes())))
<< Instruction::SWAP1 << Instruction::SWAP1