diff options
Diffstat (limited to 'libyul')
-rw-r--r-- | libyul/optimiser/Disambiguator.cpp | 3 | ||||
-rw-r--r-- | libyul/optimiser/Disambiguator.h | 12 | ||||
-rw-r--r-- | libyul/optimiser/UnusedPruner.cpp | 8 | ||||
-rw-r--r-- | libyul/optimiser/UnusedPruner.h | 4 |
4 files changed, 19 insertions, 8 deletions
diff --git a/libyul/optimiser/Disambiguator.cpp b/libyul/optimiser/Disambiguator.cpp index af3507e1..dcba97c9 100644 --- a/libyul/optimiser/Disambiguator.cpp +++ b/libyul/optimiser/Disambiguator.cpp @@ -34,6 +34,9 @@ using Scope = dev::solidity::assembly::Scope; string Disambiguator::translateIdentifier(string const& _originalName) { + if ((m_externallyUsedIdentifiers.count(_originalName))) + return _originalName; + assertThrow(!m_scopes.empty() && m_scopes.back(), OptimizerException, ""); Scope::Identifier const* id = m_scopes.back()->lookup(_originalName); assertThrow(id, OptimizerException, ""); diff --git a/libyul/optimiser/Disambiguator.h b/libyul/optimiser/Disambiguator.h index 0829fd58..e16ebfbf 100644 --- a/libyul/optimiser/Disambiguator.h +++ b/libyul/optimiser/Disambiguator.h @@ -43,9 +43,14 @@ namespace yul class Disambiguator: public ASTCopier { public: - Disambiguator(solidity::assembly::AsmAnalysisInfo const& _analysisInfo): - m_info(_analysisInfo) - {} + explicit Disambiguator( + solidity::assembly::AsmAnalysisInfo const& _analysisInfo, + std::set<std::string> const& _externallyUsedIdentifiers = {} + ): + m_info(_analysisInfo), m_externallyUsedIdentifiers(_externallyUsedIdentifiers) + { + m_nameDispenser.m_usedNames = m_externallyUsedIdentifiers; + } protected: virtual void enterScope(Block const& _block) override; @@ -58,6 +63,7 @@ protected: void leaveScopeInternal(solidity::assembly::Scope& _scope); solidity::assembly::AsmAnalysisInfo const& m_info; + std::set<std::string> const& m_externallyUsedIdentifiers; std::vector<solidity::assembly::Scope*> m_scopes; std::map<void const*, std::string> m_translations; diff --git a/libyul/optimiser/UnusedPruner.cpp b/libyul/optimiser/UnusedPruner.cpp index 74b6bee4..37a74553 100644 --- a/libyul/optimiser/UnusedPruner.cpp +++ b/libyul/optimiser/UnusedPruner.cpp @@ -33,12 +33,14 @@ using namespace std; using namespace dev; using namespace dev::yul; -UnusedPruner::UnusedPruner(Block& _ast) +UnusedPruner::UnusedPruner(Block& _ast, set<string> const& _externallyUsedFunctions) { ReferencesCounter counter; counter(_ast); m_references = counter.references(); + for (auto const& f: _externallyUsedFunctions) + ++m_references[f]; } void UnusedPruner::operator()(Block& _block) @@ -89,11 +91,11 @@ void UnusedPruner::operator()(Block& _block) ASTModifier::operator()(_block); } -void UnusedPruner::runUntilStabilised(Block& _ast) +void UnusedPruner::runUntilStabilised(Block& _ast, set<string> const& _externallyUsedFunctions) { while (true) { - UnusedPruner pruner(_ast); + UnusedPruner pruner(_ast, _externallyUsedFunctions); pruner(_ast); if (!pruner.shouldRunAgain()) return; diff --git a/libyul/optimiser/UnusedPruner.h b/libyul/optimiser/UnusedPruner.h index 327921ea..30617ff3 100644 --- a/libyul/optimiser/UnusedPruner.h +++ b/libyul/optimiser/UnusedPruner.h @@ -44,7 +44,7 @@ namespace yul class UnusedPruner: public ASTModifier { public: - explicit UnusedPruner(Block& _ast); + explicit UnusedPruner(Block& _ast, std::set<std::string> const& _externallyUsedFunctions = std::set<std::string>()); using ASTModifier::operator(); virtual void operator()(Block& _block) override; @@ -53,7 +53,7 @@ public: bool shouldRunAgain() const { return m_shouldRunAgain; } // Run the pruner until the code does not change anymore. - static void runUntilStabilised(Block& _ast); + static void runUntilStabilised(Block& _ast, std::set<std::string> const& _externallyUsedFunctions = std::set<std::string>()); private: bool used(std::string const& _name) const; |