diff options
author | chriseth <chris@ethereum.org> | 2019-01-08 00:23:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-08 00:23:05 +0800 |
commit | 9f5d34af7de481c5b8ce89057a6df2a3283d14b0 (patch) | |
tree | 273c2c234e637a8c33ebbe041d8f2c4f8ef99c51 /test | |
parent | 165a6891212bd440a65da4084a823dccbf83a433 (diff) | |
parent | 9222eff08fad8e6a0ea7df8b299880f90c68c8b3 (diff) | |
download | dexon-solidity-9f5d34af7de481c5b8ce89057a6df2a3283d14b0.tar dexon-solidity-9f5d34af7de481c5b8ce89057a6df2a3283d14b0.tar.gz dexon-solidity-9f5d34af7de481c5b8ce89057a6df2a3283d14b0.tar.bz2 dexon-solidity-9f5d34af7de481c5b8ce89057a6df2a3283d14b0.tar.lz dexon-solidity-9f5d34af7de481c5b8ce89057a6df2a3283d14b0.tar.xz dexon-solidity-9f5d34af7de481c5b8ce89057a6df2a3283d14b0.tar.zst dexon-solidity-9f5d34af7de481c5b8ce89057a6df2a3283d14b0.zip |
Merge pull request #5752 from ethereum/addDialect
[Yul] Refactor: Make the dialect available everywhere.
Diffstat (limited to 'test')
-rw-r--r-- | test/libyul/Common.cpp | 12 | ||||
-rw-r--r-- | test/libyul/YulOptimizerTest.cpp | 44 | ||||
-rw-r--r-- | test/libyul/YulOptimizerTest.h | 2 | ||||
-rw-r--r-- | test/tools/yulopti.cpp | 23 |
4 files changed, 46 insertions, 35 deletions
diff --git a/test/libyul/Common.cpp b/test/libyul/Common.cpp index a337fa8d..ea4d0208 100644 --- a/test/libyul/Common.cpp +++ b/test/libyul/Common.cpp @@ -41,6 +41,14 @@ using namespace langutil; using namespace yul; using namespace dev::solidity; +namespace +{ +shared_ptr<Dialect> defaultDialect(bool _yul) +{ + return _yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVM(); +} +} + void yul::test::printErrors(ErrorList const& _errors) { SourceReferenceFormatter formatter(cout); @@ -55,7 +63,7 @@ void yul::test::printErrors(ErrorList const& _errors) pair<shared_ptr<Block>, shared_ptr<yul::AsmAnalysisInfo>> yul::test::parse(string const& _source, bool _yul) { - shared_ptr<Dialect> dialect = _yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVM(); + shared_ptr<Dialect> dialect = defaultDialect(_yul); ErrorList errors; ErrorReporter errorReporter(errors); auto scanner = make_shared<Scanner>(CharStream(_source, "")); @@ -87,7 +95,7 @@ pair<shared_ptr<Block>, shared_ptr<yul::AsmAnalysisInfo>> yul::test::parse(strin yul::Block yul::test::disambiguate(string const& _source, bool _yul) { auto result = parse(_source, _yul); - return boost::get<Block>(Disambiguator(*result.second, {})(*result.first)); + return boost::get<Block>(Disambiguator(*defaultDialect(_yul), *result.second, {})(*result.first)); } string yul::test::format(string const& _source, bool _yul) diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 0c782b17..1b392e0f 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -117,11 +117,11 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con else if (m_optimizerStep == "commonSubexpressionEliminator") { disambiguate(); - (CommonSubexpressionEliminator{})(*m_ast); + (CommonSubexpressionEliminator{*m_dialect})(*m_ast); } else if (m_optimizerStep == "expressionSplitter") { - NameDispenser nameDispenser(*m_ast); + NameDispenser nameDispenser{*m_dialect, *m_ast}; ExpressionSplitter{nameDispenser}(*m_ast); } else if (m_optimizerStep == "expressionJoiner") @@ -132,7 +132,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con else if (m_optimizerStep == "splitJoin") { disambiguate(); - NameDispenser nameDispenser(*m_ast); + NameDispenser nameDispenser{*m_dialect, *m_ast}; ExpressionSplitter{nameDispenser}(*m_ast); ExpressionJoiner::run(*m_ast); ExpressionJoiner::run(*m_ast); @@ -150,14 +150,14 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con else if (m_optimizerStep == "expressionInliner") { disambiguate(); - ExpressionInliner(*m_ast).run(); + ExpressionInliner(*m_dialect, *m_ast).run(); } else if (m_optimizerStep == "fullInliner") { disambiguate(); (FunctionHoister{})(*m_ast); (FunctionGrouper{})(*m_ast); - NameDispenser nameDispenser(*m_ast); + NameDispenser nameDispenser{*m_dialect, *m_ast}; ExpressionSplitter{nameDispenser}(*m_ast); FullInliner(*m_ast, nameDispenser).run(); ExpressionJoiner::run(*m_ast); @@ -171,54 +171,54 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con else if (m_optimizerStep == "rematerialiser") { disambiguate(); - Rematerialiser::run(*m_ast); + Rematerialiser::run(*m_dialect, *m_ast); } else if (m_optimizerStep == "expressionSimplifier") { disambiguate(); - ExpressionSimplifier::run(*m_ast); + ExpressionSimplifier::run(*m_dialect, *m_ast); } else if (m_optimizerStep == "fullSimplify") { disambiguate(); - NameDispenser nameDispenser(*m_ast); + NameDispenser nameDispenser{*m_dialect, *m_ast}; ExpressionSplitter{nameDispenser}(*m_ast); - CommonSubexpressionEliminator{}(*m_ast); - ExpressionSimplifier::run(*m_ast); - UnusedPruner::runUntilStabilised(*m_ast); + CommonSubexpressionEliminator{*m_dialect}(*m_ast); + ExpressionSimplifier::run(*m_dialect, *m_ast); + UnusedPruner::runUntilStabilised(*m_dialect, *m_ast); ExpressionJoiner::run(*m_ast); ExpressionJoiner::run(*m_ast); } else if (m_optimizerStep == "unusedPruner") { disambiguate(); - UnusedPruner::runUntilStabilised(*m_ast); + UnusedPruner::runUntilStabilised(*m_dialect, *m_ast); } else if (m_optimizerStep == "ssaTransform") { disambiguate(); - NameDispenser nameDispenser(*m_ast); + NameDispenser nameDispenser{*m_dialect, *m_ast}; SSATransform::run(*m_ast, nameDispenser); } else if (m_optimizerStep == "redundantAssignEliminator") { disambiguate(); - RedundantAssignEliminator::run(*m_ast); + RedundantAssignEliminator::run(*m_dialect, *m_ast); } else if (m_optimizerStep == "ssaPlusCleanup") { disambiguate(); - NameDispenser nameDispenser(*m_ast); + NameDispenser nameDispenser{*m_dialect, *m_ast}; SSATransform::run(*m_ast, nameDispenser); - RedundantAssignEliminator::run(*m_ast); + RedundantAssignEliminator::run(*m_dialect, *m_ast); } else if (m_optimizerStep == "structuralSimplifier") { disambiguate(); - StructuralSimplifier{}(*m_ast); + StructuralSimplifier{*m_dialect}(*m_ast); } else if (m_optimizerStep == "fullSuite") - OptimiserSuite::run(*m_ast, *m_analysisInfo); + OptimiserSuite::run(*m_dialect, *m_ast, *m_analysisInfo); else { FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Invalid optimizer step: " << m_optimizerStep << endl; @@ -260,11 +260,11 @@ void YulOptimizerTest::printIndented(ostream& _stream, string const& _output, st bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted) { - shared_ptr<yul::Dialect> dialect = m_yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVM(); + m_dialect = m_yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVM(); ErrorList errors; ErrorReporter errorReporter(errors); shared_ptr<Scanner> scanner = make_shared<Scanner>(CharStream(m_source, "")); - m_ast = yul::Parser(errorReporter, dialect).parse(scanner, false); + m_ast = yul::Parser(errorReporter, m_dialect).parse(scanner, false); if (!m_ast || !errorReporter.errors().empty()) { FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl; @@ -277,7 +277,7 @@ bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool c errorReporter, dev::test::Options::get().evmVersion(), boost::none, - dialect + m_dialect ); if (!analyzer.analyze(*m_ast) || !errorReporter.errors().empty()) { @@ -290,7 +290,7 @@ bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool c void YulOptimizerTest::disambiguate() { - *m_ast = boost::get<Block>(Disambiguator(*m_analysisInfo)(*m_ast)); + *m_ast = boost::get<Block>(Disambiguator(*m_dialect, *m_analysisInfo)(*m_ast)); m_analysisInfo.reset(); } diff --git a/test/libyul/YulOptimizerTest.h b/test/libyul/YulOptimizerTest.h index 5648e995..5009b82c 100644 --- a/test/libyul/YulOptimizerTest.h +++ b/test/libyul/YulOptimizerTest.h @@ -30,6 +30,7 @@ namespace yul { struct AsmAnalysisInfo; struct Block; +struct Dialect; } namespace yul @@ -64,6 +65,7 @@ private: std::string m_optimizerStep; std::string m_expectation; + std::shared_ptr<Dialect> m_dialect; std::shared_ptr<Block> m_ast; std::shared_ptr<AsmAnalysisInfo> m_analysisInfo; std::string m_obtainedResult; diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index e88b0538..8ef56ffe 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -85,7 +85,7 @@ public: { ErrorReporter errorReporter(m_errors); shared_ptr<Scanner> scanner = make_shared<Scanner>(CharStream(_input, "")); - m_ast = yul::Parser(errorReporter, yul::EVMDialect::strictAssemblyForEVM()).parse(scanner, false); + m_ast = yul::Parser(errorReporter, m_dialect).parse(scanner, false); if (!m_ast || !errorReporter.errors().empty()) { cout << "Error parsing source." << endl; @@ -98,7 +98,7 @@ public: errorReporter, EVMVersion::byzantium(), langutil::Error::Type::SyntaxError, - EVMDialect::strictAssemblyForEVM() + m_dialect ); if (!analyzer.analyze(*m_ast) || !errorReporter.errors().empty()) { @@ -120,9 +120,9 @@ public: return; if (!disambiguated) { - *m_ast = boost::get<yul::Block>(Disambiguator(*m_analysisInfo)(*m_ast)); + *m_ast = boost::get<yul::Block>(Disambiguator(*m_dialect, *m_analysisInfo)(*m_ast)); m_analysisInfo.reset(); - m_nameDispenser = make_shared<NameDispenser>(*m_ast); + m_nameDispenser = make_shared<NameDispenser>(*m_dialect, *m_ast); disambiguated = true; } cout << "(q)quit/(f)flatten/(c)se/initialize var(d)ecls/(x)plit/(j)oin/(g)rouper/(h)oister/" << endl; @@ -143,7 +143,7 @@ public: ForLoopInitRewriter{}(*m_ast); break; case 'c': - (CommonSubexpressionEliminator{})(*m_ast); + (CommonSubexpressionEliminator{*m_dialect})(*m_ast); break; case 'd': (VarDeclInitializer{})(*m_ast); @@ -161,28 +161,28 @@ public: (FunctionHoister{})(*m_ast); break; case 'e': - ExpressionInliner{*m_ast}.run(); + ExpressionInliner{*m_dialect, *m_ast}.run(); break; case 'i': FullInliner(*m_ast, *m_nameDispenser).run(); break; case 's': - ExpressionSimplifier::run(*m_ast); + ExpressionSimplifier::run(*m_dialect, *m_ast); break; case 't': - (StructuralSimplifier{})(*m_ast); + (StructuralSimplifier{*m_dialect})(*m_ast); break; case 'u': - UnusedPruner::runUntilStabilised(*m_ast); + UnusedPruner::runUntilStabilised(*m_dialect, *m_ast); break; case 'a': SSATransform::run(*m_ast, *m_nameDispenser); break; case 'r': - RedundantAssignEliminator::run(*m_ast); + RedundantAssignEliminator::run(*m_dialect, *m_ast); break; case 'm': - Rematerialiser::run(*m_ast); + Rematerialiser::run(*m_dialect, *m_ast); break; default: cout << "Unknown option." << endl; @@ -194,6 +194,7 @@ public: private: ErrorList m_errors; shared_ptr<yul::Block> m_ast; + shared_ptr<Dialect> m_dialect{EVMDialect::strictAssemblyForEVMObjects()}; shared_ptr<AsmAnalysisInfo> m_analysisInfo; shared_ptr<NameDispenser> m_nameDispenser; }; |