mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Yul AST output on the CLI and in Standard JSON
This commit is contained in:
committed by
Kamil Śliwak
parent
bb16f61e1c
commit
28a1abf89a
@@ -883,6 +883,14 @@ string const& CompilerStack::yulIR(string const& _contractName) const
|
||||
return contract(_contractName).yulIR;
|
||||
}
|
||||
|
||||
Json::Value const& CompilerStack::yulIRAst(string const& _contractName) const
|
||||
{
|
||||
if (m_stackState != CompilationSuccessful)
|
||||
solThrow(CompilerError, "Compilation was not successful.");
|
||||
|
||||
return contract(_contractName).yulIRAst;
|
||||
}
|
||||
|
||||
string const& CompilerStack::yulIROptimized(string const& _contractName) const
|
||||
{
|
||||
if (m_stackState != CompilationSuccessful)
|
||||
@@ -891,6 +899,14 @@ string const& CompilerStack::yulIROptimized(string const& _contractName) const
|
||||
return contract(_contractName).yulIROptimized;
|
||||
}
|
||||
|
||||
Json::Value const& CompilerStack::yulIROptimizedAst(string const& _contractName) const
|
||||
{
|
||||
if (m_stackState != CompilationSuccessful)
|
||||
solThrow(CompilerError, "Compilation was not successful.");
|
||||
|
||||
return contract(_contractName).yulIROptimizedAst;
|
||||
}
|
||||
|
||||
evmasm::LinkerObject const& CompilerStack::object(string const& _contractName) const
|
||||
{
|
||||
if (m_stackState != CompilationSuccessful)
|
||||
@@ -1445,7 +1461,13 @@ void CompilerStack::generateIR(ContractDefinition const& _contract)
|
||||
m_debugInfoSelection,
|
||||
this
|
||||
);
|
||||
tie(compiledContract.yulIR, compiledContract.yulIROptimized) = generator.run(
|
||||
|
||||
tie(
|
||||
compiledContract.yulIR,
|
||||
compiledContract.yulIRAst,
|
||||
compiledContract.yulIROptimized,
|
||||
compiledContract.yulIROptimizedAst
|
||||
) = generator.run(
|
||||
_contract,
|
||||
createCBORMetadata(compiledContract, /* _forIR */ true),
|
||||
otherYulSources
|
||||
|
||||
@@ -276,9 +276,15 @@ public:
|
||||
/// @returns the IR representation of a contract.
|
||||
std::string const& yulIR(std::string const& _contractName) const;
|
||||
|
||||
/// @returns the IR representation of a contract AST in format.
|
||||
Json::Value const& yulIRAst(std::string const& _contractName) const;
|
||||
|
||||
/// @returns the optimized IR representation of a contract.
|
||||
std::string const& yulIROptimized(std::string const& _contractName) const;
|
||||
|
||||
/// @returns the optimized IR representation of a contract AST in JSON format.
|
||||
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;
|
||||
|
||||
@@ -380,6 +386,8 @@ private:
|
||||
evmasm::LinkerObject runtimeObject; ///< Runtime object.
|
||||
std::string yulIR; ///< Yul IR code.
|
||||
std::string yulIROptimized; ///< Optimized Yul IR code.
|
||||
Json::Value yulIRAst; ///< JSON AST of Yul IR code.
|
||||
Json::Value yulIROptimizedAst; ///< JSON AST of optimized Yul IR code.
|
||||
util::LazyInit<std::string const> metadata; ///< The metadata json that will be hashed into the chain.
|
||||
util::LazyInit<Json::Value const> abi;
|
||||
util::LazyInit<Json::Value const> storageLayout;
|
||||
|
||||
@@ -179,7 +179,7 @@ bool hashMatchesContent(string const& _hash, string const& _content)
|
||||
|
||||
bool isArtifactRequested(Json::Value const& _outputSelection, string const& _artifact, bool _wildcardMatchesExperimental)
|
||||
{
|
||||
static set<string> experimental{"ir", "irOptimized"};
|
||||
static set<string> experimental{"ir", "irAst", "irOptimized", "irOptimizedAst"};
|
||||
for (auto const& selectedArtifactJson: _outputSelection)
|
||||
{
|
||||
string const& selectedArtifact = selectedArtifactJson.asString();
|
||||
@@ -263,7 +263,7 @@ bool isBinaryRequested(Json::Value const& _outputSelection)
|
||||
// This does not include "evm.methodIdentifiers" on purpose!
|
||||
static vector<string> const outputsThatRequireBinaries = vector<string>{
|
||||
"*",
|
||||
"ir", "irOptimized",
|
||||
"ir", "irAst", "irOptimized", "irOptimizedAst",
|
||||
"evm.gasEstimates", "evm.legacyAssembly", "evm.assembly"
|
||||
} + evmObjectComponents("bytecode") + evmObjectComponents("deployedBytecode");
|
||||
|
||||
@@ -295,7 +295,7 @@ bool isEvmBytecodeRequested(Json::Value const& _outputSelection)
|
||||
}
|
||||
|
||||
/// @returns true if any Yul IR was requested. Note that as an exception, '*' does not
|
||||
/// yet match "ir" or "irOptimized"
|
||||
/// yet match "ir", "irAst", "irOptimized" or "irOptimizedAst"
|
||||
bool isIRRequested(Json::Value const& _outputSelection)
|
||||
{
|
||||
if (!_outputSelection.isObject())
|
||||
@@ -304,7 +304,12 @@ bool isIRRequested(Json::Value const& _outputSelection)
|
||||
for (auto const& fileRequests: _outputSelection)
|
||||
for (auto const& requests: fileRequests)
|
||||
for (auto const& request: requests)
|
||||
if (request == "ir" || request == "irOptimized")
|
||||
if (
|
||||
request == "ir" ||
|
||||
request == "irAst" ||
|
||||
request == "irOptimized" ||
|
||||
request == "irOptimizedAst"
|
||||
)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -1350,8 +1355,12 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
|
||||
// IR
|
||||
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "ir", wildcardMatchesExperimental))
|
||||
contractData["ir"] = compilerStack.yulIR(contractName);
|
||||
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "irAst", wildcardMatchesExperimental))
|
||||
contractData["irAst"] = compilerStack.yulIRAst(contractName);
|
||||
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "irOptimized", wildcardMatchesExperimental))
|
||||
contractData["irOptimized"] = compilerStack.yulIROptimized(contractName);
|
||||
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "irOptimizedAst", wildcardMatchesExperimental))
|
||||
contractData["irOptimizedAst"] = compilerStack.yulIROptimizedAst(contractName);
|
||||
|
||||
// EVM
|
||||
Json::Value evmData(Json::objectValue);
|
||||
@@ -1513,6 +1522,13 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
|
||||
if (isArtifactRequested(_inputsAndSettings.outputSelection, sourceName, contractName, "ir", wildcardMatchesExperimental))
|
||||
output["contracts"][sourceName][contractName]["ir"] = stack.print();
|
||||
|
||||
if (isArtifactRequested(_inputsAndSettings.outputSelection, sourceName, contractName, "ast", wildcardMatchesExperimental))
|
||||
{
|
||||
Json::Value sourceResult = Json::objectValue;
|
||||
sourceResult["id"] = 1;
|
||||
sourceResult["ast"] = stack.astJson();
|
||||
output["sources"][sourceName] = sourceResult;
|
||||
}
|
||||
stack.optimize();
|
||||
|
||||
MachineAssemblyObject object;
|
||||
|
||||
Reference in New Issue
Block a user