2019-12-19 16:58:20 +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-12-19 16:58:20 +00:00
|
|
|
/**
|
|
|
|
* Yul dialect.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libyul/Dialect.h>
|
2020-10-29 14:00:27 +00:00
|
|
|
#include <libyul/AST.h>
|
2019-12-19 16:58:20 +00:00
|
|
|
|
|
|
|
using namespace solidity::yul;
|
2020-02-18 15:11:21 +00:00
|
|
|
using namespace solidity::langutil;
|
|
|
|
|
|
|
|
Literal Dialect::zeroLiteralForType(solidity::yul::YulString _type) const
|
|
|
|
{
|
|
|
|
if (_type == boolType && _type != defaultType)
|
2021-04-27 14:53:04 +00:00
|
|
|
return {DebugData::create(), LiteralKind::Boolean, "false"_yulstring, _type};
|
|
|
|
return {DebugData::create(), LiteralKind::Number, "0"_yulstring, _type};
|
2020-02-18 15:11:21 +00:00
|
|
|
}
|
2019-12-19 16:58:20 +00:00
|
|
|
|
2020-05-11 17:56:29 +00:00
|
|
|
|
|
|
|
Literal Dialect::trueLiteral() const
|
|
|
|
{
|
|
|
|
if (boolType != defaultType)
|
2021-04-27 14:53:04 +00:00
|
|
|
return {DebugData::create(), LiteralKind::Boolean, "true"_yulstring, boolType};
|
2020-05-11 17:56:29 +00:00
|
|
|
else
|
2021-04-27 14:53:04 +00:00
|
|
|
return {DebugData::create(), LiteralKind::Number, "1"_yulstring, defaultType};
|
2020-05-11 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 17:56:05 +00:00
|
|
|
bool Dialect::validTypeForLiteral(LiteralKind _kind, YulString, YulString _type) const
|
|
|
|
{
|
|
|
|
if (_kind == LiteralKind::Boolean)
|
|
|
|
return _type == boolType;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-29 17:14:03 +00:00
|
|
|
Dialect const& Dialect::yulDeprecated()
|
2019-12-19 16:58:20 +00:00
|
|
|
{
|
2023-08-28 08:22:05 +00:00
|
|
|
static std::unique_ptr<Dialect> dialect;
|
2019-12-19 16:58:20 +00:00
|
|
|
static YulStringRepository::ResetCallback callback{[&] { dialect.reset(); }};
|
|
|
|
|
|
|
|
if (!dialect)
|
|
|
|
{
|
|
|
|
// TODO will probably change, especially the list of types.
|
2023-08-28 08:22:05 +00:00
|
|
|
dialect = std::make_unique<Dialect>();
|
2019-12-19 16:58:20 +00:00
|
|
|
dialect->defaultType = "u256"_yulstring;
|
|
|
|
dialect->boolType = "bool"_yulstring;
|
|
|
|
dialect->types = {
|
|
|
|
"bool"_yulstring,
|
|
|
|
"u8"_yulstring,
|
|
|
|
"s8"_yulstring,
|
|
|
|
"u32"_yulstring,
|
|
|
|
"s32"_yulstring,
|
|
|
|
"u64"_yulstring,
|
|
|
|
"s64"_yulstring,
|
|
|
|
"u128"_yulstring,
|
|
|
|
"s128"_yulstring,
|
|
|
|
"u256"_yulstring,
|
|
|
|
"s256"_yulstring
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return *dialect;
|
|
|
|
}
|