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/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 solidity;
32
using namespace solidity::yul;
33
using namespace solidity::util;
34
using namespace solidity::langutil;
35
36
void CodeGenerator::assemble(
37
  Block const& _parsedData,
38
  AsmAnalysisInfo& _analysisInfo,
39
  evmasm::Assembly& _assembly,
40
  langutil::EVMVersion _evmVersion,
41
  ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
42
  bool _useNamedLabelsForFunctions,
43
  bool _optimizeStackAllocation
44
)
45
61.9k
{
46
61.9k
  EthAssemblyAdapter assemblyAdapter(_assembly);
47
61.9k
  BuiltinContext builtinContext;
48
61.9k
  CodeTransform transform(
49
61.9k
    assemblyAdapter,
50
61.9k
    _analysisInfo,
51
61.9k
    _parsedData,
52
61.9k
    EVMDialect::strictAssemblyForEVM(_evmVersion),
53
61.9k
    builtinContext,
54
61.9k
    _optimizeStackAllocation,
55
61.9k
    _identifierAccessCodeGen,
56
61.9k
      _useNamedLabelsForFunctions ?
57
9.40k
      CodeTransform::UseNamedLabels::YesAndForceUnique :
58
61.9k
      CodeTransform::UseNamedLabels::Never
59
61.9k
  );
60
61.9k
  transform(_parsedData);
61
61.9k
  if (!transform.stackErrors().empty())
62
61.9k
    assertThrow(
63
61.9k
      false,
64
61.9k
      langutil::StackTooDeepError,
65
61.9k
      util::stackTooDeepString + " When compiling inline assembly" +
66
61.9k
      (transform.stackErrors().front().comment() ? ": " + *transform.stackErrors().front().comment() : ".")
67
61.9k
    );
68
61.9k
}