Skip to content

Commit

Permalink
Fix subobjects json output
Browse files Browse the repository at this point in the history
  • Loading branch information
r0qs committed Jun 26, 2024
1 parent 5ae26a9 commit dec8e3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
6 changes: 3 additions & 3 deletions libyul/YulControlFlowGraphExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Json YulControlFlowGraphExporter::exportBlock(CFG::BasicBlock const& _block)
// Convert current block to JSON
blocksJson.emplace_back(toJson(*_block));

Json exitBlockJson;
Json exitBlockJson = Json::object();
exitBlockJson["id"] = "Block" + std::to_string(getBlockId(*_block)) + "Exit";
exitBlockJson["instructions"] = Json::array();
std::visit(util::GenericVisitor{
Expand Down Expand Up @@ -127,7 +127,7 @@ Json YulControlFlowGraphExporter::exportBlock(CFG::BasicBlock const& _block)

Json YulControlFlowGraphExporter::toJson(CFG::BasicBlock const& _block)
{
Json blockJson;
Json blockJson = Json::object();
blockJson["id"] = "Block" + std::to_string(getBlockId(_block));
blockJson["instructions"] = Json::array();
for (auto const& operation: _block.operations)
Expand All @@ -139,7 +139,7 @@ Json YulControlFlowGraphExporter::toJson(CFG::BasicBlock const& _block)

Json YulControlFlowGraphExporter::toJson(Json& _ret, CFG::Operation const& _operation)
{
Json opJson;
Json opJson = Json::object();

Stack input = _operation.input;
std::visit(util::GenericVisitor{
Expand Down
21 changes: 9 additions & 12 deletions libyul/YulStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,27 +340,24 @@ Json YulStack::cfgJson() const

std::function<Json(std::vector<std::shared_ptr<ObjectNode>>)> exportCFGFromSubObjects;
exportCFGFromSubObjects = [&](std::vector<std::shared_ptr<ObjectNode>> _subObjects) -> Json {
Json subObjectsJson = Json::array();
Json subObjectsJson = Json::object();
for (std::shared_ptr<ObjectNode> const& subObjectNode: _subObjects)
if (Object const* subObject = dynamic_cast<Object const*>(subObjectNode.get()))
{
Json subObjectJson;
subObjectJson[subObject->name.str()];
subObjectJson["blocks"] = exportCFGFromObject(*subObject);
subObjectsJson[subObject->name.str()] = exportCFGFromObject(*subObject);
subObjectsJson["type"] = "subObject";
if (!subObject->subObjects.empty())
subObjectJson["subObjects"] = exportCFGFromSubObjects(subObject->subObjects);
subObjectsJson.emplace_back(subObjectJson);
subObjectsJson["subObjects"] = exportCFGFromSubObjects(subObject->subObjects);
}
return subObjectsJson;
};

Object const& object = *m_parserResult.get();

Json ret;
ret["nodeType"] = "YulCFG";
ret["object"] = exportCFGFromObject(object);
ret["subObjects"] = exportCFGFromSubObjects(object.subObjects);
return ret;
Json jsonObject = Json::object();
jsonObject[object.name.str()] = exportCFGFromObject(object);
jsonObject["type"] = "Object";
jsonObject["subObjects"] = exportCFGFromSubObjects(object.subObjects);
return jsonObject;
}

std::shared_ptr<Object> YulStack::parserResult() const
Expand Down

0 comments on commit dec8e3a

Please sign in to comment.