Merge pull request #6241 from ethereum/yul-bc-codegen

Yul codegen for break & continue statements
This commit is contained in:
chriseth
2019-03-28 14:48:50 +01:00
committed by GitHub
6 changed files with 75 additions and 4 deletions
+24 -4
View File
@@ -633,14 +633,34 @@ void CodeTransform::operator()(ForLoop const& _forLoop)
checkStackHeight(&_forLoop);
}
void CodeTransform::operator()(Break const&)
int CodeTransform::appendPopUntil(int _targetDepth)
{
yulAssert(false, "Code generation for break statement in Yul is not implemented yet.");
int const stackDiffAfter = m_assembly.stackHeight() - _targetDepth;
for (int i = 0; i < stackDiffAfter; ++i)
m_assembly.appendInstruction(solidity::Instruction::POP);
return stackDiffAfter;
}
void CodeTransform::operator()(Continue const&)
void CodeTransform::operator()(Break const& _break)
{
yulAssert(false, "Code generation for continue statement in Yul is not implemented yet.");
yulAssert(!m_context->forLoopStack.empty(), "Invalid break-statement. Requires surrounding for-loop in code generation.");
m_assembly.setSourceLocation(_break.location);
Context::JumpInfo const& jump = m_context->forLoopStack.top().done;
m_assembly.appendJumpTo(jump.label, appendPopUntil(jump.targetStackHeight));
checkStackHeight(&_break);
}
void CodeTransform::operator()(Continue const& _continue)
{
yulAssert(!m_context->forLoopStack.empty(), "Invalid continue-statement. Requires surrounding for-loop in code generation.");
m_assembly.setSourceLocation(_continue.location);
Context::JumpInfo const& jump = m_context->forLoopStack.top().post;
m_assembly.appendJumpTo(jump.label, appendPopUntil(jump.targetStackHeight));
checkStackHeight(&_continue);
}
void CodeTransform::operator()(Block const& _block)
+4
View File
@@ -217,6 +217,10 @@ private:
/// and corrects the stack height to the target stack height.
void stackError(StackTooDeepError _error, int _targetStackSize);
/// Ensures stack height is down to @p _targetDepth by appending POP instructions to the output assembly.
/// Returns the number of POP statements that have been appended.
int appendPopUntil(int _targetDepth);
AbstractAssembly& m_assembly;
AsmAnalysisInfo& m_info;
Scope* m_scope = nullptr;