aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen/LValue.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-10-14 18:27:46 +0800
committerchriseth <c@ethdev.com>2016-11-16 21:37:17 +0800
commit95d7555e3c0e8fc4826114a336e0e717fe7a1a2d (patch)
tree062dccd55852a8f0c768d16c9a6715f75c7b8c0f /libsolidity/codegen/LValue.cpp
parent6f19559de02e0bf2b53e743678d53a4ea0414eae (diff)
downloaddexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.tar
dexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.tar.gz
dexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.tar.bz2
dexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.tar.lz
dexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.tar.xz
dexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.tar.zst
dexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.zip
External functions in storage.
Diffstat (limited to 'libsolidity/codegen/LValue.cpp')
-rw-r--r--libsolidity/codegen/LValue.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp
index 69a80b6a..98ab6d41 100644
--- a/libsolidity/codegen/LValue.cpp
+++ b/libsolidity/codegen/LValue.cpp
@@ -153,7 +153,8 @@ StorageItem::StorageItem(CompilerContext& _compilerContext, Type const& _type):
{
if (m_dataType->isValueType())
{
- solAssert(m_dataType->storageSize() == m_dataType->sizeOnStack(), "");
+ if (m_dataType->category() != Type::Category::Function)
+ solAssert(m_dataType->storageSize() == m_dataType->sizeOnStack(), "");
solAssert(m_dataType->storageSize() == 1, "Invalid storage size.");
}
}
@@ -189,8 +190,16 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const
dynamic_cast<IntegerType const&>(*m_dataType).isSigned()
)
m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND;
+ else if (
+ m_dataType->category() == Type::Category::Function &&
+ dynamic_cast<FunctionType const&>(*m_dataType).location() == FunctionType::Location::External
+ )
+ CompilerUtils(m_context).splitExternalFunctionType();
else
+ {
+ solAssert(m_dataType->sizeOnStack() == 1, "");
m_context << ((u256(0x1) << (8 * m_dataType->storageBytes())) - 1) << Instruction::AND;
+ }
}
}
@@ -204,6 +213,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
solAssert(m_dataType->storageBytes() > 0, "Invalid storage bytes size.");
if (m_dataType->storageBytes() == 32)
{
+ solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size.");
// offset should be zero
m_context << Instruction::POP;
if (!_move)
@@ -222,16 +232,23 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
m_context
<< Instruction::DUP2 << ((u256(1) << (8 * m_dataType->storageBytes())) - 1)
<< Instruction::MUL;
- m_context << Instruction::NOT << Instruction::AND;
- // stack: value storage_ref multiplier cleared_value
- m_context
- << Instruction::SWAP1 << Instruction::DUP4;
+ m_context << Instruction::NOT << Instruction::AND << Instruction::SWAP1;
+ // stack: value storage_ref cleared_value multiplier
+ utils.copyToStackTop(4, m_dataType->sizeOnStack());
// stack: value storage_ref cleared_value multiplier value
- if (m_dataType->category() == Type::Category::FixedBytes)
+ if (
+ m_dataType->category() == Type::Category::Function &&
+ dynamic_cast<FunctionType const&>(*m_dataType).location() == FunctionType::Location::External
+ )
+ // Combine the two-item function type into a single stack slot.
+ utils.combineExternalFunctionType();
+ else if (m_dataType->category() == Type::Category::FixedBytes)
m_context
<< (u256(0x1) << (256 - 8 * dynamic_cast<FixedBytesType const&>(*m_dataType).numBytes()))
<< Instruction::SWAP1 << Instruction::DIV;
else
+ {
+ solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size for opaque type.");
// remove the higher order bits
m_context
<< (u256(1) << (8 * (32 - m_dataType->storageBytes())))
@@ -239,11 +256,12 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
<< Instruction::DUP2
<< Instruction::MUL
<< Instruction::DIV;
+ }
m_context << Instruction::MUL << Instruction::OR;
// stack: value storage_ref updated_value
m_context << Instruction::SWAP1 << Instruction::SSTORE;
if (_move)
- m_context << Instruction::POP;
+ utils.popStackElement(*m_dataType);
}
}
else