aboutsummaryrefslogtreecommitdiffstats
path: root/ArrayUtils.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-05-28 20:43:46 +0800
committerchriseth <c@ethdev.com>2015-05-28 20:48:07 +0800
commit72e3e359aa3d0e6eb19de4457bb64981dfd8d8af (patch)
tree2f9b78045871e347ba21eec7db5b710e665a51f4 /ArrayUtils.cpp
parentf7e3568c6202b940394097f147e0c4e6ffe7fe9c (diff)
downloaddexon-solidity-72e3e359aa3d0e6eb19de4457bb64981dfd8d8af.tar.gz
dexon-solidity-72e3e359aa3d0e6eb19de4457bb64981dfd8d8af.tar.zst
dexon-solidity-72e3e359aa3d0e6eb19de4457bb64981dfd8d8af.zip
Allow duplicate code removal for loops.
Diffstat (limited to 'ArrayUtils.cpp')
-rw-r--r--ArrayUtils.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/ArrayUtils.cpp b/ArrayUtils.cpp
index 448e4da2..397b098c 100644
--- a/ArrayUtils.cpp
+++ b/ArrayUtils.cpp
@@ -364,7 +364,13 @@ void ArrayUtils::clearStorageLoop(Type const& _type) const
return;
}
// stack: end_pos pos
- eth::AssemblyItem loopStart = m_context.newTag();
+
+ // jump to and return from the loop to allow for duplicate code removal
+ eth::AssemblyItem returnTag = m_context.pushNewTag();
+ m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
+
+ // stack: <return tag> end_pos pos
+ eth::AssemblyItem loopStart = m_context.appendJumpToNew();
m_context << loopStart;
// check for loop condition
m_context << eth::Instruction::DUP1 << eth::Instruction::DUP3
@@ -380,7 +386,11 @@ void ArrayUtils::clearStorageLoop(Type const& _type) const
m_context.appendJumpTo(loopStart);
// cleanup
m_context << zeroLoopEnd;
- m_context << eth::Instruction::POP;
+ m_context << eth::Instruction::POP << eth::Instruction::SWAP1;
+ // "return"
+ m_context << eth::Instruction::JUMP;
+
+ m_context << returnTag;
solAssert(m_context.getStackHeight() == stackHeightStart - 1, "");
}