mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Make EVMAssemblyStack impolement AbstractAssemblyStack
This commit is contained in:
parent
68d4bfe11f
commit
f1528e166a
@ -59,4 +59,97 @@ void EVMAssemblyStack::assemble()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinkerObject const& EVMAssemblyStack::object(string const& _contractName) const
|
||||||
|
{
|
||||||
|
solAssert(_contractName == m_name);
|
||||||
|
return m_object;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkerObject const& EVMAssemblyStack::runtimeObject(string const& _contractName) const
|
||||||
|
{
|
||||||
|
solAssert(_contractName == m_name);
|
||||||
|
return m_runtimeObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Review implementation here
|
||||||
|
map<string, unsigned> EVMAssemblyStack::sourceIndices() const
|
||||||
|
{
|
||||||
|
solAssert(m_evmAssembly);
|
||||||
|
|
||||||
|
map<string, unsigned> indices;
|
||||||
|
unsigned index = 0;
|
||||||
|
for (auto const& s: m_evmAssembly->sourceList())
|
||||||
|
if (s != CompilerContext::yulUtilityFileName())
|
||||||
|
indices[s] = index++;
|
||||||
|
|
||||||
|
if (indices.find(CompilerContext::yulUtilityFileName()) == indices.end())
|
||||||
|
indices[CompilerContext::yulUtilityFileName()] = index++;
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
string const* EVMAssemblyStack::sourceMapping(string const& _contractName) const
|
||||||
|
{
|
||||||
|
solAssert(_contractName == m_name);
|
||||||
|
solAssert(m_evmAssembly);
|
||||||
|
|
||||||
|
if (!m_sourceMapping.has_value())
|
||||||
|
{
|
||||||
|
// TODO: Should this be already pre-computed in assemble() and only returned here?
|
||||||
|
AssemblyItems const& items = m_evmAssembly->items();
|
||||||
|
m_sourceMapping.emplace(AssemblyItem::computeSourceMapping(items, sourceIndices()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_sourceMapping.has_value() ? &m_sourceMapping.value() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
string const* EVMAssemblyStack::runtimeSourceMapping(string const& _contractName) const
|
||||||
|
{
|
||||||
|
solAssert(_contractName == m_name);
|
||||||
|
solAssert(m_evmRuntimeAssembly);
|
||||||
|
|
||||||
|
if (!m_sourceMapping.has_value())
|
||||||
|
{
|
||||||
|
// TODO: Should this be already pre-computed in assemble() and only returned here?
|
||||||
|
AssemblyItems const& items = m_evmRuntimeAssembly->items();
|
||||||
|
m_sourceMapping.emplace(AssemblyItem::computeSourceMapping(items, sourceIndices()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_sourceMapping.has_value() ? &m_sourceMapping.value() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value EVMAssemblyStack::assemblyJSON(string const& _contractName) const
|
||||||
|
{
|
||||||
|
solAssert(_contractName == m_name);
|
||||||
|
solAssert(m_evmAssembly);
|
||||||
|
|
||||||
|
vector<string> sources = sourceNames();
|
||||||
|
if (find(sources.begin(), sources.end(), CompilerContext::yulUtilityFileName()) == sources.end())
|
||||||
|
sources.emplace_back(CompilerContext::yulUtilityFileName());
|
||||||
|
m_evmAssembly->setSourceList(sources);
|
||||||
|
return m_evmAssembly->assemblyJSON();
|
||||||
|
}
|
||||||
|
|
||||||
|
string EVMAssemblyStack::assemblyString(string const& _contractName, StringMap const& _sourceCodes) const
|
||||||
|
{
|
||||||
|
solAssert(_contractName == m_name);
|
||||||
|
solAssert(m_evmAssembly);
|
||||||
|
|
||||||
|
return m_evmAssembly->assemblyString(m_debugInfoSelection, _sourceCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
string const EVMAssemblyStack::filesystemFriendlyName(string const& _contractName) const
|
||||||
|
{
|
||||||
|
solAssert(_contractName == m_name);
|
||||||
|
|
||||||
|
// We have only one contract so there are no conflicts possible and no need to sanitize the name
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> EVMAssemblyStack::sourceNames() const
|
||||||
|
{
|
||||||
|
solAssert(m_evmAssembly);
|
||||||
|
|
||||||
|
return m_evmAssembly->sourceList();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace solidity::evmasm
|
} // namespace solidity::evmasm
|
||||||
|
@ -19,17 +19,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libevmasm/Assembly.h>
|
#include <libevmasm/Assembly.h>
|
||||||
|
#include <libevmasm/AbstractAssemblyStack.h>
|
||||||
#include <libevmasm/LinkerObject.h>
|
#include <libevmasm/LinkerObject.h>
|
||||||
|
|
||||||
|
#include <liblangutil/DebugInfoSelection.h>
|
||||||
|
|
||||||
#include <libsolutil/JSON.h>
|
#include <libsolutil/JSON.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace solidity::evmasm
|
namespace solidity::evmasm
|
||||||
{
|
{
|
||||||
|
|
||||||
class EVMAssemblyStack
|
class EVMAssemblyStack: public AbstractAssemblyStack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit EVMAssemblyStack(langutil::EVMVersion _evmVersion): m_evmVersion(_evmVersion) {}
|
explicit EVMAssemblyStack(langutil::EVMVersion _evmVersion): m_evmVersion(_evmVersion) {}
|
||||||
@ -44,19 +49,41 @@ public:
|
|||||||
|
|
||||||
evmasm::LinkerObject const& object() const { return m_object; }
|
evmasm::LinkerObject const& object() const { return m_object; }
|
||||||
evmasm::LinkerObject const& runtimeObject() const { return m_runtimeObject; }
|
evmasm::LinkerObject const& runtimeObject() const { return m_runtimeObject; }
|
||||||
|
virtual LinkerObject const& object(std::string const& _contractName) const override;
|
||||||
|
virtual LinkerObject const& runtimeObject(std::string const& _contractName) const override;
|
||||||
|
|
||||||
std::shared_ptr<evmasm::Assembly> const& evmAssembly() const { return m_evmAssembly; }
|
std::shared_ptr<evmasm::Assembly> const& evmAssembly() const { return m_evmAssembly; }
|
||||||
std::shared_ptr<evmasm::Assembly> const& evmRuntimeAssembly() const { return m_evmRuntimeAssembly; }
|
std::shared_ptr<evmasm::Assembly> const& evmRuntimeAssembly() const { return m_evmRuntimeAssembly; }
|
||||||
|
|
||||||
|
virtual std::string const* sourceMapping(std::string const& _contractName) const override;
|
||||||
|
virtual std::string const* runtimeSourceMapping(std::string const& _contractName) const override;
|
||||||
|
|
||||||
|
virtual Json::Value assemblyJSON(std::string const& _contractName) const override;
|
||||||
|
virtual std::string assemblyString(std::string const& _contractName, StringMap const& _sourceCodes) const override;
|
||||||
|
|
||||||
|
virtual std::string const filesystemFriendlyName(std::string const& _contractName) const override;
|
||||||
|
|
||||||
|
virtual std::vector<std::string> contractNames() const override { return {m_name}; }
|
||||||
|
virtual std::vector<std::string> sourceNames() const override;
|
||||||
|
std::map<std::string, unsigned> sourceIndices() const;
|
||||||
|
|
||||||
|
// TODO: This should depend on whether assemble() was successful
|
||||||
|
virtual bool compilationSuccessful() const override { return true; }
|
||||||
|
|
||||||
|
void selectDebugInfo(langutil::DebugInfoSelection _debugInfoSelection) { m_debugInfoSelection = _debugInfoSelection; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
langutil::EVMVersion m_evmVersion;
|
langutil::EVMVersion m_evmVersion;
|
||||||
|
langutil::DebugInfoSelection m_debugInfoSelection = langutil::DebugInfoSelection::Default();
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
Json::Value m_json;
|
Json::Value m_json;
|
||||||
std::shared_ptr<evmasm::Assembly> m_evmAssembly;
|
std::shared_ptr<evmasm::Assembly> m_evmAssembly;
|
||||||
std::shared_ptr<evmasm::Assembly> m_evmRuntimeAssembly;
|
std::shared_ptr<evmasm::Assembly> m_evmRuntimeAssembly;
|
||||||
evmasm::LinkerObject m_object; ///< Deployment object (includes the runtime sub-object).
|
evmasm::LinkerObject m_object; ///< Deployment object (includes the runtime sub-object).
|
||||||
evmasm::LinkerObject m_runtimeObject; ///< Runtime object.
|
evmasm::LinkerObject m_runtimeObject; ///< Runtime object.
|
||||||
|
mutable std::optional<std::string const> m_sourceMapping;
|
||||||
|
mutable std::optional<std::string const> m_runtimeSourceMapping;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace solidity::evmasm
|
} // namespace solidity::evmasm
|
||||||
|
Loading…
Reference in New Issue
Block a user