Remove asm flavour.

This commit is contained in:
chriseth
2020-01-14 17:16:09 +01:00
parent 8865ec76dc
commit 123ea0a250
31 changed files with 173 additions and 126 deletions
+5 -5
View File
@@ -15,9 +15,9 @@ object "object" {
function main()
{
let _1 := 0
mstore_internal(0, _1, _1, _1, _1)
mstore_internal(_1, _1, _1, _1, _1)
mstore_internal(32, _1, _1, _1, 1)
eth.storageStore(0, 32)
eth.storageStore(_1, 32)
}
function endian_swap_16(x) -> y
{
@@ -45,7 +45,7 @@ object "object" {
Binary representation:
0061736d0100000001160460000060017e017e60057e7e7e7e7e0060027f7f0002190108657468657265756d0c73746f7261676553746f7265000303060500010101020503010001060100071102066d656d6f72790200046d61696e00010ab501052801017e420021004200200020002000200010054220200020002000420110054200a74220a710000b1c01017e20004208864280fe0383200042088842ff018384210120010b1b01027e20001002421086210220022000421088100284210120010b1b01027e20001003422086210220022000422088100384210120010b3501007e2000a720011004370300200042087ca720021004370300200042107ca720031004370300200042187ca7200410043703000b
0061736d0100000001160460000060017e017e60057e7e7e7e7e0060027f7f0002190108657468657265756d0c73746f7261676553746f7265000303060500010101020503010001060100071102066d656d6f72790200046d61696e00010ab501052801017e420021002000200020002000200010054220200020002000420110052000a74220a710000b1c01017e20004208864280fe0383200042088842ff018384210120010b1b01027e20001002421086210220022000421088100284210120010b1b01027e20001003422086210220022000422088100384210120010b3501007e2000a720011004370300200042087ca720021004370300200042107ca720031004370300200042187ca7200410043703000b
Text representation:
(module
@@ -56,9 +56,9 @@ Text representation:
(func $main
(local $_1 i64)
(local.set $_1 (i64.const 0))
(call $mstore_internal (i64.const 0) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1))
(call $mstore_internal (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1))
(call $mstore_internal (i64.const 32) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 1))
(call $eth.storageStore (i32.wrap_i64 (i64.const 0)) (i32.wrap_i64 (i64.const 32)))
(call $eth.storageStore (i32.wrap_i64 (local.get $_1)) (i32.wrap_i64 (i64.const 32)))
)
(func $endian_swap_16
@@ -10,23 +10,21 @@
(local $p i64)
(local $r i64)
(local $hi i64)
(local $hi_1 i64)
(local $y i64)
(local $hi_2 i64)
(local $hi_1 i64)
(local $_2 i64)
(local.set $_1 (i64.const 0))
(local.set $p (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 64)))
(local.set $r (i64.add (local.get $p) (i64.const 64)))
(if (i64.ne (i64.extend_i32_u (i64.lt_u (local.get $r) (local.get $p))) (i64.const 0)) (then
(unreachable)))
(local.set $hi (i64.shl (call $endian_swap_16 (local.get $_1)) (i64.const 16)))
(local.set $hi_1 (i64.shl (i64.or (local.get $hi) (call $endian_swap_16 (i64.shr_u (local.get $_1) (i64.const 16)))) (i64.const 32)))
(local.set $y (i64.or (local.get $hi_1) (call $endian_swap_32 (i64.shr_u (local.get $_1) (i64.const 32)))))
(local.set $hi (i64.shl (i64.or (i64.shl (i64.or (i64.and (i64.shl (local.get $_1) (i64.const 8)) (i64.const 65280)) (i64.and (i64.shr_u (local.get $_1) (i64.const 8)) (i64.const 255))) (i64.const 16)) (call $endian_swap_16 (i64.shr_u (local.get $_1) (i64.const 16)))) (i64.const 32)))
(local.set $y (i64.or (local.get $hi) (call $endian_swap_32 (i64.shr_u (local.get $_1) (i64.const 32)))))
(i64.store (i32.wrap_i64 (local.get $r)) (local.get $y))
(i64.store (i32.wrap_i64 (i64.add (local.get $r) (i64.const 8))) (local.get $y))
(i64.store (i32.wrap_i64 (i64.add (local.get $r) (i64.const 16))) (local.get $y))
(local.set $hi_2 (i64.shl (call $endian_swap_32 (i64.const 128)) (i64.const 32)))
(i64.store (i32.wrap_i64 (i64.add (local.get $r) (i64.const 24))) (i64.or (local.get $hi_2) (call $endian_swap_32 (i64.shr_u (i64.const 128) (i64.const 32)))))
(local.set $hi_1 (i64.shl (call $endian_swap_32 (i64.const 128)) (i64.const 32)))
(i64.store (i32.wrap_i64 (i64.add (local.get $r) (i64.const 24))) (i64.or (local.get $hi_1) (call $endian_swap_32 (i64.shr_u (i64.const 128) (i64.const 32)))))
(local.set $_2 (datasize \"C_2_deployed\"))
(call $eth.codeCopy (i32.wrap_i64 (call $to_internal_i32ptr (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1))) (i32.wrap_i64 (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (dataoffset \"C_2_deployed\"))) (i32.wrap_i64 (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_2))))
(call $eth.finish (i32.wrap_i64 (call $to_internal_i32ptr (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1))) (i32.wrap_i64 (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_2))))
+4 -4
View File
@@ -224,8 +224,8 @@ BOOST_AUTO_TEST_CASE(vardecl_multi_conflict)
BOOST_AUTO_TEST_CASE(vardecl_bool)
{
CHECK_PARSE_ERROR("{ let x := true }", ParserError, "True and false are not valid literals.");
CHECK_PARSE_ERROR("{ let x := false }", ParserError, "True and false are not valid literals.");
successParse("{ let x := true }");
successParse("{ let x := false }");
}
BOOST_AUTO_TEST_CASE(vardecl_empty)
@@ -313,7 +313,7 @@ BOOST_AUTO_TEST_CASE(switch_duplicate_case)
BOOST_AUTO_TEST_CASE(switch_invalid_expression)
{
CHECK_PARSE_ERROR("{ switch {} default {} }", ParserError, "Literal, identifier or instruction expected.");
CHECK_PARSE_ERROR("{ switch {} default {} }", ParserError, "Literal or identifier expected.");
CHECK_PARSE_ERROR("{ switch mload default {} }", ParserError, "Expected '(' but got reserved keyword 'default'");
CHECK_PARSE_ERROR("{ switch mstore(1, 1) default {} }", TypeError, "Expected expression to return one item to the stack, but did return 0 items");
}
@@ -346,7 +346,7 @@ BOOST_AUTO_TEST_CASE(for_statement)
BOOST_AUTO_TEST_CASE(for_invalid_expression)
{
CHECK_PARSE_ERROR("{ for {} {} {} {} }", ParserError, "Literal, identifier or instruction expected.");
CHECK_PARSE_ERROR("{ for {} {} {} {} }", ParserError, "Literal or identifier expected.");
CHECK_PARSE_ERROR("{ for 1 1 {} {} }", ParserError, "Expected '{' but got 'Number'");
CHECK_PARSE_ERROR("{ for {} 1 1 {} }", ParserError, "Expected '{' but got 'Number'");
CHECK_PARSE_ERROR("{ for {} 1 {} 1 }", ParserError, "Expected '{' but got 'Number'");
@@ -8,4 +8,4 @@ contract C {
}
}
// ----
// ParserError: (101-102): Literal, identifier or instruction expected.
// ParserError: (101-102): Literal or identifier expected.
@@ -8,4 +8,4 @@ contract C {
}
}
// ----
// ParserError: (103-104): Literal, identifier or instruction expected.
// ParserError: (103-104): Literal or identifier expected.
@@ -7,4 +7,4 @@ contract C {
}
}
// ----
// ParserError: (96-97): Literal, identifier or instruction expected.
// ParserError: (96-97): Literal or identifier expected.
@@ -6,4 +6,4 @@ contract C {
}
}
// ----
// ParserError: (72-73): Literal, identifier or instruction expected.
// ParserError: (72-73): Literal or identifier expected.
@@ -7,4 +7,4 @@ contract C {
}
}
// ----
// ParserError: (87-89): Literal, identifier or instruction expected.
// ParserError: (87-89): Literal or identifier expected.
@@ -6,4 +6,4 @@ contract C {
}
}
// ----
// ParserError: (69-70): Literal, identifier or instruction expected.
// ParserError: (71-72): Expected identifier but got '='
@@ -7,4 +7,4 @@ contract C {
}
}
// ----
// ParserError: (107-108): Literal, identifier or instruction expected.
// ParserError: (109-110): Expected identifier but got '='
+22 -1
View File
@@ -75,6 +75,27 @@ pair<shared_ptr<Block>, shared_ptr<yul::AsmAnalysisInfo>> yul::test::parse(strin
return make_pair(stack.parserResult()->code, stack.parserResult()->analysisInfo);
}
pair<shared_ptr<Block>, shared_ptr<yul::AsmAnalysisInfo>> yul::test::parse(
string const& _source,
Dialect const& _dialect,
ErrorList& _errors
)
{
ErrorReporter errorReporter(_errors);
shared_ptr<Scanner> scanner = make_shared<Scanner>(CharStream(_source, ""));
shared_ptr<Object> parserResult = yul::ObjectParser(errorReporter, _dialect).parse(scanner, false);
if (!parserResult)
return {};
if (!parserResult->code || !errorReporter.errors().empty())
return {};
shared_ptr<AsmAnalysisInfo> analysisInfo = make_shared<AsmAnalysisInfo>();
AsmAnalyzer analyzer(*analysisInfo, errorReporter, _dialect, {}, parserResult->dataNames());
// TODO this should be done recursively.
if (!analyzer.analyze(*parserResult->code) || !errorReporter.errors().empty())
return {};
return {std::move(parserResult->code), std::move(analysisInfo)};
}
yul::Block yul::test::disambiguate(string const& _source, bool _yul)
{
auto result = parse(_source, _yul);
@@ -83,5 +104,5 @@ yul::Block yul::test::disambiguate(string const& _source, bool _yul)
string yul::test::format(string const& _source, bool _yul)
{
return yul::AsmPrinter(_yul)(*parse(_source, _yul).first);
return yul::AsmPrinter()(*parse(_source, _yul).first);
}
+6
View File
@@ -36,14 +36,20 @@ using ErrorList = std::vector<std::shared_ptr<Error const>>;
namespace solidity::yul
{
struct AsmAnalysisInfo;
struct Dialect;
}
namespace solidity::yul::test
{
void printErrors(langutil::ErrorList const& _errors);
std::pair<std::shared_ptr<Block>, std::shared_ptr<AsmAnalysisInfo>>
parse(std::string const& _source, bool _yul = true);
std::pair<std::shared_ptr<Block>, std::shared_ptr<AsmAnalysisInfo>>
parse(std::string const& _source, Dialect const& _dialect, langutil::ErrorList& _errors);
Block disambiguate(std::string const& _source, bool _yul = true);
std::string format(std::string const& _source, bool _yul = true);
+8 -10
View File
@@ -161,9 +161,9 @@ BOOST_AUTO_TEST_CASE(period_not_as_identifier_start)
BOOST_AUTO_TEST_CASE(period_in_identifier_spaced)
{
CHECK_ERROR("{ let x. y:u256 }", ParserError, "Expected ':' but got identifier");
CHECK_ERROR("{ let x .y:u256 }", ParserError, "Expected ':' but got '.'");
CHECK_ERROR("{ let x . y:u256 }", ParserError, "Expected ':' but got '.'");
CHECK_ERROR("{ let x. y:u256 }", ParserError, "Call or assignment expected");
CHECK_ERROR("{ let x .y:u256 }", ParserError, "Literal or identifier expected");
CHECK_ERROR("{ let x . y:u256 }", ParserError, "Literal or identifier expected");
}
BOOST_AUTO_TEST_CASE(period_in_identifier_start)
@@ -234,12 +234,12 @@ BOOST_AUTO_TEST_CASE(tokens_as_identifers)
BOOST_CHECK(successParse("{ let bool:u256 := 1:u256 }"));
}
BOOST_AUTO_TEST_CASE(lacking_types)
BOOST_AUTO_TEST_CASE(optional_types)
{
CHECK_ERROR("{ let x := 1:u256 }", ParserError, "Expected ':' but got ':='");
CHECK_ERROR("{ let x:u256 := 1 }", ParserError, "Expected ':' but got '}'");
CHECK_ERROR("{ function f(a) {} }", ParserError, "Expected ':' but got ')'");
CHECK_ERROR("{ function f(a:u256) -> b {} }", ParserError, "Expected ':' but got '{'");
BOOST_CHECK(successParse("{ let x := 1:u256 }"));
BOOST_CHECK(successParse("{ let x:u256 := 1 }"));
BOOST_CHECK(successParse("{ function f(a) {} }"));
BOOST_CHECK(successParse("{ function f(a:u256) -> b {} }"));
}
BOOST_AUTO_TEST_CASE(invalid_types)
@@ -531,7 +531,6 @@ BOOST_AUTO_TEST_CASE(builtins_parser)
{
struct SimpleDialect: public Dialect
{
SimpleDialect(): Dialect(AsmFlavour::Strict) {}
BuiltinFunction const* builtin(YulString _name) const override
{
return _name == "builtin"_yulstring ? &f : nullptr;
@@ -551,7 +550,6 @@ BOOST_AUTO_TEST_CASE(builtins_analysis)
{
struct SimpleDialect: public Dialect
{
SimpleDialect(): Dialect(AsmFlavour::Strict) {}
BuiltinFunction const* builtin(YulString _name) const override
{
return _name == "builtin"_yulstring ? &f : nullptr;
+7 -10
View File
@@ -18,6 +18,7 @@
#include <test/libyul/YulOptimizerTest.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <test/libyul/Common.h>
#include <test/Options.h>
#include <libyul/optimiser/BlockFlattener.h>
@@ -364,7 +365,7 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
return TestResult::FatalError;
}
m_obtainedResult = AsmPrinter{m_dialect->flavour == AsmFlavour::Yul}(*m_ast) + "\n";
m_obtainedResult = AsmPrinter{}(*m_ast) + "\n";
if (m_optimizerStep != m_validatedSettings["step"])
{
@@ -418,19 +419,15 @@ void YulOptimizerTest::printIndented(ostream& _stream, string const& _output, st
bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted)
{
AssemblyStack stack(
solidity::test::Options::get().evmVersion(),
m_dialect->flavour == AsmFlavour::Yul ? AssemblyStack::Language::Yul : AssemblyStack::Language::StrictAssembly,
solidity::frontend::OptimiserSettings::none()
);
if (!stack.parseAndAnalyze("", m_source) || !stack.errors().empty())
ErrorList errors;
soltestAssert(m_dialect, "");
std::tie(m_ast, m_analysisInfo) = yul::test::parse(m_source, *m_dialect, errors);
if (!m_ast || !m_analysisInfo || !errors.empty())
{
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
printErrors(_stream, stack.errors());
printErrors(_stream, errors);
return false;
}
m_ast = stack.parserResult()->code;
m_analysisInfo = stack.parserResult()->analysisInfo;
return true;
}