aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen/CompilerUtils.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/CompilerUtils.cpp
parent6f19559de02e0bf2b53e743678d53a4ea0414eae (diff)
downloaddexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.tar.gz
dexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.tar.zst
dexon-solidity-95d7555e3c0e8fc4826114a336e0e717fe7a1a2d.zip
External functions in storage.
Diffstat (limited to 'libsolidity/codegen/CompilerUtils.cpp')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 38a7a23b..8a06268c 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -139,8 +139,7 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound
)
{
solAssert(_padToWordBoundaries, "Non-padded store for function not implemented.");
- m_context << u256(0xffffffffUL) << Instruction::AND << (u256(1) << 160) << Instruction::MUL << Instruction::SWAP1;
- m_context << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::OR;
+ combineExternalFunctionType();
m_context << Instruction::DUP2 << Instruction::MSTORE;
m_context << u256(_padToWordBoundaries ? 32 : 24) << Instruction::ADD;
}
@@ -316,6 +315,21 @@ void CompilerUtils::memoryCopy()
m_context << Instruction::POP; // ignore return value
}
+void CompilerUtils::splitExternalFunctionType()
+{
+ // We have to split the right-aligned <function identifier><address> into two stack slots:
+ // address (right aligned), function identifier (right aligned)
+ m_context << Instruction::DUP1 << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::SWAP1;
+ m_context << (u256(1) << 160) << Instruction::SWAP1 << Instruction::DIV;
+ m_context << u256(0xffffffffUL) << Instruction::AND;
+}
+
+void CompilerUtils::combineExternalFunctionType()
+{
+ m_context << u256(0xffffffffUL) << Instruction::AND << (u256(1) << 160) << Instruction::MUL << Instruction::SWAP1;
+ m_context << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::OR;
+}
+
void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetType, bool _cleanupNeeded)
{
// For a type extension, we need to remove all higher-order bits that we might have ignored in
@@ -860,16 +874,8 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda
}
if (auto const* funType = dynamic_cast<FunctionType const*>(&_type))
- {
if (funType->location() == FunctionType::Location::External)
- {
- // We have to split the right-aligned <function identifier><address> into two stack slots:
- // address (right aligned), function identifier (right aligned)
- m_context << Instruction::DUP1 << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::SWAP1;
- m_context << (u256(1) << 160) << Instruction::SWAP1 << Instruction::DIV;
- m_context << u256(0xffffffffUL) << Instruction::AND;
- }
- }
+ splitExternalFunctionType();
return numBytes;
}