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
@@ -223,6 +223,31 @@ void CommandLineInterface::handleIR(string const& _contractName)
|
||||
}
|
||||
}
|
||||
|
||||
void CommandLineInterface::handleIRAst(string const& _contractName)
|
||||
{
|
||||
solAssert(CompilerInputModes.count(m_options.input.mode) == 1);
|
||||
|
||||
if (!m_options.compiler.outputs.irAstJson)
|
||||
return;
|
||||
|
||||
if (!m_options.output.dir.empty())
|
||||
createFile(
|
||||
m_compiler->filesystemFriendlyName(_contractName) + "_yul_ast.json",
|
||||
util::jsonPrint(
|
||||
m_compiler->yulIRAst(_contractName),
|
||||
m_options.formatting.json
|
||||
)
|
||||
);
|
||||
else
|
||||
{
|
||||
sout() << "IR AST:" << endl;
|
||||
sout() << util::jsonPrint(
|
||||
m_compiler->yulIRAst(_contractName),
|
||||
m_options.formatting.json
|
||||
) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CommandLineInterface::handleIROptimized(string const& _contractName)
|
||||
{
|
||||
solAssert(CompilerInputModes.count(m_options.input.mode) == 1);
|
||||
@@ -231,7 +256,10 @@ void CommandLineInterface::handleIROptimized(string const& _contractName)
|
||||
return;
|
||||
|
||||
if (!m_options.output.dir.empty())
|
||||
createFile(m_compiler->filesystemFriendlyName(_contractName) + "_opt.yul", m_compiler->yulIROptimized(_contractName));
|
||||
createFile(
|
||||
m_compiler->filesystemFriendlyName(_contractName) + "_opt.yul",
|
||||
m_compiler->yulIROptimized(_contractName)
|
||||
);
|
||||
else
|
||||
{
|
||||
sout() << "Optimized IR:" << endl;
|
||||
@@ -239,6 +267,31 @@ void CommandLineInterface::handleIROptimized(string const& _contractName)
|
||||
}
|
||||
}
|
||||
|
||||
void CommandLineInterface::handleIROptimizedAst(string const& _contractName)
|
||||
{
|
||||
solAssert(CompilerInputModes.count(m_options.input.mode) == 1);
|
||||
|
||||
if (!m_options.compiler.outputs.irOptimizedAstJson)
|
||||
return;
|
||||
|
||||
if (!m_options.output.dir.empty())
|
||||
createFile(
|
||||
m_compiler->filesystemFriendlyName(_contractName) + "_opt_yul_ast.json",
|
||||
util::jsonPrint(
|
||||
m_compiler->yulIROptimizedAst(_contractName),
|
||||
m_options.formatting.json
|
||||
)
|
||||
);
|
||||
else
|
||||
{
|
||||
sout() << "Optimized IR AST:" << endl;
|
||||
sout() << util::jsonPrint(
|
||||
m_compiler->yulIROptimizedAst(_contractName),
|
||||
m_options.formatting.json
|
||||
) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CommandLineInterface::handleBytecode(string const& _contract)
|
||||
{
|
||||
solAssert(CompilerInputModes.count(m_options.input.mode) == 1);
|
||||
@@ -690,8 +743,12 @@ void CommandLineInterface::compile()
|
||||
if (m_options.output.debugInfoSelection.has_value())
|
||||
m_compiler->selectDebugInfo(m_options.output.debugInfoSelection.value());
|
||||
// TODO: Perhaps we should not compile unless requested
|
||||
|
||||
m_compiler->enableIRGeneration(m_options.compiler.outputs.ir || m_options.compiler.outputs.irOptimized);
|
||||
m_compiler->enableIRGeneration(
|
||||
m_options.compiler.outputs.ir ||
|
||||
m_options.compiler.outputs.irOptimized ||
|
||||
m_options.compiler.outputs.irAstJson ||
|
||||
m_options.compiler.outputs.irOptimizedAstJson
|
||||
);
|
||||
m_compiler->enableEvmBytecodeGeneration(
|
||||
m_options.compiler.estimateGas ||
|
||||
m_options.compiler.outputs.asm_ ||
|
||||
@@ -1084,7 +1141,11 @@ void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::Y
|
||||
else
|
||||
serr() << "No binary representation found." << endl;
|
||||
}
|
||||
|
||||
if (m_options.compiler.outputs.astCompactJson)
|
||||
{
|
||||
sout() << "AST:" << endl << endl;
|
||||
sout() << util::jsonPrint(stack.astJson(), m_options.formatting.json) << endl;
|
||||
}
|
||||
solAssert(_targetMachine == yul::YulStack::Machine::EVM, "");
|
||||
if (m_options.compiler.outputs.asm_)
|
||||
{
|
||||
@@ -1141,7 +1202,9 @@ void CommandLineInterface::outputCompilationResults()
|
||||
|
||||
handleBytecode(contract);
|
||||
handleIR(contract);
|
||||
handleIRAst(contract);
|
||||
handleIROptimized(contract);
|
||||
handleIROptimizedAst(contract);
|
||||
handleSignatureHashes(contract);
|
||||
handleMetadata(contract);
|
||||
handleABI(contract);
|
||||
|
||||
Reference in New Issue
Block a user