@@ -176,9 +176,9 @@ StackSlot ControlFlowGraphBuilder::operator()(Expression const& _expression)
176
176
177
177
StackSlot ControlFlowGraphBuilder::operator ()(FunctionCall const & _call)
178
178
{
179
- CFG::Operation const & operation = visitFunctionCall (_call);
180
- yulAssert (operation. output .size () == 1 , " " );
181
- return operation. output .front ();
179
+ Stack const & output = visitFunctionCall (_call);
180
+ yulAssert (output.size () == 1 , " " );
181
+ return output.front ();
182
182
}
183
183
184
184
void ControlFlowGraphBuilder::operator ()(VariableDeclaration const & _varDecl)
@@ -219,8 +219,8 @@ void ControlFlowGraphBuilder::operator()(ExpressionStatement const& _exprStmt)
219
219
yulAssert (m_currentBlock, " " );
220
220
std::visit (util::GenericVisitor{
221
221
[&](FunctionCall const & _call) {
222
- CFG::Operation const & operation = visitFunctionCall (_call);
223
- yulAssert (operation. output .empty (), " " );
222
+ Stack const & output = visitFunctionCall (_call);
223
+ yulAssert (output.empty (), " " );
224
224
},
225
225
[&](auto const &) { yulAssert (false , " " ); }
226
226
}, _exprStmt.expression );
@@ -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,19 +424,11 @@ 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
- CFG::Operation const & ControlFlowGraphBuilder::visitFunctionCall (FunctionCall const & _call)
431
+ Stack const & ControlFlowGraphBuilder::visitFunctionCall (FunctionCall const & _call)
422
432
{
423
433
yulAssert (m_scope, " " );
424
434
yulAssert (m_currentBlock, " " );
@@ -439,7 +449,7 @@ CFG::Operation const& ControlFlowGraphBuilder::visitFunctionCall(FunctionCall co
439
449
}) | ranges::to<Stack>,
440
450
// operation
441
451
move (builtinCall)
442
- });
452
+ }). output ;
443
453
}
444
454
else
445
455
{
@@ -456,17 +466,17 @@ CFG::Operation const& ControlFlowGraphBuilder::visitFunctionCall(FunctionCall co
456
466
}) | ranges::to<Stack>,
457
467
// operation
458
468
CFG::FunctionCall{_call.debugData , function, _call}
459
- });
469
+ }). output ;
460
470
}
461
471
}
462
472
463
473
Stack ControlFlowGraphBuilder::visitAssignmentRightHandSide (Expression const & _expression, size_t _expectedSlotCount)
464
474
{
465
475
return std::visit (util::GenericVisitor{
466
476
[&](FunctionCall const & _call) -> Stack {
467
- CFG::Operation const & operation = visitFunctionCall (_call);
468
- yulAssert (_expectedSlotCount == operation. output .size (), " " );
469
- return operation. output ;
477
+ Stack const & output = visitFunctionCall (_call);
478
+ yulAssert (_expectedSlotCount == output.size (), " " );
479
+ return output;
470
480
},
471
481
[&](auto const & _identifierOrLiteral) -> Stack {
472
482
yulAssert (_expectedSlotCount == 1 , " " );
0 commit comments