Coverage Report

Created: 2025-09-08 08:10

/src/solidity/libyul/optimiser/BlockFlattener.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
19
#include <libyul/optimiser/BlockFlattener.h>
20
#include <libyul/AST.h>
21
22
#include <libsolutil/CommonData.h>
23
24
#include <functional>
25
26
using namespace solidity;
27
using namespace solidity::yul;
28
using namespace solidity::util;
29
30
void BlockFlattener::operator()(Block& _block)
31
9.08M
{
32
9.08M
  ASTModifier::operator()(_block);
33
34
9.08M
  iterateReplacing(
35
9.08M
    _block.statements,
36
9.08M
    [](Statement& _s) -> std::optional<std::vector<Statement>>
37
61.7M
    {
38
61.7M
      if (std::holds_alternative<Block>(_s))
39
136k
        return std::move(std::get<Block>(_s).statements);
40
61.5M
      else
41
61.5M
        return {};
42
61.7M
    }
43
9.08M
  );
44
9.08M
}
45
46
void BlockFlattener::run(OptimiserStepContext&, Block& _ast)
47
666k
{
48
666k
  BlockFlattener flattener;
49
666k
  for (auto& statement: _ast.statements)
50
2.68M
    if (auto* block = std::get_if<Block>(&statement))
51
662k
      flattener(*block);
52
2.02M
    else if (auto* function = std::get_if<FunctionDefinition>(&statement))
53
2.02M
      flattener(function->body);
54
0
    else
55
2.02M
      yulAssert(false, "BlockFlattener requires the FunctionGrouper.");
56
666k
}