mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Introduce AbstractAssemblyStack as an interface to functionality common for both CompilerStack and EVMAssemblyStack
This commit is contained in:
parent
72caea92e6
commit
7cfb34ce76
54
libevmasm/AbstractAssemblyStack.h
Normal file
54
libevmasm/AbstractAssemblyStack.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libevmasm/LinkerObject.h>
|
||||
|
||||
#include <libsolutil/Common.h>
|
||||
#include <libsolutil/JSON.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<std::string> contractNames() const = 0;
|
||||
virtual std::vector<std::string> sourceNames() const = 0;
|
||||
|
||||
virtual bool compilationSuccessful() const = 0;
|
||||
};
|
||||
|
||||
} // namespace solidity::evmasm
|
@ -1,4 +1,5 @@
|
||||
set(sources
|
||||
AbstractAssemblyStack.h
|
||||
Assembly.cpp
|
||||
Assembly.h
|
||||
AssemblyItem.cpp
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
|
||||
#include <libevmasm/AbstractAssemblyStack.h>
|
||||
#include <libevmasm/EVMAssemblyStack.h>
|
||||
#include <libevmasm/LinkerObject.h>
|
||||
|
||||
@ -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<std::string> sourceNames() const;
|
||||
virtual std::vector<std::string> 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<std::string> const& unhandledSMTLib2Queries() const { return m_unhandledSMTLib2Queries; }
|
||||
|
||||
/// @returns a list of the contract names in the sources.
|
||||
std::vector<std::string> contractNames() const;
|
||||
virtual std::vector<std::string> 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<std::string> 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.
|
||||
|
Loading…
Reference in New Issue
Block a user