Coverage Report

Created: 2022-08-24 06:55

/src/solidity/libyul/backends/evm/AsmCodeGen.cpp
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
 * Helper to compile Yul code using libevmasm.
20
 */
21
22
#include <libyul/backends/evm/AsmCodeGen.h>
23
24
#include <libyul/backends/evm/EthAssemblyAdapter.h>
25
#include <libyul/backends/evm/EVMCodeTransform.h>
26
#include <libyul/AST.h>
27
#include <libyul/AsmAnalysisInfo.h>
28
29
#include <libsolutil/StackTooDeepString.h>
30
31
using namespace std;
32
using namespace solidity;
33
using namespace solidity::yul;
34
using namespace solidity::util;
35
using namespace solidity::langutil;
36
37
void CodeGenerator::assemble(
38
  Block const& _parsedData,
39
  AsmAnalysisInfo& _analysisInfo,
40
  evmasm::Assembly& _assembly,
41
  langutil::EVMVersion _evmVersion,
42
  ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
43
  bool _useNamedLabelsForFunctions,
44
  bool _optimizeStackAllocation
45
)
46
347k
{
47
347k
  EthAssemblyAdapter assemblyAdapter(_assembly);
48
347k
  BuiltinContext builtinContext;
49
347k
  CodeTransform transform(
50
347k
    assemblyAdapter,
51
347k
    _analysisInfo,
52
347k
    _parsedData,
53
347k
    EVMDialect::strictAssemblyForEVM(_evmVersion),
54
347k
    builtinContext,
55
347k
    _optimizeStackAllocation,
56
347k
    _identifierAccessCodeGen,
57
347k
      _useNamedLabelsForFunctions ?
58
20.7k
      CodeTransform::UseNamedLabels::YesAndForceUnique :
59
347k
      CodeTransform::UseNamedLabels::Never
60
347k
  );
61
347k
  transform(_parsedData);
62
347k
  if (!transform.stackErrors().empty())
63
347k
    assertThrow(
64
347k
      false,
65
347k
      langutil::StackTooDeepError,
66
347k
      util::stackTooDeepString + " When compiling inline assembly" +
67
347k
      (transform.stackErrors().front().comment() ? ": " + *transform.stackErrors().front().comment() : ".")
68
347k
    );
69
347k
}