/* 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 . */ /** * @author Christian * @date 2014 * Code generator for contracts. */ #pragma once #include #include #include #include #include namespace dev { namespace solidity { /** * Code generator at the contract level. Can be used to generate code for exactly one contract * either either in "runtime mode" or "creation mode". */ class ContractCompiler: private ASTConstVisitor { public: explicit ContractCompiler(ContractCompiler* _runtimeCompiler, CompilerContext& _context, bool _optimise): m_optimise(_optimise), m_runtimeCompiler(_runtimeCompiler), m_context(_context) { m_context = CompilerContext(_runtimeCompiler ? &_runtimeCompiler->m_context : nullptr); } void compileContract( ContractDefinition const& _contract, std::map const& _contracts ); /// Compiles the constructor part of the contract. /// @returns the identifier of the runtime sub-assembly. size_t compileConstructor( ContractDefinition const& _contract, std::map const& _contracts ); /// Compiles a contract that uses DELEGATECALL to call into a pre-deployed version of the given /// contract at runtime, but contains the full creation-time code. /// @returns the identifier of the runtime sub-assembly. size_t compileClone( ContractDefinition const& _contract, std::map const& _contracts ); private: /// Registers the non-function objects inside the contract with the context and stores the basic /// information about the contract like the AST annotations. void initializeContext( ContractDefinition const& _contract, std::map const& _compiledContracts ); /// Adds the code that is run at creation time. Should be run after exchanging the run-time context /// with a new and initialized context. Adds the constructor code. /// @returns the identifier of the runtime sub assembly size_t packIntoContractCreator(ContractDefinition const& _contract); /// Appends state variable initialisation and constructor code. void appendInitAndConstructorCode(ContractDefinition const& _contract); void appendBaseConstructor(FunctionDefinition const& _constructor); void appendConstructor(FunctionDefinition const& _constructor); void appendFunctionSelector(ContractDefinition const& _contract); void appendCallValueCheck(); /// Creates code that unpacks the arguments for the given function represented by a vector of TypePointers. /// From memory if @a _fromMemory is true, otherwise from call data. /// Expects source offset on the stack, which is removed. void appendCalldataUnpacker(TypePointers const& _typeParameters, bool _fromMemory = false); void appendReturnValuePacker(TypePointers const& _typeParameters, bool _isLibrary); void registerStateVariables(ContractDefinition const& _contract); void initializeStateVariables(ContractDefinition const& _contract); virtual bool visit(VariableDeclaration const& _variableDeclaration) override; virtual bool visit(FunctionDefinition const& _function) override; virtual bool visit(InlineAssembly const& _inlineAssembly) override; virtual bool visit(IfStatement const& _ifStatement) override; virtual bool visit(WhileStatement const& _whileStatement) override; virtual bool visit(ForStatement const& _forStatement) override; virtual bool visit(Continue const& _continue) override; virtual bool visit(Break const& _break) override; virtual bool visit(Return const& _return) override; virtual bool visit(Throw const& _throw) override; virtual bool visit(VariableDeclarationStatement const& _variableDeclarationStatement) override; virtual bool visit(ExpressionStatement const& _expressionStatement) override; virtual bool visit(PlaceholderStatement const&) override; /// Repeatedly visits all function which are referenced but which are not compiled yet. void appendMissingFunctions(); /// Appends one layer of function modifier code of the current function, or the function /// body itself if the last modifier was reached. void appendModifierOrFunctionCode(); void appendStackVariableInitialisation(VariableDeclaration const& _variable); void compileExpression(Expression const& _expression, TypePointer const& _targetType = TypePointer()); /// @returns the runtime assembly for clone contracts. static eth::AssemblyPointer cloneRuntime(); bool const m_optimise; /// Pointer to the runtime compiler in case this is a creation compiler. ContractCompiler* m_runtimeCompiler = nullptr; CompilerContext& m_context; std::vector m_breakTags; ///< tag to jump to for a "break" statement std::vector m_continueTags; ///< tag to jump to for a "continue" statement /// Tag to jump to for a "return" statement, needs to be stacked because of modifiers. std::vector m_returnTags; unsigned m_modifierDepth = 0; FunctionDefinition const* m_currentFunction = nullptr; unsigned m_stackCleanupForReturn = 0; ///< this number of stack elements need to be removed before jump to m_returnTag // arguments for base constructors, filled in derived-to-base order std::map> const*> m_baseArguments; }; } } aster FreeBSD Ports (https://github.com/freebsd/freebsd-ports)
aboutsummaryrefslogtreecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
* multimedia/libmediainfo: Update to 22.09Po-Chuan Hsieh2022-10-092-4/+4
* Remove WWW entries moved into port MakefilesStefan Eßer2022-09-081-2/+1
* Add WWW entries to port MakefilesStefan Eßer2022-09-081-0/+1
* multimedia: remove 'Created by' linesTobias C. Berner2022-07-201-2/+0
* multimedia/libmediainfo: Update to 22.06Po-Chuan Hsieh2022-06-302-4/+4
* multimedia/libmediainfo: Remove MMS optionDaniel Engberg2022-06-161-3/+1
* multimedia/libmediainfo: Update to 22.03Po-Chuan Hsieh2022-04-163-47/+4
* multimedia/libmediainfo: Remove outdated CONFLICTS_INSTALLPo-Chuan Hsieh2022-03-261-6/+4
* multimedia/libmediainfo: Fix aa49adc65a51fff6afe04b2e1b51dc86189af1d2Po-Chuan Hsieh2022-03-253-24/+44
* multimedia/libmediainfo: Fix undefined tfsxml_* symbolsPo-Chuan Hsieh2021-12-222-0/+23
* multimedia/libmediainfo: Update to 21.09Po-Chuan Hsieh2021-09-212-5/+5
* textproc/tinyxml2: Update to 9.0.0Po-Chuan Hsieh2021-06-151-0/+1
* multimedia/libmediainfo: Update to 21.03Po-Chuan Hsieh2021-04-182-4/+4
* Remove # $FreeBSD$ from Makefiles.Mathieu Arnold2021-04-061-1/+0
* Update to 20.09Sunpoet Po-Chuan Hsieh2020-10-112-4/+4
* Convert REINPLACE_CMD to patch fileSunpoet Po-Chuan Hsieh2020-10-022-7/+36
* Update to 20.08Sunpoet Po-Chuan Hsieh2020-08-202-5/+4
* Update to 20.03Sunpoet Po-Chuan Hsieh2020-04-042-4/+4
* Update to 19.09Sunpoet Po-Chuan Hsieh2019-09-132-5/+4
* Bump PORTREVISION for ports depending on the canonical version of GCCGerald Pfeifer2019-07-271-0/+1
* Update to 19.07Sunpoet Po-Chuan Hsieh2019-07-182-4/+4
* Update to 19.04Sunpoet Po-Chuan Hsieh2019-04-252-4/+4
* Update to 18.12Sunpoet Po-Chuan Hsieh2019-01-022-5/+4
* Bump PORTREVISION for ports depending on the canonical version of GCCGerald Pfeifer2018-12-121-1/+1
* Update textproc/tinyxml2 to 7.0.1Sunpoet Po-Chuan Hsieh2018-11-191-0/+1
* Fix build on powerpc64Sunpoet Po-Chuan Hsieh2018-10-151-1/+3
* Update to 18.08.1Sunpoet Po-Chuan Hsieh2018-09-122-4/+4
* Update to 18.08Sunpoet Po-Chuan Hsieh2018-09-022-4/+4
* Update to 18.05Sunpoet Po-Chuan Hsieh2018-05-122-4/+4
* Update to 18.03.1Sunpoet Po-Chuan Hsieh2018-04-042-4/+4
* Update to 18.03Sunpoet Po-Chuan Hsieh2018-03-222-4/+4
* Update to 17.12Sunpoet Po-Chuan Hsieh2017-12-232-5/+4
* Update textproc/tinyxml2 to 6.0.0Sunpoet Po-Chuan Hsieh2017-12-201-0/+1
* Fix build on FreeBSD 10.3 i386Sunpoet Po-Chuan Hsieh2017-12-111-1/+0
* Update to 17.10Sunpoet Po-Chuan Hsieh2017-11-042-5/+4
* Update MASTER_SITES and distinfoSunpoet Po-Chuan Hsieh2017-09-132-4/+5
* Update to 0.7.99Sunpoet Po-Chuan Hsieh2017-09-132-4/+4
* Update to 0.7.98Sunpoet Po-Chuan Hsieh2017-08-122-4/+4
* Update to 0.7.97Sunpoet Po-Chuan Hsieh2017-07-042-5/+4
* Update textproc/tinyxml2 to 5.0.0Sunpoet Po-Chuan Hsieh2017-06-201-0/+1
* Update to 0.7.96Sunpoet Po-Chuan Hsieh2017-06-032-4/+4
* Update to 0.7.95Sunpoet Po-Chuan Hsieh2017-05-052-4/+4
* Update to 0.7.94Sunpoet Po-Chuan Hsieh2017-04-012-4/+4
* Update to 0.7.93Sunpoet Po-Chuan Hsieh2017-03-03