mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2027 from chriseth/sol_dupRemForLoops
Allow duplicate code removal for loops.
This commit is contained in:
commit
cf688ea738
@ -364,7 +364,13 @@ void ArrayUtils::clearStorageLoop(Type const& _type) const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// stack: end_pos pos
|
// 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;
|
m_context << loopStart;
|
||||||
// check for loop condition
|
// check for loop condition
|
||||||
m_context << eth::Instruction::DUP1 << eth::Instruction::DUP3
|
m_context << eth::Instruction::DUP1 << eth::Instruction::DUP3
|
||||||
@ -380,7 +386,11 @@ void ArrayUtils::clearStorageLoop(Type const& _type) const
|
|||||||
m_context.appendJumpTo(loopStart);
|
m_context.appendJumpTo(loopStart);
|
||||||
// cleanup
|
// cleanup
|
||||||
m_context << zeroLoopEnd;
|
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, "");
|
solAssert(m_context.getStackHeight() == stackHeightStart - 1, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user