From 112e63fe153c19cd7c2533ee66ea0b8a6b1e1747 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Fri, 1 Nov 2019 12:32:25 +0100 Subject: [PATCH] libyul: AST cleanup, eliminating dead Instruction AST type. --- libyul/AsmDataForward.h | 3 +-- libyul/AsmParser.cpp | 4 ++-- libyul/AsmPrinter.cpp | 7 ------- libyul/AsmPrinter.h | 1 - libyul/AsmScopeFiller.h | 1 - libyul/backends/wasm/EWasmCodeTransform.cpp | 6 ------ libyul/backends/wasm/EWasmCodeTransform.h | 1 - libyul/optimiser/ASTCopier.cpp | 6 ------ libyul/optimiser/ASTCopier.h | 2 -- libyul/optimiser/ASTWalker.h | 2 -- libyul/optimiser/SyntacticalEquality.cpp | 5 ----- libyul/optimiser/SyntacticalEquality.h | 2 -- 12 files changed, 3 insertions(+), 37 deletions(-) diff --git a/libyul/AsmDataForward.h b/libyul/AsmDataForward.h index 8890bd418..72574d4f1 100644 --- a/libyul/AsmDataForward.h +++ b/libyul/AsmDataForward.h @@ -27,7 +27,6 @@ namespace yul { -struct Instruction; struct Literal; struct Label; struct Identifier; @@ -49,6 +48,6 @@ struct Block; struct TypedName; using Expression = boost::variant; -using Statement = boost::variant; +using Statement = boost::variant; } diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index 4c138c337..2b1305dfd 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -232,8 +232,8 @@ Statement Parser::parseStatement() } else { - solAssert(elementary.type() == typeid(Instruction), "Invalid elementary operation."); - return boost::get(elementary); + solAssert(false, "Invalid elementary operation."); + return {}; } } diff --git a/libyul/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index 8793add6d..9f2d48838 100644 --- a/libyul/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -39,13 +39,6 @@ using namespace yul; //@TODO source locations -string AsmPrinter::operator()(yul::Instruction const& _instruction) const -{ - solAssert(!m_yul, ""); - solAssert(isValidInstruction(_instruction.instruction), "Invalid instruction"); - return boost::to_lower_copy(instructionInfo(_instruction.instruction).name); -} - string AsmPrinter::operator()(Literal const& _literal) const { switch (_literal.kind) diff --git a/libyul/AsmPrinter.h b/libyul/AsmPrinter.h index e3a2a4bf3..6777e341a 100644 --- a/libyul/AsmPrinter.h +++ b/libyul/AsmPrinter.h @@ -36,7 +36,6 @@ class AsmPrinter: public boost::static_visitor public: explicit AsmPrinter(bool _yul = false): m_yul(_yul) {} - std::string operator()(Instruction const& _instruction) const; std::string operator()(Literal const& _literal) const; std::string operator()(Identifier const& _identifier) const; std::string operator()(FunctionalInstruction const& _functionalInstruction) const; diff --git a/libyul/AsmScopeFiller.h b/libyul/AsmScopeFiller.h index 3607fae86..e403504b7 100644 --- a/libyul/AsmScopeFiller.h +++ b/libyul/AsmScopeFiller.h @@ -49,7 +49,6 @@ class ScopeFiller: public boost::static_visitor public: ScopeFiller(AsmAnalysisInfo& _info, langutil::ErrorReporter& _errorReporter); - bool operator()(Instruction const&) { return true; } bool operator()(Literal const&) { return true; } bool operator()(Identifier const&) { return true; } bool operator()(FunctionalInstruction const&) { return true; } diff --git a/libyul/backends/wasm/EWasmCodeTransform.cpp b/libyul/backends/wasm/EWasmCodeTransform.cpp index 4b073e3cd..ccfeb75ed 100644 --- a/libyul/backends/wasm/EWasmCodeTransform.cpp +++ b/libyul/backends/wasm/EWasmCodeTransform.cpp @@ -171,12 +171,6 @@ wasm::Expression EWasmCodeTransform::operator()(Literal const& _literal) return wasm::Literal{uint64_t(value)}; } -wasm::Expression EWasmCodeTransform::operator()(yul::Instruction const&) -{ - yulAssert(false, "EVM instruction used for Wasm code generation."); - return {}; -} - wasm::Expression EWasmCodeTransform::operator()(If const& _if) { return wasm::If{visit(*_if.condition), visit(_if.body.statements), {}}; diff --git a/libyul/backends/wasm/EWasmCodeTransform.h b/libyul/backends/wasm/EWasmCodeTransform.h index f99923077..683428209 100644 --- a/libyul/backends/wasm/EWasmCodeTransform.h +++ b/libyul/backends/wasm/EWasmCodeTransform.h @@ -38,7 +38,6 @@ public: static std::string run(Dialect const& _dialect, yul::Block const& _ast); public: - wasm::Expression operator()(yul::Instruction const& _instruction); wasm::Expression operator()(yul::Literal const& _literal); wasm::Expression operator()(yul::Identifier const& _identifier); wasm::Expression operator()(yul::FunctionalInstruction const& _instr); diff --git a/libyul/optimiser/ASTCopier.cpp b/libyul/optimiser/ASTCopier.cpp index 737900d86..0d8eb1ae7 100644 --- a/libyul/optimiser/ASTCopier.cpp +++ b/libyul/optimiser/ASTCopier.cpp @@ -30,12 +30,6 @@ using namespace std; using namespace dev; using namespace yul; -Statement ASTCopier::operator()(Instruction const&) -{ - assertThrow(false, OptimizerException, "Invalid operation."); - return {}; -} - Statement ASTCopier::operator()(ExpressionStatement const& _statement) { return ExpressionStatement{ _statement.location, translate(_statement.expression) }; diff --git a/libyul/optimiser/ASTCopier.h b/libyul/optimiser/ASTCopier.h index be19b55d7..4f55f3a21 100644 --- a/libyul/optimiser/ASTCopier.h +++ b/libyul/optimiser/ASTCopier.h @@ -49,7 +49,6 @@ class StatementCopier: public boost::static_visitor public: virtual ~StatementCopier() = default; virtual Statement operator()(ExpressionStatement const& _statement) = 0; - virtual Statement operator()(Instruction const& _instruction) = 0; virtual Statement operator()(Assignment const& _assignment) = 0; virtual Statement operator()(VariableDeclaration const& _varDecl) = 0; virtual Statement operator()(If const& _if) = 0; @@ -71,7 +70,6 @@ class ASTCopier: public ExpressionCopier, public StatementCopier public: virtual ~ASTCopier() = default; Expression operator()(Literal const& _literal) override; - Statement operator()(Instruction const& _instruction) override; Expression operator()(Identifier const& _identifier) override; Expression operator()(FunctionalInstruction const& _instr) override; Expression operator()(FunctionCall const&) override; diff --git a/libyul/optimiser/ASTWalker.h b/libyul/optimiser/ASTWalker.h index 8a4ba7916..d3683b913 100644 --- a/libyul/optimiser/ASTWalker.h +++ b/libyul/optimiser/ASTWalker.h @@ -43,7 +43,6 @@ class ASTWalker: public boost::static_visitor<> public: virtual ~ASTWalker() = default; virtual void operator()(Literal const&) {} - virtual void operator()(Instruction const&) { assertThrow(false, OptimizerException, ""); } virtual void operator()(Identifier const&) {} virtual void operator()(FunctionalInstruction const& _instr); virtual void operator()(FunctionCall const& _funCall); @@ -79,7 +78,6 @@ class ASTModifier: public boost::static_visitor<> public: virtual ~ASTModifier() = default; virtual void operator()(Literal&) {} - virtual void operator()(Instruction&) { assertThrow(false, OptimizerException, ""); } virtual void operator()(Identifier&) {} virtual void operator()(FunctionalInstruction& _instr); virtual void operator()(FunctionCall& _funCall); diff --git a/libyul/optimiser/SyntacticalEquality.cpp b/libyul/optimiser/SyntacticalEquality.cpp index 01a447443..d1c8ecc79 100644 --- a/libyul/optimiser/SyntacticalEquality.cpp +++ b/libyul/optimiser/SyntacticalEquality.cpp @@ -159,11 +159,6 @@ bool SyntacticallyEqual::statementEqual(ForLoop const& _lhs, ForLoop const& _rhs statementEqual(_lhs.post, _rhs.post); } -bool SyntacticallyEqual::statementEqual(Instruction const&, Instruction const&) -{ - assertThrow(false, OptimizerException, ""); -} - bool SyntacticallyEqual::statementEqual(Block const& _lhs, Block const& _rhs) { return containerEqual(_lhs.statements, _rhs.statements, [this](Statement const& _lhsStmt, Statement const& _rhsStmt) -> bool { diff --git a/libyul/optimiser/SyntacticalEquality.h b/libyul/optimiser/SyntacticalEquality.h index c61dc5817..38f5d278b 100644 --- a/libyul/optimiser/SyntacticalEquality.h +++ b/libyul/optimiser/SyntacticalEquality.h @@ -60,8 +60,6 @@ public: bool statementEqual(Leave const&, Leave const&) { return true; } bool statementEqual(Block const& _lhs, Block const& _rhs); private: - bool statementEqual(Instruction const& _lhs, Instruction const& _rhs); - bool visitDeclaration(TypedName const& _lhs, TypedName const& _rhs); template