[Yul] leave statement.

This commit is contained in:
chriseth
2019-10-29 14:32:16 +01:00
parent edf1e83fda
commit ceb8ee9124
41 changed files with 214 additions and 27 deletions
+17
View File
@@ -490,6 +490,9 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
m_assembly.appendConstant(u256(0));
}
m_context->functionExitPoints.push(
CodeTransformContext::JumpInfo{m_assembly.newLabelId(), m_assembly.stackHeight()}
);
try
{
CodeTransform(
@@ -518,6 +521,9 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
stackError(std::move(error), height);
}
m_assembly.appendLabel(m_context->functionExitPoints.top().label);
m_context->functionExitPoints.pop();
{
// The stack layout here is:
// <return label>? <arguments...> <return values...>
@@ -643,6 +649,17 @@ void CodeTransform::operator()(Continue const& _continue)
checkStackHeight(&_continue);
}
void CodeTransform::operator()(Leave const& _leave)
{
yulAssert(!m_context->functionExitPoints.empty(), "Invalid leave-statement. Requires surrounding function in code generation.");
m_assembly.setSourceLocation(_leave.location);
Context::JumpInfo const& jump = m_context->functionExitPoints.top();
m_assembly.appendJumpTo(jump.label, appendPopUntil(jump.targetStackHeight));
checkStackHeight(&_leave);
}
void CodeTransform::operator()(Block const& _block)
{
Scope* originalScope = m_scope;
+2
View File
@@ -73,6 +73,7 @@ struct CodeTransformContext
};
std::stack<ForLoopLabels> forLoopStack;
std::stack<JumpInfo> functionExitPoints;
};
/**
@@ -185,6 +186,7 @@ public:
void operator()(ForLoop const&);
void operator()(Break const&);
void operator()(Continue const&);
void operator()(Leave const&);
void operator()(Block const& _block);
private: