2019-01-28 17:11:58 +00:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2019-01-28 17:11:58 +00:00
|
|
|
/**
|
|
|
|
* Assembly interface that ignores everything. Can be used as a backend for a compilation dry-run.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libyul/backends/evm/NoOutputAssembly.h>
|
2020-04-14 08:52:27 +00:00
|
|
|
|
2020-10-29 14:00:27 +00:00
|
|
|
#include <libyul/AST.h>
|
2019-11-26 21:52:09 +00:00
|
|
|
#include <libyul/Exceptions.h>
|
2019-01-28 17:11:58 +00:00
|
|
|
|
|
|
|
#include <libevmasm/Instruction.h>
|
|
|
|
|
2021-09-03 13:55:17 +00:00
|
|
|
#include <range/v3/view/iota.hpp>
|
2020-04-14 08:52:27 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
using namespace solidity;
|
|
|
|
using namespace solidity::yul;
|
|
|
|
using namespace solidity::util;
|
|
|
|
using namespace solidity::langutil;
|
2019-01-28 17:11:58 +00:00
|
|
|
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
void NoOutputAssembly::appendInstruction(evmasm::Instruction _instr)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
2022-11-23 10:51:34 +00:00
|
|
|
m_stackHeight += instructionInfo(_instr, m_evmVersion).ret - instructionInfo(_instr, m_evmVersion).args;
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoOutputAssembly::appendConstant(u256 const&)
|
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
appendInstruction(evmasm::pushInstruction(1));
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoOutputAssembly::appendLabel(LabelID)
|
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
appendInstruction(evmasm::Instruction::JUMPDEST);
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoOutputAssembly::appendLabelReference(LabelID)
|
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
appendInstruction(evmasm::pushInstruction(1));
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NoOutputAssembly::LabelID NoOutputAssembly::newLabelId()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-08-23 02:24:09 +00:00
|
|
|
AbstractAssembly::LabelID NoOutputAssembly::namedLabel(std::string const&, size_t, size_t, std::optional<size_t>)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-08-23 02:24:09 +00:00
|
|
|
void NoOutputAssembly::appendLinkerSymbol(std::string const&)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(false, "Linker symbols not yet implemented.");
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 11:20:26 +00:00
|
|
|
void NoOutputAssembly::appendVerbatim(bytes, size_t _arguments, size_t _returnVariables)
|
2021-03-17 18:37:39 +00:00
|
|
|
{
|
2021-04-20 11:20:26 +00:00
|
|
|
m_stackHeight += static_cast<int>(_returnVariables - _arguments);
|
2021-03-17 18:37:39 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 12:22:01 +00:00
|
|
|
void NoOutputAssembly::appendJump(int _stackDiffAfter, JumpType)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
appendInstruction(evmasm::Instruction::JUMP);
|
2019-01-28 17:11:58 +00:00
|
|
|
m_stackHeight += _stackDiffAfter;
|
|
|
|
}
|
|
|
|
|
2020-06-22 12:22:01 +00:00
|
|
|
void NoOutputAssembly::appendJumpTo(LabelID _labelId, int _stackDiffAfter, JumpType _jumpType)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
2021-03-09 11:46:33 +00:00
|
|
|
appendLabelReference(_labelId);
|
|
|
|
appendJump(_stackDiffAfter, _jumpType);
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 12:22:01 +00:00
|
|
|
void NoOutputAssembly::appendJumpToIf(LabelID _labelId, JumpType)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
2021-03-09 11:46:33 +00:00
|
|
|
appendLabelReference(_labelId);
|
|
|
|
appendInstruction(evmasm::Instruction::JUMPI);
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoOutputAssembly::appendAssemblySize()
|
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
appendInstruction(evmasm::Instruction::PUSH1);
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
2023-08-23 02:24:09 +00:00
|
|
|
std::pair<std::shared_ptr<AbstractAssembly>, AbstractAssembly::SubID> NoOutputAssembly::createSubAssembly(bool, std::string)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
2019-11-26 21:52:09 +00:00
|
|
|
yulAssert(false, "Sub assemblies not implemented.");
|
2019-01-28 17:11:58 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:17:35 +00:00
|
|
|
void NoOutputAssembly::appendDataOffset(std::vector<AbstractAssembly::SubID> const&)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
appendInstruction(evmasm::Instruction::PUSH1);
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 09:17:35 +00:00
|
|
|
void NoOutputAssembly::appendDataSize(std::vector<AbstractAssembly::SubID> const&)
|
2019-01-28 17:11:58 +00:00
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
appendInstruction(evmasm::Instruction::PUSH1);
|
2019-01-28 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractAssembly::SubID NoOutputAssembly::appendData(bytes const&)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2019-02-21 09:28:34 +00:00
|
|
|
|
2020-04-14 08:52:27 +00:00
|
|
|
|
|
|
|
void NoOutputAssembly::appendImmutable(std::string const&)
|
|
|
|
{
|
|
|
|
yulAssert(false, "loadimmutable not implemented.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoOutputAssembly::appendImmutableAssignment(std::string const&)
|
|
|
|
{
|
|
|
|
yulAssert(false, "setimmutable not implemented.");
|
|
|
|
}
|
|
|
|
|
2019-05-16 08:56:56 +00:00
|
|
|
NoOutputEVMDialect::NoOutputEVMDialect(EVMDialect const& _copyFrom):
|
2019-12-19 16:58:20 +00:00
|
|
|
EVMDialect(_copyFrom.evmVersion(), _copyFrom.providesObjectAccess())
|
2019-02-21 09:28:34 +00:00
|
|
|
{
|
|
|
|
for (auto& fun: m_functions)
|
|
|
|
{
|
|
|
|
size_t returns = fun.second.returns.size();
|
2021-09-03 13:55:17 +00:00
|
|
|
fun.second.generateCode = [=](FunctionCall const& _call, AbstractAssembly& _assembly, BuiltinContext&)
|
2019-02-21 09:28:34 +00:00
|
|
|
{
|
2021-09-03 13:55:17 +00:00
|
|
|
for (size_t i: ranges::views::iota(0u, _call.arguments.size()))
|
2020-08-04 15:30:16 +00:00
|
|
|
if (!fun.second.literalArgument(i))
|
2021-09-03 13:55:17 +00:00
|
|
|
_assembly.appendInstruction(evmasm::Instruction::POP);
|
2019-02-21 09:28:34 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < returns; i++)
|
2019-02-26 18:43:24 +00:00
|
|
|
_assembly.appendConstant(u256(0));
|
2019-02-21 09:28:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|