diff options
author | chriseth <chris@ethereum.org> | 2018-11-24 00:01:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-24 00:01:18 +0800 |
commit | 9a94e503da84cc66f643b3972bf8ad4defa02060 (patch) | |
tree | 8efb3b6d25ba2574689731bcbea2eac901523d24 | |
parent | 4fb15c9327c2c4bfae29f0ff23c1ab0b1218f735 (diff) | |
parent | 8dd0338d127b50e60d50f978be68605e8f8faee5 (diff) | |
download | dexon-solidity-9a94e503da84cc66f643b3972bf8ad4defa02060.tar.gz dexon-solidity-9a94e503da84cc66f643b3972bf8ad4defa02060.tar.zst dexon-solidity-9a94e503da84cc66f643b3972bf8ad4defa02060.zip |
Merge pull request #5491 from ethereum/libyul-as-library
Libyul as static library (version 3 ;( )
112 files changed, 608 insertions, 837 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ed51e5a7..b22ade23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ configure_project(TESTS) add_subdirectory(libdevcore) add_subdirectory(liblangutil) add_subdirectory(libevmasm) +add_subdirectory(libyul) add_subdirectory(libsolidity) add_subdirectory(libsolc) diff --git a/libsolidity/CMakeLists.txt b/libsolidity/CMakeLists.txt index c57fca16..c40087f0 100644 --- a/libsolidity/CMakeLists.txt +++ b/libsolidity/CMakeLists.txt @@ -1,6 +1,6 @@ # Until we have a clear separation, libyul has to be included here -file(GLOB_RECURSE sources "*.cpp" "../libyul/*.cpp") -file(GLOB_RECURSE headers "*.h" "../libyul/*.h") +file(GLOB_RECURSE sources "*.cpp") +file(GLOB_RECURSE headers "*.h") find_package(Z3 QUIET) if (${Z3_FOUND}) @@ -26,7 +26,7 @@ if (NOT (${Z3_FOUND} OR ${CVC4_FOUND})) endif() add_library(solidity ${sources} ${headers}) -target_link_libraries(solidity PUBLIC evmasm langutil devcore ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}) +target_link_libraries(solidity PUBLIC yul evmasm langutil devcore ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}) if (${Z3_FOUND}) target_link_libraries(solidity PUBLIC ${Z3_LIBRARY}) diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index 7ac3ceff..c4931d98 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -23,12 +23,12 @@ #include <libsolidity/analysis/ReferencesResolver.h> #include <libsolidity/ast/AST.h> #include <libsolidity/analysis/NameAndTypeResolver.h> -#include <liblangutil/Exceptions.h> #include <libsolidity/analysis/ConstantEvaluator.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmAnalysis.h> +#include <libyul/AsmAnalysisInfo.h> +#include <libyul/AsmData.h> #include <liblangutil/ErrorReporter.h> +#include <liblangutil/Exceptions.h> #include <libdevcore/StringUtils.h> @@ -273,7 +273,7 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly) ErrorList errors; ErrorReporter errorsIgnored(errors); yul::ExternalIdentifierAccess::Resolver resolver = - [&](assembly::Identifier const& _identifier, yul::IdentifierContext, bool _crossesFunctionBoundary) { + [&](yul::Identifier const& _identifier, yul::IdentifierContext, bool _crossesFunctionBoundary) { auto declarations = m_resolver.nameFromCurrentScope(_identifier.name.str()); bool isSlot = boost::algorithm::ends_with(_identifier.name.str(), "_slot"); bool isOffset = boost::algorithm::ends_with(_identifier.name.str(), "_offset"); @@ -314,9 +314,9 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly) // Will be re-generated later with correct information // We use the latest EVM version because we will re-run it anyway. - assembly::AsmAnalysisInfo analysisInfo; + yul::AsmAnalysisInfo analysisInfo; boost::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError; - assembly::AsmAnalyzer(analysisInfo, errorsIgnored, EVMVersion(), errorTypeForLoose, assembly::AsmFlavour::Loose, resolver).analyze(_inlineAssembly.operations()); + yul::AsmAnalyzer(analysisInfo, errorsIgnored, EVMVersion(), errorTypeForLoose, yul::AsmFlavour::Loose, resolver).analyze(_inlineAssembly.operations()); return false; } diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 69de9f12..4e63875b 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -27,9 +27,9 @@ #include <boost/algorithm/string/join.hpp> #include <boost/range/adaptor/reversed.hpp> #include <libsolidity/ast/AST.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmAnalysis.h> +#include <libyul/AsmAnalysisInfo.h> +#include <libyul/AsmData.h> #include <liblangutil/ErrorReporter.h> #include <libdevcore/Algorithms.h> @@ -954,7 +954,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) // External references have already been resolved in a prior stage and stored in the annotation. // We run the resolve step again regardless. yul::ExternalIdentifierAccess::Resolver identifierAccess = [&]( - assembly::Identifier const& _identifier, + yul::Identifier const& _identifier, yul::IdentifierContext _context, bool ) @@ -1039,13 +1039,13 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) return size_t(1); }; solAssert(!_inlineAssembly.annotation().analysisInfo, ""); - _inlineAssembly.annotation().analysisInfo = make_shared<assembly::AsmAnalysisInfo>(); - assembly::AsmAnalyzer analyzer( + _inlineAssembly.annotation().analysisInfo = make_shared<yul::AsmAnalysisInfo>(); + yul::AsmAnalyzer analyzer( *_inlineAssembly.annotation().analysisInfo, m_errorReporter, m_evmVersion, Error::Type::SyntaxError, - assembly::AsmFlavour::Loose, + yul::AsmFlavour::Loose, identifierAccess ); if (!analyzer.analyze(_inlineAssembly.operations())) diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index 3fb4c026..1112d682 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -19,8 +19,8 @@ #include <libevmasm/SemanticInformation.h> -#include <libsolidity/inlineasm/AsmData.h> #include <libsolidity/ast/ExperimentalFeatures.h> +#include <libyul/AsmData.h> #include <liblangutil/ErrorReporter.h> @@ -40,48 +40,48 @@ public: explicit AssemblyViewPureChecker(std::function<void(StateMutability, SourceLocation const&)> _reportMutability): m_reportMutability(_reportMutability) {} - void operator()(assembly::Label const&) { } - void operator()(assembly::Instruction const& _instruction) + void operator()(yul::Label const&) { } + void operator()(yul::Instruction const& _instruction) { checkInstruction(_instruction.location, _instruction.instruction); } - void operator()(assembly::Literal const&) {} - void operator()(assembly::Identifier const&) {} - void operator()(assembly::FunctionalInstruction const& _instr) + void operator()(yul::Literal const&) {} + void operator()(yul::Identifier const&) {} + void operator()(yul::FunctionalInstruction const& _instr) { checkInstruction(_instr.location, _instr.instruction); for (auto const& arg: _instr.arguments) boost::apply_visitor(*this, arg); } - void operator()(assembly::ExpressionStatement const& _expr) + void operator()(yul::ExpressionStatement const& _expr) { boost::apply_visitor(*this, _expr.expression); } - void operator()(assembly::StackAssignment const&) {} - void operator()(assembly::Assignment const& _assignment) + void operator()(yul::StackAssignment const&) {} + void operator()(yul::Assignment const& _assignment) { boost::apply_visitor(*this, *_assignment.value); } - void operator()(assembly::VariableDeclaration const& _varDecl) + void operator()(yul::VariableDeclaration const& _varDecl) { if (_varDecl.value) boost::apply_visitor(*this, *_varDecl.value); } - void operator()(assembly::FunctionDefinition const& _funDef) + void operator()(yul::FunctionDefinition const& _funDef) { (*this)(_funDef.body); } - void operator()(assembly::FunctionCall const& _funCall) + void operator()(yul::FunctionCall const& _funCall) { for (auto const& arg: _funCall.arguments) boost::apply_visitor(*this, arg); } - void operator()(assembly::If const& _if) + void operator()(yul::If const& _if) { boost::apply_visitor(*this, *_if.condition); (*this)(_if.body); } - void operator()(assembly::Switch const& _switch) + void operator()(yul::Switch const& _switch) { boost::apply_visitor(*this, *_switch.expression); for (auto const& _case: _switch.cases) @@ -91,14 +91,14 @@ public: (*this)(_case.body); } } - void operator()(assembly::ForLoop const& _for) + void operator()(yul::ForLoop const& _for) { (*this)(_for.pre); boost::apply_visitor(*this, *_for.condition); (*this)(_for.body); (*this)(_for.post); } - void operator()(assembly::Block const& _block) + void operator()(yul::Block const& _block) { for (auto const& s: _block.statements) boost::apply_visitor(*this, s); diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index d23562ad..2f418b09 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -41,6 +41,12 @@ #include <vector> #include <memory> +namespace yul +{ +// Forward-declaration to <yul/AsmData.h> +struct Block; +} + namespace dev { namespace solidity @@ -1028,12 +1034,6 @@ public: StatementAnnotation& annotation() const override; }; -namespace assembly -{ -// Forward-declaration to AsmData.h -struct Block; -} - /** * Inline assembly. */ @@ -1043,18 +1043,18 @@ public: InlineAssembly( SourceLocation const& _location, ASTPointer<ASTString> const& _docString, - std::shared_ptr<assembly::Block> const& _operations + std::shared_ptr<yul::Block> const& _operations ): Statement(_location, _docString), m_operations(_operations) {} void accept(ASTVisitor& _visitor) override; void accept(ASTConstVisitor& _visitor) const override; - assembly::Block const& operations() const { return *m_operations; } + yul::Block const& operations() const { return *m_operations; } InlineAssemblyAnnotation& annotation() const override; private: - std::shared_ptr<assembly::Block> m_operations; + std::shared_ptr<yul::Block> m_operations; }; /** diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h index e0b3f492..e9cc905e 100644 --- a/libsolidity/ast/ASTAnnotations.h +++ b/libsolidity/ast/ASTAnnotations.h @@ -30,6 +30,12 @@ #include <vector> #include <set> +namespace yul +{ + struct AsmAnalysisInfo; + struct Identifier; +} + namespace dev { namespace solidity @@ -120,12 +126,6 @@ struct StatementAnnotation: ASTAnnotation, DocumentedAnnotation { }; -namespace assembly -{ - struct AsmAnalysisInfo; - struct Identifier; -} - struct InlineAssemblyAnnotation: StatementAnnotation { struct ExternalIdentifierInfo @@ -137,9 +137,9 @@ struct InlineAssemblyAnnotation: StatementAnnotation }; /// Mapping containing resolved references to external identifiers and their value size - std::map<assembly::Identifier const*, ExternalIdentifierInfo> externalReferences; + std::map<yul::Identifier const*, ExternalIdentifierInfo> externalReferences; /// Information generated during analysis phase. - std::shared_ptr<assembly::AsmAnalysisInfo> analysisInfo; + std::shared_ptr<yul::AsmAnalysisInfo> analysisInfo; }; struct ReturnAnnotation: StatementAnnotation diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index 6b9f7227..b9054692 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -23,8 +23,8 @@ #include <boost/algorithm/string/join.hpp> #include <libdevcore/UTF8.h> #include <libsolidity/ast/AST.h> -#include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/inlineasm/AsmPrinter.h> +#include <libyul/AsmData.h> +#include <libyul/AsmPrinter.h> using namespace std; using namespace langutil; @@ -172,7 +172,7 @@ void ASTJsonConverter::appendExpressionAttributes( _attributes += exprAttributes; } -Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair<assembly::Identifier const* ,InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const +Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair<yul::Identifier const* ,InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const { Json::Value tuple(Json::objectValue); tuple["src"] = sourceLocationToString(_info.first->location); @@ -465,7 +465,7 @@ bool ASTJsonConverter::visit(InlineAssembly const& _node) } } setJsonNode(_node, "InlineAssembly", { - make_pair("operations", Json::Value(assembly::AsmPrinter()(_node.operations()))), + make_pair("operations", Json::Value(yul::AsmPrinter()(_node.operations()))), make_pair("externalReferences", std::move(externalReferences)) }); return false; diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index dec3ac96..ef0a217a 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -135,7 +135,7 @@ private: { return _node ? toJson(*_node) : Json::nullValue; } - Json::Value inlineAssemblyIdentifierToJson(std::pair<assembly::Identifier const* , InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const; + Json::Value inlineAssemblyIdentifierToJson(std::pair<yul::Identifier const* , InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const; static std::string location(VariableDeclaration::Location _location); static std::string contractKind(ContractDefinition::ContractKind _kind); static std::string functionCallKind(FunctionCallKind _kind); diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 9e4f2882..d1bf29fc 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -25,15 +25,14 @@ #include <libsolidity/ast/AST.h> #include <libsolidity/codegen/Compiler.h> #include <libsolidity/interface/Version.h> -#include <liblangutil/ErrorReporter.h> -#include <liblangutil/Scanner.h> #include <libsolidity/interface/SourceReferenceFormatter.h> -#include <liblangutil/Scanner.h> -#include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/inlineasm/AsmCodeGen.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> +#include <libyul/AsmParser.h> +#include <libyul/AsmCodeGen.h> +#include <libyul/AsmAnalysis.h> +#include <libyul/AsmAnalysisInfo.h> #include <libyul/YulString.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/Scanner.h> #include <boost/algorithm/string/replace.hpp> @@ -43,7 +42,7 @@ // Change to "define" to output all intermediate code #undef SOL_OUTPUT_ASM #ifdef SOL_OUTPUT_ASM -#include <libsolidity/inlineasm/AsmPrinter.h> +#include <libyul/AsmPrinter.h> #endif @@ -324,7 +323,7 @@ void CompilerContext::appendInlineAssembly( yul::ExternalIdentifierAccess identifierAccess; identifierAccess.resolve = [&]( - assembly::Identifier const& _identifier, + yul::Identifier const& _identifier, yul::IdentifierContext, bool ) @@ -333,7 +332,7 @@ void CompilerContext::appendInlineAssembly( return it == _localVariables.end() ? size_t(-1) : 1; }; identifierAccess.generateCode = [&]( - assembly::Identifier const& _identifier, + yul::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly ) @@ -362,19 +361,19 @@ void CompilerContext::appendInlineAssembly( ErrorList errors; ErrorReporter errorReporter(errors); auto scanner = make_shared<langutil::Scanner>(langutil::CharStream(_assembly), "--CODEGEN--"); - auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner, false); + auto parserResult = yul::Parser(errorReporter, yul::AsmFlavour::Strict).parse(scanner, false); #ifdef SOL_OUTPUT_ASM - cout << assembly::AsmPrinter()(*parserResult) << endl; + cout << yul::AsmPrinter()(*parserResult) << endl; #endif - assembly::AsmAnalysisInfo analysisInfo; + yul::AsmAnalysisInfo analysisInfo; bool analyzerResult = false; if (parserResult) - analyzerResult = assembly::AsmAnalyzer( + analyzerResult = yul::AsmAnalyzer( analysisInfo, errorReporter, m_evmVersion, boost::none, - assembly::AsmFlavour::Strict, + yul::AsmFlavour::Strict, identifierAccess.resolve ).analyze(*parserResult); if (!parserResult || !errorReporter.errors().empty() || !analyzerResult) @@ -396,7 +395,7 @@ void CompilerContext::appendInlineAssembly( } solAssert(errorReporter.errors().empty(), "Failed to analyze inline assembly block."); - assembly::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system); + yul::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system); // Reset the source location to the one of the node (instead of the CODEGEN source location) updateSourceLocation(); diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 7a1dcd70..157d5fa7 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -21,11 +21,11 @@ */ #include <libsolidity/codegen/ContractCompiler.h> -#include <libsolidity/inlineasm/AsmCodeGen.h> -#include <libsolidity/ast/AST.h> -#include <liblangutil/ErrorReporter.h> #include <libsolidity/codegen/ExpressionCompiler.h> #include <libsolidity/codegen/CompilerUtils.h> +#include <libsolidity/ast/AST.h> +#include <libyul/AsmCodeGen.h> +#include <liblangutil/ErrorReporter.h> #include <libevmasm/Instruction.h> #include <libevmasm/Assembly.h> @@ -496,14 +496,14 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) { unsigned startStackHeight = m_context.stackHeight(); yul::ExternalIdentifierAccess identifierAccess; - identifierAccess.resolve = [&](assembly::Identifier const& _identifier, yul::IdentifierContext, bool) + identifierAccess.resolve = [&](yul::Identifier const& _identifier, yul::IdentifierContext, bool) { auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); if (ref == _inlineAssembly.annotation().externalReferences.end()) return size_t(-1); return ref->second.valueSize; }; - identifierAccess.generateCode = [&](assembly::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly) + identifierAccess.generateCode = [&](yul::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly) { auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); solAssert(ref != _inlineAssembly.annotation().externalReferences.end(), ""); @@ -615,7 +615,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) } }; solAssert(_inlineAssembly.annotation().analysisInfo, ""); - assembly::CodeGenerator::assemble( + yul::CodeGenerator::assemble( _inlineAssembly.operations(), *_inlineAssembly.annotation().analysisInfo, m_context.nonConstAssembly(), diff --git a/libsolidity/inlineasm/AsmPrinter.h b/libsolidity/inlineasm/AsmPrinter.h deleted file mode 100644 index 72048975..00000000 --- a/libsolidity/inlineasm/AsmPrinter.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - This file is part of solidity. - - solidity is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - solidity is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with solidity. If not, see <http://www.gnu.org/licenses/>. -*/ -/** - * @author Christian <c@ethdev.com> - * @date 2017 - * Converts a parsed assembly into its textual form. - */ - -#pragma once - -#include <libsolidity/inlineasm/AsmDataForward.h> - -#include <libyul/YulString.h> - -#include <boost/variant.hpp> - -namespace dev -{ -namespace solidity -{ -namespace assembly -{ - -class AsmPrinter: public boost::static_visitor<std::string> -{ -public: - explicit AsmPrinter(bool _yul = false): m_yul(_yul) {} - - std::string operator()(assembly::Instruction const& _instruction); - std::string operator()(assembly::Literal const& _literal); - std::string operator()(assembly::Identifier const& _identifier); - std::string operator()(assembly::FunctionalInstruction const& _functionalInstruction); - std::string operator()(assembly::ExpressionStatement const& _expr); - std::string operator()(assembly::Label const& _label); - std::string operator()(assembly::StackAssignment const& _assignment); - std::string operator()(assembly::Assignment const& _assignment); - std::string operator()(assembly::VariableDeclaration const& _variableDeclaration); - std::string operator()(assembly::FunctionDefinition const& _functionDefinition); - std::string operator()(assembly::FunctionCall const& _functionCall); - std::string operator()(assembly::If const& _if); - std::string operator()(assembly::Switch const& _switch); - std::string operator()(assembly::ForLoop const& _forLoop); - std::string operator()(assembly::Block const& _block); - -private: - std::string formatTypedName(TypedName _variable) const; - std::string appendTypeName(yul::YulString _type) const; - - bool m_yul = false; -}; - -} -} -} diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp index 5b6b1113..31959d93 100644 --- a/libsolidity/interface/AssemblyStack.cpp +++ b/libsolidity/interface/AssemblyStack.cpp @@ -23,17 +23,16 @@ #include <libsolidity/interface/AssemblyStack.h> #include <liblangutil/Scanner.h> -#include <libsolidity/inlineasm/AsmPrinter.h> -#include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/inlineasm/AsmCodeGen.h> - -#include <libevmasm/Assembly.h> - +#include <libyul/AsmPrinter.h> +#include <libyul/AsmParser.h> +#include <libyul/AsmAnalysis.h> +#include <libyul/AsmAnalysisInfo.h> +#include <libyul/AsmCodeGen.h> #include <libyul/backends/evm/EVMCodeTransform.h> #include <libyul/backends/evm/EVMAssembly.h> +#include <libevmasm/Assembly.h> + using namespace std; using namespace dev; using namespace langutil; @@ -41,19 +40,19 @@ using namespace dev::solidity; namespace { -assembly::AsmFlavour languageToAsmFlavour(AssemblyStack::Language _language) +yul::AsmFlavour languageToAsmFlavour(AssemblyStack::Language _language) { switch (_language) { case AssemblyStack::Language::Assembly: - return assembly::AsmFlavour::Loose; + return yul::AsmFlavour::Loose; case AssemblyStack::Language::StrictAssembly: - return assembly::AsmFlavour::Strict; + return yul::AsmFlavour::Strict; case AssemblyStack::Language::Yul: - return assembly::AsmFlavour::Yul; + return yul::AsmFlavour::Yul; } solAssert(false, ""); - return assembly::AsmFlavour::Yul; + return yul::AsmFlavour::Yul; } } @@ -70,7 +69,7 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string m_errors.clear(); m_analysisSuccessful = false; m_scanner = make_shared<Scanner>(CharStream(_source), _sourceName); - m_parserResult = assembly::Parser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false); + m_parserResult = yul::Parser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false); if (!m_errorReporter.errors().empty()) return false; solAssert(m_parserResult, ""); @@ -78,21 +77,21 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string return analyzeParsed(); } -bool AssemblyStack::analyze(assembly::Block const& _block, Scanner const* _scanner) +bool AssemblyStack::analyze(yul::Block const& _block, Scanner const* _scanner) { m_errors.clear(); m_analysisSuccessful = false; if (_scanner) m_scanner = make_shared<Scanner>(*_scanner); - m_parserResult = make_shared<assembly::Block>(_block); + m_parserResult = make_shared<yul::Block>(_block); return analyzeParsed(); } bool AssemblyStack::analyzeParsed() { - m_analysisInfo = make_shared<assembly::AsmAnalysisInfo>(); - assembly::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter, m_evmVersion, boost::none, languageToAsmFlavour(m_language)); + m_analysisInfo = make_shared<yul::AsmAnalysisInfo>(); + yul::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter, m_evmVersion, boost::none, languageToAsmFlavour(m_language)); m_analysisSuccessful = analyzer.analyze(*m_parserResult); return m_analysisSuccessful; } @@ -109,7 +108,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const { MachineAssemblyObject object; eth::Assembly assembly; - assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly); + yul::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly); object.bytecode = make_shared<eth::LinkerObject>(assembly.assemble()); object.assembly = assembly.assemblyString(); return object; @@ -133,5 +132,5 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const string AssemblyStack::print() const { solAssert(m_parserResult, ""); - return assembly::AsmPrinter(m_language == Language::Yul)(*m_parserResult); + return yul::AsmPrinter(m_language == Language::Yul)(*m_parserResult); } diff --git a/libsolidity/interface/AssemblyStack.h b/libsolidity/interface/AssemblyStack.h index d6ee33cf..03b811db 100644 --- a/libsolidity/interface/AssemblyStack.h +++ b/libsolidity/interface/AssemblyStack.h @@ -34,16 +34,17 @@ namespace langutil class Scanner; } -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { struct AsmAnalysisInfo; struct Block; } +namespace dev +{ +namespace solidity +{ + struct MachineAssemblyObject { std::shared_ptr<eth::LinkerObject> bytecode; @@ -73,7 +74,7 @@ public: /// Runs analysis step on the supplied block, returns false if input cannot be assembled. /// Multiple calls overwrite the previous state. - bool analyze(assembly::Block const& _block, langutil::Scanner const* _scanner = nullptr); + bool analyze(yul::Block const& _block, langutil::Scanner const* _scanner = nullptr); /// Run the assembly step (should only be called after parseAndAnalyze). MachineAssemblyObject assemble(Machine _machine) const; @@ -93,8 +94,8 @@ private: std::shared_ptr<langutil::Scanner> m_scanner; bool m_analysisSuccessful = false; - std::shared_ptr<assembly::Block> m_parserResult; - std::shared_ptr<assembly::AsmAnalysisInfo> m_analysisInfo; + std::shared_ptr<yul::Block> m_parserResult; + std::shared_ptr<yul::AsmAnalysisInfo> m_analysisInfo; langutil::ErrorList m_errors; langutil::ErrorReporter m_errorReporter; }; diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index ae85276e..de4a7ec2 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -27,7 +27,6 @@ #include <libsolidity/interface/Version.h> #include <libsolidity/analysis/SemVerHandler.h> #include <libsolidity/ast/AST.h> -#include <liblangutil/Scanner.h> #include <libsolidity/parsing/Parser.h> #include <libsolidity/analysis/ControlFlowAnalyzer.h> #include <libsolidity/analysis/ControlFlowGraph.h> @@ -45,10 +44,12 @@ #include <libsolidity/interface/Natspec.h> #include <libsolidity/interface/GasEstimator.h> -#include <libevmasm/Exceptions.h> - #include <libyul/YulString.h> +#include <liblangutil/Scanner.h> + +#include <libevmasm/Exceptions.h> + #include <libdevcore/SwarmHash.h> #include <libdevcore/JSON.h> diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index de5293b4..ffe2be83 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -22,11 +22,11 @@ #include <cctype> #include <vector> -#include <liblangutil/SourceLocation.h> #include <libsolidity/parsing/Parser.h> -#include <liblangutil/Scanner.h> -#include <libsolidity/inlineasm/AsmParser.h> +#include <libyul/AsmParser.h> +#include <liblangutil/SourceLocation.h> #include <liblangutil/ErrorReporter.h> +#include <liblangutil/Scanner.h> using namespace std; using namespace langutil; @@ -1012,8 +1012,8 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con m_scanner->next(); } - assembly::Parser asmParser(m_errorReporter); - shared_ptr<assembly::Block> block = asmParser.parse(m_scanner, true); + yul::Parser asmParser(m_errorReporter); + shared_ptr<yul::Block> block = asmParser.parse(m_scanner, true); nodeFactory.markEndPosition(); return nodeFactory.createNode<InlineAssembly>(_docString, block); } diff --git a/libyul/ASTDataForward.h b/libyul/ASTDataForward.h deleted file mode 100644 index 8c49e68f..00000000 --- a/libyul/ASTDataForward.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - This file is part of solidity. - - solidity is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - solidity is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with solidity. If not, see <http://www.gnu.org/licenses/>. -*/ -/** - * @date 2017 - * Pull in some identifiers from the solidity::assembly namespace. - */ - -#pragma once - -#include <libsolidity/inlineasm/AsmDataForward.h> - -namespace dev -{ -namespace yul -{ - -using Instruction = solidity::assembly::Instruction; -using Literal = solidity::assembly::Literal; -using Label = solidity::assembly::Label; -using StackAssignment = solidity::assembly::StackAssignment; -using Identifier = solidity::assembly::Identifier; -using Assignment = solidity::assembly::Assignment; -using VariableDeclaration = solidity::assembly::VariableDeclaration; -using FunctionalInstruction = solidity::assembly::FunctionalInstruction; -using FunctionDefinition = solidity::assembly::FunctionDefinition; -using FunctionCall = solidity::assembly::FunctionCall; -using If = solidity::assembly::If; -using Case = solidity::assembly::Case; -using Switch = solidity::assembly::Switch; -using ForLoop = solidity::assembly::ForLoop; -using ExpressionStatement = solidity::assembly::ExpressionStatement; -using Block = solidity::assembly::Block; - -using TypedName = solidity::assembly::TypedName; -class YulString; - -using Expression = boost::variant<FunctionalInstruction, FunctionCall, Identifier, Literal>; -using Statement = boost::variant<ExpressionStatement, Instruction, Label, StackAssignment, Assignment, VariableDeclaration, FunctionDefinition, If, Switch, ForLoop, Block>; - -} -} diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index fb96f73c..d3f6de84 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -18,12 +18,12 @@ * Analyzer part of inline assembly. */ -#include <libsolidity/inlineasm/AsmAnalysis.h> +#include <libyul/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/inlineasm/AsmScopeFiller.h> -#include <libsolidity/inlineasm/AsmScope.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> +#include <libyul/AsmData.h> +#include <libyul/AsmScopeFiller.h> +#include <libyul/AsmScope.h> +#include <libyul/AsmAnalysisInfo.h> #include <liblangutil/ErrorReporter.h> @@ -36,8 +36,9 @@ using namespace std; using namespace dev; using namespace langutil; +using namespace yul; +using namespace dev; using namespace dev::solidity; -using namespace dev::solidity::assembly; namespace { @@ -65,7 +66,7 @@ bool AsmAnalyzer::operator()(Label const& _label) return true; } -bool AsmAnalyzer::operator()(assembly::Instruction const& _instruction) +bool AsmAnalyzer::operator()(yul::Instruction const& _instruction) { checkLooseFeature( _instruction.location, @@ -78,11 +79,11 @@ bool AsmAnalyzer::operator()(assembly::Instruction const& _instruction) return true; } -bool AsmAnalyzer::operator()(assembly::Literal const& _literal) +bool AsmAnalyzer::operator()(Literal const& _literal) { expectValidType(_literal.type.str(), _literal.location); ++m_stackHeight; - if (_literal.kind == assembly::LiteralKind::String && _literal.value.str().size() > 32) + if (_literal.kind == LiteralKind::String && _literal.value.str().size() > 32) { m_errorReporter.typeError( _literal.location, @@ -90,7 +91,7 @@ bool AsmAnalyzer::operator()(assembly::Literal const& _literal) ); return false; } - else if (_literal.kind == assembly::LiteralKind::Number && bigint(_literal.value.str()) > u256(-1)) + else if (_literal.kind == LiteralKind::Number && bigint(_literal.value.str()) > u256(-1)) { m_errorReporter.typeError( _literal.location, @@ -98,7 +99,7 @@ bool AsmAnalyzer::operator()(assembly::Literal const& _literal) ); return false; } - else if (_literal.kind == assembly::LiteralKind::Boolean) + else if (_literal.kind == LiteralKind::Boolean) { solAssert(m_flavour == AsmFlavour::Yul, ""); solAssert(_literal.value == YulString{string("true")} || _literal.value == YulString{string("false")}, ""); @@ -107,7 +108,7 @@ bool AsmAnalyzer::operator()(assembly::Literal const& _literal) return true; } -bool AsmAnalyzer::operator()(assembly::Identifier const& _identifier) +bool AsmAnalyzer::operator()(Identifier const& _identifier) { solAssert(!_identifier.name.empty(), ""); size_t numErrorsBefore = m_errorReporter.errors().size(); @@ -177,7 +178,7 @@ bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr) return success; } -bool AsmAnalyzer::operator()(assembly::ExpressionStatement const& _statement) +bool AsmAnalyzer::operator()(ExpressionStatement const& _statement) { int initialStackHeight = m_stackHeight; bool success = boost::apply_visitor(*this, _statement.expression); @@ -198,7 +199,7 @@ bool AsmAnalyzer::operator()(assembly::ExpressionStatement const& _statement) return success; } -bool AsmAnalyzer::operator()(assembly::StackAssignment const& _assignment) +bool AsmAnalyzer::operator()(StackAssignment const& _assignment) { checkLooseFeature( _assignment.location, @@ -209,7 +210,7 @@ bool AsmAnalyzer::operator()(assembly::StackAssignment const& _assignment) return success; } -bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment) +bool AsmAnalyzer::operator()(Assignment const& _assignment) { solAssert(_assignment.value, ""); int const expectedItems = _assignment.variableNames.size(); @@ -235,7 +236,7 @@ bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment) return success; } -bool AsmAnalyzer::operator()(assembly::VariableDeclaration const& _varDecl) +bool AsmAnalyzer::operator()(VariableDeclaration const& _varDecl) { bool success = true; int const numVariables = _varDecl.variables.size(); @@ -261,7 +262,7 @@ bool AsmAnalyzer::operator()(assembly::VariableDeclaration const& _varDecl) return success; } -bool AsmAnalyzer::operator()(assembly::FunctionDefinition const& _funDef) +bool AsmAnalyzer::operator()(FunctionDefinition const& _funDef) { solAssert(!_funDef.name.empty(), ""); Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get(); @@ -283,7 +284,7 @@ bool AsmAnalyzer::operator()(assembly::FunctionDefinition const& _funDef) return success; } -bool AsmAnalyzer::operator()(assembly::FunctionCall const& _funCall) +bool AsmAnalyzer::operator()(FunctionCall const& _funCall) { solAssert(!_funCall.functionName.name.empty(), ""); bool success = true; @@ -397,7 +398,7 @@ bool AsmAnalyzer::operator()(Switch const& _switch) return success; } -bool AsmAnalyzer::operator()(assembly::ForLoop const& _for) +bool AsmAnalyzer::operator()(ForLoop const& _for) { solAssert(_for.condition, ""); @@ -486,7 +487,7 @@ bool AsmAnalyzer::expectDeposit(int _deposit, int _oldHeight, SourceLocation con return true; } -bool AsmAnalyzer::checkAssignment(assembly::Identifier const& _variable, size_t _valueSize) +bool AsmAnalyzer::checkAssignment(Identifier const& _variable, size_t _valueSize) { solAssert(!_variable.name.empty(), ""); bool success = true; diff --git a/libsolidity/inlineasm/AsmAnalysis.h b/libyul/AsmAnalysis.h index 194f736e..34e32eb0 100644 --- a/libsolidity/inlineasm/AsmAnalysis.h +++ b/libyul/AsmAnalysis.h @@ -23,11 +23,11 @@ #include <liblangutil/Exceptions.h> #include <liblangutil/EVMVersion.h> -#include <libsolidity/inlineasm/AsmScope.h> +#include <libyul/AsmScope.h> #include <libyul/backends/evm/AbstractAssembly.h> -#include <libsolidity/inlineasm/AsmDataForward.h> +#include <libyul/AsmDataForward.h> #include <boost/variant.hpp> #include <boost/optional.hpp> @@ -41,11 +41,7 @@ class ErrorReporter; struct SourceLocation; } -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { struct AsmAnalysisInfo; @@ -61,10 +57,10 @@ public: explicit AsmAnalyzer( AsmAnalysisInfo& _analysisInfo, langutil::ErrorReporter& _errorReporter, - EVMVersion _evmVersion, + dev::solidity::EVMVersion _evmVersion, boost::optional<langutil::Error::Type> _errorTypeForLoose, AsmFlavour _flavour = AsmFlavour::Loose, - yul::ExternalIdentifierAccess::Resolver const& _resolver = yul::ExternalIdentifierAccess::Resolver() + ExternalIdentifierAccess::Resolver const& _resolver = ExternalIdentifierAccess::Resolver() ): m_resolver(_resolver), m_info(_analysisInfo), @@ -74,23 +70,23 @@ public: m_errorTypeForLoose(_errorTypeForLoose) {} - bool analyze(assembly::Block const& _block); - - bool operator()(assembly::Instruction const&); - bool operator()(assembly::Literal const& _literal); - bool operator()(assembly::Identifier const&); - bool operator()(assembly::FunctionalInstruction const& _functionalInstruction); - bool operator()(assembly::Label const& _label); - bool operator()(assembly::ExpressionStatement const&); - bool operator()(assembly::StackAssignment const&); - bool operator()(assembly::Assignment const& _assignment); - bool operator()(assembly::VariableDeclaration const& _variableDeclaration); - bool operator()(assembly::FunctionDefinition const& _functionDefinition); - bool operator()(assembly::FunctionCall const& _functionCall); - bool operator()(assembly::If const& _if); - bool operator()(assembly::Switch const& _switch); - bool operator()(assembly::ForLoop const& _forLoop); - bool operator()(assembly::Block const& _block); + bool analyze(Block const& _block); + + bool operator()(Instruction const&); + bool operator()(Literal const& _literal); + bool operator()(Identifier const&); + bool operator()(FunctionalInstruction const& _functionalInstruction); + bool operator()(Label const& _label); + bool operator()(ExpressionStatement const&); + bool operator()(StackAssignment const&); + bool operator()(Assignment const& _assignment); + bool operator()(VariableDeclaration const& _variableDeclaration); + bool operator()(FunctionDefinition const& _functionDefinition); + bool operator()(FunctionCall const& _functionCall); + bool operator()(If const& _if); + bool operator()(Switch const& _switch); + bool operator()(ForLoop const& _forLoop); + bool operator()(Block const& _block); private: /// Visits the statement and expects it to deposit one item onto the stack. @@ -99,11 +95,11 @@ private: /// Verifies that a variable to be assigned to exists and has the same size /// as the value, @a _valueSize, unless that is equal to -1. - bool checkAssignment(assembly::Identifier const& _assignment, size_t _valueSize = size_t(-1)); + bool checkAssignment(Identifier const& _assignment, size_t _valueSize = size_t(-1)); - Scope& scope(assembly::Block const* _block); + Scope& scope(Block const* _block); void expectValidType(std::string const& type, langutil::SourceLocation const& _location); - void warnOnInstructions(solidity::Instruction _instr, langutil::SourceLocation const& _location); + void warnOnInstructions(dev::solidity::Instruction _instr, langutil::SourceLocation const& _location); /// Depending on @a m_flavour and @a m_errorTypeForLoose, throws an internal compiler /// exception (if the flavour is not Loose), reports an error/warning @@ -118,11 +114,9 @@ private: std::set<Scope::Variable const*> m_activeVariables; AsmAnalysisInfo& m_info; langutil::ErrorReporter& m_errorReporter; - EVMVersion m_evmVersion; + dev::solidity::EVMVersion m_evmVersion; AsmFlavour m_flavour = AsmFlavour::Loose; boost::optional<langutil::Error::Type> m_errorTypeForLoose; }; } -} -} diff --git a/libsolidity/inlineasm/AsmAnalysisInfo.cpp b/libyul/AsmAnalysisInfo.cpp index 22318b12..450c0f8f 100644 --- a/libsolidity/inlineasm/AsmAnalysisInfo.cpp +++ b/libyul/AsmAnalysisInfo.cpp @@ -18,9 +18,9 @@ * Information generated during analyzer part of inline assembly. */ -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> +#include <libyul/AsmAnalysisInfo.h> -#include <libsolidity/inlineasm/AsmScope.h> +#include <libyul/AsmScope.h> #include <ostream> diff --git a/libsolidity/inlineasm/AsmAnalysisInfo.h b/libyul/AsmAnalysisInfo.h index bd3b28c4..08a35ade 100644 --- a/libsolidity/inlineasm/AsmAnalysisInfo.h +++ b/libyul/AsmAnalysisInfo.h @@ -20,7 +20,7 @@ #pragma once -#include <libsolidity/inlineasm/AsmDataForward.h> +#include <libyul/AsmDataForward.h> #include <boost/variant.hpp> @@ -28,11 +28,7 @@ #include <memory> #include <vector> -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { struct Scope; @@ -40,13 +36,11 @@ struct Scope; struct AsmAnalysisInfo { using StackHeightInfo = std::map<void const*, int>; - using Scopes = std::map<assembly::Block const*, std::shared_ptr<Scope>>; + using Scopes = std::map<Block const*, std::shared_ptr<Scope>>; Scopes scopes; StackHeightInfo stackHeightInfo; /// Virtual blocks which will be used for scopes for function arguments and return values. - std::map<FunctionDefinition const*, std::shared_ptr<assembly::Block const>> virtualBlocks; + std::map<FunctionDefinition const*, std::shared_ptr<Block const>> virtualBlocks; }; } -} -} diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libyul/AsmCodeGen.cpp index 2800cc7b..23bf395d 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libyul/AsmCodeGen.cpp @@ -20,20 +20,21 @@ * Code-generating part of inline assembly. */ -#include <libsolidity/inlineasm/AsmCodeGen.h> +#include <libyul/AsmCodeGen.h> -#include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/inlineasm/AsmScope.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> +#include <libyul/AsmParser.h> +#include <libyul/AsmData.h> +#include <libyul/AsmScope.h> +#include <libyul/AsmAnalysis.h> +#include <libyul/AsmAnalysisInfo.h> + +#include <libyul/backends/evm/AbstractAssembly.h> +#include <libyul/backends/evm/EVMCodeTransform.h> #include <libevmasm/Assembly.h> -#include <liblangutil/SourceLocation.h> #include <libevmasm/Instruction.h> -#include <libyul/backends/evm/AbstractAssembly.h> -#include <libyul/backends/evm/EVMCodeTransform.h> +#include <liblangutil/SourceLocation.h> #include <libdevcore/CommonIO.h> @@ -47,10 +48,10 @@ using namespace std; using namespace dev; using namespace langutil; +using namespace yul; using namespace dev::solidity; -using namespace dev::solidity::assembly; -class EthAssemblyAdapter: public yul::AbstractAssembly +class EthAssemblyAdapter: public AbstractAssembly { public: explicit EthAssemblyAdapter(eth::Assembly& _assembly): @@ -142,16 +143,16 @@ private: eth::Assembly& m_assembly; }; -void assembly::CodeGenerator::assemble( +void CodeGenerator::assemble( Block const& _parsedData, AsmAnalysisInfo& _analysisInfo, eth::Assembly& _assembly, - yul::ExternalIdentifierAccess const& _identifierAccess, + ExternalIdentifierAccess const& _identifierAccess, bool _useNamedLabelsForFunctions ) { EthAssemblyAdapter assemblyAdapter(_assembly); - yul::CodeTransform( + CodeTransform( assemblyAdapter, _analysisInfo, false, diff --git a/libsolidity/inlineasm/AsmCodeGen.h b/libyul/AsmCodeGen.h index bbc31397..fd5ac0a1 100644 --- a/libsolidity/inlineasm/AsmCodeGen.h +++ b/libyul/AsmCodeGen.h @@ -22,7 +22,7 @@ #pragma once -#include <libsolidity/inlineasm/AsmAnalysis.h> +#include <libyul/AsmAnalysis.h> #include <functional> @@ -32,9 +32,9 @@ namespace eth { class Assembly; } -namespace solidity -{ -namespace assembly +} + +namespace yul { struct Block; @@ -45,12 +45,10 @@ public: static void assemble( Block const& _parsedData, AsmAnalysisInfo& _analysisInfo, - eth::Assembly& _assembly, + dev::eth::Assembly& _assembly, yul::ExternalIdentifierAccess const& _identifierAccess = yul::ExternalIdentifierAccess(), bool _useNamedLabelsForFunctions = false ); }; } -} -} diff --git a/libsolidity/inlineasm/AsmData.h b/libyul/AsmData.h index 23a9db75..86c373a4 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libyul/AsmData.h @@ -22,34 +22,28 @@ #pragma once -#include <libsolidity/inlineasm/AsmDataForward.h> +#include <libyul/AsmDataForward.h> +#include <libyul/YulString.h> #include <libevmasm/Instruction.h> #include <liblangutil/SourceLocation.h> -#include <libyul/YulString.h> - #include <boost/variant.hpp> #include <boost/noncopyable.hpp> #include <map> #include <memory> -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { -using YulString = dev::yul::YulString; using Type = YulString; struct TypedName { langutil::SourceLocation location; YulString name; Type type; }; using TypedNameList = std::vector<TypedName>; /// Direct EVM instruction (except PUSHi and JUMPDEST) -struct Instruction { langutil::SourceLocation location; solidity::Instruction instruction; }; +struct Instruction { langutil::SourceLocation location; dev::solidity::Instruction instruction; }; /// Literal number or string (up to 32 bytes) enum class LiteralKind { Number, Boolean, String }; struct Literal { langutil::SourceLocation location; LiteralKind kind; YulString value; Type type; }; @@ -67,7 +61,7 @@ struct StackAssignment { langutil::SourceLocation location; Identifier variableN /// the same amount of items as the number of variables. struct Assignment { langutil::SourceLocation location; std::vector<Identifier> variableNames; std::shared_ptr<Expression> value; }; /// Functional instruction, e.g. "mul(mload(20:u256), add(2:u256, x))" -struct FunctionalInstruction { langutil::SourceLocation location; solidity::Instruction instruction; std::vector<Expression> arguments; }; +struct FunctionalInstruction { langutil::SourceLocation location; dev::solidity::Instruction instruction; std::vector<Expression> arguments; }; struct FunctionCall { langutil::SourceLocation location; Identifier functionName; std::vector<Expression> arguments; }; /// Statement that contains only a single expression struct ExpressionStatement { langutil::SourceLocation location; Expression expression; }; @@ -100,5 +94,3 @@ template <class T> inline langutil::SourceLocation locationOf(T const& _node) } } -} -} diff --git a/libsolidity/inlineasm/AsmDataForward.h b/libyul/AsmDataForward.h index 69cf8f1d..046c8248 100644 --- a/libsolidity/inlineasm/AsmDataForward.h +++ b/libyul/AsmDataForward.h @@ -24,11 +24,7 @@ #include <boost/variant.hpp> -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { struct Instruction; @@ -61,5 +57,3 @@ enum class AsmFlavour }; } -} -} diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libyul/AsmParser.cpp index b11f70e0..2ce94f85 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -20,7 +20,7 @@ * Solidity inline assembly parser. */ -#include <libsolidity/inlineasm/AsmParser.h> +#include <libyul/AsmParser.h> #include <liblangutil/Scanner.h> #include <liblangutil/ErrorReporter.h> @@ -32,10 +32,10 @@ using namespace std; using namespace dev; using namespace langutil; +using namespace yul; using namespace dev::solidity; -using namespace dev::solidity::assembly; -shared_ptr<assembly::Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner) +shared_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner) { m_recursionDepth = 0; try @@ -54,10 +54,10 @@ shared_ptr<assembly::Block> Parser::parse(std::shared_ptr<Scanner> const& _scann return nullptr; } -assembly::Block Parser::parseBlock() +Block Parser::parseBlock() { RecursionGuard recursionGuard(*this); - assembly::Block block = createWithLocation<Block>(); + Block block = createWithLocation<Block>(); expectToken(Token::LBrace); while (currentToken() != Token::RBrace) block.statements.emplace_back(parseStatement()); @@ -66,7 +66,7 @@ assembly::Block Parser::parseBlock() return block; } -assembly::Statement Parser::parseStatement() +Statement Parser::parseStatement() { RecursionGuard recursionGuard(*this); switch (currentToken()) @@ -79,7 +79,7 @@ assembly::Statement Parser::parseStatement() return parseBlock(); case Token::If: { - assembly::If _if = createWithLocation<assembly::If>(); + If _if = createWithLocation<If>(); m_scanner->next(); _if.condition = make_shared<Expression>(parseExpression()); _if.body = parseBlock(); @@ -87,7 +87,7 @@ assembly::Statement Parser::parseStatement() } case Token::Switch: { - assembly::Switch _switch = createWithLocation<assembly::Switch>(); + Switch _switch = createWithLocation<Switch>(); m_scanner->next(); _switch.expression = make_shared<Expression>(parseExpression()); while (m_scanner->currentToken() == Token::Case) @@ -109,7 +109,7 @@ assembly::Statement Parser::parseStatement() { if (m_flavour != AsmFlavour::Loose) break; - assembly::StackAssignment assignment = createWithLocation<assembly::StackAssignment>(); + StackAssignment assignment = createWithLocation<StackAssignment>(); advance(); expectToken(Token::Colon); assignment.variableName.location = location(); @@ -139,9 +139,9 @@ assembly::Statement Parser::parseStatement() { // if a comma follows, a multiple assignment is assumed - if (elementary.type() != typeid(assembly::Identifier)) + if (elementary.type() != typeid(Identifier)) fatalParserError("Label name / variable name must precede \",\" (multiple assignment)."); - assembly::Identifier const& identifier = boost::get<assembly::Identifier>(elementary); + Identifier const& identifier = boost::get<Identifier>(elementary); Assignment assignment = createWithLocation<Assignment>(identifier.location); assignment.variableNames.emplace_back(identifier); @@ -150,9 +150,9 @@ assembly::Statement Parser::parseStatement() { expectToken(Token::Comma); elementary = parseElementaryOperation(); - if (elementary.type() != typeid(assembly::Identifier)) + if (elementary.type() != typeid(Identifier)) fatalParserError("Variable name expected in multiple assignment."); - assignment.variableNames.emplace_back(boost::get<assembly::Identifier>(elementary)); + assignment.variableNames.emplace_back(boost::get<Identifier>(elementary)); } while (currentToken() == Token::Comma); @@ -165,15 +165,15 @@ assembly::Statement Parser::parseStatement() } case Token::Colon: { - if (elementary.type() != typeid(assembly::Identifier)) + if (elementary.type() != typeid(Identifier)) fatalParserError("Label name / variable name must precede \":\"."); - assembly::Identifier const& identifier = boost::get<assembly::Identifier>(elementary); + Identifier const& identifier = boost::get<Identifier>(elementary); advance(); // identifier:=: should be parsed as identifier: =: (i.e. a label), // while identifier:= (being followed by a non-colon) as identifier := (assignment). if (currentToken() == Token::Assign && peekNextToken() != Token::Colon) { - assembly::Assignment assignment = createWithLocation<assembly::Assignment>(identifier.location); + Assignment assignment = createWithLocation<Assignment>(identifier.location); if (m_flavour != AsmFlavour::Yul && instructions().count(identifier.name.str())) fatalParserError("Cannot use instruction names for identifier names."); advance(); @@ -197,36 +197,36 @@ assembly::Statement Parser::parseStatement() fatalParserError("Call or assignment expected."); break; } - if (elementary.type() == typeid(assembly::Identifier)) + if (elementary.type() == typeid(Identifier)) { - Expression expr = boost::get<assembly::Identifier>(elementary); + Expression expr = boost::get<Identifier>(elementary); return ExpressionStatement{locationOf(expr), expr}; } - else if (elementary.type() == typeid(assembly::Literal)) + else if (elementary.type() == typeid(Literal)) { - Expression expr = boost::get<assembly::Literal>(elementary); + Expression expr = boost::get<Literal>(elementary); return ExpressionStatement{locationOf(expr), expr}; } else { - solAssert(elementary.type() == typeid(assembly::Instruction), "Invalid elementary operation."); - return boost::get<assembly::Instruction>(elementary); + solAssert(elementary.type() == typeid(Instruction), "Invalid elementary operation."); + return boost::get<Instruction>(elementary); } } -assembly::Case Parser::parseCase() +Case Parser::parseCase() { RecursionGuard recursionGuard(*this); - assembly::Case _case = createWithLocation<assembly::Case>(); + Case _case = createWithLocation<Case>(); if (m_scanner->currentToken() == Token::Default) m_scanner->next(); else if (m_scanner->currentToken() == Token::Case) { m_scanner->next(); ElementaryOperation literal = parseElementaryOperation(); - if (literal.type() != typeid(assembly::Literal)) + if (literal.type() != typeid(Literal)) fatalParserError("Literal expected."); - _case.value = make_shared<Literal>(boost::get<assembly::Literal>(std::move(literal))); + _case.value = make_shared<Literal>(boost::get<Literal>(std::move(literal))); } else fatalParserError("Case or default case expected."); @@ -235,7 +235,7 @@ assembly::Case Parser::parseCase() return _case; } -assembly::ForLoop Parser::parseForLoop() +ForLoop Parser::parseForLoop() { RecursionGuard recursionGuard(*this); ForLoop forLoop = createWithLocation<ForLoop>(); @@ -248,7 +248,7 @@ assembly::ForLoop Parser::parseForLoop() return forLoop; } -assembly::Expression Parser::parseExpression() +Expression Parser::parseExpression() { RecursionGuard recursionGuard(*this); // In strict mode, this might parse a plain Instruction, but @@ -293,12 +293,12 @@ assembly::Expression Parser::parseExpression() Instruction& instr = boost::get<Instruction>(operation); return FunctionalInstruction{std::move(instr.location), instr.instruction, {}}; } - else if (operation.type() == typeid(assembly::Identifier)) - return boost::get<assembly::Identifier>(operation); + else if (operation.type() == typeid(Identifier)) + return boost::get<Identifier>(operation); else { - solAssert(operation.type() == typeid(assembly::Literal), ""); - return boost::get<assembly::Literal>(operation); + solAssert(operation.type() == typeid(Literal), ""); + return boost::get<Literal>(operation); } } @@ -420,7 +420,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() return ret; } -assembly::VariableDeclaration Parser::parseVariableDeclaration() +VariableDeclaration Parser::parseVariableDeclaration() { RecursionGuard recursionGuard(*this); VariableDeclaration varDecl = createWithLocation<VariableDeclaration>(); @@ -445,7 +445,7 @@ assembly::VariableDeclaration Parser::parseVariableDeclaration() return varDecl; } -assembly::FunctionDefinition Parser::parseFunctionDefinition() +FunctionDefinition Parser::parseFunctionDefinition() { RecursionGuard recursionGuard(*this); FunctionDefinition funDef = createWithLocation<FunctionDefinition>(); @@ -477,7 +477,7 @@ assembly::FunctionDefinition Parser::parseFunctionDefinition() return funDef; } -assembly::Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) +Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) { RecursionGuard recursionGuard(*this); if (_initialOp.type() == typeid(Instruction)) diff --git a/libsolidity/inlineasm/AsmParser.h b/libyul/AsmParser.h index 9e13799a..cea3b667 100644 --- a/libsolidity/inlineasm/AsmParser.h +++ b/libyul/AsmParser.h @@ -24,16 +24,12 @@ #include <memory> #include <vector> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <liblangutil/SourceLocation.h> #include <liblangutil/Scanner.h> #include <liblangutil/ParserBase.h> -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { class Parser: public langutil::ParserBase @@ -48,7 +44,7 @@ public: std::shared_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner); protected: - using ElementaryOperation = boost::variant<assembly::Instruction, assembly::Literal, assembly::Identifier>; + using ElementaryOperation = boost::variant<Instruction, Literal, Identifier>; /// Creates an inline assembly node with the given source location. template <class T> T createWithLocation(langutil::SourceLocation const& _loc = {}) const @@ -71,7 +67,7 @@ protected: Case parseCase(); ForLoop parseForLoop(); /// Parses a functional expression that has to push exactly one stack element - assembly::Expression parseExpression(); + Expression parseExpression(); static std::map<std::string, dev::solidity::Instruction> const& instructions(); static std::map<dev::solidity::Instruction, std::string> const& instructionNames(); /// Parses an elementary operation, i.e. a literal, identifier or instruction. @@ -80,7 +76,7 @@ protected: ElementaryOperation parseElementaryOperation(); VariableDeclaration parseVariableDeclaration(); FunctionDefinition parseFunctionDefinition(); - assembly::Expression parseCall(ElementaryOperation&& _initialOp); + Expression parseCall(ElementaryOperation&& _initialOp); TypedName parseTypedName(); std::string expectAsmIdentifier(); @@ -91,5 +87,3 @@ private: }; } -} -} diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index 7151fcfa..eaaba9f3 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -20,8 +20,8 @@ * Converts a parsed assembly into its textual form. */ -#include <libsolidity/inlineasm/AsmPrinter.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmPrinter.h> +#include <libyul/AsmData.h> #include <liblangutil/Exceptions.h> #include <libdevcore/CommonData.h> @@ -35,19 +35,19 @@ using namespace std; using namespace dev; +using namespace yul; using namespace dev::solidity; -using namespace dev::solidity::assembly; //@TODO source locations -string AsmPrinter::operator()(assembly::Instruction const& _instruction) +string AsmPrinter::operator()(yul::Instruction const& _instruction) { solAssert(!m_yul, ""); solAssert(isValidInstruction(_instruction.instruction), "Invalid instruction"); return boost::to_lower_copy(instructionInfo(_instruction.instruction).name); } -string AsmPrinter::operator()(assembly::Literal const& _literal) +string AsmPrinter::operator()(Literal const& _literal) { switch (_literal.kind) { @@ -90,13 +90,13 @@ string AsmPrinter::operator()(assembly::Literal const& _literal) return "\"" + out + "\"" + appendTypeName(_literal.type); } -string AsmPrinter::operator()(assembly::Identifier const& _identifier) +string AsmPrinter::operator()(Identifier const& _identifier) { solAssert(!_identifier.name.empty(), "Invalid identifier."); return _identifier.name.str(); } -string AsmPrinter::operator()(assembly::FunctionalInstruction const& _functionalInstruction) +string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstruction) { solAssert(!m_yul, ""); solAssert(isValidInstruction(_functionalInstruction.instruction), "Invalid instruction"); @@ -114,21 +114,21 @@ string AsmPrinter::operator()(ExpressionStatement const& _statement) return boost::apply_visitor(*this, _statement.expression); } -string AsmPrinter::operator()(assembly::Label const& _label) +string AsmPrinter::operator()(Label const& _label) { solAssert(!m_yul, ""); solAssert(!_label.name.empty(), "Invalid label."); return _label.name.str() + ":"; } -string AsmPrinter::operator()(assembly::StackAssignment const& _assignment) +string AsmPrinter::operator()(StackAssignment const& _assignment) { solAssert(!m_yul, ""); solAssert(!_assignment.variableName.name.empty(), "Invalid variable name."); return "=: " + (*this)(_assignment.variableName); } -string AsmPrinter::operator()(assembly::Assignment const& _assignment) +string AsmPrinter::operator()(Assignment const& _assignment) { solAssert(_assignment.variableNames.size() >= 1, ""); string variables = (*this)(_assignment.variableNames.front()); @@ -137,7 +137,7 @@ string AsmPrinter::operator()(assembly::Assignment const& _assignment) return variables + " := " + boost::apply_visitor(*this, *_assignment.value); } -string AsmPrinter::operator()(assembly::VariableDeclaration const& _variableDeclaration) +string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) { string out = "let "; out += boost::algorithm::join( @@ -154,7 +154,7 @@ string AsmPrinter::operator()(assembly::VariableDeclaration const& _variableDecl return out; } -string AsmPrinter::operator()(assembly::FunctionDefinition const& _functionDefinition) +string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition) { solAssert(!_functionDefinition.name.empty(), "Invalid function name."); string out = "function " + _functionDefinition.name.str() + "("; @@ -179,7 +179,7 @@ string AsmPrinter::operator()(assembly::FunctionDefinition const& _functionDefin return out + "\n" + (*this)(_functionDefinition.body); } -string AsmPrinter::operator()(assembly::FunctionCall const& _functionCall) +string AsmPrinter::operator()(FunctionCall const& _functionCall) { return (*this)(_functionCall.functionName) + "(" + @@ -210,7 +210,7 @@ string AsmPrinter::operator()(Switch const& _switch) return out; } -string AsmPrinter::operator()(assembly::ForLoop const& _forLoop) +string AsmPrinter::operator()(ForLoop const& _forLoop) { solAssert(_forLoop.condition, "Invalid for loop condition."); string out = "for "; diff --git a/libyul/AsmPrinter.h b/libyul/AsmPrinter.h new file mode 100644 index 00000000..61dfc18c --- /dev/null +++ b/libyul/AsmPrinter.h @@ -0,0 +1,62 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see <http://www.gnu.org/licenses/>. +*/ +/** + * @author Christian <c@ethdev.com> + * @date 2017 + * Converts a parsed assembly into its textual form. + */ + +#pragma once + +#include <libyul/AsmDataForward.h> + +#include <libyul/YulString.h> + +#include <boost/variant.hpp> + +namespace yul +{ + +class AsmPrinter: public boost::static_visitor<std::string> +{ +public: + explicit AsmPrinter(bool _yul = false): m_yul(_yul) {} + + std::string operator()(Instruction const& _instruction); + std::string operator()(Literal const& _literal); + std::string operator()(Identifier const& _identifier); + std::string operator()(FunctionalInstruction const& _functionalInstruction); + std::string operator()(ExpressionStatement const& _expr); + std::string operator()(Label const& _label); + std::string operator()(StackAssignment const& _assignment); + std::string operator()(Assignment const& _assignment); + std::string operator()(VariableDeclaration const& _variableDeclaration); + std::string operator()(FunctionDefinition const& _functionDefinition); + std::string operator()(FunctionCall const& _functionCall); + std::string operator()(If const& _if); + std::string operator()(Switch const& _switch); + std::string operator()(ForLoop const& _forLoop); + std::string operator()(Block const& _block); + +private: + std::string formatTypedName(TypedName _variable) const; + std::string appendTypeName(YulString _type) const; + + bool m_yul = false; +}; + +} diff --git a/libsolidity/inlineasm/AsmScope.cpp b/libyul/AsmScope.cpp index 10893b96..b71f2367 100644 --- a/libsolidity/inlineasm/AsmScope.cpp +++ b/libyul/AsmScope.cpp @@ -18,13 +18,13 @@ * Scopes for identifiers. */ -#include <libsolidity/inlineasm/AsmScope.h> +#include <libyul/AsmScope.h> using namespace std; using namespace dev; -using namespace dev::solidity::assembly; +using namespace yul; -bool Scope::registerLabel(yul::YulString _name) +bool Scope::registerLabel(YulString _name) { if (exists(_name)) return false; @@ -32,7 +32,7 @@ bool Scope::registerLabel(yul::YulString _name) return true; } -bool Scope::registerVariable(yul::YulString _name, YulType const& _type) +bool Scope::registerVariable(YulString _name, YulType const& _type) { if (exists(_name)) return false; @@ -42,7 +42,7 @@ bool Scope::registerVariable(yul::YulString _name, YulType const& _type) return true; } -bool Scope::registerFunction(yul::YulString _name, std::vector<YulType> const& _arguments, std::vector<YulType> const& _returns) +bool Scope::registerFunction(YulString _name, std::vector<YulType> const& _arguments, std::vector<YulType> const& _returns) { if (exists(_name)) return false; @@ -50,7 +50,7 @@ bool Scope::registerFunction(yul::YulString _name, std::vector<YulType> const& _ return true; } -Scope::Identifier* Scope::lookup(yul::YulString _name) +Scope::Identifier* Scope::lookup(YulString _name) { bool crossedFunctionBoundary = false; for (Scope* s = this; s; s = s->superScope) @@ -70,7 +70,7 @@ Scope::Identifier* Scope::lookup(yul::YulString _name) return nullptr; } -bool Scope::exists(yul::YulString _name) const +bool Scope::exists(YulString _name) const { if (identifiers.count(_name)) return true; diff --git a/libsolidity/inlineasm/AsmScope.h b/libyul/AsmScope.h index 12c05716..2a8ef49e 100644 --- a/libsolidity/inlineasm/AsmScope.h +++ b/libyul/AsmScope.h @@ -32,16 +32,12 @@ #include <functional> #include <memory> -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { struct Scope { - using YulType = yul::YulString; + using YulType = YulString; using LabelID = size_t; struct Variable { YulType type; }; @@ -53,13 +49,13 @@ struct Scope }; using Identifier = boost::variant<Variable, Label, Function>; - using Visitor = GenericVisitor<Variable const, Label const, Function const>; - using NonconstVisitor = GenericVisitor<Variable, Label, Function>; + using Visitor = dev::GenericVisitor<Variable const, Label const, Function const>; + using NonconstVisitor = dev::GenericVisitor<Variable, Label, Function>; - bool registerVariable(yul::YulString _name, YulType const& _type); - bool registerLabel(yul::YulString _name); + bool registerVariable(YulString _name, YulType const& _type); + bool registerLabel(YulString _name); bool registerFunction( - yul::YulString _name, + YulString _name, std::vector<YulType> const& _arguments, std::vector<YulType> const& _returns ); @@ -69,12 +65,12 @@ struct Scope /// will any lookups across assembly boundaries. /// The pointer will be invalidated if the scope is modified. /// @param _crossedFunction if true, we already crossed a function boundary during recursive lookup - Identifier* lookup(yul::YulString _name); + Identifier* lookup(YulString _name); /// Looks up the identifier in this and super scopes (will not find variables across function /// boundaries and generally stops at assembly boundaries) and calls the visitor, returns /// false if not found. template <class V> - bool lookup(yul::YulString _name, V const& _visitor) + bool lookup(YulString _name, V const& _visitor) { if (Identifier* id = lookup(_name)) { @@ -86,7 +82,7 @@ struct Scope } /// @returns true if the name exists in this scope or in super scopes (also searches /// across function and assembly boundaries). - bool exists(yul::YulString _name) const; + bool exists(YulString _name) const; /// @returns the number of variables directly registered inside the scope. size_t numberOfVariables() const; @@ -97,9 +93,7 @@ struct Scope /// If true, variables from the super scope are not visible here (other identifiers are), /// but they are still taken into account to prevent shadowing. bool functionScope = false; - std::map<yul::YulString, Identifier> identifiers; + std::map<YulString, Identifier> identifiers; }; } -} -} diff --git a/libsolidity/inlineasm/AsmScopeFiller.cpp b/libyul/AsmScopeFiller.cpp index 09934bd8..ee797d6a 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.cpp +++ b/libyul/AsmScopeFiller.cpp @@ -18,11 +18,11 @@ * Module responsible for registering identifiers inside their scopes. */ -#include <libsolidity/inlineasm/AsmScopeFiller.h> +#include <libyul/AsmScopeFiller.h> -#include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/inlineasm/AsmScope.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> +#include <libyul/AsmData.h> +#include <libyul/AsmScope.h> +#include <libyul/AsmAnalysisInfo.h> #include <liblangutil/ErrorReporter.h> #include <liblangutil/Exceptions.h> @@ -37,8 +37,8 @@ using namespace std; using namespace dev; using namespace langutil; +using namespace yul; using namespace dev::solidity; -using namespace dev::solidity::assembly; ScopeFiller::ScopeFiller(AsmAnalysisInfo& _info, ErrorReporter& _errorReporter): m_info(_info), m_errorReporter(_errorReporter) @@ -65,7 +65,7 @@ bool ScopeFiller::operator()(Label const& _item) return true; } -bool ScopeFiller::operator()(assembly::VariableDeclaration const& _varDecl) +bool ScopeFiller::operator()(VariableDeclaration const& _varDecl) { for (auto const& variable: _varDecl.variables) if (!registerVariable(variable, _varDecl.location, *m_currentScope)) @@ -73,7 +73,7 @@ bool ScopeFiller::operator()(assembly::VariableDeclaration const& _varDecl) return true; } -bool ScopeFiller::operator()(assembly::FunctionDefinition const& _funDef) +bool ScopeFiller::operator()(FunctionDefinition const& _funDef) { bool success = true; vector<Scope::YulType> arguments; diff --git a/libsolidity/inlineasm/AsmScopeFiller.h b/libyul/AsmScopeFiller.h index 7454fd6c..e8fb88d5 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.h +++ b/libyul/AsmScopeFiller.h @@ -20,7 +20,7 @@ #pragma once -#include <libsolidity/inlineasm/AsmDataForward.h> +#include <libyul/AsmDataForward.h> #include <boost/variant.hpp> @@ -33,11 +33,7 @@ class ErrorReporter; struct SourceLocation; } -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { struct TypedName; @@ -53,21 +49,21 @@ class ScopeFiller: public boost::static_visitor<bool> public: ScopeFiller(AsmAnalysisInfo& _info, langutil::ErrorReporter& _errorReporter); - bool operator()(assembly::Instruction const&) { return true; } - bool operator()(assembly::Literal const&) { return true; } - bool operator()(assembly::Identifier const&) { return true; } - bool operator()(assembly::FunctionalInstruction const&) { return true; } - bool operator()(assembly::ExpressionStatement const& _expr); - bool operator()(assembly::Label const& _label); - bool operator()(assembly::StackAssignment const&) { return true; } - bool operator()(assembly::Assignment const&) { return true; } - bool operator()(assembly::VariableDeclaration const& _variableDeclaration); - bool operator()(assembly::FunctionDefinition const& _functionDefinition); - bool operator()(assembly::FunctionCall const&) { return true; } - bool operator()(assembly::If const& _if); - bool operator()(assembly::Switch const& _switch); - bool operator()(assembly::ForLoop const& _forLoop); - bool operator()(assembly::Block const& _block); + bool operator()(Instruction const&) { return true; } + bool operator()(Literal const&) { return true; } + bool operator()(Identifier const&) { return true; } + bool operator()(FunctionalInstruction const&) { return true; } + bool operator()(ExpressionStatement const& _expr); + bool operator()(Label const& _label); + bool operator()(StackAssignment const&) { return true; } + bool operator()(Assignment const&) { return true; } + bool operator()(VariableDeclaration const& _variableDeclaration); + bool operator()(FunctionDefinition const& _functionDefinition); + bool operator()(FunctionCall const&) { return true; } + bool operator()(If const& _if); + bool operator()(Switch const& _switch); + bool operator()(ForLoop const& _forLoop); + bool operator()(Block const& _block); private: bool registerVariable( @@ -76,7 +72,7 @@ private: Scope& _scope ); - Scope& scope(assembly::Block const* _block); + Scope& scope(Block const* _block); Scope* m_currentScope = nullptr; AsmAnalysisInfo& m_info; @@ -84,5 +80,3 @@ private: }; } -} -} diff --git a/libyul/CMakeLists.txt b/libyul/CMakeLists.txt new file mode 100644 index 00000000..8fbea689 --- /dev/null +++ b/libyul/CMakeLists.txt @@ -0,0 +1,43 @@ +add_library(yul + AsmAnalysis.cpp + AsmAnalysisInfo.cpp + AsmCodeGen.cpp + AsmParser.cpp + AsmPrinter.cpp + AsmScope.cpp + AsmScopeFiller.cpp + backends/evm/EVMAssembly.cpp + backends/evm/EVMCodeTransform.cpp + optimiser/ASTCopier.cpp + optimiser/ASTWalker.cpp + optimiser/BlockFlattener.cpp + optimiser/CommonSubexpressionEliminator.cpp + optimiser/DataFlowAnalyzer.cpp + optimiser/Disambiguator.cpp + optimiser/ExpressionInliner.cpp + optimiser/ExpressionJoiner.cpp + optimiser/ExpressionSimplifier.cpp + optimiser/ExpressionSplitter.cpp + optimiser/ForLoopInitRewriter.cpp + optimiser/FullInliner.cpp + optimiser/FunctionGrouper.cpp + optimiser/FunctionHoister.cpp + optimiser/InlinableExpressionFunctionFinder.cpp + optimiser/MainFunction.cpp + optimiser/Metrics.cpp + optimiser/NameCollector.cpp + optimiser/NameDispenser.cpp + optimiser/RedundantAssignEliminator.cpp + optimiser/Rematerialiser.cpp + optimiser/SSATransform.cpp + optimiser/SSAValueTracker.cpp + optimiser/Semantics.cpp + optimiser/SimplificationRules.cpp + optimiser/Substitution.cpp + optimiser/Suite.cpp + optimiser/SyntacticalEquality.cpp + optimiser/UnusedPruner.cpp + optimiser/Utilities.cpp + optimiser/VarDeclPropagator.cpp +) +target_link_libraries(yul PUBLIC devcore) diff --git a/libyul/Exceptions.h b/libyul/Exceptions.h index 0c421dbf..e10e53ef 100644 --- a/libyul/Exceptions.h +++ b/libyul/Exceptions.h @@ -23,18 +23,15 @@ #include <libdevcore/Exceptions.h> #include <libdevcore/Assertions.h> -namespace dev -{ namespace yul { -struct YulException: virtual Exception {}; +struct YulException: virtual dev::Exception {}; struct OptimizerException: virtual YulException {}; struct YulAssertion: virtual YulException {}; /// Assertion that throws an YulAssertion containing the given description if it is not met. #define yulAssert(CONDITION, DESCRIPTION) \ - assertThrow(CONDITION, ::dev::yul::YulException, DESCRIPTION) + assertThrow(CONDITION, ::yul::YulException, DESCRIPTION) } -} diff --git a/libyul/YulString.h b/libyul/YulString.h index ad900a70..2179c23b 100644 --- a/libyul/YulString.h +++ b/libyul/YulString.h @@ -27,8 +27,6 @@ #include <vector> #include <string> -namespace dev -{ namespace yul { @@ -130,4 +128,3 @@ private: }; } -} diff --git a/libyul/backends/evm/AbstractAssembly.h b/libyul/backends/evm/AbstractAssembly.h index 5a1140cb..97b1d305 100644 --- a/libyul/backends/evm/AbstractAssembly.h +++ b/libyul/backends/evm/AbstractAssembly.h @@ -22,6 +22,7 @@ #pragma once +#include <libdevcore/Common.h> #include <libdevcore/CommonData.h> #include <functional> @@ -36,14 +37,13 @@ namespace dev namespace solidity { enum class Instruction: uint8_t; -namespace assembly -{ -struct Instruction; -struct Identifier; } } + namespace yul { +struct Instruction; +struct Identifier; /// /// Assembly class that abstracts both the libevmasm assembly and the new Yul assembly. @@ -61,9 +61,9 @@ public: /// at the beginning. virtual int stackHeight() const = 0; /// Append an EVM instruction. - virtual void appendInstruction(solidity::Instruction _instruction) = 0; + virtual void appendInstruction(dev::solidity::Instruction _instruction) = 0; /// Append a constant. - virtual void appendConstant(u256 const& _constant) = 0; + virtual void appendConstant(dev::u256 const& _constant) = 0; /// Append a label. virtual void appendLabel(LabelID _labelId) = 0; /// Append a label reference. @@ -106,18 +106,15 @@ enum class IdentifierContext { LValue, RValue }; /// to inline assembly (not used in standalone assembly mode). struct ExternalIdentifierAccess { - using Resolver = std::function<size_t(solidity::assembly::Identifier const&, IdentifierContext, bool /*_crossesFunctionBoundary*/)>; + using Resolver = std::function<size_t(Identifier const&, IdentifierContext, bool /*_crossesFunctionBoundary*/)>; /// Resolve an external reference given by the identifier in the given context. /// @returns the size of the value (number of stack slots) or size_t(-1) if not found. Resolver resolve; - using CodeGenerator = std::function<void(solidity::assembly::Identifier const&, IdentifierContext, yul::AbstractAssembly&)>; + using CodeGenerator = std::function<void(Identifier const&, IdentifierContext, yul::AbstractAssembly&)>; /// Generate code for retrieving the value (rvalue context) or storing the value (lvalue context) /// of an identifier. The code should be appended to the assembly. In rvalue context, the value is supposed /// to be put onto the stack, in lvalue context, the value is assumed to be at the top of the stack. CodeGenerator generateCode; }; - - -} } diff --git a/libyul/backends/evm/EVMAssembly.cpp b/libyul/backends/evm/EVMAssembly.cpp index 791b6226..99506317 100644 --- a/libyul/backends/evm/EVMAssembly.cpp +++ b/libyul/backends/evm/EVMAssembly.cpp @@ -27,7 +27,7 @@ using namespace std; using namespace dev; using namespace langutil; -using namespace dev::yul; +using namespace yul; namespace { diff --git a/libyul/backends/evm/EVMAssembly.h b/libyul/backends/evm/EVMAssembly.h index c9190634..d0a437cc 100644 --- a/libyul/backends/evm/EVMAssembly.h +++ b/libyul/backends/evm/EVMAssembly.h @@ -31,8 +31,6 @@ namespace langutil struct SourceLocation; } -namespace dev -{ namespace yul { @@ -48,9 +46,9 @@ public: /// at the beginning. int stackHeight() const override { return m_stackHeight; } /// Append an EVM instruction. - void appendInstruction(solidity::Instruction _instruction) override; + void appendInstruction(dev::solidity::Instruction _instruction) override; /// Append a constant. - void appendConstant(u256 const& _constant) override; + void appendConstant(dev::u256 const& _constant) override; /// Append a label. void appendLabel(LabelID _labelId) override; /// Append a label reference. @@ -81,17 +79,17 @@ public: void appendAssemblySize() override; /// Resolves references inside the bytecode and returns the linker object. - eth::LinkerObject finalize(); + dev::eth::LinkerObject finalize(); private: void setLabelToCurrentPosition(AbstractAssembly::LabelID _labelId); void appendLabelReferenceInternal(AbstractAssembly::LabelID _labelId); - void updateReference(size_t pos, size_t size, u256 value); + void updateReference(size_t pos, size_t size, dev::u256 value); bool m_evm15 = false; ///< if true, switch to evm1.5 mode LabelID m_nextLabelId = 0; int m_stackHeight = 0; - bytes m_bytecode; + dev::bytes m_bytecode; std::map<std::string, LabelID> m_namedLabels; std::map<LabelID, size_t> m_labelPositions; std::map<size_t, LabelID> m_labelReferences; @@ -99,4 +97,3 @@ private: }; } -} diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index 23e09756..12abd754 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -20,8 +20,8 @@ #include <libyul/backends/evm/EVMCodeTransform.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmAnalysisInfo.h> +#include <libyul/AsmData.h> #include <liblangutil/Exceptions.h> @@ -29,11 +29,9 @@ using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; -using Scope = dev::solidity::assembly::Scope; - void CodeTransform::operator()(VariableDeclaration const& _varDecl) { solAssert(m_scope, ""); @@ -147,7 +145,7 @@ void CodeTransform::operator()(FunctionalInstruction const& _instruction) solAssert(_instruction.arguments.size() == 1, ""); } m_assembly.setSourceLocation(_instruction.location); - auto label = labelFromIdentifier(boost::get<assembly::Identifier>(_instruction.arguments.at(0))); + auto label = labelFromIdentifier(boost::get<Identifier>(_instruction.arguments.at(0))); if (isJumpI) m_assembly.appendJumpToIf(label); else @@ -163,7 +161,7 @@ void CodeTransform::operator()(FunctionalInstruction const& _instruction) checkStackHeight(&_instruction); } -void CodeTransform::operator()(assembly::Identifier const& _identifier) +void CodeTransform::operator()(Identifier const& _identifier) { m_assembly.setSourceLocation(_identifier.location); // First search internals, then externals. @@ -197,12 +195,12 @@ void CodeTransform::operator()(assembly::Identifier const& _identifier) checkStackHeight(&_identifier); } -void CodeTransform::operator()(assembly::Literal const& _literal) +void CodeTransform::operator()(Literal const& _literal) { m_assembly.setSourceLocation(_literal.location); - if (_literal.kind == assembly::LiteralKind::Number) + if (_literal.kind == LiteralKind::Number) m_assembly.appendConstant(u256(_literal.value.str())); - else if (_literal.kind == assembly::LiteralKind::Boolean) + else if (_literal.kind == LiteralKind::Boolean) { if (_literal.value.str() == "true") m_assembly.appendConstant(u256(1)); @@ -217,7 +215,7 @@ void CodeTransform::operator()(assembly::Literal const& _literal) checkStackHeight(&_literal); } -void CodeTransform::operator()(assembly::Instruction const& _instruction) +void CodeTransform::operator()(yul::Instruction const& _instruction) { solAssert(!m_evm15 || _instruction.instruction != solidity::Instruction::JUMP, "Bare JUMP instruction used for EVM1.5"); solAssert(!m_evm15 || _instruction.instruction != solidity::Instruction::JUMPI, "Bare JUMPI instruction used for EVM1.5"); @@ -522,7 +520,7 @@ void CodeTransform::generateAssignment(Identifier const& _variableName) } } -int CodeTransform::variableHeightDiff(solidity::assembly::Scope::Variable const& _var, bool _forSwap) const +int CodeTransform::variableHeightDiff(Scope::Variable const& _var, bool _forSwap) const { solAssert(m_context->variableStackHeights.count(&_var), ""); int heightDiff = m_assembly.stackHeight() - m_context->variableStackHeights[&_var]; diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h index c0de8ad6..d559f85a 100644 --- a/libyul/backends/evm/EVMCodeTransform.h +++ b/libyul/backends/evm/EVMCodeTransform.h @@ -20,25 +20,21 @@ #include <libyul/backends/evm/EVMAssembly.h> -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> -#include <libsolidity/inlineasm/AsmScope.h> +#include <libyul/AsmScope.h> #include <boost/variant.hpp> #include <boost/optional.hpp> -namespace dev -{ -namespace solidity +namespace langutil { class ErrorReporter; -namespace assembly -{ -struct AsmAnalysisInfo; -} } + namespace yul { +struct AsmAnalysisInfo; class EVMAssembly; class CodeTransform: public boost::static_visitor<> @@ -47,8 +43,8 @@ public: /// Create the code transformer. /// @param _identifierAccess used to resolve identifiers external to the inline assembly CodeTransform( - yul::AbstractAssembly& _assembly, - solidity::assembly::AsmAnalysisInfo& _analysisInfo, + AbstractAssembly& _assembly, + AsmAnalysisInfo& _analysisInfo, bool _yul = false, bool _evm15 = false, ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(), @@ -69,15 +65,14 @@ public: protected: struct Context { - using Scope = solidity::assembly::Scope; std::map<Scope::Label const*, AbstractAssembly::LabelID> labelIDs; std::map<Scope::Function const*, AbstractAssembly::LabelID> functionEntryIDs; std::map<Scope::Variable const*, int> variableStackHeights; }; CodeTransform( - yul::AbstractAssembly& _assembly, - solidity::assembly::AsmAnalysisInfo& _analysisInfo, + AbstractAssembly& _assembly, + AsmAnalysisInfo& _analysisInfo, bool _yul, bool _evm15, ExternalIdentifierAccess const& _identifierAccess, @@ -116,8 +111,8 @@ private: AbstractAssembly::LabelID labelFromIdentifier(Identifier const& _identifier); /// @returns the label ID corresponding to the given label, allocating a new one if /// necessary. - AbstractAssembly::LabelID labelID(solidity::assembly::Scope::Label const& _label); - AbstractAssembly::LabelID functionEntryID(YulString _name, solidity::assembly::Scope::Function const& _function); + AbstractAssembly::LabelID labelID(Scope::Label const& _label); + AbstractAssembly::LabelID functionEntryID(YulString _name, Scope::Function const& _function); /// Generates code for an expression that is supposed to return a single value. void visitExpression(Expression const& _expression); @@ -133,15 +128,15 @@ private: /// Determines the stack height difference to the given variables. Throws /// if it is not yet in scope or the height difference is too large. Returns /// the (positive) stack height difference otherwise. - int variableHeightDiff(solidity::assembly::Scope::Variable const& _var, bool _forSwap) const; + int variableHeightDiff(Scope::Variable const& _var, bool _forSwap) const; void expectDeposit(int _deposit, int _oldHeight) const; void checkStackHeight(void const* _astElement) const; - yul::AbstractAssembly& m_assembly; - solidity::assembly::AsmAnalysisInfo& m_info; - solidity::assembly::Scope* m_scope = nullptr; + AbstractAssembly& m_assembly; + AsmAnalysisInfo& m_info; + Scope* m_scope = nullptr; bool m_yul = false; bool m_evm15 = false; bool m_useNamedLabelsForFunctions = false; @@ -155,4 +150,3 @@ private: }; } -} diff --git a/libyul/optimiser/ASTCopier.cpp b/libyul/optimiser/ASTCopier.cpp index d0c8dd45..f18b0e6b 100644 --- a/libyul/optimiser/ASTCopier.cpp +++ b/libyul/optimiser/ASTCopier.cpp @@ -22,13 +22,13 @@ #include <libyul/Exceptions.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/Common.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; Statement ASTCopier::operator()(Instruction const&) { diff --git a/libyul/optimiser/ASTCopier.h b/libyul/optimiser/ASTCopier.h index 95e58a56..4d2f18ae 100644 --- a/libyul/optimiser/ASTCopier.h +++ b/libyul/optimiser/ASTCopier.h @@ -20,7 +20,7 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/YulString.h> @@ -31,8 +31,6 @@ #include <set> #include <memory> -namespace dev -{ namespace yul { @@ -123,4 +121,3 @@ std::vector<T> ASTCopier::translateVector(std::vector<T> const& _values) } -} diff --git a/libyul/optimiser/ASTWalker.cpp b/libyul/optimiser/ASTWalker.cpp index e29dda6b..0d568007 100644 --- a/libyul/optimiser/ASTWalker.cpp +++ b/libyul/optimiser/ASTWalker.cpp @@ -20,13 +20,13 @@ #include <libyul/optimiser/ASTWalker.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <boost/range/adaptor/reversed.hpp> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; diff --git a/libyul/optimiser/ASTWalker.h b/libyul/optimiser/ASTWalker.h index 38cb85ea..b59b405e 100644 --- a/libyul/optimiser/ASTWalker.h +++ b/libyul/optimiser/ASTWalker.h @@ -20,7 +20,7 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/Exceptions.h> #include <libyul/YulString.h> @@ -32,8 +32,6 @@ #include <set> #include <map> -namespace dev -{ namespace yul { @@ -120,4 +118,3 @@ protected: }; } -} diff --git a/libyul/optimiser/BlockFlattener.cpp b/libyul/optimiser/BlockFlattener.cpp index 04f3ad7f..e6f08524 100644 --- a/libyul/optimiser/BlockFlattener.cpp +++ b/libyul/optimiser/BlockFlattener.cpp @@ -15,14 +15,14 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ #include <libyul/optimiser/BlockFlattener.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/Visitor.h> #include <libdevcore/CommonData.h> #include <functional> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void BlockFlattener::operator()(Block& _block) { diff --git a/libyul/optimiser/BlockFlattener.h b/libyul/optimiser/BlockFlattener.h index 88c49dda..b732422d 100644 --- a/libyul/optimiser/BlockFlattener.h +++ b/libyul/optimiser/BlockFlattener.h @@ -18,8 +18,6 @@ #include <libyul/optimiser/ASTWalker.h> -namespace dev -{ namespace yul { @@ -31,4 +29,3 @@ public: }; } -} diff --git a/libyul/optimiser/CommonSubexpressionEliminator.cpp b/libyul/optimiser/CommonSubexpressionEliminator.cpp index 64605362..9b851333 100644 --- a/libyul/optimiser/CommonSubexpressionEliminator.cpp +++ b/libyul/optimiser/CommonSubexpressionEliminator.cpp @@ -24,12 +24,11 @@ #include <libyul/optimiser/Metrics.h> #include <libyul/optimiser/SyntacticalEquality.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void CommonSubexpressionEliminator::visit(Expression& _e) { diff --git a/libyul/optimiser/CommonSubexpressionEliminator.h b/libyul/optimiser/CommonSubexpressionEliminator.h index 16b39f5b..ac1ebe3a 100644 --- a/libyul/optimiser/CommonSubexpressionEliminator.h +++ b/libyul/optimiser/CommonSubexpressionEliminator.h @@ -23,8 +23,6 @@ #include <libyul/optimiser/DataFlowAnalyzer.h> -namespace dev -{ namespace yul { @@ -42,4 +40,3 @@ protected: }; } -} diff --git a/libyul/optimiser/DataFlowAnalyzer.cpp b/libyul/optimiser/DataFlowAnalyzer.cpp index 134777d0..64c67b38 100644 --- a/libyul/optimiser/DataFlowAnalyzer.cpp +++ b/libyul/optimiser/DataFlowAnalyzer.cpp @@ -25,8 +25,7 @@ #include <libyul/optimiser/NameCollector.h> #include <libyul/optimiser/Semantics.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> @@ -34,7 +33,7 @@ using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void DataFlowAnalyzer::operator()(Assignment& _assignment) { diff --git a/libyul/optimiser/DataFlowAnalyzer.h b/libyul/optimiser/DataFlowAnalyzer.h index a946529a..cd134d48 100644 --- a/libyul/optimiser/DataFlowAnalyzer.h +++ b/libyul/optimiser/DataFlowAnalyzer.h @@ -23,14 +23,11 @@ #pragma once #include <libyul/optimiser/ASTWalker.h> - #include <libyul/YulString.h> #include <map> #include <set> -namespace dev -{ namespace yul { @@ -88,4 +85,3 @@ protected: }; } -} diff --git a/libyul/optimiser/Disambiguator.cpp b/libyul/optimiser/Disambiguator.cpp index 4303f412..fda5895b 100644 --- a/libyul/optimiser/Disambiguator.cpp +++ b/libyul/optimiser/Disambiguator.cpp @@ -21,17 +21,14 @@ #include <libyul/optimiser/Disambiguator.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/inlineasm/AsmScope.h> +#include <libyul/AsmData.h> +#include <libyul/AsmScope.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; -using Scope = dev::solidity::assembly::Scope; - YulString Disambiguator::translateIdentifier(YulString _originalName) { if ((m_externallyUsedIdentifiers.count(_originalName))) diff --git a/libyul/optimiser/Disambiguator.h b/libyul/optimiser/Disambiguator.h index 0fcd41d9..bb83417b 100644 --- a/libyul/optimiser/Disambiguator.h +++ b/libyul/optimiser/Disambiguator.h @@ -20,20 +20,16 @@ #pragma once -#include <libyul/ASTDataForward.h> - +#include <libyul/AsmDataForward.h> +#include <libyul/AsmAnalysisInfo.h> #include <libyul/optimiser/ASTCopier.h> #include <libyul/optimiser/NameDispenser.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> - #include <boost/variant.hpp> #include <boost/optional.hpp> #include <set> -namespace dev -{ namespace yul { @@ -44,7 +40,7 @@ class Disambiguator: public ASTCopier { public: explicit Disambiguator( - solidity::assembly::AsmAnalysisInfo const& _analysisInfo, + AsmAnalysisInfo const& _analysisInfo, std::set<YulString> const& _externallyUsedIdentifiers = {} ): m_info(_analysisInfo), m_externallyUsedIdentifiers(_externallyUsedIdentifiers), m_nameDispenser(m_externallyUsedIdentifiers) @@ -58,16 +54,15 @@ protected: void leaveFunction(FunctionDefinition const& _function) override; YulString translateIdentifier(YulString _name) override; - void enterScopeInternal(solidity::assembly::Scope& _scope); - void leaveScopeInternal(solidity::assembly::Scope& _scope); + void enterScopeInternal(Scope& _scope); + void leaveScopeInternal(Scope& _scope); - solidity::assembly::AsmAnalysisInfo const& m_info; + AsmAnalysisInfo const& m_info; std::set<YulString> const& m_externallyUsedIdentifiers; - std::vector<solidity::assembly::Scope*> m_scopes; + std::vector<Scope*> m_scopes; std::map<void const*, YulString> m_translations; NameDispenser m_nameDispenser; }; } -} diff --git a/libyul/optimiser/ExpressionInliner.cpp b/libyul/optimiser/ExpressionInliner.cpp index 07e88191..27d43ac0 100644 --- a/libyul/optimiser/ExpressionInliner.cpp +++ b/libyul/optimiser/ExpressionInliner.cpp @@ -23,14 +23,13 @@ #include <libyul/optimiser/InlinableExpressionFunctionFinder.h> #include <libyul/optimiser/Substitution.h> #include <libyul/optimiser/Semantics.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <boost/algorithm/cxx11/all_of.hpp> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; void ExpressionInliner::run() diff --git a/libyul/optimiser/ExpressionInliner.h b/libyul/optimiser/ExpressionInliner.h index ee98da8f..14e80c0a 100644 --- a/libyul/optimiser/ExpressionInliner.h +++ b/libyul/optimiser/ExpressionInliner.h @@ -20,16 +20,13 @@ #pragma once #include <libyul/optimiser/ASTWalker.h> - -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <boost/variant.hpp> #include <boost/optional.hpp> #include <set> -namespace dev -{ namespace yul { @@ -69,4 +66,3 @@ private: } -} diff --git a/libyul/optimiser/ExpressionJoiner.cpp b/libyul/optimiser/ExpressionJoiner.cpp index 7e57a629..de2b5d53 100644 --- a/libyul/optimiser/ExpressionJoiner.cpp +++ b/libyul/optimiser/ExpressionJoiner.cpp @@ -24,8 +24,7 @@ #include <libyul/optimiser/NameCollector.h> #include <libyul/optimiser/Utilities.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> @@ -33,7 +32,7 @@ using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; void ExpressionJoiner::operator()(FunctionalInstruction& _instruction) diff --git a/libyul/optimiser/ExpressionJoiner.h b/libyul/optimiser/ExpressionJoiner.h index 0cc61981..643d62b0 100644 --- a/libyul/optimiser/ExpressionJoiner.h +++ b/libyul/optimiser/ExpressionJoiner.h @@ -20,14 +20,11 @@ */ #pragma once -#include <libyul/ASTDataForward.h> - +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTWalker.h> #include <map> -namespace dev -{ namespace yul { @@ -99,4 +96,3 @@ private: }; } -} diff --git a/libyul/optimiser/ExpressionSimplifier.cpp b/libyul/optimiser/ExpressionSimplifier.cpp index 64e9d7e7..cda44e8e 100644 --- a/libyul/optimiser/ExpressionSimplifier.cpp +++ b/libyul/optimiser/ExpressionSimplifier.cpp @@ -23,14 +23,13 @@ #include <libyul/optimiser/SimplificationRules.h> #include <libyul/optimiser/Semantics.h> #include <libyul/optimiser/SSAValueTracker.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; diff --git a/libyul/optimiser/ExpressionSimplifier.h b/libyul/optimiser/ExpressionSimplifier.h index 5965a1bb..fe3507f8 100644 --- a/libyul/optimiser/ExpressionSimplifier.h +++ b/libyul/optimiser/ExpressionSimplifier.h @@ -20,12 +20,10 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTWalker.h> -namespace dev -{ namespace yul { @@ -52,4 +50,3 @@ private: }; } -} diff --git a/libyul/optimiser/ExpressionSplitter.cpp b/libyul/optimiser/ExpressionSplitter.cpp index 42730864..a3b2dc11 100644 --- a/libyul/optimiser/ExpressionSplitter.cpp +++ b/libyul/optimiser/ExpressionSplitter.cpp @@ -23,7 +23,7 @@ #include <libyul/optimiser/ASTWalker.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> @@ -32,7 +32,7 @@ using namespace std; using namespace dev; using namespace langutil; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; void ExpressionSplitter::operator()(FunctionalInstruction& _instruction) diff --git a/libyul/optimiser/ExpressionSplitter.h b/libyul/optimiser/ExpressionSplitter.h index 82274203..d4d2b3f6 100644 --- a/libyul/optimiser/ExpressionSplitter.h +++ b/libyul/optimiser/ExpressionSplitter.h @@ -20,15 +20,13 @@ */ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTWalker.h> #include <libyul/optimiser/NameDispenser.h> #include <vector> -namespace dev -{ namespace yul { @@ -83,4 +81,3 @@ private: }; } -} diff --git a/libyul/optimiser/ForLoopInitRewriter.cpp b/libyul/optimiser/ForLoopInitRewriter.cpp index 0decf5e2..80d39248 100644 --- a/libyul/optimiser/ForLoopInitRewriter.cpp +++ b/libyul/optimiser/ForLoopInitRewriter.cpp @@ -15,13 +15,13 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ #include <libyul/optimiser/ForLoopInitRewriter.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> #include <functional> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void ForLoopInitRewriter::operator()(Block& _block) { diff --git a/libyul/optimiser/ForLoopInitRewriter.h b/libyul/optimiser/ForLoopInitRewriter.h index 64f53711..e925c6c2 100644 --- a/libyul/optimiser/ForLoopInitRewriter.h +++ b/libyul/optimiser/ForLoopInitRewriter.h @@ -18,8 +18,6 @@ #include <libyul/optimiser/ASTWalker.h> -namespace dev -{ namespace yul { @@ -36,4 +34,3 @@ public: }; } -} diff --git a/libyul/optimiser/FullInliner.cpp b/libyul/optimiser/FullInliner.cpp index c9057cf3..8ae26fbb 100644 --- a/libyul/optimiser/FullInliner.cpp +++ b/libyul/optimiser/FullInliner.cpp @@ -27,8 +27,7 @@ #include <libyul/optimiser/Metrics.h> #include <libyul/optimiser/SSAValueTracker.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> #include <libdevcore/Visitor.h> @@ -37,7 +36,7 @@ using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser): diff --git a/libyul/optimiser/FullInliner.h b/libyul/optimiser/FullInliner.h index 5ebb3bf6..a8fe76c6 100644 --- a/libyul/optimiser/FullInliner.h +++ b/libyul/optimiser/FullInliner.h @@ -19,7 +19,7 @@ */ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTCopier.h> #include <libyul/optimiser/ASTWalker.h> @@ -33,8 +33,6 @@ #include <set> -namespace dev -{ namespace yul { @@ -153,4 +151,3 @@ public: } -} diff --git a/libyul/optimiser/FunctionGrouper.cpp b/libyul/optimiser/FunctionGrouper.cpp index 3d2e5322..02ce22cd 100644 --- a/libyul/optimiser/FunctionGrouper.cpp +++ b/libyul/optimiser/FunctionGrouper.cpp @@ -21,13 +21,13 @@ #include <libyul/optimiser/FunctionGrouper.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <boost/range/algorithm_ext/erase.hpp> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; diff --git a/libyul/optimiser/FunctionGrouper.h b/libyul/optimiser/FunctionGrouper.h index 63cfbfb1..3b3f48a7 100644 --- a/libyul/optimiser/FunctionGrouper.h +++ b/libyul/optimiser/FunctionGrouper.h @@ -21,10 +21,8 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> -namespace dev -{ namespace yul { @@ -43,4 +41,3 @@ public: }; } -} diff --git a/libyul/optimiser/FunctionHoister.cpp b/libyul/optimiser/FunctionHoister.cpp index c196dead..bd1c781b 100644 --- a/libyul/optimiser/FunctionHoister.cpp +++ b/libyul/optimiser/FunctionHoister.cpp @@ -22,14 +22,13 @@ #include <libyul/optimiser/FunctionHoister.h> #include <libyul/optimiser/Utilities.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; void FunctionHoister::operator()(Block& _block) diff --git a/libyul/optimiser/FunctionHoister.h b/libyul/optimiser/FunctionHoister.h index 823b9e2b..31092069 100644 --- a/libyul/optimiser/FunctionHoister.h +++ b/libyul/optimiser/FunctionHoister.h @@ -21,12 +21,9 @@ #pragma once -#include <libyul/ASTDataForward.h> - +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTWalker.h> -namespace dev -{ namespace yul { @@ -49,4 +46,3 @@ private: }; } -} diff --git a/libyul/optimiser/InlinableExpressionFunctionFinder.cpp b/libyul/optimiser/InlinableExpressionFunctionFinder.cpp index deaaee97..662cdf25 100644 --- a/libyul/optimiser/InlinableExpressionFunctionFinder.cpp +++ b/libyul/optimiser/InlinableExpressionFunctionFinder.cpp @@ -21,12 +21,11 @@ #include <libyul/optimiser/InlinableExpressionFunctionFinder.h> #include <libyul/optimiser/Utilities.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void InlinableExpressionFunctionFinder::operator()(Identifier const& _identifier) { diff --git a/libyul/optimiser/InlinableExpressionFunctionFinder.h b/libyul/optimiser/InlinableExpressionFunctionFinder.h index a96f042f..afde8a2a 100644 --- a/libyul/optimiser/InlinableExpressionFunctionFinder.h +++ b/libyul/optimiser/InlinableExpressionFunctionFinder.h @@ -20,13 +20,11 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTWalker.h> #include <set> -namespace dev -{ namespace yul { @@ -66,4 +64,3 @@ private: }; } -} diff --git a/libyul/optimiser/MainFunction.cpp b/libyul/optimiser/MainFunction.cpp index f3306598..63eea2db 100644 --- a/libyul/optimiser/MainFunction.cpp +++ b/libyul/optimiser/MainFunction.cpp @@ -24,13 +24,13 @@ #include <libyul/optimiser/NameCollector.h> #include <libyul/Exceptions.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; void MainFunction::operator()(Block& _block) diff --git a/libyul/optimiser/MainFunction.h b/libyul/optimiser/MainFunction.h index 4a73283a..96acc0ac 100644 --- a/libyul/optimiser/MainFunction.h +++ b/libyul/optimiser/MainFunction.h @@ -21,10 +21,8 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> -namespace dev -{ namespace yul { @@ -38,4 +36,3 @@ public: }; } -} diff --git a/libyul/optimiser/Metrics.cpp b/libyul/optimiser/Metrics.cpp index 066c6b58..a5557fb3 100644 --- a/libyul/optimiser/Metrics.cpp +++ b/libyul/optimiser/Metrics.cpp @@ -20,10 +20,10 @@ #include <libyul/optimiser/Metrics.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> using namespace dev; -using namespace dev::yul; +using namespace yul; size_t CodeSize::codeSize(Statement const& _statement) { diff --git a/libyul/optimiser/Metrics.h b/libyul/optimiser/Metrics.h index e65110a8..ca244600 100644 --- a/libyul/optimiser/Metrics.h +++ b/libyul/optimiser/Metrics.h @@ -22,8 +22,6 @@ #include <libyul/optimiser/ASTWalker.h> -namespace dev -{ namespace yul { @@ -49,4 +47,3 @@ private: }; } -} diff --git a/libyul/optimiser/NameCollector.cpp b/libyul/optimiser/NameCollector.cpp index 36f55b99..f9079827 100644 --- a/libyul/optimiser/NameCollector.cpp +++ b/libyul/optimiser/NameCollector.cpp @@ -20,11 +20,11 @@ #include <libyul/optimiser/NameCollector.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void NameCollector::operator()(VariableDeclaration const& _varDecl) { diff --git a/libyul/optimiser/NameCollector.h b/libyul/optimiser/NameCollector.h index 8ef0178d..c177a399 100644 --- a/libyul/optimiser/NameCollector.h +++ b/libyul/optimiser/NameCollector.h @@ -25,8 +25,6 @@ #include <map> #include <set> -namespace dev -{ namespace yul { @@ -83,4 +81,3 @@ private: }; } -} diff --git a/libyul/optimiser/NameDispenser.cpp b/libyul/optimiser/NameDispenser.cpp index 3c870fa5..e7cdc60f 100644 --- a/libyul/optimiser/NameDispenser.cpp +++ b/libyul/optimiser/NameDispenser.cpp @@ -21,12 +21,11 @@ #include <libyul/optimiser/NameDispenser.h> #include <libyul/optimiser/NameCollector.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; NameDispenser::NameDispenser(Block const& _ast): NameDispenser(NameCollector(_ast).names()) diff --git a/libyul/optimiser/NameDispenser.h b/libyul/optimiser/NameDispenser.h index 7311440b..664a5265 100644 --- a/libyul/optimiser/NameDispenser.h +++ b/libyul/optimiser/NameDispenser.h @@ -19,14 +19,12 @@ */ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/YulString.h> #include <set> -namespace dev -{ namespace yul { @@ -58,4 +56,3 @@ private: }; } -} diff --git a/libyul/optimiser/RedundantAssignEliminator.cpp b/libyul/optimiser/RedundantAssignEliminator.cpp index b7217074..7b18e8ca 100644 --- a/libyul/optimiser/RedundantAssignEliminator.cpp +++ b/libyul/optimiser/RedundantAssignEliminator.cpp @@ -22,8 +22,7 @@ #include <libyul/optimiser/RedundantAssignEliminator.h> #include <libyul/optimiser/Semantics.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> @@ -31,7 +30,7 @@ using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; void RedundantAssignEliminator::operator()(Identifier const& _identifier) diff --git a/libyul/optimiser/RedundantAssignEliminator.h b/libyul/optimiser/RedundantAssignEliminator.h index 76106aae..54d65823 100644 --- a/libyul/optimiser/RedundantAssignEliminator.h +++ b/libyul/optimiser/RedundantAssignEliminator.h @@ -21,14 +21,11 @@ #pragma once -#include <libyul/ASTDataForward.h> - +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTWalker.h> #include <map> -namespace dev -{ namespace yul { @@ -190,4 +187,3 @@ private: }; } -} diff --git a/libyul/optimiser/Rematerialiser.cpp b/libyul/optimiser/Rematerialiser.cpp index 38d50ef4..4180bfc3 100644 --- a/libyul/optimiser/Rematerialiser.cpp +++ b/libyul/optimiser/Rematerialiser.cpp @@ -23,12 +23,11 @@ #include <libyul/optimiser/Metrics.h> #include <libyul/optimiser/ASTCopier.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void Rematerialiser::visit(Expression& _e) { diff --git a/libyul/optimiser/Rematerialiser.h b/libyul/optimiser/Rematerialiser.h index f0e7cb01..b3841519 100644 --- a/libyul/optimiser/Rematerialiser.h +++ b/libyul/optimiser/Rematerialiser.h @@ -22,8 +22,6 @@ #include <libyul/optimiser/DataFlowAnalyzer.h> -namespace dev -{ namespace yul { @@ -41,4 +39,3 @@ protected: }; } -} diff --git a/libyul/optimiser/SSATransform.cpp b/libyul/optimiser/SSATransform.cpp index 6fb4b08d..928c0859 100644 --- a/libyul/optimiser/SSATransform.cpp +++ b/libyul/optimiser/SSATransform.cpp @@ -23,8 +23,7 @@ #include <libyul/optimiser/NameCollector.h> #include <libyul/optimiser/NameDispenser.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> @@ -32,7 +31,7 @@ using namespace std; using namespace dev; using namespace langutil; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; void SSATransform::operator()(Identifier& _identifier) diff --git a/libyul/optimiser/SSATransform.h b/libyul/optimiser/SSATransform.h index bb642549..4cb62f23 100644 --- a/libyul/optimiser/SSATransform.h +++ b/libyul/optimiser/SSATransform.h @@ -20,14 +20,11 @@ */ #pragma once -#include <libyul/ASTDataForward.h> - +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTWalker.h> #include <vector> -namespace dev -{ namespace yul { @@ -95,4 +92,3 @@ private: }; } -} diff --git a/libyul/optimiser/SSAValueTracker.cpp b/libyul/optimiser/SSAValueTracker.cpp index 491117da..35b29b04 100644 --- a/libyul/optimiser/SSAValueTracker.cpp +++ b/libyul/optimiser/SSAValueTracker.cpp @@ -21,11 +21,11 @@ #include <libyul/optimiser/SSAValueTracker.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void SSAValueTracker::operator()(Assignment const& _assignment) { diff --git a/libyul/optimiser/SSAValueTracker.h b/libyul/optimiser/SSAValueTracker.h index acd5229c..e182e013 100644 --- a/libyul/optimiser/SSAValueTracker.h +++ b/libyul/optimiser/SSAValueTracker.h @@ -26,8 +26,6 @@ #include <map> #include <set> -namespace dev -{ namespace yul { @@ -54,4 +52,3 @@ private: }; } -} diff --git a/libyul/optimiser/Semantics.cpp b/libyul/optimiser/Semantics.cpp index 3c49016e..91bb2709 100644 --- a/libyul/optimiser/Semantics.cpp +++ b/libyul/optimiser/Semantics.cpp @@ -21,8 +21,7 @@ #include <libyul/optimiser/Semantics.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libevmasm/SemanticInformation.h> @@ -30,7 +29,7 @@ using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; MovableChecker::MovableChecker(Expression const& _expression) { diff --git a/libyul/optimiser/Semantics.h b/libyul/optimiser/Semantics.h index a7e8706b..70c50806 100644 --- a/libyul/optimiser/Semantics.h +++ b/libyul/optimiser/Semantics.h @@ -24,8 +24,6 @@ #include <set> -namespace dev -{ namespace yul { @@ -57,4 +55,3 @@ private: }; } -} diff --git a/libyul/optimiser/SimplificationRules.cpp b/libyul/optimiser/SimplificationRules.cpp index a15ed391..b3190fef 100644 --- a/libyul/optimiser/SimplificationRules.cpp +++ b/libyul/optimiser/SimplificationRules.cpp @@ -24,15 +24,14 @@ #include <libyul/optimiser/ASTCopier.h> #include <libyul/optimiser/Semantics.h> #include <libyul/optimiser/SyntacticalEquality.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libevmasm/RuleList.h> using namespace std; using namespace dev; using namespace langutil; -using namespace dev::yul; +using namespace yul; SimplificationRule<Pattern> const* SimplificationRules::findFirstMatch( @@ -124,7 +123,7 @@ bool Pattern::matches(Expression const& _expr, map<YulString, Expression const*> if (expr->type() != typeid(Literal)) return false; Literal const& literal = boost::get<Literal>(*expr); - if (literal.kind != assembly::LiteralKind::Number) + if (literal.kind != LiteralKind::Number) return false; if (m_data && *m_data != u256(literal.value.str())) return false; @@ -194,7 +193,7 @@ Expression Pattern::toExpression(SourceLocation const& _location) const if (m_kind == PatternKind::Constant) { assertThrow(m_data, OptimizerException, "No match group and no constant value given."); - return Literal{_location, assembly::LiteralKind::Number, YulString{formatNumber(*m_data)}, {}}; + return Literal{_location, LiteralKind::Number, YulString{formatNumber(*m_data)}, {}}; } else if (m_kind == PatternKind::Operation) { @@ -209,7 +208,7 @@ Expression Pattern::toExpression(SourceLocation const& _location) const u256 Pattern::d() const { Literal const& literal = boost::get<Literal>(matchGroupValue()); - assertThrow(literal.kind == assembly::LiteralKind::Number, OptimizerException, ""); + assertThrow(literal.kind == LiteralKind::Number, OptimizerException, ""); assertThrow(isValidDecimal(literal.value.str()) || isValidHex(literal.value.str()), OptimizerException, ""); return u256(literal.value.str()); } diff --git a/libyul/optimiser/SimplificationRules.h b/libyul/optimiser/SimplificationRules.h index bd6aa4de..16aaba04 100644 --- a/libyul/optimiser/SimplificationRules.h +++ b/libyul/optimiser/SimplificationRules.h @@ -23,17 +23,14 @@ #include <libevmasm/ExpressionClasses.h> #include <libevmasm/SimplificationRule.h> -#include <libyul/ASTDataForward.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmDataForward.h> +#include <libyul/AsmData.h> #include <boost/noncopyable.hpp> #include <functional> #include <vector> -namespace dev -{ namespace yul { @@ -86,11 +83,11 @@ public: /// Matches any expression. Pattern(PatternKind _kind = PatternKind::Any): m_kind(_kind) {} // Matches a specific constant value. - Pattern(unsigned _value): Pattern(u256(_value)) {} + Pattern(unsigned _value): Pattern(dev::u256(_value)) {} // Matches a specific constant value. - Pattern(u256 const& _value): m_kind(PatternKind::Constant), m_data(std::make_shared<u256>(_value)) {} + Pattern(dev::u256 const& _value): m_kind(PatternKind::Constant), m_data(std::make_shared<dev::u256>(_value)) {} // Matches a given instruction with given arguments - Pattern(solidity::Instruction _instruction, std::vector<Pattern> const& _arguments = {}); + Pattern(dev::solidity::Instruction _instruction, std::vector<Pattern> const& _arguments = {}); /// Sets this pattern to be part of the match group with the identifier @a _group. /// Inside one rule, all patterns in the same match group have to match expressions from the /// same expression equivalence class. @@ -101,9 +98,9 @@ public: std::vector<Pattern> arguments() const { return m_arguments; } /// @returns the data of the matched expression if this pattern is part of a match group. - u256 d() const; + dev::u256 d() const; - solidity::Instruction instruction() const; + dev::solidity::Instruction instruction() const; /// Turns this pattern into an actual expression. Should only be called /// for patterns resulting from an action, i.e. with match groups assigned. @@ -113,12 +110,11 @@ private: Expression const& matchGroupValue() const; PatternKind m_kind = PatternKind::Any; - solidity::Instruction m_instruction; ///< Only valid if m_kind is Operation - std::shared_ptr<u256> m_data; ///< Only valid if m_kind is Constant + dev::solidity::Instruction m_instruction; ///< Only valid if m_kind is Operation + std::shared_ptr<dev::u256> m_data; ///< Only valid if m_kind is Constant std::vector<Pattern> m_arguments; unsigned m_matchGroup = 0; std::map<unsigned, Expression const*>* m_matchGroups = nullptr; }; } -} diff --git a/libyul/optimiser/Substitution.cpp b/libyul/optimiser/Substitution.cpp index 9b3d4c03..bc9efe96 100644 --- a/libyul/optimiser/Substitution.cpp +++ b/libyul/optimiser/Substitution.cpp @@ -20,11 +20,11 @@ #include <libyul/optimiser/Substitution.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; Expression Substitution::translate(Expression const& _expression) { diff --git a/libyul/optimiser/Substitution.h b/libyul/optimiser/Substitution.h index 3cc4b45e..41f73b92 100644 --- a/libyul/optimiser/Substitution.h +++ b/libyul/optimiser/Substitution.h @@ -21,13 +21,10 @@ #pragma once #include <libyul/optimiser/ASTCopier.h> - #include <libyul/YulString.h> #include <map> -namespace dev -{ namespace yul { @@ -47,4 +44,3 @@ private: }; } -} diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index 4d6dad45..36f0e1eb 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -35,21 +35,19 @@ #include <libyul/optimiser/SSATransform.h> #include <libyul/optimiser/RedundantAssignEliminator.h> #include <libyul/optimiser/VarDeclPropagator.h> - -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/inlineasm/AsmData.h> - -#include <libsolidity/inlineasm/AsmPrinter.h> +#include <libyul/AsmAnalysisInfo.h> +#include <libyul/AsmData.h> +#include <libyul/AsmPrinter.h> #include <libdevcore/CommonData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; void OptimiserSuite::run( Block& _ast, - solidity::assembly::AsmAnalysisInfo const& _analysisInfo, + AsmAnalysisInfo const& _analysisInfo, set<YulString> const& _externallyUsedIdentifiers ) { diff --git a/libyul/optimiser/Suite.h b/libyul/optimiser/Suite.h index 5b564c56..795326b4 100644 --- a/libyul/optimiser/Suite.h +++ b/libyul/optimiser/Suite.h @@ -20,23 +20,16 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/YulString.h> #include <set> -namespace dev -{ -namespace solidity -{ -namespace assembly -{ -struct AsmAnalysisInfo; -} -} namespace yul { +struct AsmAnalysisInfo; + /** * Optimiser suite that combines all steps and also provides the settings for the heuristics */ @@ -45,11 +38,10 @@ class OptimiserSuite public: static void run( Block& _ast, - solidity::assembly::AsmAnalysisInfo const& _analysisInfo, + AsmAnalysisInfo const& _analysisInfo, std::set<YulString> const& _externallyUsedIdentifiers = {} ); }; } -} diff --git a/libyul/optimiser/SyntacticalEquality.cpp b/libyul/optimiser/SyntacticalEquality.cpp index 66912383..99ce06e5 100644 --- a/libyul/optimiser/SyntacticalEquality.cpp +++ b/libyul/optimiser/SyntacticalEquality.cpp @@ -21,14 +21,13 @@ #include <libyul/optimiser/SyntacticalEquality.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; bool SyntacticalEqualityChecker::equal(Expression const& _e1, Expression const& _e2) { diff --git a/libyul/optimiser/SyntacticalEquality.h b/libyul/optimiser/SyntacticalEquality.h index e9fbebe0..63c51b4f 100644 --- a/libyul/optimiser/SyntacticalEquality.h +++ b/libyul/optimiser/SyntacticalEquality.h @@ -20,12 +20,10 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <vector> -namespace dev -{ namespace yul { @@ -47,4 +45,3 @@ protected: }; } -} diff --git a/libyul/optimiser/UnusedPruner.cpp b/libyul/optimiser/UnusedPruner.cpp index 71e86798..31aead82 100644 --- a/libyul/optimiser/UnusedPruner.cpp +++ b/libyul/optimiser/UnusedPruner.cpp @@ -24,14 +24,13 @@ #include <libyul/optimiser/Semantics.h> #include <libyul/optimiser/Utilities.h> #include <libyul/Exceptions.h> - -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <boost/algorithm/cxx11/none_of.hpp> using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; UnusedPruner::UnusedPruner(Block& _ast, set<YulString> const& _externallyUsedFunctions) { diff --git a/libyul/optimiser/UnusedPruner.h b/libyul/optimiser/UnusedPruner.h index b5b46443..64e02b35 100644 --- a/libyul/optimiser/UnusedPruner.h +++ b/libyul/optimiser/UnusedPruner.h @@ -26,8 +26,6 @@ #include <map> #include <set> -namespace dev -{ namespace yul { @@ -62,4 +60,3 @@ private: }; } -} diff --git a/libyul/optimiser/Utilities.cpp b/libyul/optimiser/Utilities.cpp index df01ed39..b8cdd339 100644 --- a/libyul/optimiser/Utilities.cpp +++ b/libyul/optimiser/Utilities.cpp @@ -20,7 +20,7 @@ #include <libyul/optimiser/Utilities.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> @@ -28,9 +28,9 @@ using namespace std; using namespace dev; -using namespace dev::yul; +using namespace yul; -void dev::yul::removeEmptyBlocks(Block& _block) +void yul::removeEmptyBlocks(Block& _block) { auto isEmptyBlock = [](Statement const& _st) -> bool { return _st.type() == typeid(Block) && boost::get<Block>(_st).statements.empty(); diff --git a/libyul/optimiser/Utilities.h b/libyul/optimiser/Utilities.h index 5b18a27c..c543b119 100644 --- a/libyul/optimiser/Utilities.h +++ b/libyul/optimiser/Utilities.h @@ -20,10 +20,8 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> -namespace dev -{ namespace yul { @@ -31,4 +29,3 @@ namespace yul void removeEmptyBlocks(Block& _block); } -} diff --git a/libyul/optimiser/VarDeclPropagator.cpp b/libyul/optimiser/VarDeclPropagator.cpp index 537b7020..bf974f44 100644 --- a/libyul/optimiser/VarDeclPropagator.cpp +++ b/libyul/optimiser/VarDeclPropagator.cpp @@ -16,7 +16,7 @@ */ #include <libyul/optimiser/VarDeclPropagator.h> -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <libdevcore/CommonData.h> #include <boost/range/algorithm_ext/erase.hpp> #include <algorithm> @@ -24,10 +24,7 @@ using namespace std; using namespace dev; -using namespace dev::yul; - -using dev::solidity::assembly::TypedName; -using dev::solidity::assembly::TypedNameList; +using namespace yul; void VarDeclPropagator::operator()(Block& _block) { diff --git a/libyul/optimiser/VarDeclPropagator.h b/libyul/optimiser/VarDeclPropagator.h index 4522d23a..1908c214 100644 --- a/libyul/optimiser/VarDeclPropagator.h +++ b/libyul/optimiser/VarDeclPropagator.h @@ -17,16 +17,14 @@ #pragma once -#include <libyul/ASTDataForward.h> +#include <libyul/AsmDataForward.h> #include <libyul/optimiser/ASTWalker.h> #include <libyul/Exceptions.h> -#include <libsolidity/inlineasm/AsmDataForward.h> +#include <libyul/AsmDataForward.h> #include <vector> #include <set> #include <map> -namespace dev -{ namespace yul { @@ -60,4 +58,3 @@ private: }; } -} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index acfc7d00..10b78bdc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,7 +27,7 @@ add_executable(soltest ${sources} ${headers} ${liblll_sources} ${liblll_headers} ${libsolidity_sources} ${libsolidity_headers} ) -target_link_libraries(soltest PRIVATE libsolc solidity evmasm devcore ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) +target_link_libraries(soltest PRIVATE libsolc yul solidity evmasm devcore ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) if (LLL) target_link_libraries(soltest PRIVATE lll) diff --git a/test/boostTest.cpp b/test/boostTest.cpp index 6ff6d2d2..7cb0c143 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -144,7 +144,7 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) master, dev::test::Options::get().testPath / "libyul", "yulOptimizerTests", - dev::yul::test::YulOptimizerTest::create + yul::test::YulOptimizerTest::create ) > 0, "no Yul Optimizer tests found"); if (!dev::test::Options::get().disableSMT) { diff --git a/test/libyul/Common.cpp b/test/libyul/Common.cpp index 8913483f..d7785287 100644 --- a/test/libyul/Common.cpp +++ b/test/libyul/Common.cpp @@ -23,25 +23,24 @@ #include <test/Options.h> +#include <libsolidity/interface/SourceReferenceFormatter.h> + #include <libyul/optimiser/Disambiguator.h> +#include <libyul/AsmParser.h> +#include <libyul/AsmAnalysis.h> +#include <libyul/AsmPrinter.h> #include <liblangutil/Scanner.h> - -#include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmPrinter.h> - -#include <libsolidity/interface/SourceReferenceFormatter.h> #include <liblangutil/ErrorReporter.h> #include <boost/test/unit_test.hpp> using namespace std; using namespace langutil; -using namespace dev::yul; +using namespace yul; using namespace dev::solidity; -void dev::yul::test::printErrors(ErrorList const& _errors, Scanner const& _scanner) +void yul::test::printErrors(ErrorList const& _errors, Scanner const& _scanner) { SourceReferenceFormatter formatter(cout, [&](std::string const&) -> Scanner const& { return _scanner; }); @@ -53,18 +52,18 @@ void dev::yul::test::printErrors(ErrorList const& _errors, Scanner const& _scann } -pair<shared_ptr<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::yul::test::parse(string const& _source, bool _yul) +pair<shared_ptr<Block>, shared_ptr<yul::AsmAnalysisInfo>> yul::test::parse(string const& _source, bool _yul) { - auto flavour = _yul ? assembly::AsmFlavour::Yul : assembly::AsmFlavour::Strict; + auto flavour = _yul ? yul::AsmFlavour::Yul : yul::AsmFlavour::Strict; ErrorList errors; ErrorReporter errorReporter(errors); auto scanner = make_shared<Scanner>(CharStream(_source), ""); - auto parserResult = assembly::Parser(errorReporter, flavour).parse(scanner, false); + auto parserResult = yul::Parser(errorReporter, flavour).parse(scanner, false); if (parserResult) { BOOST_REQUIRE(errorReporter.errors().empty()); - auto analysisInfo = make_shared<assembly::AsmAnalysisInfo>(); - assembly::AsmAnalyzer analyzer( + auto analysisInfo = make_shared<yul::AsmAnalysisInfo>(); + yul::AsmAnalyzer analyzer( *analysisInfo, errorReporter, dev::test::Options::get().evmVersion(), @@ -84,13 +83,13 @@ pair<shared_ptr<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::yul::test::p return {}; } -assembly::Block dev::yul::test::disambiguate(string const& _source, bool _yul) +yul::Block yul::test::disambiguate(string const& _source, bool _yul) { auto result = parse(_source, _yul); return boost::get<Block>(Disambiguator(*result.second, {})(*result.first)); } -string dev::yul::test::format(string const& _source, bool _yul) +string yul::test::format(string const& _source, bool _yul) { - return assembly::AsmPrinter(_yul)(*parse(_source, _yul).first); + return yul::AsmPrinter(_yul)(*parse(_source, _yul).first); } diff --git a/test/libyul/Common.h b/test/libyul/Common.h index 390e214f..a1c64ca5 100644 --- a/test/libyul/Common.h +++ b/test/libyul/Common.h @@ -21,7 +21,7 @@ #pragma once -#include <libsolidity/inlineasm/AsmData.h> +#include <libyul/AsmData.h> #include <string> #include <vector> @@ -34,26 +34,21 @@ class Error; using ErrorList = std::vector<std::shared_ptr<Error const>>; } -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { struct AsmAnalysisInfo; } -} + namespace yul { namespace test { void printErrors(langutil::ErrorList const& _errors, langutil::Scanner const& _scanner); -std::pair<std::shared_ptr<solidity::assembly::Block>, std::shared_ptr<solidity::assembly::AsmAnalysisInfo>> +std::pair<std::shared_ptr<Block>, std::shared_ptr<AsmAnalysisInfo>> parse(std::string const& _source, bool _yul = true); -solidity::assembly::Block disambiguate(std::string const& _source, bool _yul = true); +Block disambiguate(std::string const& _source, bool _yul = true); std::string format(std::string const& _source, bool _yul = true); } } -} diff --git a/test/libyul/Inliner.cpp b/test/libyul/Inliner.cpp index 66810298..631cda08 100644 --- a/test/libyul/Inliner.cpp +++ b/test/libyul/Inliner.cpp @@ -26,8 +26,7 @@ #include <libyul/optimiser/FullInliner.h> #include <libyul/optimiser/FunctionHoister.h> #include <libyul/optimiser/FunctionGrouper.h> - -#include <libsolidity/inlineasm/AsmPrinter.h> +#include <libyul/AsmPrinter.h> #include <boost/test/unit_test.hpp> @@ -36,8 +35,8 @@ using namespace std; using namespace dev; -using namespace dev::yul; -using namespace dev::yul::test; +using namespace yul; +using namespace yul::test; using namespace dev::solidity; namespace diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index 4aa3dd5c..6f946362 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -23,9 +23,9 @@ #include <test/libsolidity/ErrorCheck.h> -#include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> +#include <libyul/AsmParser.h> +#include <libyul/AsmAnalysis.h> +#include <libyul/AsmAnalysisInfo.h> #include <liblangutil/Scanner.h> #include <liblangutil/ErrorReporter.h> @@ -36,11 +36,10 @@ #include <memory> using namespace std; +using namespace dev; using namespace langutil; -namespace dev -{ -namespace solidity +namespace yul { namespace test { @@ -53,16 +52,16 @@ bool parse(string const& _source, ErrorReporter& errorReporter) try { auto scanner = make_shared<Scanner>(CharStream(_source)); - auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Yul).parse(scanner, false); + auto parserResult = yul::Parser(errorReporter, yul::AsmFlavour::Yul).parse(scanner, false); if (parserResult) { - assembly::AsmAnalysisInfo analysisInfo; - return (assembly::AsmAnalyzer( + yul::AsmAnalysisInfo analysisInfo; + return (yul::AsmAnalyzer( analysisInfo, errorReporter, dev::test::Options::get().evmVersion(), boost::none, - assembly::AsmFlavour::Yul + yul::AsmFlavour::Yul )).analyze(*parserResult); } } @@ -117,7 +116,7 @@ do \ { \ Error err = expectError((text), false); \ BOOST_CHECK(err.type() == (Error::Type::typ)); \ - BOOST_CHECK(searchErrorMessage(err, (substring))); \ + BOOST_CHECK(dev::solidity::searchErrorMessage(err, (substring))); \ } while(0) BOOST_AUTO_TEST_SUITE(YulParser) @@ -303,5 +302,4 @@ BOOST_AUTO_TEST_CASE(if_statement_invalid) BOOST_AUTO_TEST_SUITE_END() } -} } // end namespaces diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 6b2b81c3..9c2da493 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -21,9 +21,6 @@ #include <test/Options.h> -#include <liblangutil/ErrorReporter.h> -#include <liblangutil/Scanner.h> - #include <libyul/optimiser/BlockFlattener.h> #include <libyul/optimiser/VarDeclPropagator.h> #include <libyul/optimiser/Disambiguator.h> @@ -43,12 +40,14 @@ #include <libyul/optimiser/SSATransform.h> #include <libyul/optimiser/RedundantAssignEliminator.h> #include <libyul/optimiser/Suite.h> - -#include <libsolidity/inlineasm/AsmPrinter.h> -#include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> +#include <libyul/AsmPrinter.h> +#include <libyul/AsmParser.h> +#include <libyul/AsmAnalysis.h> #include <libsolidity/interface/SourceReferenceFormatter.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/Scanner.h> + #include <boost/test/unit_test.hpp> #include <boost/algorithm/string.hpp> @@ -56,8 +55,8 @@ using namespace dev; using namespace langutil; -using namespace dev::yul; -using namespace dev::yul::test; +using namespace yul; +using namespace yul::test; using namespace dev::solidity; using namespace dev::solidity::test; using namespace std; @@ -93,9 +92,9 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename) bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted) { - assembly::AsmPrinter printer{m_yul}; + yul::AsmPrinter printer{m_yul}; shared_ptr<Block> ast; - shared_ptr<assembly::AsmAnalysisInfo> analysisInfo; + shared_ptr<yul::AsmAnalysisInfo> analysisInfo; if (!parse(_stream, _linePrefix, _formatted)) return false; @@ -257,19 +256,19 @@ void YulOptimizerTest::printIndented(ostream& _stream, string const& _output, st bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted) { - assembly::AsmFlavour flavour = m_yul ? assembly::AsmFlavour::Yul : assembly::AsmFlavour::Strict; + yul::AsmFlavour flavour = m_yul ? yul::AsmFlavour::Yul : yul::AsmFlavour::Strict; ErrorList errors; ErrorReporter errorReporter(errors); shared_ptr<Scanner> scanner = make_shared<Scanner>(CharStream(m_source), ""); - m_ast = assembly::Parser(errorReporter, flavour).parse(scanner, false); + m_ast = yul::Parser(errorReporter, flavour).parse(scanner, false); if (!m_ast || !errorReporter.errors().empty()) { FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl; printErrors(_stream, errorReporter.errors(), *scanner); return false; } - m_analysisInfo = make_shared<assembly::AsmAnalysisInfo>(); - assembly::AsmAnalyzer analyzer( + m_analysisInfo = make_shared<yul::AsmAnalysisInfo>(); + yul::AsmAnalyzer analyzer( *m_analysisInfo, errorReporter, dev::test::Options::get().evmVersion(), diff --git a/test/libyul/YulOptimizerTest.h b/test/libyul/YulOptimizerTest.h index d11ff8fb..72c4299f 100644 --- a/test/libyul/YulOptimizerTest.h +++ b/test/libyul/YulOptimizerTest.h @@ -26,22 +26,18 @@ class Error; using ErrorList = std::vector<std::shared_ptr<Error const>>; } -namespace dev -{ -namespace solidity -{ -namespace assembly +namespace yul { struct AsmAnalysisInfo; struct Block; } -} + namespace yul { namespace test { -class YulOptimizerTest: public solidity::test::TestCase +class YulOptimizerTest: public dev::solidity::test::TestCase { public: static std::unique_ptr<TestCase> create(std::string const& _filename) @@ -68,11 +64,10 @@ private: std::string m_optimizerStep; std::string m_expectation; - std::shared_ptr<solidity::assembly::Block> m_ast; - std::shared_ptr<solidity::assembly::AsmAnalysisInfo> m_analysisInfo; + 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 8bc807d4..7a147137 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -21,12 +21,12 @@ #include <libdevcore/CommonIO.h> #include <liblangutil/ErrorReporter.h> #include <liblangutil/Scanner.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> -#include <libsolidity/inlineasm/AsmAnalysisInfo.h> +#include <libyul/AsmAnalysis.h> +#include <libyul/AsmAnalysisInfo.h> #include <libsolidity/parsing/Parser.h> -#include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/inlineasm/AsmPrinter.h> +#include <libyul/AsmData.h> +#include <libyul/AsmParser.h> +#include <libyul/AsmPrinter.h> #include <libsolidity/interface/SourceReferenceFormatter.h> #include <libyul/optimiser/BlockFlattener.h> @@ -60,8 +60,7 @@ using namespace std; using namespace dev; using namespace langutil; using namespace dev::solidity; -using namespace dev::solidity::assembly; -using namespace dev::yul; +using namespace yul; namespace po = boost::program_options; @@ -83,14 +82,14 @@ public: { ErrorReporter errorReporter(m_errors); shared_ptr<Scanner> scanner = make_shared<Scanner>(CharStream(_input), ""); - m_ast = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner, false); + m_ast = yul::Parser(errorReporter, yul::AsmFlavour::Strict).parse(scanner, false); if (!m_ast || !errorReporter.errors().empty()) { cout << "Error parsing source." << endl; printErrors(*scanner); return false; } - m_analysisInfo = make_shared<assembly::AsmAnalysisInfo>(); + m_analysisInfo = make_shared<yul::AsmAnalysisInfo>(); AsmAnalyzer analyzer( *m_analysisInfo, errorReporter, @@ -118,7 +117,7 @@ public: return; if (!disambiguated) { - *m_ast = boost::get<assembly::Block>(Disambiguator(*m_analysisInfo)(*m_ast)); + *m_ast = boost::get<yul::Block>(Disambiguator(*m_analysisInfo)(*m_ast)); m_analysisInfo.reset(); m_nameDispenser = make_shared<NameDispenser>(*m_ast); disambiguated = true; @@ -187,7 +186,7 @@ public: private: ErrorList m_errors; - shared_ptr<assembly::Block> m_ast; + shared_ptr<yul::Block> m_ast; shared_ptr<AsmAnalysisInfo> m_analysisInfo; shared_ptr<NameDispenser> m_nameDispenser; }; |