/src/solidity/libyul/optimiser/FunctionHoister.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 | | * Optimiser component that changes the code so that it consists of a block starting with |
20 | | * a single block followed only by function definitions and with no functions defined |
21 | | * anywhere else. |
22 | | */ |
23 | | |
24 | | #include <libyul/optimiser/FunctionHoister.h> |
25 | | #include <libyul/optimiser/OptimizerUtilities.h> |
26 | | #include <libyul/AST.h> |
27 | | |
28 | | #include <libsolutil/CommonData.h> |
29 | | |
30 | | using namespace std; |
31 | | using namespace solidity; |
32 | | using namespace solidity::yul; |
33 | | |
34 | | void FunctionHoister::operator()(Block& _block) |
35 | 0 | { |
36 | 0 | bool topLevel = m_isTopLevel; |
37 | 0 | m_isTopLevel = false; |
38 | 0 | for (auto&& statement: _block.statements) |
39 | 0 | { |
40 | 0 | std::visit(*this, statement); |
41 | 0 | if (holds_alternative<FunctionDefinition>(statement)) |
42 | 0 | { |
43 | 0 | m_functions.emplace_back(std::move(statement)); |
44 | 0 | statement = Block{_block.debugData, {}}; |
45 | 0 | } |
46 | 0 | } |
47 | 0 | removeEmptyBlocks(_block); |
48 | 0 | if (topLevel) |
49 | 0 | _block.statements += std::move(m_functions); |
50 | 0 | } |