@@ -239,6 +239,9 @@ void ControlFlowGraphBuilder::operator()(ExpressionStatement const& _exprStmt)
239
239
void ControlFlowGraphBuilder::operator ()(Block const & _block)
240
240
{
241
241
ScopedSaveAndRestore saveScope (m_scope, m_info.scopes .at (&_block).get ());
242
+ for (auto const & statement: _block.statements )
243
+ if (auto const * function = get_if<FunctionDefinition>(&statement))
244
+ registerFunction (*function);
242
245
for (auto const & statement: _block.statements )
243
246
std::visit (*this , statement);
244
247
}
@@ -386,11 +389,26 @@ void ControlFlowGraphBuilder::operator()(FunctionDefinition const& _function)
386
389
Scope::Function& function = std::get<Scope::Function>(m_scope->identifiers .at (_function.name ));
387
390
m_graph.functions .emplace_back (&function);
388
391
392
+ CFG::FunctionInfo& functionInfo = m_graph.functionInfo .at (&function);
393
+
394
+ ControlFlowGraphBuilder builder{m_graph, m_info, m_dialect};
395
+ builder.m_currentFunction = &functionInfo;
396
+ builder.m_currentBlock = functionInfo.entry ;
397
+ builder (_function.body );
398
+ builder.m_currentBlock ->exit = CFG::BasicBlock::FunctionReturn{debugDataOf (_function), &functionInfo};
399
+ }
400
+
401
+ void ControlFlowGraphBuilder::registerFunction (FunctionDefinition const & _function)
402
+ {
403
+ yulAssert (m_scope, " " );
404
+ yulAssert (m_scope->identifiers .count (_function.name ), " " );
405
+ Scope::Function& function = std::get<Scope::Function>(m_scope->identifiers .at (_function.name ));
406
+
389
407
yulAssert (m_info.scopes .at (&_function.body ), " " );
390
408
Scope* virtualFunctionScope = m_info.scopes .at (m_info.virtualBlocks .at (&_function).get ()).get ();
391
409
yulAssert (virtualFunctionScope, " " );
392
410
393
- auto && [it, inserted] = m_graph.functionInfo .emplace (std::make_pair (&function, CFG::FunctionInfo{
411
+ bool inserted = m_graph.functionInfo .emplace (std::make_pair (&function, CFG::FunctionInfo{
394
412
_function.debugData ,
395
413
function,
396
414
&m_graph.makeBlock (debugDataOf (_function.body )),
@@ -406,18 +424,10 @@ void ControlFlowGraphBuilder::operator()(FunctionDefinition const& _function)
406
424
_retVar.debugData
407
425
};
408
426
}) | ranges::to<vector>
409
- }));
410
- yulAssert (inserted, " " );
411
- CFG::FunctionInfo& functionInfo = it->second ;
412
-
413
- ControlFlowGraphBuilder builder{m_graph, m_info, m_dialect};
414
- builder.m_currentFunction = &functionInfo;
415
- builder.m_currentBlock = functionInfo.entry ;
416
- builder (_function.body );
417
- builder.m_currentBlock ->exit = CFG::BasicBlock::FunctionReturn{debugDataOf (_function), &functionInfo};
427
+ })).second ;
428
+ yulAssert (inserted);
418
429
}
419
430
420
-
421
431
Stack const & ControlFlowGraphBuilder::visitFunctionCall (FunctionCall const & _call)
422
432
{
423
433
yulAssert (m_scope, " " );
0 commit comments