diff --git a/libevmasm/AbstractAssemblyStack.h b/libevmasm/AbstractAssemblyStack.h new file mode 100644 index 000000000..6be78cbc7 --- /dev/null +++ b/libevmasm/AbstractAssemblyStack.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 . +*/ +// SPDX-License-Identifier: GPL-3.0 + +#pragma once + +#include + +#include +#include + +#include +#include + +namespace solidity::evmasm +{ + +class AbstractAssemblyStack +{ +public: + virtual ~AbstractAssemblyStack() {} + + virtual LinkerObject const& object(std::string const& _contractName) const = 0; + virtual LinkerObject const& runtimeObject(std::string const& _contractName) const = 0; + + virtual std::string const* sourceMapping(std::string const& _contractName) const = 0; + virtual std::string const* runtimeSourceMapping(std::string const& _contractName) const = 0; + + virtual Json::Value assemblyJSON(std::string const& _contractName) const = 0; + virtual std::string assemblyString(std::string const& _contractName, StringMap const& _sourceCodes) const = 0; + + virtual std::string const filesystemFriendlyName(std::string const& _contractName) const = 0; + + virtual std::vector contractNames() const = 0; + virtual std::vector sourceNames() const = 0; + + virtual bool compilationSuccessful() const = 0; +}; + +} // namespace solidity::evmasm diff --git a/libevmasm/CMakeLists.txt b/libevmasm/CMakeLists.txt index dbe9d14f8..c1918540e 100644 --- a/libevmasm/CMakeLists.txt +++ b/libevmasm/CMakeLists.txt @@ -1,4 +1,5 @@ set(sources + AbstractAssemblyStack.h Assembly.cpp Assembly.h AssemblyItem.cpp diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index c55e55b59..448a67562 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -90,7 +91,7 @@ class DeclarationContainer; * If error recovery is active, it is possible to progress through the stages even when * there are errors. In any case, producing code is only possible without errors. */ -class CompilerStack: public langutil::CharStreamProvider +class CompilerStack: public langutil::CharStreamProvider, public evmasm::AbstractAssemblyStack { public: /// Noncopyable. @@ -142,7 +143,7 @@ public: bool hasError() const { return m_hasError; } - bool compilationSuccessful() const { return m_stackState >= CompilationSuccessful; } + virtual bool compilationSuccessful() const override { return m_stackState >= CompilationSuccessful; } /// Resets the compiler to an empty state. Unless @a _keepSettings is set to true, /// all settings are reset as well. @@ -249,7 +250,7 @@ public: bool compile(State _stopAfter = State::CompilationSuccessful); /// @returns the list of sources (paths) used - std::vector sourceNames() const; + virtual std::vector sourceNames() const override; /// @returns a mapping assigning each source name its index inside the vector returned /// by sourceNames(). @@ -270,13 +271,13 @@ public: std::vector const& unhandledSMTLib2Queries() const { return m_unhandledSMTLib2Queries; } /// @returns a list of the contract names in the sources. - std::vector contractNames() const; + virtual std::vector contractNames() const override; /// @returns the name of the last contract. If _sourceName is defined the last contract of that source will be returned. std::string const lastContractName(std::optional const& _sourceName = std::nullopt) const; /// @returns either the contract's name or a mixture of its name and source file, sanitized for filesystem use - std::string const filesystemFriendlyName(std::string const& _contractName) const; + virtual std::string const filesystemFriendlyName(std::string const& _contractName) const override; /// @returns the IR representation of a contract. std::string const& yulIR(std::string const& _contractName) const; @@ -291,10 +292,10 @@ public: Json::Value const& yulIROptimizedAst(std::string const& _contractName) const; /// @returns the assembled object for a contract. - evmasm::LinkerObject const& object(std::string const& _contractName) const; + virtual evmasm::LinkerObject const& object(std::string const& _contractName) const override; /// @returns the runtime object for the contract. - evmasm::LinkerObject const& runtimeObject(std::string const& _contractName) const; + virtual evmasm::LinkerObject const& runtimeObject(std::string const& _contractName) const override; /// @returns normal contract assembly items evmasm::AssemblyItems const* assemblyItems(std::string const& _contractName) const; @@ -308,21 +309,21 @@ public: /// @returns the string that provides a mapping between bytecode and sourcecode or a nullptr /// if the contract does not (yet) have bytecode. - std::string const* sourceMapping(std::string const& _contractName) const; + virtual std::string const* sourceMapping(std::string const& _contractName) const override; /// @returns the string that provides a mapping between runtime bytecode and sourcecode. /// if the contract does not (yet) have bytecode. - std::string const* runtimeSourceMapping(std::string const& _contractName) const; + virtual std::string const* runtimeSourceMapping(std::string const& _contractName) const override; /// @return a verbose text representation of the assembly. /// @arg _sourceCodes is the map of input files to source code strings /// Prerequisite: Successful compilation. - std::string assemblyString(std::string const& _contractName, StringMap const& _sourceCodes = StringMap()) const; + virtual std::string assemblyString(std::string const& _contractName, StringMap const& _sourceCodes = StringMap()) const override; /// @returns a JSON representation of the assembly. /// @arg _sourceCodes is the map of input files to source code strings /// Prerequisite: Successful compilation. - Json::Value assemblyJSON(std::string const& _contractName) const; + virtual Json::Value assemblyJSON(std::string const& _contractName) const override; /// @returns a JSON representing the contract ABI. /// Prerequisite: Successful call to parse or compile.