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 b30c404
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 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
17 changes: 7 additions & 10 deletions libyul/YulStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,25 +340,22 @@ 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);
Json ret = Json::object();
ret[object.name.str()] = exportCFGFromObject(object);
ret["type"] = "Object";
ret["subObjects"] = exportCFGFromSubObjects(object.subObjects);
return ret;
}
Expand Down

0 comments on commit b30c404

Please sign in to comment.