Coverage Report

Created: 2022-08-24 06:40

/src/solidity/libyul/Dialect.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
 * Yul dialect.
20
 */
21
22
#pragma once
23
24
#include <libyul/YulString.h>
25
#include <libyul/ControlFlowSideEffects.h>
26
#include <libyul/SideEffects.h>
27
28
#include <vector>
29
#include <set>
30
#include <optional>
31
32
namespace solidity::yul
33
{
34
35
class YulString;
36
using Type = YulString;
37
enum class LiteralKind;
38
struct Literal;
39
40
struct BuiltinFunction
41
{
42
  YulString name;
43
  std::vector<Type> parameters;
44
  std::vector<Type> returns;
45
  SideEffects sideEffects;
46
  ControlFlowSideEffects controlFlowSideEffects;
47
  /// If true, this is the msize instruction or might contain it.
48
  bool isMSize = false;
49
  /// Must be empty or the same length as the arguments.
50
  /// If set at index i, the i'th argument has to be a literal which means it can't be moved to variables.
51
  std::vector<std::optional<LiteralKind>> literalArguments{};
52
  std::optional<LiteralKind> literalArgument(size_t i) const
53
14.2M
  {
54
14.2M
    return literalArguments.empty() ? std::nullopt : literalArguments.at(i);
55
14.2M
  }
56
};
57
58
struct Dialect
59
{
60
  /// Noncopiable.
61
  Dialect(Dialect const&) = delete;
62
  Dialect& operator=(Dialect const&) = delete;
63
64
  /// Default type, can be omitted.
65
  YulString defaultType;
66
  /// Type used for the literals "true" and "false".
67
  YulString boolType;
68
  std::set<YulString> types = {{}};
69
70
  /// @returns the builtin function of the given name or a nullptr if it is not a builtin function.
71
0
  virtual BuiltinFunction const* builtin(YulString /*_name*/) const { return nullptr; }
72
73
  /// @returns true if the identifier is reserved. This includes the builtins too.
74
0
  virtual bool reservedIdentifier(YulString _name) const { return builtin(_name) != nullptr; }
75
76
0
  virtual BuiltinFunction const* discardFunction(YulString /* _type */) const { return nullptr; }
77
0
  virtual BuiltinFunction const* equalityFunction(YulString /* _type */) const { return nullptr; }
78
0
  virtual BuiltinFunction const* booleanNegationFunction() const { return nullptr; }
79
80
0
  virtual BuiltinFunction const* memoryStoreFunction(YulString /* _type */) const { return nullptr; }
81
0
  virtual BuiltinFunction const* memoryLoadFunction(YulString /* _type */) const { return nullptr; }
82
0
  virtual BuiltinFunction const* storageStoreFunction(YulString /* _type */) const { return nullptr; }
83
0
  virtual BuiltinFunction const* storageLoadFunction(YulString /* _type */) const { return nullptr; }
84
0
  virtual YulString hashFunction(YulString /* _type */ ) const { return YulString{}; }
85
86
  /// Check whether the given type is legal for the given literal value.
87
  /// Should only be called if the type exists in the dialect at all.
88
  virtual bool validTypeForLiteral(LiteralKind _kind, YulString _value, YulString _type) const;
89
90
  virtual Literal zeroLiteralForType(YulString _type) const;
91
  virtual Literal trueLiteral() const;
92
93
12.8k
  virtual std::set<YulString> fixedFunctionNames() const { return {}; }
94
95
30.7k
  Dialect() = default;
96
30.7k
  virtual ~Dialect() = default;
97
98
  /// Old "yul" dialect. This is only used for testing.
99
  static Dialect const& yulDeprecated();
100
};
101
102
}