Coverage Report

Created: 2025-09-08 08:10

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