diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index 119d0fb22..f1594a1e0 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -47,12 +47,6 @@ public: } 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()(yul::ExpressionStatement const& _expr) { boost::apply_visitor(*this, _expr.expression); diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index dce6bc013..fbd842f46 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -179,22 +179,6 @@ bool AsmAnalyzer::operator()(Identifier const& _identifier) return success; } -bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr) -{ - solAssert(m_dialect.flavour != AsmFlavour::Yul, ""); - bool success = true; - for (auto const& arg: _instr.arguments | boost::adaptors::reversed) - if (!expectExpression(arg)) - success = false; - // Parser already checks that the number of arguments is correct. - auto const& info = instructionInfo(_instr.instruction); - solAssert(info.args == int(_instr.arguments.size()), ""); - m_stackHeight += info.ret - info.args; - m_info.stackHeightInfo[&_instr] = m_stackHeight; - warnOnInstructions(_instr.instruction, _instr.location); - return success; -} - bool AsmAnalyzer::operator()(ExpressionStatement const& _statement) { int initialStackHeight = m_stackHeight; diff --git a/libyul/AsmAnalysis.h b/libyul/AsmAnalysis.h index 217581508..41002a38a 100644 --- a/libyul/AsmAnalysis.h +++ b/libyul/AsmAnalysis.h @@ -82,7 +82,6 @@ public: bool operator()(Instruction const&); bool operator()(Literal const& _literal); bool operator()(Identifier const&); - bool operator()(FunctionalInstruction const& _functionalInstruction); bool operator()(ExpressionStatement const&); bool operator()(Assignment const& _assignment); bool operator()(VariableDeclaration const& _variableDeclaration); diff --git a/libyul/AsmData.h b/libyul/AsmData.h index 8c44ce307..6e5b1de32 100644 --- a/libyul/AsmData.h +++ b/libyul/AsmData.h @@ -56,8 +56,6 @@ struct Identifier { langutil::SourceLocation location; YulString name; }; /// a single stack slot and expects a single expression on the right hand returning /// the same amount of items as the number of variables. struct Assignment { langutil::SourceLocation location; std::vector variableNames; std::unique_ptr value; }; -/// Functional instruction, e.g. "mul(mload(20:u256), add(2:u256, x))" -struct FunctionalInstruction { langutil::SourceLocation location; dev::eth::Instruction instruction; std::vector arguments; }; struct FunctionCall { langutil::SourceLocation location; Identifier functionName; std::vector arguments; }; /// Statement that contains only a single expression struct ExpressionStatement { langutil::SourceLocation location; Expression expression; }; diff --git a/libyul/AsmDataForward.h b/libyul/AsmDataForward.h index 72574d4f1..f88d7e4c3 100644 --- a/libyul/AsmDataForward.h +++ b/libyul/AsmDataForward.h @@ -32,7 +32,6 @@ struct Label; struct Identifier; struct Assignment; struct VariableDeclaration; -struct FunctionalInstruction; struct FunctionDefinition; struct FunctionCall; struct If; @@ -47,7 +46,7 @@ struct Block; struct TypedName; -using Expression = boost::variant; +using Expression = boost::variant; using Statement = boost::variant; } diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index 2b1305dfd..b72c526b5 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -462,84 +462,15 @@ FunctionDefinition Parser::parseFunctionDefinition() Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) { RecursionGuard recursionGuard(*this); - if (_initialOp.type() == typeid(Instruction)) - { - solAssert(m_dialect.flavour != AsmFlavour::Yul, "Instructions are invalid in Yul"); - Instruction& instruction = boost::get(_initialOp); - FunctionalInstruction ret; - ret.instruction = instruction.instruction; - ret.location = std::move(instruction.location); - dev::eth::Instruction instr = ret.instruction; - dev::eth::InstructionInfo instrInfo = instructionInfo(instr); - if (dev::eth::isDupInstruction(instr)) - fatalParserError("DUPi instructions not allowed for functional notation"); - if (dev::eth::isSwapInstruction(instr)) - fatalParserError("SWAPi instructions not allowed for functional notation"); - expectToken(Token::LParen); - unsigned args = unsigned(instrInfo.args); - for (unsigned i = 0; i < args; ++i) - { - /// check for premature closing parentheses - if (currentToken() == Token::RParen) - fatalParserError(string( - "Expected expression (instruction \"" + - instructionNames().at(instr) + - "\" expects " + - to_string(args) + - " arguments)" - )); - ret.arguments.emplace_back(parseExpression()); - if (i != args - 1) - { - if (currentToken() != Token::Comma) - fatalParserError(string( - "Expected ',' (instruction \"" + - instructionNames().at(instr) + - "\" expects " + - to_string(args) + - " arguments)" - )); - else - advance(); - } - } - ret.location.end = endPosition(); - if (currentToken() == Token::Comma) - fatalParserError(string( - "Expected ')' (instruction \"" + - instructionNames().at(instr) + - "\" expects " + - to_string(args) + - " arguments)" - )); - expectToken(Token::RParen); - return ret; - } - else if (_initialOp.type() == typeid(Identifier) || _initialOp.type() == typeid(FunctionCall)) + FunctionCall ret; + if (_initialOp.type() == typeid(Identifier)) { - FunctionCall ret; - if (_initialOp.type() == typeid(Identifier)) - { - ret.functionName = std::move(boost::get(_initialOp)); - ret.location = ret.functionName.location; - } - else - ret = std::move(boost::get(_initialOp)); - expectToken(Token::LParen); - if (currentToken() != Token::RParen) - { - ret.arguments.emplace_back(parseExpression()); - while (currentToken() != Token::RParen) - { - expectToken(Token::Comma); - ret.arguments.emplace_back(parseExpression()); - } - } - ret.location.end = endPosition(); - expectToken(Token::RParen); - return ret; + ret.functionName = std::move(boost::get(_initialOp)); + ret.location = ret.functionName.location; } + else if (_initialOp.type() == typeid(FunctionCall)) + ret = std::move(boost::get(_initialOp)); else fatalParserError( m_dialect.flavour == AsmFlavour::Yul ? @@ -547,7 +478,19 @@ Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) "Assembly instruction or function name required in front of \"(\")" ); - return {}; + expectToken(Token::LParen); + if (currentToken() != Token::RParen) + { + ret.arguments.emplace_back(parseExpression()); + while (currentToken() != Token::RParen) + { + expectToken(Token::Comma); + ret.arguments.emplace_back(parseExpression()); + } + } + ret.location.end = endPosition(); + expectToken(Token::RParen); + return ret; } TypedName Parser::parseTypedName() diff --git a/libyul/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index 9f2d48838..7fb78f534 100644 --- a/libyul/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -88,19 +88,6 @@ string AsmPrinter::operator()(Identifier const& _identifier) const return _identifier.name.str(); } -string AsmPrinter::operator()(FunctionalInstruction const& _functionalInstruction) const -{ - solAssert(!m_yul, ""); - solAssert(isValidInstruction(_functionalInstruction.instruction), "Invalid instruction"); - return - boost::to_lower_copy(instructionInfo(_functionalInstruction.instruction).name) + - "(" + - boost::algorithm::join( - _functionalInstruction.arguments | boost::adaptors::transformed(boost::apply_visitor(*this)), - ", ") + - ")"; -} - string AsmPrinter::operator()(ExpressionStatement const& _statement) const { return boost::apply_visitor(*this, _statement.expression); diff --git a/libyul/AsmPrinter.h b/libyul/AsmPrinter.h index 6777e341a..1d99ad635 100644 --- a/libyul/AsmPrinter.h +++ b/libyul/AsmPrinter.h @@ -38,7 +38,6 @@ public: std::string operator()(Literal const& _literal) const; std::string operator()(Identifier const& _identifier) const; - std::string operator()(FunctionalInstruction const& _functionalInstruction) const; std::string operator()(ExpressionStatement const& _expr) const; std::string operator()(Assignment const& _assignment) const; std::string operator()(VariableDeclaration const& _variableDeclaration) const; diff --git a/libyul/AsmScopeFiller.h b/libyul/AsmScopeFiller.h index e403504b7..657322c15 100644 --- a/libyul/AsmScopeFiller.h +++ b/libyul/AsmScopeFiller.h @@ -51,7 +51,6 @@ public: 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()(Assignment const&) { return true; } bool operator()(VariableDeclaration const& _variableDeclaration); diff --git a/libyul/backends/evm/ConstantOptimiser.cpp b/libyul/backends/evm/ConstantOptimiser.cpp index f8b4854d8..ec10ee450 100644 --- a/libyul/backends/evm/ConstantOptimiser.cpp +++ b/libyul/backends/evm/ConstantOptimiser.cpp @@ -69,10 +69,6 @@ struct MiniEVMInterpreter: boost::static_visitor return 0; } - u256 operator()(FunctionalInstruction const& _instr) - { - return eval(_instr.instruction, _instr.arguments); - } u256 operator()(FunctionCall const& _funCall) { BuiltinFunctionForEVM const* fun = m_dialect.builtin(_funCall.functionName.name); diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index 681e93049..515e927f0 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -303,40 +303,6 @@ void CodeTransform::operator()(FunctionCall const& _call) } } -void CodeTransform::operator()(FunctionalInstruction const& _instruction) -{ - if (m_evm15 && ( - _instruction.instruction == dev::eth::Instruction::JUMP || - _instruction.instruction == dev::eth::Instruction::JUMPI - )) - { - bool const isJumpI = _instruction.instruction == dev::eth::Instruction::JUMPI; - if (isJumpI) - { - solAssert(_instruction.arguments.size() == 2, ""); - visitExpression(_instruction.arguments.at(1)); - } - else - { - solAssert(_instruction.arguments.size() == 1, ""); - } - m_assembly.setSourceLocation(_instruction.location); - auto label = labelFromIdentifier(boost::get(_instruction.arguments.at(0))); - if (isJumpI) - m_assembly.appendJumpToIf(label); - else - m_assembly.appendJumpTo(label); - } - else - { - for (auto const& arg: _instruction.arguments | boost::adaptors::reversed) - visitExpression(arg); - m_assembly.setSourceLocation(_instruction.location); - m_assembly.appendInstruction(_instruction.instruction); - } - checkStackHeight(&_instruction); -} - void CodeTransform::operator()(Identifier const& _identifier) { m_assembly.setSourceLocation(_identifier.location); diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h index 83752a9fa..8cacdd0f3 100644 --- a/libyul/backends/evm/EVMCodeTransform.h +++ b/libyul/backends/evm/EVMCodeTransform.h @@ -175,7 +175,6 @@ public: void operator()(Instruction const& _instruction); void operator()(Literal const& _literal); void operator()(Identifier const& _identifier); - void operator()(FunctionalInstruction const& _instr); void operator()(FunctionCall const&); void operator()(ExpressionStatement const& _statement); void operator()(Assignment const& _assignment); diff --git a/libyul/backends/evm/EVMMetrics.cpp b/libyul/backends/evm/EVMMetrics.cpp index 5211e5132..3d9ad9861 100644 --- a/libyul/backends/evm/EVMMetrics.cpp +++ b/libyul/backends/evm/EVMMetrics.cpp @@ -85,12 +85,6 @@ void GasMeterVisitor::operator()(FunctionCall const& _funCall) yulAssert(false, "Functions not implemented."); } -void GasMeterVisitor::operator()(FunctionalInstruction const& _fun) -{ - ASTWalker::operator()(_fun); - instructionCostsInternal(_fun.instruction); -} - void GasMeterVisitor::operator()(Literal const& _lit) { m_runGas += dev::eth::GasMeter::runGas(dev::eth::Instruction::PUSH1); diff --git a/libyul/backends/evm/EVMMetrics.h b/libyul/backends/evm/EVMMetrics.h index 8a8987b94..ff670d577 100644 --- a/libyul/backends/evm/EVMMetrics.h +++ b/libyul/backends/evm/EVMMetrics.h @@ -81,7 +81,6 @@ public: {} void operator()(FunctionCall const& _funCall) override; - void operator()(FunctionalInstruction const& _instr) override; void operator()(Literal const& _literal) override; void operator()(Identifier const& _identifier) override; diff --git a/libyul/backends/wasm/EWasmCodeTransform.cpp b/libyul/backends/wasm/EWasmCodeTransform.cpp index 3d5ec4bb0..54e17771f 100644 --- a/libyul/backends/wasm/EWasmCodeTransform.cpp +++ b/libyul/backends/wasm/EWasmCodeTransform.cpp @@ -110,12 +110,6 @@ wasm::Expression EWasmCodeTransform::operator()(ExpressionStatement const& _stat return visitReturnByValue(_statement.expression); } -wasm::Expression EWasmCodeTransform::operator()(FunctionalInstruction const& _f) -{ - yulAssert(false, "EVM instruction in ewasm code: " + eth::instructionInfo(_f.instruction).name); - return {}; -} - wasm::Expression EWasmCodeTransform::operator()(FunctionCall const& _call) { bool typeConversionNeeded = false; diff --git a/libyul/backends/wasm/EWasmCodeTransform.h b/libyul/backends/wasm/EWasmCodeTransform.h index 0f3a601f5..ad70a64a9 100644 --- a/libyul/backends/wasm/EWasmCodeTransform.h +++ b/libyul/backends/wasm/EWasmCodeTransform.h @@ -40,7 +40,6 @@ public: public: wasm::Expression operator()(yul::Literal const& _literal); wasm::Expression operator()(yul::Identifier const& _identifier); - wasm::Expression operator()(yul::FunctionalInstruction const& _instr); wasm::Expression operator()(yul::FunctionCall const&); wasm::Expression operator()(yul::ExpressionStatement const& _statement); wasm::Expression operator()(yul::Assignment const& _assignment); diff --git a/libyul/backends/wasm/WordSizeTransform.cpp b/libyul/backends/wasm/WordSizeTransform.cpp index 81c80da99..c1bbdd478 100644 --- a/libyul/backends/wasm/WordSizeTransform.cpp +++ b/libyul/backends/wasm/WordSizeTransform.cpp @@ -37,11 +37,6 @@ void WordSizeTransform::operator()(FunctionDefinition& _fd) (*this)(_fd.body); } -void WordSizeTransform::operator()(FunctionalInstruction& _ins) -{ - rewriteFunctionCallArguments(_ins.arguments); -} - void WordSizeTransform::operator()(FunctionCall& _fc) { if (BuiltinFunction const* fun = m_inputDialect.builtin(_fc.functionName.name)) @@ -111,10 +106,7 @@ void WordSizeTransform::operator()(Block& _block) return {std::move(ret)}; } - if ( - !varDecl.value || - varDecl.value->type() == typeid(FunctionalInstruction) || - varDecl.value->type() == typeid(FunctionCall) + if (!varDecl.value || varDecl.value->type() == typeid(FunctionCall) ) { if (varDecl.value) visit(*varDecl.value); @@ -171,10 +163,7 @@ void WordSizeTransform::operator()(Block& _block) return {std::move(ret)}; } - if ( - assignment.value->type() == typeid(FunctionalInstruction) || - assignment.value->type() == typeid(FunctionCall) - ) + if (assignment.value->type() == typeid(FunctionCall)) { if (assignment.value) visit(*assignment.value); rewriteIdentifierList(assignment.variableNames); diff --git a/libyul/backends/wasm/WordSizeTransform.h b/libyul/backends/wasm/WordSizeTransform.h index 21d586439..6b9413cdf 100644 --- a/libyul/backends/wasm/WordSizeTransform.h +++ b/libyul/backends/wasm/WordSizeTransform.h @@ -37,11 +37,11 @@ namespace yul * but wasm only supports values up to 64 bits, so we use four u64 values to simulate * one u256 value. * - * For FunctionalInstruction that accepts or returns u256 values, they accepts or returns + * For FunctionCall that accepts or returns u256 values, they accepts or returns * four times the number of values after this transformation, with the order of significance, * from the most significant to the least significant. * - * For example, the FunctionalInstruction MUL supplied by code generator + * For example, the FunctionCall MUL supplied by code generator * should take 8 arguments and return 4 values (instead of 2 and 1) after this transformation. * * mul(a1, a2, a3, a4, b1, b2, b3, b4) -> c1, c2, c3, c4 @@ -61,7 +61,6 @@ class WordSizeTransform: public ASTModifier { public: void operator()(FunctionDefinition&) override; - void operator()(FunctionalInstruction&) override; void operator()(FunctionCall&) override; void operator()(If&) override; void operator()(Switch&) override; diff --git a/libyul/optimiser/ASTCopier.cpp b/libyul/optimiser/ASTCopier.cpp index 0668afb8d..e87c5fcb5 100644 --- a/libyul/optimiser/ASTCopier.cpp +++ b/libyul/optimiser/ASTCopier.cpp @@ -62,15 +62,6 @@ Expression ASTCopier::operator()(FunctionCall const& _call) }; } -Expression ASTCopier::operator()(FunctionalInstruction const& _instruction) -{ - return FunctionalInstruction{ - _instruction.location, - _instruction.instruction, - translateVector(_instruction.arguments) - }; -} - Expression ASTCopier::operator()(Identifier const& _identifier) { return translate(_identifier); diff --git a/libyul/optimiser/ASTCopier.h b/libyul/optimiser/ASTCopier.h index 4f55f3a21..075afabcf 100644 --- a/libyul/optimiser/ASTCopier.h +++ b/libyul/optimiser/ASTCopier.h @@ -40,7 +40,6 @@ public: virtual ~ExpressionCopier() = default; virtual Expression operator()(Literal const& _literal) = 0; virtual Expression operator()(Identifier const& _identifier) = 0; - virtual Expression operator()(FunctionalInstruction const& _instr) = 0; virtual Expression operator()(FunctionCall const&) = 0; }; @@ -71,7 +70,6 @@ public: virtual ~ASTCopier() = default; Expression operator()(Literal const& _literal) override; Expression operator()(Identifier const& _identifier) override; - Expression operator()(FunctionalInstruction const& _instr) override; Expression operator()(FunctionCall const&) override; Statement operator()(ExpressionStatement const& _statement) override; Statement operator()(Assignment const& _assignment) override; diff --git a/libyul/optimiser/ASTWalker.cpp b/libyul/optimiser/ASTWalker.cpp index 022e4305e..1d26d3873 100644 --- a/libyul/optimiser/ASTWalker.cpp +++ b/libyul/optimiser/ASTWalker.cpp @@ -28,11 +28,6 @@ using namespace std; using namespace dev; using namespace yul; -void ASTWalker::operator()(FunctionalInstruction const& _instr) -{ - walkVector(_instr.arguments | boost::adaptors::reversed); -} - void ASTWalker::operator()(FunctionCall const& _funCall) { // Does not visit _funCall.functionName on purpose @@ -102,11 +97,6 @@ void ASTWalker::visit(Expression const& _e) boost::apply_visitor(*this, _e); } -void ASTModifier::operator()(FunctionalInstruction& _instr) -{ - walkVector(_instr.arguments | boost::adaptors::reversed); -} - void ASTModifier::operator()(FunctionCall& _funCall) { // Does not visit _funCall.functionName on purpose diff --git a/libyul/optimiser/ASTWalker.h b/libyul/optimiser/ASTWalker.h index d3683b913..7d39f53a5 100644 --- a/libyul/optimiser/ASTWalker.h +++ b/libyul/optimiser/ASTWalker.h @@ -44,7 +44,6 @@ public: virtual ~ASTWalker() = default; virtual void operator()(Literal const&) {} virtual void operator()(Identifier const&) {} - virtual void operator()(FunctionalInstruction const& _instr); virtual void operator()(FunctionCall const& _funCall); virtual void operator()(ExpressionStatement const& _statement); virtual void operator()(Assignment const& _assignment); @@ -79,7 +78,6 @@ public: virtual ~ASTModifier() = default; virtual void operator()(Literal&) {} virtual void operator()(Identifier&) {} - virtual void operator()(FunctionalInstruction& _instr); virtual void operator()(FunctionCall& _funCall); virtual void operator()(ExpressionStatement& _statement); virtual void operator()(Assignment& _assignment); diff --git a/libyul/optimiser/BlockHasher.cpp b/libyul/optimiser/BlockHasher.cpp index 631697c60..af4ee3725 100644 --- a/libyul/optimiser/BlockHasher.cpp +++ b/libyul/optimiser/BlockHasher.cpp @@ -76,14 +76,6 @@ void BlockHasher::operator()(Identifier const& _identifier) hash64(it->second.id); } -void BlockHasher::operator()(FunctionalInstruction const& _instr) -{ - hash64(compileTimeLiteralHash("FunctionalInstruction")); - hash8(static_cast>(_instr.instruction)); - hash64(_instr.arguments.size()); - ASTWalker::operator()(_instr); -} - void BlockHasher::operator()(FunctionCall const& _funCall) { hash64(compileTimeLiteralHash("FunctionCall")); diff --git a/libyul/optimiser/BlockHasher.h b/libyul/optimiser/BlockHasher.h index e4aa90b99..4e9ddc732 100644 --- a/libyul/optimiser/BlockHasher.h +++ b/libyul/optimiser/BlockHasher.h @@ -49,7 +49,6 @@ public: void operator()(Literal const&) override; void operator()(Identifier const&) override; - void operator()(FunctionalInstruction const& _instr) override; void operator()(FunctionCall const& _funCall) override; void operator()(ExpressionStatement const& _statement) override; void operator()(Assignment const& _assignment) override; diff --git a/libyul/optimiser/CallGraphGenerator.cpp b/libyul/optimiser/CallGraphGenerator.cpp index 0c11464ee..cfcb46a28 100644 --- a/libyul/optimiser/CallGraphGenerator.cpp +++ b/libyul/optimiser/CallGraphGenerator.cpp @@ -36,14 +36,6 @@ map> CallGraphGenerator::callGraph(Block const& _ast) return std::move(gen.m_callGraph); } -void CallGraphGenerator::operator()(FunctionalInstruction const& _functionalInstruction) -{ - string name = dev::eth::instructionInfo(_functionalInstruction.instruction).name; - std::transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); }); - m_callGraph[m_currentFunction].insert(YulString{name}); - ASTWalker::operator()(_functionalInstruction); -} - void CallGraphGenerator::operator()(FunctionCall const& _functionCall) { m_callGraph[m_currentFunction].insert(_functionCall.functionName.name); diff --git a/libyul/optimiser/CallGraphGenerator.h b/libyul/optimiser/CallGraphGenerator.h index 4dc420900..0588c736e 100644 --- a/libyul/optimiser/CallGraphGenerator.h +++ b/libyul/optimiser/CallGraphGenerator.h @@ -42,7 +42,6 @@ public: static std::map> callGraph(Block const& _ast); using ASTWalker::operator(); - void operator()(FunctionalInstruction const& _functionalInstruction) override; void operator()(FunctionCall const& _functionCall) override; void operator()(FunctionDefinition const& _functionDefinition) override; diff --git a/libyul/optimiser/ExpressionJoiner.cpp b/libyul/optimiser/ExpressionJoiner.cpp index 911d44de0..a20071dbc 100644 --- a/libyul/optimiser/ExpressionJoiner.cpp +++ b/libyul/optimiser/ExpressionJoiner.cpp @@ -40,11 +40,6 @@ void ExpressionJoiner::run(OptimiserStepContext&, Block& _ast) } -void ExpressionJoiner::operator()(FunctionalInstruction& _instruction) -{ - handleArguments(_instruction.arguments); -} - void ExpressionJoiner::operator()(FunctionCall& _funCall) { handleArguments(_funCall.arguments); diff --git a/libyul/optimiser/ExpressionJoiner.h b/libyul/optimiser/ExpressionJoiner.h index e3b496b7c..4cc28f826 100644 --- a/libyul/optimiser/ExpressionJoiner.h +++ b/libyul/optimiser/ExpressionJoiner.h @@ -78,7 +78,6 @@ private: explicit ExpressionJoiner(Block& _ast); void operator()(Block& _block) override; - void operator()(FunctionalInstruction&) override; void operator()(FunctionCall&) override; using ASTModifier::visit; diff --git a/libyul/optimiser/ExpressionSplitter.cpp b/libyul/optimiser/ExpressionSplitter.cpp index 86fb6206f..389358a1b 100644 --- a/libyul/optimiser/ExpressionSplitter.cpp +++ b/libyul/optimiser/ExpressionSplitter.cpp @@ -41,12 +41,6 @@ void ExpressionSplitter::run(OptimiserStepContext& _context, Block& _ast) ExpressionSplitter{_context.dialect, _context.dispenser}(_ast); } -void ExpressionSplitter::operator()(FunctionalInstruction& _instruction) -{ - for (auto& arg: _instruction.arguments | boost::adaptors::reversed) - outlineExpression(arg); -} - void ExpressionSplitter::operator()(FunctionCall& _funCall) { if (BuiltinFunction const* builtin = m_dialect.builtin(_funCall.functionName.name)) diff --git a/libyul/optimiser/ExpressionSplitter.h b/libyul/optimiser/ExpressionSplitter.h index 7a2a97464..aefda79ab 100644 --- a/libyul/optimiser/ExpressionSplitter.h +++ b/libyul/optimiser/ExpressionSplitter.h @@ -61,7 +61,6 @@ public: static constexpr char const* name{"ExpressionSplitter"}; static void run(OptimiserStepContext&, Block& _ast); - void operator()(FunctionalInstruction&) override; void operator()(FunctionCall&) override; void operator()(If&) override; void operator()(Switch&) override; diff --git a/libyul/optimiser/KnowledgeBase.cpp b/libyul/optimiser/KnowledgeBase.cpp index 2c13ac05b..e6c9dd7c2 100644 --- a/libyul/optimiser/KnowledgeBase.cpp +++ b/libyul/optimiser/KnowledgeBase.cpp @@ -77,9 +77,6 @@ Expression KnowledgeBase::simplify(Expression _expression) if (_expression.type() == typeid(FunctionCall)) for (Expression& arg: boost::get(_expression).arguments) arg = simplify(arg); - else if (_expression.type() == typeid(FunctionalInstruction)) - for (Expression& arg: boost::get(_expression).arguments) - arg = simplify(arg); if (auto match = SimplificationRules::findFirstMatch(_expression, m_dialect, m_variableValues)) return simplify(match->action().toExpression(locationOf(_expression))); diff --git a/libyul/optimiser/LoadResolver.cpp b/libyul/optimiser/LoadResolver.cpp index 184214254..1e2b8e0e5 100644 --- a/libyul/optimiser/LoadResolver.cpp +++ b/libyul/optimiser/LoadResolver.cpp @@ -55,11 +55,6 @@ void LoadResolver::visit(Expression& _e) if (builtin->instruction) tryResolve(_e, *builtin->instruction, funCall.arguments); } - else if (_e.type() == typeid(FunctionalInstruction)) - { - FunctionalInstruction const& instruction = boost::get(_e); - tryResolve(_e, instruction.instruction, instruction.arguments); - } } void LoadResolver::tryResolve( diff --git a/libyul/optimiser/Metrics.cpp b/libyul/optimiser/Metrics.cpp index 1e3751fc2..02d3e8fe8 100644 --- a/libyul/optimiser/Metrics.cpp +++ b/libyul/optimiser/Metrics.cpp @@ -120,13 +120,6 @@ void CodeCost::operator()(FunctionCall const& _funCall) m_cost += 49; } -void CodeCost::operator()(FunctionalInstruction const& _instr) -{ - yulAssert(m_cost >= 1, "Should assign cost one in visit(Expression)."); - addInstructionCost(_instr.instruction); - ASTWalker::operator()(_instr); -} - void CodeCost::operator()(Literal const& _literal) { yulAssert(m_cost >= 1, "Should assign cost one in visit(Expression)."); diff --git a/libyul/optimiser/Metrics.h b/libyul/optimiser/Metrics.h index 5fe3eef7b..8ad1208b0 100644 --- a/libyul/optimiser/Metrics.h +++ b/libyul/optimiser/Metrics.h @@ -81,7 +81,6 @@ private: CodeCost(Dialect const& _dialect): m_dialect(_dialect) {} void operator()(FunctionCall const& _funCall) override; - void operator()(FunctionalInstruction const& _instr) override; void operator()(Literal const& _literal) override; void visit(Statement const& _statement) override; void visit(Expression const& _expression) override; diff --git a/libyul/optimiser/Semantics.cpp b/libyul/optimiser/Semantics.cpp index de0e1be50..508890f61 100644 --- a/libyul/optimiser/Semantics.cpp +++ b/libyul/optimiser/Semantics.cpp @@ -61,13 +61,6 @@ SideEffectsCollector::SideEffectsCollector( operator()(_ast); } -void SideEffectsCollector::operator()(FunctionalInstruction const& _instr) -{ - ASTWalker::operator()(_instr); - - m_sideEffects += EVMDialect::sideEffectsOfInstruction(_instr.instruction); -} - void SideEffectsCollector::operator()(FunctionCall const& _functionCall) { ASTWalker::operator()(_functionCall); @@ -88,14 +81,6 @@ bool MSizeFinder::containsMSize(Dialect const& _dialect, Block const& _ast) return finder.m_msizeFound; } -void MSizeFinder::operator()(FunctionalInstruction const& _instr) -{ - ASTWalker::operator()(_instr); - - if (_instr.instruction == eth::Instruction::MSIZE) - m_msizeFound = true; -} - void MSizeFinder::operator()(FunctionCall const& _functionCall) { ASTWalker::operator()(_functionCall); @@ -181,11 +166,7 @@ TerminationFinder::ControlFlow TerminationFinder::controlFlowKind(Statement cons bool TerminationFinder::isTerminatingBuiltin(ExpressionStatement const& _exprStmnt) { - if (_exprStmnt.expression.type() == typeid(FunctionalInstruction)) - return eth::SemanticInformation::terminatesControlFlow( - boost::get(_exprStmnt.expression).instruction - ); - else if (_exprStmnt.expression.type() == typeid(FunctionCall)) + if (_exprStmnt.expression.type() == typeid(FunctionCall)) if (auto const* dialect = dynamic_cast(&m_dialect)) if (auto const* builtin = dialect->builtin(boost::get(_exprStmnt.expression).functionName.name)) if (builtin->instruction) diff --git a/libyul/optimiser/Semantics.h b/libyul/optimiser/Semantics.h index 4ecb48053..def879cff 100644 --- a/libyul/optimiser/Semantics.h +++ b/libyul/optimiser/Semantics.h @@ -54,7 +54,6 @@ public: ); using ASTWalker::operator(); - void operator()(FunctionalInstruction const& _functionalInstruction) override; void operator()(FunctionCall const& _functionCall) override; bool movable() const { return m_sideEffects.movable; } @@ -104,7 +103,6 @@ public: static bool containsMSize(Dialect const& _dialect, Block const& _ast); using ASTWalker::operator(); - void operator()(FunctionalInstruction const& _instr); void operator()(FunctionCall const& _funCall); private: diff --git a/libyul/optimiser/SimplificationRules.cpp b/libyul/optimiser/SimplificationRules.cpp index 96f225f8c..b62fb9e6f 100644 --- a/libyul/optimiser/SimplificationRules.cpp +++ b/libyul/optimiser/SimplificationRules.cpp @@ -67,9 +67,7 @@ bool SimplificationRules::isInitialized() const std::optional const*>> SimplificationRules::instructionAndArguments(Dialect const& _dialect, Expression const& _expr) { - if (_expr.type() == typeid(FunctionalInstruction)) - return make_pair(boost::get(_expr).instruction, &boost::get(_expr).arguments); - else if (_expr.type() == typeid(FunctionCall)) + if (_expr.type() == typeid(FunctionCall)) if (auto const* dialect = dynamic_cast(&_dialect)) if (auto const* builtin = dialect->builtin(boost::get(_expr).functionName.name)) if (builtin->instruction) @@ -225,8 +223,15 @@ Expression Pattern::toExpression(SourceLocation const& _location) const vector arguments; for (auto const& arg: m_arguments) arguments.emplace_back(arg.toExpression(_location)); - // TODO convert to FunctionCall - return FunctionalInstruction{_location, m_instruction, std::move(arguments)}; + + string name = instructionInfo(m_instruction).name; + transform(begin(name), end(name), begin(name), [](auto _c) { return tolower(_c); }); + + return FunctionCall{ + _location, + Identifier{_location, YulString{name}}, + std::move(arguments) + }; } assertThrow(false, OptimizerException, "Pattern of kind 'any', but no match group."); } diff --git a/libyul/optimiser/SyntacticalEquality.cpp b/libyul/optimiser/SyntacticalEquality.cpp index d1c8ecc79..f6046ea47 100644 --- a/libyul/optimiser/SyntacticalEquality.cpp +++ b/libyul/optimiser/SyntacticalEquality.cpp @@ -46,15 +46,6 @@ bool SyntacticallyEqual::operator()(Statement const& _lhs, Statement const& _rhs }, _lhs, _rhs); } -bool SyntacticallyEqual::expressionEqual(FunctionalInstruction const& _lhs, FunctionalInstruction const& _rhs) -{ - return - _lhs.instruction == _rhs.instruction && - containerEqual(_lhs.arguments, _rhs.arguments, [this](Expression const& _lhsExpr, Expression const& _rhsExpr) -> bool { - return (*this)(_lhsExpr, _rhsExpr); - }); -} - bool SyntacticallyEqual::expressionEqual(FunctionCall const& _lhs, FunctionCall const& _rhs) { return diff --git a/libyul/optimiser/SyntacticalEquality.h b/libyul/optimiser/SyntacticalEquality.h index 38f5d278b..f0a4fee1e 100644 --- a/libyul/optimiser/SyntacticalEquality.h +++ b/libyul/optimiser/SyntacticalEquality.h @@ -42,7 +42,6 @@ public: bool operator()(Expression const& _lhs, Expression const& _rhs); bool operator()(Statement const& _lhs, Statement const& _rhs); - bool expressionEqual(FunctionalInstruction const& _lhs, FunctionalInstruction const& _rhs); bool expressionEqual(FunctionCall const& _lhs, FunctionCall const& _rhs); bool expressionEqual(Identifier const& _lhs, Identifier const& _rhs); bool expressionEqual(Literal const& _lhs, Literal const& _rhs); diff --git a/test/tools/yulInterpreter/Interpreter.cpp b/test/tools/yulInterpreter/Interpreter.cpp index 3f8d5b737..4adf3a291 100644 --- a/test/tools/yulInterpreter/Interpreter.cpp +++ b/test/tools/yulInterpreter/Interpreter.cpp @@ -227,15 +227,6 @@ void ExpressionEvaluator::operator()(Identifier const& _identifier) setValue(m_variables.at(_identifier.name)); } -void ExpressionEvaluator::operator()(FunctionalInstruction const& _instr) -{ - evaluateArgs(_instr.arguments); - EVMInstructionInterpreter interpreter(m_state); - // The instruction might also return nothing, but it does not - // hurt to set the value in that case. - setValue(interpreter.eval(_instr.instruction, values())); -} - void ExpressionEvaluator::operator()(FunctionCall const& _funCall) { evaluateArgs(_funCall.arguments); diff --git a/test/tools/yulInterpreter/Interpreter.h b/test/tools/yulInterpreter/Interpreter.h index 5117f9492..d3ef30419 100644 --- a/test/tools/yulInterpreter/Interpreter.h +++ b/test/tools/yulInterpreter/Interpreter.h @@ -169,7 +169,6 @@ public: void operator()(Literal const&) override; void operator()(Identifier const&) override; - void operator()(FunctionalInstruction const& _instr) override; void operator()(FunctionCall const& _funCall) override; /// Asserts that the expression has exactly one value and returns it.