/* 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 . */ /** * Common code generator for translating Yul / inline assembly to EWasm. */ #pragma once #include #include #include #include namespace yul { struct AsmAnalysisInfo; class EWasmCodeTransform: public boost::static_visitor { public: EWasmCodeTransform( AsmAnalysisInfo&, Dialect const& _dialect ): m_dialect(_dialect) {} std::string run(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); wasm::Expression operator()(yul::FunctionCall const&); wasm::Expression operator()(yul::ExpressionStatement const& _statement); wasm::Expression operator()(yul::Label const& _label); wasm::Expression operator()(yul::StackAssignment const& _assignment); wasm::Expression operator()(yul::Assignment const& _assignment); wasm::Expression operator()(yul::VariableDeclaration const& _varDecl); wasm::Expression operator()(yul::If const& _if); wasm::Expression operator()(yul::Switch const& _switch); wasm::Expression operator()(yul::FunctionDefinition const&); wasm::Expression operator()(yul::ForLoop const&); wasm::Expression operator()(yul::Break const&); wasm::Expression operator()(yul::Continue const&); wasm::Expression operator()(yul::Block const& _block); private: std::unique_ptr visit(yul::Expression const& _expression); wasm::Expression visitReturnByValue(yul::Expression const& _expression); std::vector visit(std::vector const& _expressions); wasm::Expression visit(yul::Statement const& _statement); std::vector visit(std::vector const& _statements); wasm::FunctionDefinition translateFunction(yul::FunctionDefinition const& _funDef); std::string newLabel(); std::vector m_localVariables; size_t m_labelCounter = 0; std::stack> m_breakContinueLabelNames; Dialect const& m_dialect; }; }