Coverage Report

Created: 2026-08-14 07:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solidity/libevmasm/EVMAssemblyStack.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
#pragma once
20
21
#include <libevmasm/AbstractAssemblyStack.h>
22
#include <libevmasm/Assembly.h>
23
#include <libevmasm/LinkerObject.h>
24
25
#include <libsolutil/JSON.h>
26
27
#include <map>
28
#include <string>
29
#include <utility>
30
31
namespace solidity::evmasm
32
{
33
34
class EVMAssemblyStack: public AbstractAssemblyStack
35
{
36
public:
37
  explicit EVMAssemblyStack(
38
    langutil::EVMVersion _evmVersion,
39
    Assembly::OptimiserSettings _optimiserSettings
40
  ):
41
0
    m_evmVersion(_evmVersion),
42
0
    m_optimiserSettings(std::move(_optimiserSettings))
43
0
  {}
44
45
  /// Runs parsing and analysis steps.
46
  /// Multiple calls overwrite the previous state.
47
  /// @throws AssemblyImportException, if JSON could not be validated.
48
  void parseAndAnalyze(std::string const& _sourceName, std::string const& _source);
49
50
  /// Runs analysis steps.
51
  /// Multiple calls overwrite the previous state.
52
  /// @throws AssemblyImportException, if JSON could not be validated.
53
  void analyze(std::string const& _sourceName, Json const& _assemblyJson);
54
55
  void assemble();
56
57
0
  std::string const& name() const { return m_name; }
58
59
0
  LinkerObject const& object() const { return m_object; }
60
  LinkerObject const& object(std::string const& _contractName) const override;
61
0
  LinkerObject const& runtimeObject() const { return m_runtimeObject; }
62
  LinkerObject const& runtimeObject(std::string const& _contractName) const override;
63
64
0
  std::shared_ptr<evmasm::Assembly> const& evmAssembly() const { return m_evmAssembly; }
65
0
  std::shared_ptr<evmasm::Assembly> const& evmRuntimeAssembly() const { return m_evmRuntimeAssembly; }
66
67
0
  std::string const& sourceMapping() const { return m_sourceMapping; }
68
  std::string const* sourceMapping(std::string const& _contractName) const override;
69
0
  std::string const& runtimeSourceMapping() const { return m_runtimeSourceMapping; }
70
  std::string const* runtimeSourceMapping(std::string const& _contractName) const override;
71
72
  Json ethdebug(std::string const& _contractName) const override;
73
  Json ethdebugRuntime(std::string const& _contractName) const override;
74
  Json ethdebug() const override;
75
  Json ethdebugCompilation() const override;
76
77
  Json assemblyJSON() const;
78
  Json assemblyJSON(std::string const& _contractName) const override;
79
  std::string assemblyString(StringMap const& _sourceCodes) const;
80
  std::string assemblyString(std::string const& _contractName, StringMap const& _sourceCodes) const override;
81
82
  std::string const filesystemFriendlyName(std::string const& _contractName) const override;
83
84
0
  std::vector<std::string> contractNames() const override { return {m_name}; }
85
  std::vector<std::string> sourceNames() const override;
86
  std::map<std::string, unsigned> sourceIndices() const;
87
88
0
  bool compilationSuccessful() const override { return m_evmAssembly != nullptr; }
89
90
  void selectDebugInfo(langutil::DebugInfoSelection _debugInfoSelection)
91
0
  {
92
0
    m_debugInfoSelection = _debugInfoSelection;
93
0
  }
94
95
private:
96
  langutil::EVMVersion m_evmVersion;
97
  Assembly::OptimiserSettings m_optimiserSettings;
98
  std::string m_name;
99
  std::shared_ptr<evmasm::Assembly> m_evmAssembly;
100
  std::shared_ptr<evmasm::Assembly> m_evmRuntimeAssembly;
101
  evmasm::LinkerObject m_object; ///< Deployment object (includes the runtime sub-object).
102
  evmasm::LinkerObject m_runtimeObject; ///< Runtime object.
103
  std::vector<std::string> m_sourceList;
104
  langutil::DebugInfoSelection m_debugInfoSelection = langutil::DebugInfoSelection::Default();
105
  std::string m_sourceMapping;
106
  std::string m_runtimeSourceMapping;
107
  std::unique_ptr<Json> m_ethdebug;
108
  std::unique_ptr<Json> m_ethdebugRuntime;
109
};
110
111
} // namespace solidity::evmasm