Coverage Report

Created: 2026-06-30 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solidity/libyul/optimiser/OptimizerUtilities.h
Line
Count
Source
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
 * Small useful snippets for the optimiser.
20
 */
21
22
#pragma once
23
24
#include <libsolutil/Common.h>
25
#include <libyul/ASTForward.h>
26
#include <libyul/Dialect.h>
27
#include <libyul/optimiser/ASTWalker.h>
28
#include <liblangutil/EVMVersion.h>
29
30
#include <optional>
31
#include <string_view>
32
33
namespace solidity::evmasm
34
{
35
enum class Instruction: uint8_t;
36
}
37
38
namespace solidity::yul
39
{
40
41
/// Removes statements that are just empty blocks (non-recursive).
42
/// If this is run on the outermost block, the FunctionGrouper should be run afterwards to keep
43
/// the canonical form.
44
void removeEmptyBlocks(Block& _block);
45
46
/// Returns true if a given literal can not be used as an identifier.
47
/// This includes Yul keywords and builtins of the given dialect.
48
bool isRestrictedIdentifier(Dialect const& _dialect, std::string_view _identifier);
49
50
/// Helper function that returns the instruction, if the `_name` is a BuiltinFunction
51
std::optional<evmasm::Instruction> toEVMInstruction(Dialect const& _dialect, FunctionName const& _name);
52
53
/// Helper function that returns the EVM version from a dialect.
54
/// It returns the default EVM version if dialect is not an EVMDialect.
55
langutil::EVMVersion const evmVersionFromDialect(Dialect const& _dialect);
56
57
class StatementRemover: public ASTModifier
58
{
59
public:
60
653k
  explicit StatementRemover(std::set<Statement const*> const& _toRemove): m_toRemove(_toRemove) {}
61
62
  void operator()(Block& _block) override;
63
private:
64
  std::set<Statement const*> const& m_toRemove;
65
};
66
67
}