Coverage Report

Created: 2026-08-14 07:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solidity/libyul/backends/evm/NoOutputAssembly.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
 * Assembly interface that ignores everything. Can be used as a backend for a compilation dry-run.
20
 */
21
22
#pragma once
23
24
#include <libyul/backends/evm/AbstractAssembly.h>
25
26
#include <libyul/backends/evm/EVMDialect.h>
27
28
#include <libevmasm/LinkerObject.h>
29
30
#include <map>
31
32
namespace solidity::langutil
33
{
34
struct SourceLocation;
35
}
36
37
namespace solidity::yul
38
{
39
40
class NoOutputAssembly;
41
42
/**
43
 * Assembly class that just ignores everything and only performs stack counting.
44
 * The purpose is to use this assembly for compilation dry-runs.
45
 */
46
class NoOutputAssembly: public AbstractAssembly
47
{
48
public:
49
83.4k
  explicit NoOutputAssembly(langutil::EVMVersion _evmVersion): m_evmVersion(_evmVersion) { }
50
  ~NoOutputAssembly() override = default;
51
52
16.7M
  void setSourceLocation(langutil::SourceLocation const&) override {}
53
25.9M
  int stackHeight() const override { return m_stackHeight; }
54
378k
  void setStackHeight(int height) override { m_stackHeight = height; }
55
  void appendInstruction(evmasm::Instruction _instruction) override;
56
  void appendConstant(u256 const& _constant) override;
57
  void appendLabel(LabelID _labelId) override;
58
  void appendLabelReference(LabelID _labelId) override;
59
  LabelID newLabelId() override;
60
  LabelID namedLabel(std::string const& _name, size_t _params, size_t _returns, std::optional<size_t> _sourceID) override;
61
  void appendLinkerSymbol(std::string const& _name) override;
62
  void appendVerbatim(bytes _data, size_t _arguments, size_t _returnVariables) override;
63
64
  void appendJump(int _stackDiffAfter, JumpType _jumpType) override;
65
  void appendJumpTo(LabelID _labelId, int _stackDiffAfter, JumpType _jumpType) override;
66
  void appendJumpToIf(LabelID _labelId, JumpType _jumpType) override;
67
68
  void appendAssemblySize() override;
69
  std::pair<std::shared_ptr<AbstractAssembly>, SubID> createSubAssembly(bool _creation, std::string _name = "") override;
70
  void appendDataOffset(std::vector<SubID> const& _subPath) override;
71
  void appendDataSize(std::vector<SubID> const& _subPath) override;
72
  SubID appendData(bytes const& _data) override;
73
74
0
  void appendToAuxiliaryData(bytes const&) override {}
75
76
  void appendImmutable(std::string const& _identifier) override;
77
  void appendImmutableAssignment(std::string const& _identifier) override;
78
79
159k
  void markAsInvalid() override {}
80
81
0
  langutil::EVMVersion evmVersion() const override { return m_evmVersion; }
82
83
private:
84
  int m_stackHeight = 0;
85
  langutil::EVMVersion m_evmVersion;
86
};
87
88
89
/**
90
 * EVM dialect that does not generate any code.
91
 */
92
class NoOutputEVMDialect: public EVMDialect
93
{
94
public:
95
  explicit NoOutputEVMDialect(EVMDialect const& _copyFrom);
96
97
  BuiltinFunctionForEVM const& builtin(BuiltinHandle const& _handle) const override;
98
99
private:
100
  static std::vector<BuiltinFunctionForEVM> defineNoOutputBuiltins();
101
};
102
103
104
}