mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use old yul dialect only in tests.
This commit is contained in:
parent
d07dd55096
commit
a66782537a
@ -59,12 +59,12 @@ Dialect const& languageToDialect(AssemblyStack::Language _language, EVMVersion _
|
||||
case AssemblyStack::Language::StrictAssembly:
|
||||
return EVMDialect::strictAssemblyForEVMObjects(_version);
|
||||
case AssemblyStack::Language::Yul:
|
||||
return Dialect::yul();
|
||||
return EVMDialectTyped::instance(_version);
|
||||
case AssemblyStack::Language::Ewasm:
|
||||
return WasmDialect::instance();
|
||||
}
|
||||
yulAssert(false, "");
|
||||
return Dialect::yul();
|
||||
return Dialect::yulDeprecated();
|
||||
}
|
||||
|
||||
}
|
||||
@ -236,7 +236,7 @@ string AssemblyStack::print() const
|
||||
{
|
||||
yulAssert(m_parserResult, "");
|
||||
yulAssert(m_parserResult->code, "");
|
||||
return m_parserResult->toString(m_language == Language::Yul) + "\n";
|
||||
return m_parserResult->toString(&languageToDialect(m_language, m_evmVersion)) + "\n";
|
||||
}
|
||||
|
||||
shared_ptr<Object> AssemblyStack::parserResult() const
|
||||
|
@ -23,7 +23,7 @@
|
||||
using namespace solidity::yul;
|
||||
using namespace std;
|
||||
|
||||
Dialect const& Dialect::yul()
|
||||
Dialect const& Dialect::yulDeprecated()
|
||||
{
|
||||
static unique_ptr<Dialect> dialect;
|
||||
static YulStringRepository::ResetCallback callback{[&] { dialect.reset(); }};
|
||||
|
@ -65,7 +65,8 @@ struct Dialect: boost::noncopyable
|
||||
Dialect() = default;
|
||||
virtual ~Dialect() = default;
|
||||
|
||||
static Dialect const& yul();
|
||||
/// Old "yul" dialect. This is only used for testing.
|
||||
static Dialect const& yulDeprecated();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -45,18 +45,18 @@ string indent(std::string const& _input)
|
||||
|
||||
}
|
||||
|
||||
string Data::toString(bool) const
|
||||
string Data::toString(Dialect const*) const
|
||||
{
|
||||
return "data \"" + name.str() + "\" hex\"" + util::toHex(data) + "\"";
|
||||
}
|
||||
|
||||
string Object::toString(bool _yul) const
|
||||
string Object::toString(Dialect const* _dialect) const
|
||||
{
|
||||
yulAssert(code, "No code");
|
||||
string inner = "code " + AsmPrinter{}(*code);
|
||||
string inner = "code " + (_dialect ? AsmPrinter{*_dialect} : AsmPrinter{})(*code);
|
||||
|
||||
for (auto const& obj: subObjects)
|
||||
inner += "\n" + obj->toString(_yul);
|
||||
inner += "\n" + obj->toString(_dialect);
|
||||
|
||||
return "object \"" + name.str() + "\" {\n" + indent(inner) + "\n}";
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
namespace solidity::yul
|
||||
{
|
||||
struct Dialect;
|
||||
struct AsmAnalysisInfo;
|
||||
|
||||
|
||||
@ -39,7 +40,8 @@ struct AsmAnalysisInfo;
|
||||
struct ObjectNode
|
||||
{
|
||||
virtual ~ObjectNode() = default;
|
||||
virtual std::string toString(bool _yul) const = 0;
|
||||
virtual std::string toString(Dialect const* _dialect) const = 0;
|
||||
std::string toString() { return toString(nullptr); }
|
||||
|
||||
YulString name;
|
||||
};
|
||||
@ -50,7 +52,7 @@ struct ObjectNode
|
||||
struct Data: ObjectNode
|
||||
{
|
||||
Data(YulString _name, bytes _data): data(std::move(_data)) { name = _name; }
|
||||
std::string toString(bool _yul) const override;
|
||||
std::string toString(Dialect const* _dialect) const override;
|
||||
|
||||
bytes data;
|
||||
};
|
||||
@ -62,7 +64,7 @@ struct Object: ObjectNode
|
||||
{
|
||||
public:
|
||||
/// @returns a (parseable) string representation. Includes types if @a _yul is set.
|
||||
std::string toString(bool _yul) const override;
|
||||
std::string toString(Dialect const* _dialect) const override;
|
||||
|
||||
/// @returns the set of names of data objects accessible from within the code of
|
||||
/// this object.
|
||||
|
@ -15,30 +15,30 @@ object "object" {
|
||||
function main()
|
||||
{
|
||||
let _1 := 0
|
||||
mstore_internal(0:i64, _1, _1, _1, _1)
|
||||
mstore_internal(32:i64, _1, _1, _1, 1)
|
||||
eth.storageStore(0:i64, 32:i64)
|
||||
mstore_internal(0, _1, _1, _1, _1)
|
||||
mstore_internal(32, _1, _1, _1, 1)
|
||||
eth.storageStore(0, 32)
|
||||
}
|
||||
function endian_swap_16(x:i64) -> y:i64
|
||||
function endian_swap_16(x) -> y
|
||||
{
|
||||
y := i64.or(i64.and(i64.shl(x, 8:i64), 0xff00:i64), i64.and(i64.shr_u(x, 8:i64), 0xff:i64))
|
||||
y := i64.or(i64.and(i64.shl(x, 8), 0xff00), i64.and(i64.shr_u(x, 8), 0xff))
|
||||
}
|
||||
function endian_swap_32(x:i64) -> y:i64
|
||||
function endian_swap_32(x) -> y
|
||||
{
|
||||
let hi:i64 := i64.shl(endian_swap_16(x), 16:i64)
|
||||
y := i64.or(hi, endian_swap_16(i64.shr_u(x, 16:i64)))
|
||||
let hi := i64.shl(endian_swap_16(x), 16)
|
||||
y := i64.or(hi, endian_swap_16(i64.shr_u(x, 16)))
|
||||
}
|
||||
function endian_swap(x:i64) -> y:i64
|
||||
function endian_swap(x) -> y
|
||||
{
|
||||
let hi:i64 := i64.shl(endian_swap_32(x), 32:i64)
|
||||
y := i64.or(hi, endian_swap_32(i64.shr_u(x, 32:i64)))
|
||||
let hi := i64.shl(endian_swap_32(x), 32)
|
||||
y := i64.or(hi, endian_swap_32(i64.shr_u(x, 32)))
|
||||
}
|
||||
function mstore_internal(pos:i64, y1:i64, y2:i64, y3:i64, y4:i64)
|
||||
function mstore_internal(pos, y1, y2, y3, y4)
|
||||
{
|
||||
i64.store(pos, endian_swap(y1))
|
||||
i64.store(i64.add(pos, 8:i64), endian_swap(y2))
|
||||
i64.store(i64.add(pos, 16:i64), endian_swap(y3))
|
||||
i64.store(i64.add(pos, 24:i64), endian_swap(y4))
|
||||
i64.store(i64.add(pos, 8), endian_swap(y2))
|
||||
i64.store(i64.add(pos, 16), endian_swap(y3))
|
||||
i64.store(i64.add(pos, 24), endian_swap(y4))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace
|
||||
{
|
||||
Dialect const& defaultDialect(bool _yul)
|
||||
{
|
||||
return _yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVM(solidity::test::CommonOptions::get().evmVersion());
|
||||
return _yul ? yul::Dialect::yulDeprecated() : yul::EVMDialect::strictAssemblyForEVM(solidity::test::CommonOptions::get().evmVersion());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,12 +99,12 @@ std::optional<Error> parseAndReturnFirstError(string const& _source, Dialect con
|
||||
return {};
|
||||
}
|
||||
|
||||
bool successParse(std::string const& _source, Dialect const& _dialect = Dialect::yul(), bool _allowWarnings = true)
|
||||
bool successParse(std::string const& _source, Dialect const& _dialect = Dialect::yulDeprecated(), bool _allowWarnings = true)
|
||||
{
|
||||
return !parseAndReturnFirstError(_source, _dialect, _allowWarnings);
|
||||
}
|
||||
|
||||
Error expectError(std::string const& _source, Dialect const& _dialect = Dialect::yul(), bool _allowWarnings = false)
|
||||
Error expectError(std::string const& _source, Dialect const& _dialect = Dialect::yulDeprecated(), bool _allowWarnings = false)
|
||||
{
|
||||
|
||||
auto error = parseAndReturnFirstError(_source, _dialect, _allowWarnings);
|
||||
@ -122,7 +122,7 @@ do \
|
||||
BOOST_CHECK(solidity::frontend::test::searchErrorMessage(err, (substring))); \
|
||||
} while(0)
|
||||
|
||||
#define CHECK_ERROR(text, typ, substring) CHECK_ERROR_DIALECT(text, typ, substring, Dialect::yul())
|
||||
#define CHECK_ERROR(text, typ, substring) CHECK_ERROR_DIALECT(text, typ, substring, Dialect::yulDeprecated())
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(YulParser)
|
||||
|
||||
|
@ -105,7 +105,7 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename)
|
||||
{
|
||||
auto dialectName = m_settings["dialect"];
|
||||
if (dialectName == "yul")
|
||||
m_dialect = &Dialect::yul();
|
||||
m_dialect = &Dialect::yulDeprecated();
|
||||
else if (dialectName == "ewasm")
|
||||
m_dialect = &WasmDialect::instance();
|
||||
else if (dialectName == "evm")
|
||||
|
Loading…
Reference in New Issue
Block a user