Coverage Report

Created: 2022-08-24 06:31

/src/solidity/libsolidity/codegen/Compiler.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
 * @author Christian <c@ethdev.com>
20
 * @date 2014
21
 * Solidity AST to EVM bytecode compiler.
22
 */
23
24
#pragma once
25
26
#include <libsolidity/codegen/CompilerContext.h>
27
#include <libsolidity/interface/OptimiserSettings.h>
28
#include <libsolidity/interface/DebugSettings.h>
29
#include <liblangutil/EVMVersion.h>
30
#include <libevmasm/Assembly.h>
31
#include <functional>
32
#include <ostream>
33
34
namespace solidity::frontend
35
{
36
37
class Compiler
38
{
39
public:
40
  Compiler(langutil::EVMVersion _evmVersion, RevertStrings _revertStrings, OptimiserSettings _optimiserSettings):
41
    m_optimiserSettings(std::move(_optimiserSettings)),
42
    m_runtimeContext(_evmVersion, _revertStrings),
43
    m_context(_evmVersion, _revertStrings, &m_runtimeContext)
44
0
  { }
45
46
  /// Compiles a contract.
47
  /// @arg _metadata contains the to be injected metadata CBOR
48
  void compileContract(
49
    ContractDefinition const& _contract,
50
    std::map<ContractDefinition const*, std::shared_ptr<Compiler const>> const& _otherCompilers,
51
    bytes const& _metadata
52
  );
53
  /// @returns Entire assembly.
54
0
  evmasm::Assembly const& assembly() const { return m_context.assembly(); }
55
  /// @returns Runtime assembly.
56
0
  evmasm::Assembly const& runtimeAssembly() const { return m_context.assembly().sub(m_runtimeSub); }
57
  /// @returns Entire assembly as a shared pointer to non-const.
58
0
  std::shared_ptr<evmasm::Assembly> assemblyPtr() const { return m_context.assemblyPtr(); }
59
  /// @returns Runtime assembly as a shared pointer.
60
  std::shared_ptr<evmasm::Assembly> runtimeAssemblyPtr() const;
61
62
0
  std::string generatedYulUtilityCode() const { return m_context.generatedYulUtilityCode(); }
63
0
  std::string runtimeGeneratedYulUtilityCode() const { return m_runtimeContext.generatedYulUtilityCode(); }
64
65
private:
66
  OptimiserSettings const m_optimiserSettings;
67
  CompilerContext m_runtimeContext;
68
  size_t m_runtimeSub = size_t(-1); ///< Identifier of the runtime sub-assembly, if present.
69
  CompilerContext m_context;
70
};
71
72
}