From 0ec7a0e72cbc2ab2f05005a19ff29651a47c1b45 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 4 Dec 2018 15:10:47 +0100 Subject: Move AsmCodeGen. --- libsolidity/codegen/AsmCodeGen.h | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 libsolidity/codegen/AsmCodeGen.h (limited to 'libsolidity/codegen/AsmCodeGen.h') diff --git a/libsolidity/codegen/AsmCodeGen.h b/libsolidity/codegen/AsmCodeGen.h new file mode 100644 index 00000000..fd5ac0a1 --- /dev/null +++ b/libsolidity/codegen/AsmCodeGen.h @@ -0,0 +1,54 @@ +/* + 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 2016 + * Code-generating part of inline assembly. + */ + +#pragma once + +#include + +#include + +namespace dev +{ +namespace eth +{ +class Assembly; +} +} + +namespace yul +{ +struct Block; + +class CodeGenerator +{ +public: + /// Performs code generation and appends generated to _assembly. + static void assemble( + Block const& _parsedData, + AsmAnalysisInfo& _analysisInfo, + dev::eth::Assembly& _assembly, + yul::ExternalIdentifierAccess const& _identifierAccess = yul::ExternalIdentifierAccess(), + bool _useNamedLabelsForFunctions = false + ); +}; + +} -- cgit v1.2.3 From 3ebb78a886b606cad345534758b4dcc4ab2863d0 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 4 Dec 2018 15:20:29 +0100 Subject: Adjust include paths. --- libsolidity/codegen/AsmCodeGen.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'libsolidity/codegen/AsmCodeGen.h') diff --git a/libsolidity/codegen/AsmCodeGen.h b/libsolidity/codegen/AsmCodeGen.h index fd5ac0a1..95d0e51c 100644 --- a/libsolidity/codegen/AsmCodeGen.h +++ b/libsolidity/codegen/AsmCodeGen.h @@ -15,9 +15,7 @@ along with solidity. If not, see . */ /** - * @author Christian - * @date 2016 - * Code-generating part of inline assembly. + * Adaptor between the abstract assembly and eth assembly. */ #pragma once -- cgit v1.2.3 From 7ee1ddc172a29ed1ccdd545a996d19f4c2a145a3 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 4 Dec 2018 15:36:03 +0100 Subject: Switch namespaces. --- libsolidity/codegen/AsmCodeGen.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'libsolidity/codegen/AsmCodeGen.h') diff --git a/libsolidity/codegen/AsmCodeGen.h b/libsolidity/codegen/AsmCodeGen.h index 95d0e51c..dc529e10 100644 --- a/libsolidity/codegen/AsmCodeGen.h +++ b/libsolidity/codegen/AsmCodeGen.h @@ -24,25 +24,28 @@ #include +namespace yul +{ +struct Block; +} + namespace dev { namespace eth { class Assembly; } -} -namespace yul +namespace solidity { -struct Block; class CodeGenerator { public: /// Performs code generation and appends generated to _assembly. static void assemble( - Block const& _parsedData, - AsmAnalysisInfo& _analysisInfo, + yul::Block const& _parsedData, + yul::AsmAnalysisInfo& _analysisInfo, dev::eth::Assembly& _assembly, yul::ExternalIdentifierAccess const& _identifierAccess = yul::ExternalIdentifierAccess(), bool _useNamedLabelsForFunctions = false @@ -50,3 +53,4 @@ public: }; } +} -- cgit v1.2.3 From 4721cf332f0ca8af5fa16244c651cd6a635b3cdc Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 4 Dec 2018 16:26:38 +0100 Subject: Expose EthAssemblyAdapter. --- libsolidity/codegen/AsmCodeGen.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'libsolidity/codegen/AsmCodeGen.h') diff --git a/libsolidity/codegen/AsmCodeGen.h b/libsolidity/codegen/AsmCodeGen.h index dc529e10..b5bd33d5 100644 --- a/libsolidity/codegen/AsmCodeGen.h +++ b/libsolidity/codegen/AsmCodeGen.h @@ -21,6 +21,9 @@ #pragma once #include +#include + +#include #include @@ -34,11 +37,39 @@ namespace dev namespace eth { class Assembly; +class AssemblyItem; } namespace solidity { +class EthAssemblyAdapter: public yul::AbstractAssembly +{ +public: + explicit EthAssemblyAdapter(eth::Assembly& _assembly); + void setSourceLocation(langutil::SourceLocation const& _location) override; + int stackHeight() const override; + void appendInstruction(solidity::Instruction _instruction) override; + void appendConstant(u256 const& _constant) override; + void appendLabel(LabelID _labelId) override; + void appendLabelReference(LabelID _labelId) override; + size_t newLabelId() override; + size_t namedLabel(std::string const& _name) override; + void appendLinkerSymbol(std::string const& _linkerSymbol) override; + void appendJump(int _stackDiffAfter) override; + void appendJumpTo(LabelID _labelId, int _stackDiffAfter) override; + void appendJumpToIf(LabelID _labelId) override; + void appendBeginsub(LabelID, int) override; + void appendJumpsub(LabelID, int, int) override; + void appendReturnsub(int, int) override; + void appendAssemblySize() override; + +private: + static LabelID assemblyTagToIdentifier(eth::AssemblyItem const& _tag); + + eth::Assembly& m_assembly; +}; + class CodeGenerator { public: -- cgit v1.2.3 From f6ed29b88b0a721984173df04f04ad4c48d8711d Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 4 Dec 2018 18:57:07 +0100 Subject: Extend abstract assembly to be able to handle sub-objects. --- libsolidity/codegen/AsmCodeGen.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libsolidity/codegen/AsmCodeGen.h') diff --git a/libsolidity/codegen/AsmCodeGen.h b/libsolidity/codegen/AsmCodeGen.h index b5bd33d5..4c6d97f4 100644 --- a/libsolidity/codegen/AsmCodeGen.h +++ b/libsolidity/codegen/AsmCodeGen.h @@ -63,11 +63,17 @@ public: void appendJumpsub(LabelID, int, int) override; void appendReturnsub(int, int) override; void appendAssemblySize() override; + std::pair, SubID> createSubAssembly() override; + void appendDataOffset(SubID _sub) override; + void appendDataSize(SubID _sub) override; + SubID appendData(dev::bytes const& _data) override; private: static LabelID assemblyTagToIdentifier(eth::AssemblyItem const& _tag); eth::Assembly& m_assembly; + std::map m_dataHashBySubId; + size_t m_nextDataCounter = std::numeric_limits::max() / 2; }; class CodeGenerator -- cgit v1.2.3 From 362648a45042d74da4e631520c0be581902c871b Mon Sep 17 00:00:00 2001 From: liangdzou Date: Tue, 25 Sep 2018 10:47:25 +0800 Subject: Reuse stack slots in Yul to EVM code generation. --- libsolidity/codegen/AsmCodeGen.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libsolidity/codegen/AsmCodeGen.h') diff --git a/libsolidity/codegen/AsmCodeGen.h b/libsolidity/codegen/AsmCodeGen.h index 4c6d97f4..303d32ee 100644 --- a/libsolidity/codegen/AsmCodeGen.h +++ b/libsolidity/codegen/AsmCodeGen.h @@ -85,7 +85,8 @@ public: yul::AsmAnalysisInfo& _analysisInfo, dev::eth::Assembly& _assembly, yul::ExternalIdentifierAccess const& _identifierAccess = yul::ExternalIdentifierAccess(), - bool _useNamedLabelsForFunctions = false + bool _useNamedLabelsForFunctions = false, + bool _optimize = false ); }; -- cgit v1.2.3 From ab7667627149e5793343b81af43f3fa1b328097d Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Mon, 17 Dec 2018 17:06:11 +0100 Subject: Sort includes in libsolidity/codegen --- libsolidity/codegen/AsmCodeGen.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'libsolidity/codegen/AsmCodeGen.h') diff --git a/libsolidity/codegen/AsmCodeGen.h b/libsolidity/codegen/AsmCodeGen.h index 303d32ee..516b0a36 100644 --- a/libsolidity/codegen/AsmCodeGen.h +++ b/libsolidity/codegen/AsmCodeGen.h @@ -22,9 +22,7 @@ #include #include - #include - #include namespace yul -- cgit v1.2.3