solidity/libyul/backends/evm/AsmCodeGen.cpp

69 lines
2.1 KiB
C++
Raw Normal View History

/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
/**
* Helper to compile Yul code using libevmasm.
*/
2019-02-13 10:35:49 +00:00
#include <libyul/backends/evm/AsmCodeGen.h>
2017-02-15 13:52:53 +00:00
#include <libyul/backends/evm/EthAssemblyAdapter.h>
#include <libyul/backends/evm/EVMCodeTransform.h>
#include <libyul/AST.h>
#include <libyul/AsmAnalysisInfo.h>
#include <libsolutil/StackTooDeepString.h>
2019-12-11 16:31:36 +00:00
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::util;
using namespace solidity::langutil;
void CodeGenerator::assemble(
2017-04-12 16:32:25 +00:00
Block const& _parsedData,
AsmAnalysisInfo& _analysisInfo,
2019-12-11 16:31:36 +00:00
evmasm::Assembly& _assembly,
langutil::EVMVersion _evmVersion,
ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
bool _useNamedLabelsForFunctions,
2019-02-26 18:55:13 +00:00
bool _optimizeStackAllocation
2017-04-12 16:32:25 +00:00
)
{
EthAssemblyAdapter assemblyAdapter(_assembly);
BuiltinContext builtinContext;
2019-01-29 09:51:25 +00:00
CodeTransform transform(
assemblyAdapter,
_analysisInfo,
_parsedData,
EVMDialect::strictAssemblyForEVM(_evmVersion),
builtinContext,
2019-02-26 18:55:13 +00:00
_optimizeStackAllocation,
_identifierAccessCodeGen,
_useNamedLabelsForFunctions ?
CodeTransform::UseNamedLabels::YesAndForceUnique :
CodeTransform::UseNamedLabels::Never
2019-01-29 09:51:25 +00:00
);
transform(_parsedData);
if (!transform.stackErrors().empty())
assertThrow(
false,
langutil::StackTooDeepError,
util::stackTooDeepString + " When compiling inline assembly" +
(transform.stackErrors().front().comment() ? ": " + *transform.stackErrors().front().comment() : ".")
);
}