2016-03-01 21:56:39 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2016-03-01 21:56:39 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2016-03-01 21:56:39 +00:00
|
|
|
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.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2016-03-01 21:56:39 +00:00
|
|
|
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
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2016-03-01 21:56:39 +00:00
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2016-03-01 21:56:39 +00:00
|
|
|
/**
|
2020-11-02 11:53:17 +00:00
|
|
|
* Helper to compile Yul code using libevmasm.
|
2016-03-01 21:56:39 +00:00
|
|
|
*/
|
|
|
|
|
2019-02-13 10:35:49 +00:00
|
|
|
#include <libyul/backends/evm/AsmCodeGen.h>
|
2017-02-15 13:52:53 +00:00
|
|
|
|
2020-11-02 11:53:17 +00:00
|
|
|
#include <libyul/backends/evm/EthAssemblyAdapter.h>
|
2018-11-23 10:31:45 +00:00
|
|
|
#include <libyul/backends/evm/EVMCodeTransform.h>
|
2020-11-02 11:53:17 +00:00
|
|
|
#include <libyul/AST.h>
|
|
|
|
#include <libyul/AsmAnalysisInfo.h>
|
2016-03-01 21:56:39 +00:00
|
|
|
|
2022-05-04 21:55:40 +00:00
|
|
|
#include <libsolutil/StackTooDeepString.h>
|
|
|
|
|
2016-03-01 21:56:39 +00:00
|
|
|
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;
|
2016-03-01 21:56:39 +00:00
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
void CodeGenerator::assemble(
|
2017-04-12 16:32:25 +00:00
|
|
|
Block const& _parsedData,
|
2017-04-26 13:41:08 +00:00
|
|
|
AsmAnalysisInfo& _analysisInfo,
|
2019-12-11 16:31:36 +00:00
|
|
|
evmasm::Assembly& _assembly,
|
2019-02-25 14:29:57 +00:00
|
|
|
langutil::EVMVersion _evmVersion,
|
2021-08-04 16:38:10 +00:00
|
|
|
ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
|
2018-09-25 02:47:25 +00:00
|
|
|
bool _useNamedLabelsForFunctions,
|
2019-02-26 18:55:13 +00:00
|
|
|
bool _optimizeStackAllocation
|
2017-04-12 16:32:25 +00:00
|
|
|
)
|
2016-05-08 14:24:47 +00:00
|
|
|
{
|
2017-04-28 16:15:18 +00:00
|
|
|
EthAssemblyAdapter assemblyAdapter(_assembly);
|
2019-05-15 21:40:30 +00:00
|
|
|
BuiltinContext builtinContext;
|
2019-01-29 09:51:25 +00:00
|
|
|
CodeTransform transform(
|
|
|
|
assemblyAdapter,
|
|
|
|
_analysisInfo,
|
|
|
|
_parsedData,
|
2019-05-16 08:56:56 +00:00
|
|
|
EVMDialect::strictAssemblyForEVM(_evmVersion),
|
2019-05-15 21:40:30 +00:00
|
|
|
builtinContext,
|
2019-02-26 18:55:13 +00:00
|
|
|
_optimizeStackAllocation,
|
2021-08-04 16:38:10 +00:00
|
|
|
_identifierAccessCodeGen,
|
2021-10-14 14:18:20 +00:00
|
|
|
_useNamedLabelsForFunctions ?
|
|
|
|
CodeTransform::UseNamedLabels::YesAndForceUnique :
|
|
|
|
CodeTransform::UseNamedLabels::Never
|
2019-01-29 09:51:25 +00:00
|
|
|
);
|
2020-07-08 10:54:52 +00:00
|
|
|
transform(_parsedData);
|
|
|
|
if (!transform.stackErrors().empty())
|
2020-07-01 07:46:06 +00:00
|
|
|
assertThrow(
|
2019-11-22 17:02:12 +00:00
|
|
|
false,
|
2020-07-01 07:46:06 +00:00
|
|
|
langutil::StackTooDeepError,
|
2022-05-04 21:55:40 +00:00
|
|
|
util::stackTooDeepString + " When compiling inline assembly" +
|
2020-07-08 10:54:52 +00:00
|
|
|
(transform.stackErrors().front().comment() ? ": " + *transform.stackErrors().front().comment() : ".")
|
2019-11-22 17:02:12 +00:00
|
|
|
);
|
2016-03-01 21:56:39 +00:00
|
|
|
}
|