Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust Yul CFG export output #15513

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions libyul/YulControlFlowGraphExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ Json YulControlFlowGraphExporter::exportBlock(SSACFG const& _cfg, SSACFG::BlockI
Json exitBlockJson = Json::object();
std::visit(util::GenericVisitor{
[&](SSACFG::BasicBlock::MainExit const&) {
exitBlockJson["targets"] = { "Block" + std::to_string(_blockId.value) };
exitBlockJson["type"] = "MainExit";
},
[&](SSACFG::BasicBlock::Jump const& _jump)
Expand All @@ -115,12 +114,10 @@ Json YulControlFlowGraphExporter::exportBlock(SSACFG const& _cfg, SSACFG::BlockI
_addChild(_conditionalJump.nonZero);
},
[&](SSACFG::BasicBlock::FunctionReturn const& _return) {
exitBlockJson["instructions"] = toJson(_cfg, _return.returnValues);
exitBlockJson["targets"] = { "Block" + std::to_string(_blockId.value) };
exitBlockJson["returnValues"] = toJson(_cfg, _return.returnValues);
exitBlockJson["type"] = "FunctionReturn";
},
[&](SSACFG::BasicBlock::Terminated const&) {
exitBlockJson["targets"] = { "Block" + std::to_string(_blockId.value) };
exitBlockJson["type"] = "Terminated";
},
[&](SSACFG::BasicBlock::JumpTable const&) {
Expand Down
1 change: 1 addition & 0 deletions scripts/common_cmdline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function stripCLIDecorations
-e '/^IR:$/d' \
-e '/^Optimized IR:$/d' \
-e '/^EVM assembly:$/d' \
-e '/^Yul Control Flow Graph:$/d' \
-e '/^JSON AST (compact format):$/d' \
-e '/^Function signatures:$/d' \
-e '/^Contract Storage Layout:$/d' \
Expand Down
2 changes: 2 additions & 0 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static bool needsHumanTargetedStdout(CommandLineOptions const& _options)
_options.compiler.outputs.abi ||
_options.compiler.outputs.asm_ ||
_options.compiler.outputs.asmJson ||
_options.compiler.outputs.yulCFGJson ||
_options.compiler.outputs.binary ||
_options.compiler.outputs.binaryRuntime ||
_options.compiler.outputs.metadata ||
Expand Down Expand Up @@ -311,6 +312,7 @@ void CommandLineInterface::handleYulCFGExport(std::string const& _contractName)
);
else
{
sout() << "Yul Control Flow Graph:" << std::endl;
sout() << util::jsonPrint(
yulCFGJson.value_or(Json{}),
m_options.formatting.json
Expand Down
19 changes: 19 additions & 0 deletions test/cmdlineTests/standard_yul_cfg_json_export/in.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;

interface I {
function f() external pure returns (uint);
}

contract C is I {
function f() public pure override returns (uint) {
return 42;
}
}

contract D {
function f() public returns (uint) {
C c = new C();
return c.f();
}
}
13 changes: 13 additions & 0 deletions test/cmdlineTests/standard_yul_cfg_json_export/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_yul_cfg_json_export/in.sol"]}
},
"settings": {
"optimizer": {
"enabled": true
},
"viaIR": true,
"outputSelection": {"*": {"*": ["yulCFGJson"]}}
}
}
Loading