Coverage Report

Created: 2022-08-24 06:40

/src/solidity/libyul/optimiser/SSAValueTracker.h
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
 * Component that collects variables that are never assigned to and their
20
 * initial values.
21
 */
22
23
#pragma once
24
25
#include <libyul/optimiser/ASTWalker.h>
26
#include <libyul/AST.h> // Needed for m_zero below.
27
28
#include <map>
29
#include <set>
30
31
namespace solidity::yul
32
{
33
34
/**
35
 * Class that walks the AST and stores the initial value of each variable
36
 * that is never assigned to.
37
 *
38
 * A special zero constant expression is used for the default value of variables.
39
 *
40
 * Prerequisite: Disambiguator
41
 */
42
class SSAValueTracker: public ASTWalker
43
{
44
public:
45
  using ASTWalker::operator();
46
  void operator()(FunctionDefinition const& _funDef) override;
47
  void operator()(VariableDeclaration const& _varDecl) override;
48
  void operator()(Assignment const& _assignment) override;
49
50
73.0k
  std::map<YulString, Expression const*> const& values() const { return m_values; }
51
0
  Expression const* value(YulString _name) const { return m_values.at(_name); }
52
53
  static std::set<YulString> ssaVariables(Block const& _ast);
54
55
private:
56
  void setValue(YulString _name, Expression const* _value);
57
58
  /// Special expression whose address will be used in m_values.
59
  /// YulString does not need to be reset because SSAValueTracker is short-lived.
60
  Expression const m_zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}};
61
  std::map<YulString, Expression const*> m_values;
62
};
63
64
}