Remove `leave` at end of function.

This commit is contained in:
chriseth 2019-10-24 18:52:54 +02:00
parent ceb8ee9124
commit f98925d8b6
2 changed files with 9 additions and 0 deletions

View File

@ -136,6 +136,13 @@ void ControlFlowSimplifier::operator()(Block& _block)
simplify(_block.statements);
}
void ControlFlowSimplifier::operator()(FunctionDefinition& _funDef)
{
ASTModifier::operator()(_funDef);
if (!_funDef.body.statements.empty() && _funDef.body.statements.back().type() == typeid(Leave))
_funDef.body.statements.pop_back();
}
void ControlFlowSimplifier::visit(Statement& _st)
{
if (_st.type() == typeid(ForLoop))

View File

@ -34,6 +34,7 @@ struct OptimiserStepContext;
* - replace switch with only default case with pop(expression) and body
* - replace switch with const expr with matching case body
* - replace ``for`` with terminating control flow and without other break/continue by ``if``
* - remove ``leave`` at the end of a function.
*
* None of these operations depend on the data flow. The StructuralSimplifier
* performs similar tasks that do depend on data flow.
@ -55,6 +56,7 @@ public:
void operator()(Break&) override { ++m_numBreakStatements; }
void operator()(Continue&) override { ++m_numContinueStatements; }
void operator()(Block& _block) override;
void operator()(FunctionDefinition& _funDef) override;
void visit(Statement& _st) override;