diff options
-rw-r--r-- | libsolidity/interface/AssemblyStack.cpp | 2 | ||||
-rw-r--r-- | libyul/optimiser/CommonSubexpressionEliminator.h | 3 | ||||
-rw-r--r-- | libyul/optimiser/DataFlowAnalyzer.cpp | 2 | ||||
-rw-r--r-- | libyul/optimiser/DataFlowAnalyzer.h | 4 | ||||
-rw-r--r-- | libyul/optimiser/Disambiguator.cpp | 3 | ||||
-rw-r--r-- | libyul/optimiser/Disambiguator.h | 8 | ||||
-rw-r--r-- | libyul/optimiser/ExpressionInliner.cpp | 2 | ||||
-rw-r--r-- | libyul/optimiser/ExpressionInliner.h | 6 | ||||
-rw-r--r-- | libyul/optimiser/ExpressionSimplifier.cpp | 8 | ||||
-rw-r--r-- | libyul/optimiser/ExpressionSimplifier.h | 8 | ||||
-rw-r--r-- | libyul/optimiser/NameDispenser.cpp | 10 | ||||
-rw-r--r-- | libyul/optimiser/NameDispenser.h | 6 | ||||
-rw-r--r-- | libyul/optimiser/RedundantAssignEliminator.cpp | 6 | ||||
-rw-r--r-- | libyul/optimiser/RedundantAssignEliminator.h | 5 | ||||
-rw-r--r-- | libyul/optimiser/Rematerialiser.cpp | 7 | ||||
-rw-r--r-- | libyul/optimiser/Rematerialiser.h | 4 | ||||
-rw-r--r-- | libyul/optimiser/Semantics.cpp | 17 | ||||
-rw-r--r-- | libyul/optimiser/Semantics.h | 6 | ||||
-rw-r--r-- | libyul/optimiser/SimplificationRules.cpp | 13 | ||||
-rw-r--r-- | libyul/optimiser/SimplificationRules.h | 9 | ||||
-rw-r--r-- | libyul/optimiser/StructuralSimplifier.h | 2 | ||||
-rw-r--r-- | libyul/optimiser/Suite.cpp | 71 | ||||
-rw-r--r-- | libyul/optimiser/Suite.h | 2 | ||||
-rw-r--r-- | libyul/optimiser/UnusedPruner.cpp | 15 | ||||
-rw-r--r-- | libyul/optimiser/UnusedPruner.h | 14 | ||||
-rwxr-xr-x | test/cmdlineTests.sh | 39 | ||||
-rw-r--r-- | test/cmdlineTests/data_storage/args (renamed from test/cmdlineTests/data_storage.sol.args) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/data_storage/input.sol (renamed from test/cmdlineTests/data_storage.sol) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/data_storage/output (renamed from test/cmdlineTests/data_storage.sol.stdout) | 2 | ||||
-rw-r--r-- | test/cmdlineTests/gas_test_dispatch/args (renamed from test/cmdlineTests/gas_test_dispatch.sol.args) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/gas_test_dispatch/input.sol (renamed from test/cmdlineTests/gas_test_dispatch.sol) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/gas_test_dispatch/output (renamed from test/cmdlineTests/gas_test_dispatch.sol.stdout) | 6 | ||||
-rw-r--r-- | test/cmdlineTests/gas_test_dispatch_optimize/args (renamed from test/cmdlineTests/gas_test_dispatch_optimize.sol.args) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/gas_test_dispatch_optimize/input.sol (renamed from test/cmdlineTests/gas_test_dispatch_optimize.sol) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/gas_test_dispatch_optimize/output (renamed from test/cmdlineTests/gas_test_dispatch_optimize.sol.stdout) | 6 | ||||
-rw-r--r-- | test/cmdlineTests/standard_binaries_requested/input.json (renamed from test/cmdlineTests/standard_binaries_requested.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_binaries_requested/output.json (renamed from test/cmdlineTests/standard_binaries_requested.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_default_success/exit (renamed from test/cmdlineTests/standard.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_default_success/input.json (renamed from test/cmdlineTests/standard.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_default_success/output.json (renamed from test/cmdlineTests/standard.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_method_identifiers_requested/input.json (renamed from test/cmdlineTests/standard_methodIdentifiersRequested.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_method_identifiers_requested/output.json (renamed from test/cmdlineTests/standard_methodIdentifiersRequested.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_only_ast_requested/input.json (renamed from test/cmdlineTests/standard_only_ast_requested.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_only_ast_requested/output.json (renamed from test/cmdlineTests/standard_only_ast_requested.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_auxiliary_input/exit (renamed from test/cmdlineTests/standard_wrong_key_auxiliary_input.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_auxiliary_input/input.json (renamed from test/cmdlineTests/standard_wrong_key_auxiliary_input.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_auxiliary_input/output.json (renamed from test/cmdlineTests/standard_wrong_key_auxiliary_input.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_metadata/exit (renamed from test/cmdlineTests/standard_wrong_key_metadata.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_metadata/input.json (renamed from test/cmdlineTests/standard_wrong_key_metadata.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_metadata/output.json (renamed from test/cmdlineTests/standard_wrong_key_metadata.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_optimizer/exit (renamed from test/cmdlineTests/standard_wrong_key_optimizer.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_optimizer/input.json (renamed from test/cmdlineTests/standard_wrong_key_optimizer.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_optimizer/output.json (renamed from test/cmdlineTests/standard_wrong_key_optimizer.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_root/exit (renamed from test/cmdlineTests/standard_wrong_key_root.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_root/input.json (renamed from test/cmdlineTests/standard_wrong_key_root.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_root/output.json (renamed from test/cmdlineTests/standard_wrong_key_root.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_settings/exit (renamed from test/cmdlineTests/standard_wrong_key_settings.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_settings/input.json (renamed from test/cmdlineTests/standard_wrong_key_settings.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_settings/output.json (renamed from test/cmdlineTests/standard_wrong_key_settings.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_source/exit (renamed from test/cmdlineTests/standard_wrong_key_source.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_source/input.json (renamed from test/cmdlineTests/standard_wrong_key_source.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_key_source/output.json (renamed from test/cmdlineTests/standard_wrong_key_source.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input/exit (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input/input.json (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input/output.json (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/exit (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/input.json (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/output.json (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/exit (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/input.json (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/output.json (renamed from test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_metadata/exit (renamed from test/cmdlineTests/standard_wrong_type_metadata.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_metadata/input.json (renamed from test/cmdlineTests/standard_wrong_type_metadata.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_metadata/output.json (renamed from test/cmdlineTests/standard_wrong_type_metadata.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_optimizer/exit (renamed from test/cmdlineTests/standard_wrong_type_optimizer.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_optimizer/input.json (renamed from test/cmdlineTests/standard_wrong_type_optimizer.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_optimizer/output.json (renamed from test/cmdlineTests/standard_wrong_type_optimizer.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection/exit (renamed from test/cmdlineTests/standard_wrong_type_output_selection.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection/input.json (renamed from test/cmdlineTests/standard_wrong_type_output_selection.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection/output.json (renamed from test/cmdlineTests/standard_wrong_type_output_selection.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_contract/exit (renamed from test/cmdlineTests/standard_wrong_type_output_selection_contract.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_contract/input.json (renamed from test/cmdlineTests/standard_wrong_type_output_selection_contract.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_contract/output.json (renamed from test/cmdlineTests/standard_wrong_type_output_selection_contract.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_file/exit (renamed from test/cmdlineTests/standard_wrong_type_output_selection_file.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_file/input.json (renamed from test/cmdlineTests/standard_wrong_type_output_selection_file.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_file/output.json (renamed from test/cmdlineTests/standard_wrong_type_output_selection_file.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_output/exit (renamed from test/cmdlineTests/standard_wrong_type_output_selection_output.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_output/input.json (renamed from test/cmdlineTests/standard_wrong_type_output_selection_output.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_output_selection_output/output.json (renamed from test/cmdlineTests/standard_wrong_type_output_selection_output.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_remappings/exit (renamed from test/cmdlineTests/standard_wrong_type_remappings.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_remappings/input.json (renamed from test/cmdlineTests/standard_wrong_type_remappings.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_remappings/output.json (renamed from test/cmdlineTests/standard_wrong_type_remappings.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_remappings_entry/exit (renamed from test/cmdlineTests/standard_wrong_type_remappings_entry.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_remappings_entry/input.json (renamed from test/cmdlineTests/standard_wrong_type_remappings_entry.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_remappings_entry/output.json (renamed from test/cmdlineTests/standard_wrong_type_remappings_entry.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_root/exit (renamed from test/cmdlineTests/standard_wrong_type_root.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_root/input.json (renamed from test/cmdlineTests/standard_wrong_type_root.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_root/output.json (renamed from test/cmdlineTests/standard_wrong_type_root.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_settings/exit (renamed from test/cmdlineTests/standard_wrong_type_settings.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_settings/input.json (renamed from test/cmdlineTests/standard_wrong_type_settings.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_settings/output.json (renamed from test/cmdlineTests/standard_wrong_type_settings.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_source/exit (renamed from test/cmdlineTests/standard_wrong_type_source.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_source/input.json (renamed from test/cmdlineTests/standard_wrong_type_source.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_source/output.json (renamed from test/cmdlineTests/standard_wrong_type_source.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_sources/exit (renamed from test/cmdlineTests/standard_wrong_type_sources.json.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_sources/input.json (renamed from test/cmdlineTests/standard_wrong_type_sources.json) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/standard_wrong_type_sources/output.json (renamed from test/cmdlineTests/standard_wrong_type_sources.json.stdout) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line/err (renamed from test/cmdlineTests/too_long_line.sol.err) | 4 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line/exit (renamed from test/cmdlineTests/too_long_line.sol.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line/input.sol (renamed from test/cmdlineTests/too_long_line.sol) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_both_sides_short/err (renamed from test/cmdlineTests/too_long_line_both_sides_short.sol.err) | 4 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_both_sides_short/exit (renamed from test/cmdlineTests/too_long_line_both_sides_short.sol.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_both_sides_short/input.sol (renamed from test/cmdlineTests/too_long_line_both_sides_short.sol) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_edge_in/err (renamed from test/cmdlineTests/too_long_line_edge_in.sol.err) | 4 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_edge_in/exit (renamed from test/cmdlineTests/too_long_line_edge_in.sol.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_edge_in/input.sol (renamed from test/cmdlineTests/too_long_line_edge_in.sol) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_edge_out/err (renamed from test/cmdlineTests/too_long_line_edge_out.sol.err) | 4 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_edge_out/exit (renamed from test/cmdlineTests/too_long_line_edge_out.sol.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_edge_out/input.sol (renamed from test/cmdlineTests/too_long_line_edge_out.sol) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_left_short.sol.err | 6 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_left_short/err | 6 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_left_short/exit (renamed from test/cmdlineTests/too_long_line_left_short.sol.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_left_short/input.sol (renamed from test/cmdlineTests/too_long_line_left_short.sol) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_right_short/err (renamed from test/cmdlineTests/too_long_line_right_short.sol.err) | 4 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_right_short/exit (renamed from test/cmdlineTests/too_long_line_right_short.sol.exit) | 0 | ||||
-rw-r--r-- | test/cmdlineTests/too_long_line_right_short/input.sol (renamed from test/cmdlineTests/too_long_line_right_short.sol) | 0 | ||||
-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 |
130 files changed, 238 insertions, 161 deletions
diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp index 69bceefc..6d30f5f7 100644 --- a/libsolidity/interface/AssemblyStack.cpp +++ b/libsolidity/interface/AssemblyStack.cpp @@ -134,7 +134,7 @@ void AssemblyStack::optimize(yul::Object& _object) for (auto& subNode: _object.subObjects) if (auto subObject = dynamic_cast<yul::Object*>(subNode.get())) optimize(*subObject); - yul::OptimiserSuite::run(*_object.code, *_object.analysisInfo); + yul::OptimiserSuite::run(*languageToDialect(m_language), *_object.code, *_object.analysisInfo); } MachineAssemblyObject AssemblyStack::assemble(Machine _machine, bool _optimize) const diff --git a/libyul/optimiser/CommonSubexpressionEliminator.h b/libyul/optimiser/CommonSubexpressionEliminator.h index ac1ebe3a..4b7973e2 100644 --- a/libyul/optimiser/CommonSubexpressionEliminator.h +++ b/libyul/optimiser/CommonSubexpressionEliminator.h @@ -34,6 +34,9 @@ namespace yul */ class CommonSubexpressionEliminator: public DataFlowAnalyzer { +public: + CommonSubexpressionEliminator(Dialect const& _dialect): DataFlowAnalyzer(_dialect) {} + protected: using ASTModifier::visit; void visit(Expression& _e) override; diff --git a/libyul/optimiser/DataFlowAnalyzer.cpp b/libyul/optimiser/DataFlowAnalyzer.cpp index c8d236dc..e97bcdc4 100644 --- a/libyul/optimiser/DataFlowAnalyzer.cpp +++ b/libyul/optimiser/DataFlowAnalyzer.cpp @@ -142,7 +142,7 @@ void DataFlowAnalyzer::handleAssignment(set<YulString> const& _variables, Expres static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}}; clearValues(_variables); - MovableChecker movableChecker; + MovableChecker movableChecker{m_dialect}; if (_value) movableChecker.visit(*_value); else diff --git a/libyul/optimiser/DataFlowAnalyzer.h b/libyul/optimiser/DataFlowAnalyzer.h index 4f12ff6a..5fb5db95 100644 --- a/libyul/optimiser/DataFlowAnalyzer.h +++ b/libyul/optimiser/DataFlowAnalyzer.h @@ -30,6 +30,7 @@ namespace yul { +struct Dialect; /** * Base class to perform data flow analysis during AST walks. @@ -43,6 +44,8 @@ namespace yul class DataFlowAnalyzer: public ASTModifier { public: + explicit DataFlowAnalyzer(Dialect const& _dialect): m_dialect(_dialect) {} + using ASTModifier::operator(); void operator()(Assignment& _assignment) override; void operator()(VariableDeclaration& _varDecl) override; @@ -84,6 +87,7 @@ protected: }; /// List of scopes. std::vector<Scope> m_variableScopes; + Dialect const& m_dialect; }; } diff --git a/libyul/optimiser/Disambiguator.cpp b/libyul/optimiser/Disambiguator.cpp index fda5895b..cb56ee99 100644 --- a/libyul/optimiser/Disambiguator.cpp +++ b/libyul/optimiser/Disambiguator.cpp @@ -23,6 +23,7 @@ #include <libyul/Exceptions.h> #include <libyul/AsmData.h> #include <libyul/AsmScope.h> +#include <libyul/Dialect.h> using namespace std; using namespace dev; @@ -31,7 +32,7 @@ using namespace dev::solidity; YulString Disambiguator::translateIdentifier(YulString _originalName) { - if ((m_externallyUsedIdentifiers.count(_originalName))) + if (m_dialect.builtin(_originalName) || m_externallyUsedIdentifiers.count(_originalName)) return _originalName; assertThrow(!m_scopes.empty() && m_scopes.back(), OptimizerException, ""); diff --git a/libyul/optimiser/Disambiguator.h b/libyul/optimiser/Disambiguator.h index bb83417b..ec6a0879 100644 --- a/libyul/optimiser/Disambiguator.h +++ b/libyul/optimiser/Disambiguator.h @@ -32,6 +32,7 @@ namespace yul { +struct Dialect; /** * Creates a copy of a Yul AST replacing all identifiers by unique names. @@ -40,10 +41,14 @@ class Disambiguator: public ASTCopier { public: explicit Disambiguator( + Dialect const& _dialect, AsmAnalysisInfo const& _analysisInfo, std::set<YulString> const& _externallyUsedIdentifiers = {} ): - m_info(_analysisInfo), m_externallyUsedIdentifiers(_externallyUsedIdentifiers), m_nameDispenser(m_externallyUsedIdentifiers) + m_info(_analysisInfo), + m_dialect(_dialect), + m_externallyUsedIdentifiers(_externallyUsedIdentifiers), + m_nameDispenser(_dialect, m_externallyUsedIdentifiers) { } @@ -58,6 +63,7 @@ protected: void leaveScopeInternal(Scope& _scope); AsmAnalysisInfo const& m_info; + Dialect const& m_dialect; std::set<YulString> const& m_externallyUsedIdentifiers; std::vector<Scope*> m_scopes; diff --git a/libyul/optimiser/ExpressionInliner.cpp b/libyul/optimiser/ExpressionInliner.cpp index 27d43ac0..858c8733 100644 --- a/libyul/optimiser/ExpressionInliner.cpp +++ b/libyul/optimiser/ExpressionInliner.cpp @@ -56,7 +56,7 @@ void ExpressionInliner::visit(Expression& _expression) bool movable = boost::algorithm::all_of( funCall.arguments, - [=](Expression const& _arg) { return MovableChecker(_arg).movable(); } + [=](Expression const& _arg) { return MovableChecker(m_dialect, _arg).movable(); } ); if (m_inlinableFunctions.count(funCall.functionName.name) && movable) { diff --git a/libyul/optimiser/ExpressionInliner.h b/libyul/optimiser/ExpressionInliner.h index 14e80c0a..e6e710f8 100644 --- a/libyul/optimiser/ExpressionInliner.h +++ b/libyul/optimiser/ExpressionInliner.h @@ -29,6 +29,7 @@ namespace yul { +struct Dialect; /** * Optimiser component that modifies an AST in place, inlining functions that can be @@ -44,8 +45,8 @@ namespace yul class ExpressionInliner: public ASTModifier { public: - ExpressionInliner(Block& _block): - m_block(_block) + ExpressionInliner(Dialect const& _dialect, Block& _block): + m_block(_block), m_dialect(_dialect) {} void run(); @@ -62,6 +63,7 @@ private: std::set<YulString> m_currentFunctions; Block& m_block; + Dialect const& m_dialect; }; diff --git a/libyul/optimiser/ExpressionSimplifier.cpp b/libyul/optimiser/ExpressionSimplifier.cpp index cda44e8e..b26e4245 100644 --- a/libyul/optimiser/ExpressionSimplifier.cpp +++ b/libyul/optimiser/ExpressionSimplifier.cpp @@ -36,7 +36,7 @@ using namespace dev::solidity; void ExpressionSimplifier::visit(Expression& _expression) { ASTModifier::visit(_expression); - while (auto match = SimplificationRules::findFirstMatch(_expression, m_ssaValues)) + while (auto match = SimplificationRules::findFirstMatch(_expression, m_dialect, m_ssaValues)) { // Do not apply the rule if it removes non-constant parts of the expression. // TODO: The check could actually be less strict than "movable". @@ -45,15 +45,15 @@ void ExpressionSimplifier::visit(Expression& _expression) // so if the value of the variable is not movable, the expression that references // the variable still is. - if (match->removesNonConstants && !MovableChecker(_expression).movable()) + if (match->removesNonConstants && !MovableChecker(m_dialect, _expression).movable()) return; _expression = match->action().toExpression(locationOf(_expression)); } } -void ExpressionSimplifier::run(Block& _ast) +void ExpressionSimplifier::run(Dialect const& _dialect, Block& _ast) { SSAValueTracker ssaValues; ssaValues(_ast); - ExpressionSimplifier{ssaValues.values()}(_ast); + ExpressionSimplifier{_dialect, ssaValues.values()}(_ast); } diff --git a/libyul/optimiser/ExpressionSimplifier.h b/libyul/optimiser/ExpressionSimplifier.h index fe3507f8..b1122e91 100644 --- a/libyul/optimiser/ExpressionSimplifier.h +++ b/libyul/optimiser/ExpressionSimplifier.h @@ -26,6 +26,7 @@ namespace yul { +struct Dialect; /** * Applies simplification rules to all expressions. @@ -40,12 +41,13 @@ public: using ASTModifier::operator(); virtual void visit(Expression& _expression); - static void run(Block& _ast); + static void run(Dialect const& _dialect, Block& _ast); private: - explicit ExpressionSimplifier(std::map<YulString, Expression const*> _ssaValues): - m_ssaValues(std::move(_ssaValues)) + explicit ExpressionSimplifier(Dialect const& _dialect, std::map<YulString, Expression const*> _ssaValues): + m_dialect(_dialect), m_ssaValues(std::move(_ssaValues)) {} + Dialect const& m_dialect; std::map<YulString, Expression const*> m_ssaValues; }; diff --git a/libyul/optimiser/NameDispenser.cpp b/libyul/optimiser/NameDispenser.cpp index e7cdc60f..172e6907 100644 --- a/libyul/optimiser/NameDispenser.cpp +++ b/libyul/optimiser/NameDispenser.cpp @@ -22,17 +22,19 @@ #include <libyul/optimiser/NameCollector.h> #include <libyul/AsmData.h> +#include <libyul/Dialect.h> using namespace std; using namespace dev; using namespace yul; -NameDispenser::NameDispenser(Block const& _ast): - NameDispenser(NameCollector(_ast).names()) +NameDispenser::NameDispenser(Dialect const& _dialect, Block const& _ast): + NameDispenser(_dialect, NameCollector(_ast).names()) { } -NameDispenser::NameDispenser(set<YulString> _usedNames): +NameDispenser::NameDispenser(Dialect const& _dialect, set<YulString> _usedNames): + m_dialect(_dialect), m_usedNames(std::move(_usedNames)) { } @@ -51,7 +53,7 @@ YulString NameDispenser::newName(YulString _nameHint, YulString _context) YulString NameDispenser::newNameInternal(YulString _nameHint) { YulString name = _nameHint; - while (name.empty() || m_usedNames.count(name)) + while (name.empty() || m_usedNames.count(name) || m_dialect.builtin(name)) { m_counter++; name = YulString(_nameHint.str() + "_" + to_string(m_counter)); diff --git a/libyul/optimiser/NameDispenser.h b/libyul/optimiser/NameDispenser.h index 664a5265..719743e6 100644 --- a/libyul/optimiser/NameDispenser.h +++ b/libyul/optimiser/NameDispenser.h @@ -27,6 +27,7 @@ namespace yul { +struct Dialect; /** * Optimizer component that can be used to generate new names that @@ -38,9 +39,9 @@ class NameDispenser { public: /// Initialize the name dispenser with all the names used in the given AST. - explicit NameDispenser(Block const& _ast); + explicit NameDispenser(Dialect const& _dialect, Block const& _ast); /// Initialize the name dispenser with the given used names. - explicit NameDispenser(std::set<YulString> _usedNames); + explicit NameDispenser(Dialect const& _dialect, std::set<YulString> _usedNames); /// @returns a currently unused name that should be similar to _nameHint /// and prefixed by _context if present. @@ -51,6 +52,7 @@ public: private: YulString newNameInternal(YulString _nameHint); + Dialect const& m_dialect; std::set<YulString> m_usedNames; size_t m_counter = 0; }; diff --git a/libyul/optimiser/RedundantAssignEliminator.cpp b/libyul/optimiser/RedundantAssignEliminator.cpp index 7b18e8ca..f6d7676f 100644 --- a/libyul/optimiser/RedundantAssignEliminator.cpp +++ b/libyul/optimiser/RedundantAssignEliminator.cpp @@ -150,9 +150,9 @@ void RedundantAssignEliminator::operator()(Block const& _block) ASTWalker::operator()(_block); } -void RedundantAssignEliminator::run(Block& _ast) +void RedundantAssignEliminator::run(Dialect const& _dialect, Block& _ast) { - RedundantAssignEliminator rae; + RedundantAssignEliminator rae{_dialect}; rae(_ast); AssignmentRemover remover{rae.m_assignmentsToRemove}; @@ -211,7 +211,7 @@ void RedundantAssignEliminator::finalize(YulString _variable) for (auto& assignment: m_assignments[_variable]) { assertThrow(assignment.second != State::Undecided, OptimizerException, ""); - if (assignment.second == State{State::Unused} && MovableChecker{*assignment.first->value}.movable()) + if (assignment.second == State{State::Unused} && MovableChecker{*m_dialect, *assignment.first->value}.movable()) // TODO the only point where we actually need this // to be a set is for the for loop m_assignmentsToRemove.insert(assignment.first); diff --git a/libyul/optimiser/RedundantAssignEliminator.h b/libyul/optimiser/RedundantAssignEliminator.h index 4f82e7a2..2f4dd380 100644 --- a/libyul/optimiser/RedundantAssignEliminator.h +++ b/libyul/optimiser/RedundantAssignEliminator.h @@ -28,6 +28,7 @@ namespace yul { +struct Dialect; /** * Optimiser component that removes assignments to variables that are not used @@ -98,6 +99,7 @@ namespace yul class RedundantAssignEliminator: public ASTWalker { public: + explicit RedundantAssignEliminator(Dialect const& _dialect): m_dialect(&_dialect) {} RedundantAssignEliminator(RedundantAssignEliminator const&) = default; RedundantAssignEliminator& operator=(RedundantAssignEliminator const&) = default; RedundantAssignEliminator(RedundantAssignEliminator&&) = default; @@ -112,7 +114,7 @@ public: void operator()(ForLoop const&) override; void operator()(Block const& _block) override; - static void run(Block& _ast); + static void run(Dialect const& _dialect, Block& _ast); private: RedundantAssignEliminator() = default; @@ -167,6 +169,7 @@ private: void changeUndecidedTo(YulString _variable, State _newState); void finalize(YulString _variable); + Dialect const* m_dialect; std::set<YulString> m_declaredVariables; // TODO check that this does not cause nondeterminism! // This could also be a pseudo-map from state to assignment. diff --git a/libyul/optimiser/Rematerialiser.cpp b/libyul/optimiser/Rematerialiser.cpp index 247defda..56f6e99c 100644 --- a/libyul/optimiser/Rematerialiser.cpp +++ b/libyul/optimiser/Rematerialiser.cpp @@ -30,12 +30,13 @@ using namespace std; using namespace dev; using namespace yul; -void Rematerialiser::run(Block& _ast) +void Rematerialiser::run(Dialect const& _dialect, Block& _ast) { - Rematerialiser{_ast}(_ast); + Rematerialiser{_dialect, _ast}(_ast); } -Rematerialiser::Rematerialiser(Block& _ast): +Rematerialiser::Rematerialiser(Dialect const& _dialect, Block& _ast): + DataFlowAnalyzer(_dialect), m_referenceCounts(ReferencesCounter::countReferences(_ast)) { } diff --git a/libyul/optimiser/Rematerialiser.h b/libyul/optimiser/Rematerialiser.h index c34353de..731697c8 100644 --- a/libyul/optimiser/Rematerialiser.h +++ b/libyul/optimiser/Rematerialiser.h @@ -38,10 +38,10 @@ namespace yul class Rematerialiser: public DataFlowAnalyzer { public: - static void run(Block& _ast); + static void run(Dialect const& _dialect, Block& _ast); protected: - Rematerialiser(Block& _ast); + Rematerialiser(Dialect const& _dialect, Block& _ast); using ASTModifier::visit; void visit(Expression& _e) override; diff --git a/libyul/optimiser/Semantics.cpp b/libyul/optimiser/Semantics.cpp index 91bb2709..7edf97d7 100644 --- a/libyul/optimiser/Semantics.cpp +++ b/libyul/optimiser/Semantics.cpp @@ -22,6 +22,7 @@ #include <libyul/Exceptions.h> #include <libyul/AsmData.h> +#include <libyul/Dialect.h> #include <libevmasm/SemanticInformation.h> @@ -31,7 +32,13 @@ using namespace std; using namespace dev; using namespace yul; -MovableChecker::MovableChecker(Expression const& _expression) +MovableChecker::MovableChecker(Dialect const& _dialect): + m_dialect(_dialect) +{ +} + +MovableChecker::MovableChecker(Dialect const& _dialect, Expression const& _expression): + MovableChecker(_dialect) { visit(_expression); } @@ -50,8 +57,14 @@ void MovableChecker::operator()(FunctionalInstruction const& _instr) ASTWalker::operator()(_instr); } -void MovableChecker::operator()(FunctionCall const&) +void MovableChecker::operator()(FunctionCall const& _functionCall) { + if (BuiltinFunction const* f = m_dialect.builtin(_functionCall.functionName.name)) + if (f->movable) + { + ASTWalker::operator()(_functionCall); + return; + } m_movable = false; } diff --git a/libyul/optimiser/Semantics.h b/libyul/optimiser/Semantics.h index 70c50806..a81a489f 100644 --- a/libyul/optimiser/Semantics.h +++ b/libyul/optimiser/Semantics.h @@ -26,6 +26,7 @@ namespace yul { +struct Dialect; /** * Specific AST walker that determines whether an expression is movable. @@ -33,8 +34,8 @@ namespace yul class MovableChecker: public ASTWalker { public: - MovableChecker() = default; - explicit MovableChecker(Expression const& _expression); + explicit MovableChecker(Dialect const& _dialect); + MovableChecker(Dialect const& _dialect, Expression const& _expression); void operator()(Identifier const& _identifier) override; void operator()(FunctionalInstruction const& _functionalInstruction) override; @@ -48,6 +49,7 @@ public: std::set<YulString> const& referencedVariables() const { return m_variableReferences; } private: + Dialect const& m_dialect; /// Which variables the current expression references. std::set<YulString> m_variableReferences; /// Is the current expression movable or not. diff --git a/libyul/optimiser/SimplificationRules.cpp b/libyul/optimiser/SimplificationRules.cpp index 45b0ca2c..da9c7d9d 100644 --- a/libyul/optimiser/SimplificationRules.cpp +++ b/libyul/optimiser/SimplificationRules.cpp @@ -36,6 +36,7 @@ using namespace yul; SimplificationRule<Pattern> const* SimplificationRules::findFirstMatch( Expression const& _expr, + Dialect const& _dialect, map<YulString, Expression const*> const& _ssaValues ) { @@ -49,7 +50,7 @@ SimplificationRule<Pattern> const* SimplificationRules::findFirstMatch( for (auto const& rule: rules.m_rules[uint8_t(instruction.instruction)]) { rules.resetMatchGroups(); - if (rule.pattern.matches(_expr, _ssaValues)) + if (rule.pattern.matches(_expr, _dialect, _ssaValues)) return &rule; } return nullptr; @@ -104,7 +105,11 @@ void Pattern::setMatchGroup(unsigned _group, map<unsigned, Expression const*>& _ m_matchGroups = &_matchGroups; } -bool Pattern::matches(Expression const& _expr, map<YulString, Expression const*> const& _ssaValues) const +bool Pattern::matches( + Expression const& _expr, + Dialect const& _dialect, + map<YulString, Expression const*> const& _ssaValues +) const { Expression const* expr = &_expr; @@ -139,7 +144,7 @@ bool Pattern::matches(Expression const& _expr, map<YulString, Expression const*> return false; assertThrow(m_arguments.size() == instr.arguments.size(), OptimizerException, ""); for (size_t i = 0; i < m_arguments.size(); ++i) - if (!m_arguments[i].matches(instr.arguments.at(i), _ssaValues)) + if (!m_arguments[i].matches(instr.arguments.at(i), _dialect, _ssaValues)) return false; } else @@ -167,7 +172,7 @@ bool Pattern::matches(Expression const& _expr, map<YulString, Expression const*> assertThrow(firstMatch, OptimizerException, "Match set but to null."); return SyntacticalEqualityChecker::equal(*firstMatch, _expr) && - MovableChecker(_expr).movable(); + MovableChecker(_dialect, _expr).movable(); } else if (m_kind == PatternKind::Any) (*m_matchGroups)[m_matchGroup] = &_expr; diff --git a/libyul/optimiser/SimplificationRules.h b/libyul/optimiser/SimplificationRules.h index 16aaba04..8213a185 100644 --- a/libyul/optimiser/SimplificationRules.h +++ b/libyul/optimiser/SimplificationRules.h @@ -33,7 +33,7 @@ namespace yul { - +struct Dialect; class Pattern; /** @@ -49,6 +49,7 @@ public: /// @param _ssaValues values of variables that are assigned exactly once. static SimplificationRule<Pattern> const* findFirstMatch( Expression const& _expr, + Dialect const& _dialect, std::map<YulString, Expression const*> const& _ssaValues ); @@ -93,7 +94,11 @@ public: /// same expression equivalence class. void setMatchGroup(unsigned _group, std::map<unsigned, Expression const*>& _matchGroups); unsigned matchGroup() const { return m_matchGroup; } - bool matches(Expression const& _expr, std::map<YulString, Expression const*> const& _ssaValues) const; + bool matches( + Expression const& _expr, + Dialect const& _dialect, + std::map<YulString, Expression const*> const& _ssaValues + ) const; std::vector<Pattern> arguments() const { return m_arguments; } diff --git a/libyul/optimiser/StructuralSimplifier.h b/libyul/optimiser/StructuralSimplifier.h index bbd8e005..d68a9620 100644 --- a/libyul/optimiser/StructuralSimplifier.h +++ b/libyul/optimiser/StructuralSimplifier.h @@ -38,6 +38,8 @@ namespace yul class StructuralSimplifier: public DataFlowAnalyzer { public: + explicit StructuralSimplifier(Dialect const& _dialect): DataFlowAnalyzer(_dialect) {} + using DataFlowAnalyzer::operator(); void operator()(Block& _block) override; private: diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index c0fd15a2..9b6e1337 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -47,6 +47,7 @@ using namespace dev; using namespace yul; void OptimiserSuite::run( + Dialect const& _dialect, Block& _ast, AsmAnalysisInfo const& _analysisInfo, set<YulString> const& _externallyUsedIdentifiers @@ -54,69 +55,69 @@ void OptimiserSuite::run( { set<YulString> reservedIdentifiers = _externallyUsedIdentifiers; - Block ast = boost::get<Block>(Disambiguator(_analysisInfo, reservedIdentifiers)(_ast)); + Block ast = boost::get<Block>(Disambiguator(_dialect, _analysisInfo, reservedIdentifiers)(_ast)); (VarDeclInitializer{})(ast); (FunctionHoister{})(ast); (FunctionGrouper{})(ast); (ForLoopInitRewriter{})(ast); - StructuralSimplifier{}(ast); + StructuralSimplifier{_dialect}(ast); - NameDispenser dispenser{ast}; + NameDispenser dispenser{_dialect, ast}; for (size_t i = 0; i < 4; i++) { ExpressionSplitter{dispenser}(ast); SSATransform::run(ast, dispenser); - RedundantAssignEliminator::run(ast); - RedundantAssignEliminator::run(ast); + RedundantAssignEliminator::run(_dialect, ast); + RedundantAssignEliminator::run(_dialect, ast); - CommonSubexpressionEliminator{}(ast); - ExpressionSimplifier::run(ast); - StructuralSimplifier{}(ast); + CommonSubexpressionEliminator{_dialect}(ast); + ExpressionSimplifier::run(_dialect, ast); + StructuralSimplifier{_dialect}(ast); SSATransform::run(ast, dispenser); - RedundantAssignEliminator::run(ast); - RedundantAssignEliminator::run(ast); - UnusedPruner::runUntilStabilised(ast, reservedIdentifiers); - CommonSubexpressionEliminator{}(ast); - UnusedPruner::runUntilStabilised(ast, reservedIdentifiers); + RedundantAssignEliminator::run(_dialect, ast); + RedundantAssignEliminator::run(_dialect, ast); + UnusedPruner::runUntilStabilised(_dialect, ast, reservedIdentifiers); + CommonSubexpressionEliminator{_dialect}(ast); + UnusedPruner::runUntilStabilised(_dialect, ast, reservedIdentifiers); SSATransform::run(ast, dispenser); - RedundantAssignEliminator::run(ast); - RedundantAssignEliminator::run(ast); + RedundantAssignEliminator::run(_dialect, ast); + RedundantAssignEliminator::run(_dialect, ast); ExpressionJoiner::run(ast); ExpressionJoiner::run(ast); - ExpressionInliner(ast).run(); - UnusedPruner::runUntilStabilised(ast); + ExpressionInliner(_dialect, ast).run(); + UnusedPruner::runUntilStabilised(_dialect, ast); ExpressionSplitter{dispenser}(ast); SSATransform::run(ast, dispenser); - RedundantAssignEliminator::run(ast); - RedundantAssignEliminator::run(ast); - CommonSubexpressionEliminator{}(ast); + RedundantAssignEliminator::run(_dialect, ast); + RedundantAssignEliminator::run(_dialect, ast); + CommonSubexpressionEliminator{_dialect}(ast); FullInliner{ast, dispenser}.run(); SSATransform::run(ast, dispenser); - RedundantAssignEliminator::run(ast); - RedundantAssignEliminator::run(ast); - ExpressionSimplifier::run(ast); - StructuralSimplifier{}(ast); - CommonSubexpressionEliminator{}(ast); + RedundantAssignEliminator::run(_dialect, ast); + RedundantAssignEliminator::run(_dialect, ast); + ExpressionSimplifier::run(_dialect, ast); + StructuralSimplifier{_dialect}(ast); + CommonSubexpressionEliminator{_dialect}(ast); SSATransform::run(ast, dispenser); - RedundantAssignEliminator::run(ast); - RedundantAssignEliminator::run(ast); - UnusedPruner::runUntilStabilised(ast, reservedIdentifiers); - CommonSubexpressionEliminator{}(ast); + RedundantAssignEliminator::run(_dialect, ast); + RedundantAssignEliminator::run(_dialect, ast); + UnusedPruner::runUntilStabilised(_dialect, ast, reservedIdentifiers); + CommonSubexpressionEliminator{_dialect}(ast); } ExpressionJoiner::run(ast); - Rematerialiser::run(ast); - UnusedPruner::runUntilStabilised(ast); + Rematerialiser::run(_dialect, ast); + UnusedPruner::runUntilStabilised(_dialect, ast); ExpressionJoiner::run(ast); - UnusedPruner::runUntilStabilised(ast); + UnusedPruner::runUntilStabilised(_dialect, ast); ExpressionJoiner::run(ast); - UnusedPruner::runUntilStabilised(ast); + UnusedPruner::runUntilStabilised(_dialect, ast); ExpressionJoiner::run(ast); - Rematerialiser::run(ast); - UnusedPruner::runUntilStabilised(ast); + Rematerialiser::run(_dialect, ast); + UnusedPruner::runUntilStabilised(_dialect, ast); _ast = std::move(ast); } diff --git a/libyul/optimiser/Suite.h b/libyul/optimiser/Suite.h index 795326b4..ce40b204 100644 --- a/libyul/optimiser/Suite.h +++ b/libyul/optimiser/Suite.h @@ -29,6 +29,7 @@ namespace yul { struct AsmAnalysisInfo; +struct Dialect; /** * Optimiser suite that combines all steps and also provides the settings for the heuristics @@ -37,6 +38,7 @@ class OptimiserSuite { public: static void run( + Dialect const& _dialect, Block& _ast, AsmAnalysisInfo const& _analysisInfo, diff --git a/libyul/optimiser/UnusedPruner.cpp b/libyul/optimiser/UnusedPruner.cpp index 31aead82..53c412e3 100644 --- a/libyul/optimiser/UnusedPruner.cpp +++ b/libyul/optimiser/UnusedPruner.cpp @@ -32,7 +32,8 @@ using namespace std; using namespace dev; using namespace yul; -UnusedPruner::UnusedPruner(Block& _ast, set<YulString> const& _externallyUsedFunctions) +UnusedPruner::UnusedPruner(Dialect const& _dialect, Block& _ast, set<YulString> const& _externallyUsedFunctions): + m_dialect(_dialect) { ReferencesCounter counter; counter(_ast); @@ -69,7 +70,7 @@ void UnusedPruner::operator()(Block& _block) { if (!varDecl.value) statement = Block{std::move(varDecl.location), {}}; - else if (MovableChecker(*varDecl.value).movable()) + else if (MovableChecker(m_dialect, *varDecl.value).movable()) { subtractReferences(ReferencesCounter::countReferences(*varDecl.value)); statement = Block{std::move(varDecl.location), {}}; @@ -87,7 +88,7 @@ void UnusedPruner::operator()(Block& _block) else if (statement.type() == typeid(ExpressionStatement)) { ExpressionStatement& exprStmt = boost::get<ExpressionStatement>(statement); - if (MovableChecker(exprStmt.expression).movable()) + if (MovableChecker(m_dialect, exprStmt.expression).movable()) { // pop(x) should be movable! subtractReferences(ReferencesCounter::countReferences(exprStmt.expression)); @@ -100,11 +101,15 @@ void UnusedPruner::operator()(Block& _block) ASTModifier::operator()(_block); } -void UnusedPruner::runUntilStabilised(Block& _ast, set<YulString> const& _externallyUsedFunctions) +void UnusedPruner::runUntilStabilised( + Dialect const& _dialect, + Block& _ast, + set<YulString> const& _externallyUsedFunctions +) { while (true) { - UnusedPruner pruner(_ast, _externallyUsedFunctions); + UnusedPruner pruner(_dialect, _ast, _externallyUsedFunctions); pruner(_ast); if (!pruner.shouldRunAgain()) return; diff --git a/libyul/optimiser/UnusedPruner.h b/libyul/optimiser/UnusedPruner.h index 64e02b35..72279d4a 100644 --- a/libyul/optimiser/UnusedPruner.h +++ b/libyul/optimiser/UnusedPruner.h @@ -28,6 +28,7 @@ namespace yul { +struct Dialect; /** * Optimisation stage that removes unused variables and functions and also @@ -40,7 +41,11 @@ namespace yul class UnusedPruner: public ASTModifier { public: - explicit UnusedPruner(Block& _ast, std::set<YulString> const& _externallyUsedFunctions = {}); + UnusedPruner( + Dialect const& _dialect, + Block& _ast, + std::set<YulString> const& _externallyUsedFunctions = {} + ); using ASTModifier::operator(); void operator()(Block& _block) override; @@ -49,12 +54,17 @@ public: bool shouldRunAgain() const { return m_shouldRunAgain; } // Run the pruner until the code does not change anymore. - static void runUntilStabilised(Block& _ast, std::set<YulString> const& _externallyUsedFunctions = {}); + static void runUntilStabilised( + Dialect const& _dialect, + Block& _ast, + std::set<YulString> const& _externallyUsedFunctions = {} + ); private: bool used(YulString _name) const; void subtractReferences(std::map<YulString, size_t> const& _subtrahend); + Dialect const& m_dialect; bool m_shouldRunAgain = false; std::map<YulString, size_t> m_references; }; diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index 3beee552..1ef1b320 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -215,32 +215,27 @@ printTask "Testing passing empty remappings..." test_solc_behaviour "${0}" "=/some/remapping/target" "" "" 1 "Invalid remapping: \"=/some/remapping/target\"." test_solc_behaviour "${0}" "ctx:=/some/remapping/target" "" "" 1 "Invalid remapping: \"ctx:=/some/remapping/target\"." -printTask "Running standard JSON commandline tests..." -( - cd "$REPO_ROOT"/test/cmdlineTests/ - for file in *.json - do - args="--standard-json" - stdin="$REPO_ROOT/test/cmdlineTests/$file" - stdout=$(cat $file.stdout 2>/dev/null || true) - exitCode=$(cat $file.exit 2>/dev/null || true) - err=$(cat $file.err 2>/dev/null || true) - printTask " - $file" - test_solc_behaviour "" "$args" "$stdin" "$stdout" "$exitCode" "$err" - done -) - printTask "Running general commandline tests..." ( cd "$REPO_ROOT"/test/cmdlineTests/ - for file in *.sol + for tdir in */ do - args=$(cat $file.args 2>/dev/null || true) - stdout=$(cat $file.stdout 2>/dev/null || true) - exitCode=$(cat $file.exit 2>/dev/null || true) - err=$(cat $file.err 2>/dev/null || true) - printTask " - $file" - test_solc_behaviour "$file" "$args" "" "$stdout" "$exitCode" "$err" + if [ -e "${tdir}/input.json" ] + then + inputFile="" + stdin="${tdir}/input.json" + stdout=$(cat ${tdir}/output.json 2>/dev/null || true) + args="--standard-json "$(cat ${tdir}/args 2>/dev/null || true) + else + inputFile="${tdir}input.sol" + stdin="" + stdout=$(cat ${tdir}/output 2>/dev/null || true) + args=$(cat ${tdir}/args 2>/dev/null || true) + fi + exitCode=$(cat ${tdir}/exit 2>/dev/null || true) + err=$(cat ${tdir}/err 2>/dev/null || true) + printTask " - ${tdir}" + test_solc_behaviour "$inputFile" "$args" "$stdin" "$stdout" "$exitCode" "$err" done ) diff --git a/test/cmdlineTests/data_storage.sol.args b/test/cmdlineTests/data_storage/args index 3684987e..3684987e 100644 --- a/test/cmdlineTests/data_storage.sol.args +++ b/test/cmdlineTests/data_storage/args diff --git a/test/cmdlineTests/data_storage.sol b/test/cmdlineTests/data_storage/input.sol index cc602cc9..cc602cc9 100644 --- a/test/cmdlineTests/data_storage.sol +++ b/test/cmdlineTests/data_storage/input.sol diff --git a/test/cmdlineTests/data_storage.sol.stdout b/test/cmdlineTests/data_storage/output index 4a5250f7..e0dae4bd 100644 --- a/test/cmdlineTests/data_storage.sol.stdout +++ b/test/cmdlineTests/data_storage/output @@ -1,5 +1,5 @@ -======= data_storage.sol:C ======= +======= data_storage/input.sol:C ======= Gas estimation: construction: 306 + 264400 = 264706 diff --git a/test/cmdlineTests/gas_test_dispatch.sol.args b/test/cmdlineTests/gas_test_dispatch/args index 3684987e..3684987e 100644 --- a/test/cmdlineTests/gas_test_dispatch.sol.args +++ b/test/cmdlineTests/gas_test_dispatch/args diff --git a/test/cmdlineTests/gas_test_dispatch.sol b/test/cmdlineTests/gas_test_dispatch/input.sol index a5ca9e7d..a5ca9e7d 100644 --- a/test/cmdlineTests/gas_test_dispatch.sol +++ b/test/cmdlineTests/gas_test_dispatch/input.sol diff --git a/test/cmdlineTests/gas_test_dispatch.sol.stdout b/test/cmdlineTests/gas_test_dispatch/output index 117affad..d817e85c 100644 --- a/test/cmdlineTests/gas_test_dispatch.sol.stdout +++ b/test/cmdlineTests/gas_test_dispatch/output @@ -1,5 +1,5 @@ -======= gas_test_dispatch.sol:Large ======= +======= gas_test_dispatch/input.sol:Large ======= Gas estimation: construction: 1034 + 998400 = 999434 @@ -27,7 +27,7 @@ external: g8(uint256): 20721 g9(uint256): 20678 -======= gas_test_dispatch.sol:Medium ======= +======= gas_test_dispatch/input.sol:Medium ======= Gas estimation: construction: 411 + 376600 = 377011 @@ -42,7 +42,7 @@ external: g8(uint256): 20699 g9(uint256): 20655 -======= gas_test_dispatch.sol:Small ======= +======= gas_test_dispatch/input.sol:Small ======= Gas estimation: construction: 153 + 107800 = 107953 diff --git a/test/cmdlineTests/gas_test_dispatch_optimize.sol.args b/test/cmdlineTests/gas_test_dispatch_optimize/args index 814e0591..814e0591 100644 --- a/test/cmdlineTests/gas_test_dispatch_optimize.sol.args +++ b/test/cmdlineTests/gas_test_dispatch_optimize/args diff --git a/test/cmdlineTests/gas_test_dispatch_optimize.sol b/test/cmdlineTests/gas_test_dispatch_optimize/input.sol index a5ca9e7d..a5ca9e7d 100644 --- a/test/cmdlineTests/gas_test_dispatch_optimize.sol +++ b/test/cmdlineTests/gas_test_dispatch_optimize/input.sol diff --git a/test/cmdlineTests/gas_test_dispatch_optimize.sol.stdout b/test/cmdlineTests/gas_test_dispatch_optimize/output index 76fa086e..fd8e9e93 100644 --- a/test/cmdlineTests/gas_test_dispatch_optimize.sol.stdout +++ b/test/cmdlineTests/gas_test_dispatch_optimize/output @@ -1,5 +1,5 @@ -======= gas_test_dispatch_optimize.sol:Large ======= +======= gas_test_dispatch_optimize/input.sol:Large ======= Gas estimation: construction: 300 + 262000 = 262300 @@ -27,7 +27,7 @@ external: g8(uint256): 20980 g9(uint256): 20826 -======= gas_test_dispatch_optimize.sol:Medium ======= +======= gas_test_dispatch_optimize/input.sol:Medium ======= Gas estimation: construction: 190 + 143000 = 143190 @@ -42,7 +42,7 @@ external: g8(uint256): 20870 g9(uint256): 20826 -======= gas_test_dispatch_optimize.sol:Small ======= +======= gas_test_dispatch_optimize/input.sol:Small ======= Gas estimation: construction: 117 + 67400 = 67517 diff --git a/test/cmdlineTests/standard_binaries_requested.json b/test/cmdlineTests/standard_binaries_requested/input.json index 65f19543..65f19543 100644 --- a/test/cmdlineTests/standard_binaries_requested.json +++ b/test/cmdlineTests/standard_binaries_requested/input.json diff --git a/test/cmdlineTests/standard_binaries_requested.json.stdout b/test/cmdlineTests/standard_binaries_requested/output.json index 2baef22a..2baef22a 100644 --- a/test/cmdlineTests/standard_binaries_requested.json.stdout +++ b/test/cmdlineTests/standard_binaries_requested/output.json diff --git a/test/cmdlineTests/standard.json.exit b/test/cmdlineTests/standard_default_success/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard.json.exit +++ b/test/cmdlineTests/standard_default_success/exit diff --git a/test/cmdlineTests/standard.json b/test/cmdlineTests/standard_default_success/input.json index 826253b8..826253b8 100644 --- a/test/cmdlineTests/standard.json +++ b/test/cmdlineTests/standard_default_success/input.json diff --git a/test/cmdlineTests/standard.json.stdout b/test/cmdlineTests/standard_default_success/output.json index 59b90c8c..59b90c8c 100644 --- a/test/cmdlineTests/standard.json.stdout +++ b/test/cmdlineTests/standard_default_success/output.json diff --git a/test/cmdlineTests/standard_methodIdentifiersRequested.json b/test/cmdlineTests/standard_method_identifiers_requested/input.json index 79a3c75d..79a3c75d 100644 --- a/test/cmdlineTests/standard_methodIdentifiersRequested.json +++ b/test/cmdlineTests/standard_method_identifiers_requested/input.json diff --git a/test/cmdlineTests/standard_methodIdentifiersRequested.json.stdout b/test/cmdlineTests/standard_method_identifiers_requested/output.json index 7e3f139f..7e3f139f 100644 --- a/test/cmdlineTests/standard_methodIdentifiersRequested.json.stdout +++ b/test/cmdlineTests/standard_method_identifiers_requested/output.json diff --git a/test/cmdlineTests/standard_only_ast_requested.json b/test/cmdlineTests/standard_only_ast_requested/input.json index 7abd6da5..7abd6da5 100644 --- a/test/cmdlineTests/standard_only_ast_requested.json +++ b/test/cmdlineTests/standard_only_ast_requested/input.json diff --git a/test/cmdlineTests/standard_only_ast_requested.json.stdout b/test/cmdlineTests/standard_only_ast_requested/output.json index b884ab7d..b884ab7d 100644 --- a/test/cmdlineTests/standard_only_ast_requested.json.stdout +++ b/test/cmdlineTests/standard_only_ast_requested/output.json diff --git a/test/cmdlineTests/standard_wrong_key_auxiliary_input.json.exit b/test/cmdlineTests/standard_wrong_key_auxiliary_input/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_key_auxiliary_input.json.exit +++ b/test/cmdlineTests/standard_wrong_key_auxiliary_input/exit diff --git a/test/cmdlineTests/standard_wrong_key_auxiliary_input.json b/test/cmdlineTests/standard_wrong_key_auxiliary_input/input.json index 51dbce41..51dbce41 100644 --- a/test/cmdlineTests/standard_wrong_key_auxiliary_input.json +++ b/test/cmdlineTests/standard_wrong_key_auxiliary_input/input.json diff --git a/test/cmdlineTests/standard_wrong_key_auxiliary_input.json.stdout b/test/cmdlineTests/standard_wrong_key_auxiliary_input/output.json index 077ac47e..077ac47e 100644 --- a/test/cmdlineTests/standard_wrong_key_auxiliary_input.json.stdout +++ b/test/cmdlineTests/standard_wrong_key_auxiliary_input/output.json diff --git a/test/cmdlineTests/standard_wrong_key_metadata.json.exit b/test/cmdlineTests/standard_wrong_key_metadata/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_key_metadata.json.exit +++ b/test/cmdlineTests/standard_wrong_key_metadata/exit diff --git a/test/cmdlineTests/standard_wrong_key_metadata.json b/test/cmdlineTests/standard_wrong_key_metadata/input.json index 490e489a..490e489a 100644 --- a/test/cmdlineTests/standard_wrong_key_metadata.json +++ b/test/cmdlineTests/standard_wrong_key_metadata/input.json diff --git a/test/cmdlineTests/standard_wrong_key_metadata.json.stdout b/test/cmdlineTests/standard_wrong_key_metadata/output.json index 077ac47e..077ac47e 100644 --- a/test/cmdlineTests/standard_wrong_key_metadata.json.stdout +++ b/test/cmdlineTests/standard_wrong_key_metadata/output.json diff --git a/test/cmdlineTests/standard_wrong_key_optimizer.json.exit b/test/cmdlineTests/standard_wrong_key_optimizer/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_key_optimizer.json.exit +++ b/test/cmdlineTests/standard_wrong_key_optimizer/exit diff --git a/test/cmdlineTests/standard_wrong_key_optimizer.json b/test/cmdlineTests/standard_wrong_key_optimizer/input.json index c28c3a92..c28c3a92 100644 --- a/test/cmdlineTests/standard_wrong_key_optimizer.json +++ b/test/cmdlineTests/standard_wrong_key_optimizer/input.json diff --git a/test/cmdlineTests/standard_wrong_key_optimizer.json.stdout b/test/cmdlineTests/standard_wrong_key_optimizer/output.json index 077ac47e..077ac47e 100644 --- a/test/cmdlineTests/standard_wrong_key_optimizer.json.stdout +++ b/test/cmdlineTests/standard_wrong_key_optimizer/output.json diff --git a/test/cmdlineTests/standard_wrong_key_root.json.exit b/test/cmdlineTests/standard_wrong_key_root/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_key_root.json.exit +++ b/test/cmdlineTests/standard_wrong_key_root/exit diff --git a/test/cmdlineTests/standard_wrong_key_root.json b/test/cmdlineTests/standard_wrong_key_root/input.json index 4689c50c..4689c50c 100644 --- a/test/cmdlineTests/standard_wrong_key_root.json +++ b/test/cmdlineTests/standard_wrong_key_root/input.json diff --git a/test/cmdlineTests/standard_wrong_key_root.json.stdout b/test/cmdlineTests/standard_wrong_key_root/output.json index 077ac47e..077ac47e 100644 --- a/test/cmdlineTests/standard_wrong_key_root.json.stdout +++ b/test/cmdlineTests/standard_wrong_key_root/output.json diff --git a/test/cmdlineTests/standard_wrong_key_settings.json.exit b/test/cmdlineTests/standard_wrong_key_settings/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_key_settings.json.exit +++ b/test/cmdlineTests/standard_wrong_key_settings/exit diff --git a/test/cmdlineTests/standard_wrong_key_settings.json b/test/cmdlineTests/standard_wrong_key_settings/input.json index d7809b1c..d7809b1c 100644 --- a/test/cmdlineTests/standard_wrong_key_settings.json +++ b/test/cmdlineTests/standard_wrong_key_settings/input.json diff --git a/test/cmdlineTests/standard_wrong_key_settings.json.stdout b/test/cmdlineTests/standard_wrong_key_settings/output.json index 077ac47e..077ac47e 100644 --- a/test/cmdlineTests/standard_wrong_key_settings.json.stdout +++ b/test/cmdlineTests/standard_wrong_key_settings/output.json diff --git a/test/cmdlineTests/standard_wrong_key_source.json.exit b/test/cmdlineTests/standard_wrong_key_source/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_key_source.json.exit +++ b/test/cmdlineTests/standard_wrong_key_source/exit diff --git a/test/cmdlineTests/standard_wrong_key_source.json b/test/cmdlineTests/standard_wrong_key_source/input.json index d8a8aa16..d8a8aa16 100644 --- a/test/cmdlineTests/standard_wrong_key_source.json +++ b/test/cmdlineTests/standard_wrong_key_source/input.json diff --git a/test/cmdlineTests/standard_wrong_key_source.json.stdout b/test/cmdlineTests/standard_wrong_key_source/output.json index 077ac47e..077ac47e 100644 --- a/test/cmdlineTests/standard_wrong_key_source.json.stdout +++ b/test/cmdlineTests/standard_wrong_key_source/output.json diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input.json.exit b/test/cmdlineTests/standard_wrong_type_auxiliary_input/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input.json.exit +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input/exit diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input.json b/test/cmdlineTests/standard_wrong_type_auxiliary_input/input.json index 8d2c7593..8d2c7593 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input.json +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input/input.json diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input.json.stdout b/test/cmdlineTests/standard_wrong_type_auxiliary_input/output.json index 046cb6d9..046cb6d9 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input/output.json diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json.exit b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json.exit +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/exit diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/input.json index 9175050f..9175050f 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/input.json diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json.stdout b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/output.json index 3efaea20..3efaea20 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses/output.json diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json.exit b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json.exit +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/exit diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/input.json index aa7d451b..aa7d451b 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/input.json diff --git a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json.stdout b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/output.json index a05176be..a05176be 100644 --- a/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_auxiliary_input_smtlib2responses_member/output.json diff --git a/test/cmdlineTests/standard_wrong_type_metadata.json.exit b/test/cmdlineTests/standard_wrong_type_metadata/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_metadata.json.exit +++ b/test/cmdlineTests/standard_wrong_type_metadata/exit diff --git a/test/cmdlineTests/standard_wrong_type_metadata.json b/test/cmdlineTests/standard_wrong_type_metadata/input.json index d4dd06a1..d4dd06a1 100644 --- a/test/cmdlineTests/standard_wrong_type_metadata.json +++ b/test/cmdlineTests/standard_wrong_type_metadata/input.json diff --git a/test/cmdlineTests/standard_wrong_type_metadata.json.stdout b/test/cmdlineTests/standard_wrong_type_metadata/output.json index 7b997cec..7b997cec 100644 --- a/test/cmdlineTests/standard_wrong_type_metadata.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_metadata/output.json diff --git a/test/cmdlineTests/standard_wrong_type_optimizer.json.exit b/test/cmdlineTests/standard_wrong_type_optimizer/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_optimizer.json.exit +++ b/test/cmdlineTests/standard_wrong_type_optimizer/exit diff --git a/test/cmdlineTests/standard_wrong_type_optimizer.json b/test/cmdlineTests/standard_wrong_type_optimizer/input.json index b42ca550..b42ca550 100644 --- a/test/cmdlineTests/standard_wrong_type_optimizer.json +++ b/test/cmdlineTests/standard_wrong_type_optimizer/input.json diff --git a/test/cmdlineTests/standard_wrong_type_optimizer.json.stdout b/test/cmdlineTests/standard_wrong_type_optimizer/output.json index d43b6470..d43b6470 100644 --- a/test/cmdlineTests/standard_wrong_type_optimizer.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_optimizer/output.json diff --git a/test/cmdlineTests/standard_wrong_type_output_selection.json.exit b/test/cmdlineTests/standard_wrong_type_output_selection/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection.json.exit +++ b/test/cmdlineTests/standard_wrong_type_output_selection/exit diff --git a/test/cmdlineTests/standard_wrong_type_output_selection.json b/test/cmdlineTests/standard_wrong_type_output_selection/input.json index a7b615d1..a7b615d1 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection.json +++ b/test/cmdlineTests/standard_wrong_type_output_selection/input.json diff --git a/test/cmdlineTests/standard_wrong_type_output_selection.json.stdout b/test/cmdlineTests/standard_wrong_type_output_selection/output.json index 39e74882..39e74882 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_output_selection/output.json diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_contract.json.exit b/test/cmdlineTests/standard_wrong_type_output_selection_contract/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_contract.json.exit +++ b/test/cmdlineTests/standard_wrong_type_output_selection_contract/exit diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_contract.json b/test/cmdlineTests/standard_wrong_type_output_selection_contract/input.json index 9840a97e..9840a97e 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_contract.json +++ b/test/cmdlineTests/standard_wrong_type_output_selection_contract/input.json diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_contract.json.stdout b/test/cmdlineTests/standard_wrong_type_output_selection_contract/output.json index a4ba320e..a4ba320e 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_contract.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_output_selection_contract/output.json diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_file.json.exit b/test/cmdlineTests/standard_wrong_type_output_selection_file/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_file.json.exit +++ b/test/cmdlineTests/standard_wrong_type_output_selection_file/exit diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_file.json b/test/cmdlineTests/standard_wrong_type_output_selection_file/input.json index 7ab12ba8..7ab12ba8 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_file.json +++ b/test/cmdlineTests/standard_wrong_type_output_selection_file/input.json diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_file.json.stdout b/test/cmdlineTests/standard_wrong_type_output_selection_file/output.json index 8874e636..8874e636 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_file.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_output_selection_file/output.json diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_output.json.exit b/test/cmdlineTests/standard_wrong_type_output_selection_output/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_output.json.exit +++ b/test/cmdlineTests/standard_wrong_type_output_selection_output/exit diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_output.json b/test/cmdlineTests/standard_wrong_type_output_selection_output/input.json index 3e5cd661..3e5cd661 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_output.json +++ b/test/cmdlineTests/standard_wrong_type_output_selection_output/input.json diff --git a/test/cmdlineTests/standard_wrong_type_output_selection_output.json.stdout b/test/cmdlineTests/standard_wrong_type_output_selection_output/output.json index a4ba320e..a4ba320e 100644 --- a/test/cmdlineTests/standard_wrong_type_output_selection_output.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_output_selection_output/output.json diff --git a/test/cmdlineTests/standard_wrong_type_remappings.json.exit b/test/cmdlineTests/standard_wrong_type_remappings/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_remappings.json.exit +++ b/test/cmdlineTests/standard_wrong_type_remappings/exit diff --git a/test/cmdlineTests/standard_wrong_type_remappings.json b/test/cmdlineTests/standard_wrong_type_remappings/input.json index 1436e014..1436e014 100644 --- a/test/cmdlineTests/standard_wrong_type_remappings.json +++ b/test/cmdlineTests/standard_wrong_type_remappings/input.json diff --git a/test/cmdlineTests/standard_wrong_type_remappings.json.stdout b/test/cmdlineTests/standard_wrong_type_remappings/output.json index b5e4ea5c..b5e4ea5c 100644 --- a/test/cmdlineTests/standard_wrong_type_remappings.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_remappings/output.json diff --git a/test/cmdlineTests/standard_wrong_type_remappings_entry.json.exit b/test/cmdlineTests/standard_wrong_type_remappings_entry/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_remappings_entry.json.exit +++ b/test/cmdlineTests/standard_wrong_type_remappings_entry/exit diff --git a/test/cmdlineTests/standard_wrong_type_remappings_entry.json b/test/cmdlineTests/standard_wrong_type_remappings_entry/input.json index c96611f3..c96611f3 100644 --- a/test/cmdlineTests/standard_wrong_type_remappings_entry.json +++ b/test/cmdlineTests/standard_wrong_type_remappings_entry/input.json diff --git a/test/cmdlineTests/standard_wrong_type_remappings_entry.json.stdout b/test/cmdlineTests/standard_wrong_type_remappings_entry/output.json index 0fc71ded..0fc71ded 100644 --- a/test/cmdlineTests/standard_wrong_type_remappings_entry.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_remappings_entry/output.json diff --git a/test/cmdlineTests/standard_wrong_type_root.json.exit b/test/cmdlineTests/standard_wrong_type_root/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_root.json.exit +++ b/test/cmdlineTests/standard_wrong_type_root/exit diff --git a/test/cmdlineTests/standard_wrong_type_root.json b/test/cmdlineTests/standard_wrong_type_root/input.json index 4763607a..4763607a 100644 --- a/test/cmdlineTests/standard_wrong_type_root.json +++ b/test/cmdlineTests/standard_wrong_type_root/input.json diff --git a/test/cmdlineTests/standard_wrong_type_root.json.stdout b/test/cmdlineTests/standard_wrong_type_root/output.json index 15c12e77..15c12e77 100644 --- a/test/cmdlineTests/standard_wrong_type_root.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_root/output.json diff --git a/test/cmdlineTests/standard_wrong_type_settings.json.exit b/test/cmdlineTests/standard_wrong_type_settings/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_settings.json.exit +++ b/test/cmdlineTests/standard_wrong_type_settings/exit diff --git a/test/cmdlineTests/standard_wrong_type_settings.json b/test/cmdlineTests/standard_wrong_type_settings/input.json index 7cdb0881..7cdb0881 100644 --- a/test/cmdlineTests/standard_wrong_type_settings.json +++ b/test/cmdlineTests/standard_wrong_type_settings/input.json diff --git a/test/cmdlineTests/standard_wrong_type_settings.json.stdout b/test/cmdlineTests/standard_wrong_type_settings/output.json index c78c6086..c78c6086 100644 --- a/test/cmdlineTests/standard_wrong_type_settings.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_settings/output.json diff --git a/test/cmdlineTests/standard_wrong_type_source.json.exit b/test/cmdlineTests/standard_wrong_type_source/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_source.json.exit +++ b/test/cmdlineTests/standard_wrong_type_source/exit diff --git a/test/cmdlineTests/standard_wrong_type_source.json b/test/cmdlineTests/standard_wrong_type_source/input.json index d58504fe..d58504fe 100644 --- a/test/cmdlineTests/standard_wrong_type_source.json +++ b/test/cmdlineTests/standard_wrong_type_source/input.json diff --git a/test/cmdlineTests/standard_wrong_type_source.json.stdout b/test/cmdlineTests/standard_wrong_type_source/output.json index 98fe32fd..98fe32fd 100644 --- a/test/cmdlineTests/standard_wrong_type_source.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_source/output.json diff --git a/test/cmdlineTests/standard_wrong_type_sources.json.exit b/test/cmdlineTests/standard_wrong_type_sources/exit index 573541ac..573541ac 100644 --- a/test/cmdlineTests/standard_wrong_type_sources.json.exit +++ b/test/cmdlineTests/standard_wrong_type_sources/exit diff --git a/test/cmdlineTests/standard_wrong_type_sources.json b/test/cmdlineTests/standard_wrong_type_sources/input.json index 76e1ae7d..76e1ae7d 100644 --- a/test/cmdlineTests/standard_wrong_type_sources.json +++ b/test/cmdlineTests/standard_wrong_type_sources/input.json diff --git a/test/cmdlineTests/standard_wrong_type_sources.json.stdout b/test/cmdlineTests/standard_wrong_type_sources/output.json index ac6c613f..ac6c613f 100644 --- a/test/cmdlineTests/standard_wrong_type_sources.json.stdout +++ b/test/cmdlineTests/standard_wrong_type_sources/output.json diff --git a/test/cmdlineTests/too_long_line.sol.err b/test/cmdlineTests/too_long_line/err index 55cd1935..bfbc8e1e 100644 --- a/test/cmdlineTests/too_long_line.sol.err +++ b/test/cmdlineTests/too_long_line/err @@ -1,6 +1,6 @@ -too_long_line.sol:1:1: Warning: Source file does not specify required compiler version! +too_long_line/input.sol:1:1: Warning: Source file does not specify required compiler version! contract C { ^ (Relevant source part starts here and spans across multiple lines). -too_long_line.sol:2:164: Error: Identifier not found or not unique. +too_long_line/input.sol:2:164: Error: Identifier not found or not unique. ... ffffffffffffffffffffffffffffffffff(announcementType Type, string Announcement, string ... ^--------------^ diff --git a/test/cmdlineTests/too_long_line.sol.exit b/test/cmdlineTests/too_long_line/exit index d00491fd..d00491fd 100644 --- a/test/cmdlineTests/too_long_line.sol.exit +++ b/test/cmdlineTests/too_long_line/exit diff --git a/test/cmdlineTests/too_long_line.sol b/test/cmdlineTests/too_long_line/input.sol index 7df1057a..7df1057a 100644 --- a/test/cmdlineTests/too_long_line.sol +++ b/test/cmdlineTests/too_long_line/input.sol diff --git a/test/cmdlineTests/too_long_line_both_sides_short.sol.err b/test/cmdlineTests/too_long_line_both_sides_short/err index 9a5ebfba..2868fcb1 100644 --- a/test/cmdlineTests/too_long_line_both_sides_short.sol.err +++ b/test/cmdlineTests/too_long_line_both_sides_short/err @@ -1,6 +1,6 @@ -too_long_line_both_sides_short.sol:1:1: Warning: Source file does not specify required compiler version! +too_long_line_both_sides_short/input.sol:1:1: Warning: Source file does not specify required compiler version! contract C { ^ (Relevant source part starts here and spans across multiple lines). -too_long_line_both_sides_short.sol:2:15: Error: Identifier not found or not unique. +too_long_line_both_sides_short/input.sol:2:15: Error: Identifier not found or not unique. function f(announcementTypeXXXXXXXXXXXXXXXXXXX ... XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Type, ^-------------------------------------------------------------------------^ diff --git a/test/cmdlineTests/too_long_line_both_sides_short.sol.exit b/test/cmdlineTests/too_long_line_both_sides_short/exit index d00491fd..d00491fd 100644 --- a/test/cmdlineTests/too_long_line_both_sides_short.sol.exit +++ b/test/cmdlineTests/too_long_line_both_sides_short/exit diff --git a/test/cmdlineTests/too_long_line_both_sides_short.sol b/test/cmdlineTests/too_long_line_both_sides_short/input.sol index 062f0292..062f0292 100644 --- a/test/cmdlineTests/too_long_line_both_sides_short.sol +++ b/test/cmdlineTests/too_long_line_both_sides_short/input.sol diff --git a/test/cmdlineTests/too_long_line_edge_in.sol.err b/test/cmdlineTests/too_long_line_edge_in/err index ad3b7805..626451e1 100644 --- a/test/cmdlineTests/too_long_line_edge_in.sol.err +++ b/test/cmdlineTests/too_long_line_edge_in/err @@ -1,6 +1,6 @@ -too_long_line_edge_in.sol:1:1: Warning: Source file does not specify required compiler version! +too_long_line_edge_in/input.sol:1:1: Warning: Source file does not specify required compiler version! contract C { ^ (Relevant source part starts here and spans across multiple lines). -too_long_line_edge_in.sol:2:36: Error: Identifier not found or not unique. +too_long_line_edge_in/input.sol:2:36: Error: Identifier not found or not unique. function ffffffffffffffffffffff(announcementTypeTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Ty, string A) onlyOwner external { ^----------------------------------------------------------------------------------------------^ diff --git a/test/cmdlineTests/too_long_line_edge_in.sol.exit b/test/cmdlineTests/too_long_line_edge_in/exit index d00491fd..d00491fd 100644 --- a/test/cmdlineTests/too_long_line_edge_in.sol.exit +++ b/test/cmdlineTests/too_long_line_edge_in/exit diff --git a/test/cmdlineTests/too_long_line_edge_in.sol b/test/cmdlineTests/too_long_line_edge_in/input.sol index 6f181c83..6f181c83 100644 --- a/test/cmdlineTests/too_long_line_edge_in.sol +++ b/test/cmdlineTests/too_long_line_edge_in/input.sol diff --git a/test/cmdlineTests/too_long_line_edge_out.sol.err b/test/cmdlineTests/too_long_line_edge_out/err index d8495c11..7a4f935a 100644 --- a/test/cmdlineTests/too_long_line_edge_out.sol.err +++ b/test/cmdlineTests/too_long_line_edge_out/err @@ -1,6 +1,6 @@ -too_long_line_edge_out.sol:1:1: Warning: Source file does not specify required compiler version! +too_long_line_edge_out/input.sol:1:1: Warning: Source file does not specify required compiler version! contract C { ^ (Relevant source part starts here and spans across multiple lines). -too_long_line_edge_out.sol:2:37: Error: Identifier not found or not unique. +too_long_line_edge_out/input.sol:2:37: Error: Identifier not found or not unique. ... function fffffffffffffffffffffff(announcementTypeTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Typ, string A) onlyOwner external ... ^----------------------------------------------------------------------------------------------^ diff --git a/test/cmdlineTests/too_long_line_edge_out.sol.exit b/test/cmdlineTests/too_long_line_edge_out/exit index d00491fd..d00491fd 100644 --- a/test/cmdlineTests/too_long_line_edge_out.sol.exit +++ b/test/cmdlineTests/too_long_line_edge_out/exit diff --git a/test/cmdlineTests/too_long_line_edge_out.sol b/test/cmdlineTests/too_long_line_edge_out/input.sol index 29d3cee6..29d3cee6 100644 --- a/test/cmdlineTests/too_long_line_edge_out.sol +++ b/test/cmdlineTests/too_long_line_edge_out/input.sol diff --git a/test/cmdlineTests/too_long_line_left_short.sol.err b/test/cmdlineTests/too_long_line_left_short.sol.err deleted file mode 100644 index 00b6be5c..00000000 --- a/test/cmdlineTests/too_long_line_left_short.sol.err +++ /dev/null @@ -1,6 +0,0 @@ -too_long_line_left_short.sol:1:1: Warning: Source file does not specify required compiler version! -contract C { -^ (Relevant source part starts here and spans across multiple lines). -too_long_line_left_short.sol:2:15: Error: Identifier not found or not unique. - function f(announcementType Type, string Announcement, string ... - ^--------------^ diff --git a/test/cmdlineTests/too_long_line_left_short/err b/test/cmdlineTests/too_long_line_left_short/err new file mode 100644 index 00000000..4aa830b6 --- /dev/null +++ b/test/cmdlineTests/too_long_line_left_short/err @@ -0,0 +1,6 @@ +too_long_line_left_short/input.sol:1:1: Warning: Source file does not specify required compiler version! +contract C { +^ (Relevant source part starts here and spans across multiple lines). +too_long_line_left_short/input.sol:2:15: Error: Identifier not found or not unique. + function f(announcementType Type, string Announcement, string ... + ^--------------^ diff --git a/test/cmdlineTests/too_long_line_left_short.sol.exit b/test/cmdlineTests/too_long_line_left_short/exit index d00491fd..d00491fd 100644 --- a/test/cmdlineTests/too_long_line_left_short.sol.exit +++ b/test/cmdlineTests/too_long_line_left_short/exit diff --git a/test/cmdlineTests/too_long_line_left_short.sol b/test/cmdlineTests/too_long_line_left_short/input.sol index 2accfcce..2accfcce 100644 --- a/test/cmdlineTests/too_long_line_left_short.sol +++ b/test/cmdlineTests/too_long_line_left_short/input.sol diff --git a/test/cmdlineTests/too_long_line_right_short.sol.err b/test/cmdlineTests/too_long_line_right_short/err index 88072d95..ed992565 100644 --- a/test/cmdlineTests/too_long_line_right_short.sol.err +++ b/test/cmdlineTests/too_long_line_right_short/err @@ -1,6 +1,6 @@ -too_long_line_right_short.sol:1:1: Warning: Source file does not specify required compiler version! +too_long_line_right_short/input.sol:1:1: Warning: Source file does not specify required compiler version! contract C { ^ (Relevant source part starts here and spans across multiple lines). -too_long_line_right_short.sol:2:164: Error: Identifier not found or not unique. +too_long_line_right_short/input.sol:2:164: Error: Identifier not found or not unique. ... ffffffffffffffffffffffffffffffffff(announcementType Type, ^--------------^ diff --git a/test/cmdlineTests/too_long_line_right_short.sol.exit b/test/cmdlineTests/too_long_line_right_short/exit index d00491fd..d00491fd 100644 --- a/test/cmdlineTests/too_long_line_right_short.sol.exit +++ b/test/cmdlineTests/too_long_line_right_short/exit diff --git a/test/cmdlineTests/too_long_line_right_short.sol b/test/cmdlineTests/too_long_line_right_short/input.sol index 936b3961..936b3961 100644 --- a/test/cmdlineTests/too_long_line_right_short.sol +++ b/test/cmdlineTests/too_long_line_right_short/input.sol 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; }; |