solidity/libyul/backends/evm/AsmCodeGen.cpp

66 lines
1.9 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>
using namespace std;
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 const& _identifierAccess,
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,
2019-01-29 09:51:25 +00:00
_identifierAccess,
_useNamedLabelsForFunctions
);
transform(_parsedData);
if (!transform.stackErrors().empty())
assertThrow(
false,
langutil::StackTooDeepError,
"Stack too deep when compiling inline assembly" +
(transform.stackErrors().front().comment() ? ": " + *transform.stackErrors().front().comment() : ".")
);
}