Skip to content

Commit

Permalink
enable dot file loading in Gephi
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshi15108 committed Sep 15, 2023
1 parent b074b5f commit 668cafb
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions inou/graphviz/graphviz.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// This file is distributed under the BSD 3-Clause License. See LICENSE for details.

#include "graphviz.hpp"

#include <fcntl.h>
Expand Down Expand Up @@ -67,17 +66,17 @@ void Graphviz::populate_lg_handle_xedge(const Node &node, const XEdge &out, std:
auto dp_name = graphviz_legalize_name(out.driver.has_name() ? out.driver.get_name() : "unk");

if (node.get_type_op() == Ntype_op::Const) {
data += fmt::format(" {}->{}[label=<{}b:({},{})>];\n", dn_name, sn_name, dbits, dp_pid, sp_pid);
data += fmt::format(" {} -> {} [ label = <{}b:({},{})> ];\n", dn_name, sn_name, dbits, dp_pid, sp_pid);
} else if (node.get_type_op() == Ntype_op::TupAdd) {
data += fmt::format(" {}->{}[label=<{}b:({},{}):<font color=\"#0000ff\">{}</font>>];\n",
data += fmt::format(" {} -> {} [ label = <{}b:({},{}):<font color=\"#0000ff\">{}</font>> ];\n",
dn_name,
sn_name,
dbits,
dp_pid,
sp_pid,
dp_name);
} else {
data += fmt::format(" {}->{}[label=<{}b:({},{}):{}>];\n", dn_name, sn_name, dbits, dp_pid, sp_pid, dp_name);
data += fmt::format(" {} -> {} [ label = <{}b:({},{}):{}> ];\n", dn_name, sn_name, dbits, dp_pid, sp_pid, dp_name);
}
}

Expand Down Expand Up @@ -118,7 +117,7 @@ void Graphviz::do_hierarchy(Lgraph *lg) {

Node h_inp(g, Hierarchy::hierarchical_root(), Hardcoded_input_nid);
for (auto e : h_inp.inp_edges()) {
fmt::print("edge from:{} to:{}\n", e.driver.get_class_lgraph()->get_name(), e.sink.get_class_lgraph()->get_name());
fmt::print("edge from: {} to: {}\n", e.driver.get_class_lgraph()->get_name(), e.sink.get_class_lgraph()->get_name());

auto p = std::pair(e.driver.get_class_lgraph()->get_name(), e.sink.get_class_lgraph()->get_name());
if (p.first == p.second) {
Expand All @@ -129,7 +128,7 @@ void Graphviz::do_hierarchy(Lgraph *lg) {
}
added.insert(p);

data += fmt::format(" {}->{};\n",
data += fmt::format(" {} -> {};\n",
graphviz_legalize_name(e.driver.get_class_lgraph()->get_name()),
graphviz_legalize_name(e.sink.get_class_lgraph()->get_name()));
}
Expand All @@ -147,7 +146,7 @@ void Graphviz::do_hierarchy(Lgraph *lg) {
}
added.insert(p);

data += fmt::format(" {}->{};\n",
data += fmt::format(" {} -> {};\n",
graphviz_legalize_name(e.driver.get_class_lgraph()->get_name()),
graphviz_legalize_name(e.sink.get_class_lgraph()->get_name()));
}
Expand Down Expand Up @@ -180,7 +179,7 @@ void Graphviz::create_color_map(Lgraph *lg) {
for (auto e : color2id) {
RGB color(static_cast<double>(e.second) / color2id.size());
color2rgb[e.first] = color.to_s();
data += fmt::format(" c{} [label=<{}>,style=\"filled\",fillcolor=\"{}\"];\n", e.second, e.first, color.to_s());
data += fmt::format(" c{} [ label = <{}> , style = \"filled\" , fillcolor = \"{}\" ];\n", e.second, e.first, color.to_s());
}

absl::flat_hash_set<uint64_t> edges; // hackish graph
Expand Down Expand Up @@ -208,7 +207,7 @@ void Graphviz::create_color_map(Lgraph *lg) {
continue;
}

data += fmt::format(" c{}->c{};\n", c, sc);
data += fmt::format(" c{} -> c{};\n", c, sc);

edges.insert(edge);
}
Expand Down Expand Up @@ -260,13 +259,13 @@ void Graphviz::populate_lg_data(Lgraph *g, std::string_view dot_postfix) {
if (node.has_color()) {
const auto it = color2rgb.find(node.get_color());
if (it != color2rgb.end()) {
color = absl::StrCat("fillcolor=\"", it->second, "\" ");
color = absl::StrCat("fillcolor = \"", it->second, "\" ");
}
}
if (node.get_type_op() == Ntype_op::Const) {
data += fmt::format(" {} [{}label=<{}:{}>];\n", gv_name, color, node_info, node.get_type_const().to_pyrope());
data += fmt::format(" {} [ {} label = <{}:{}> ];\n", gv_name, color, node_info, node.get_type_const().to_pyrope());
} else {
data += fmt::format(" {} [{}label=<{}>];\n", gv_name, color, node_info);
data += fmt::format(" {} [ {} label = <{}> ];\n", gv_name, color, node_info);
}

for (const auto &out : node.out_edges()) {
Expand All @@ -276,7 +275,7 @@ void Graphviz::populate_lg_data(Lgraph *g, std::string_view dot_postfix) {

g->each_graph_input([&](const Node_pin &pin) {
auto io_name = graphviz_legalize_name(pin.get_pin_name());
data += fmt::format(" {} [label=<{}>];\n", io_name, io_name); // pin.debug_name());
data += fmt::format(" {} [ label = <{}> ];\n", io_name, io_name); // pin.debug_name());

for (const auto &out : pin.out_edges()) {
populate_lg_handle_xedge(pin.get_node(), out, data, verbose);
Expand All @@ -287,7 +286,7 @@ void Graphviz::populate_lg_data(Lgraph *g, std::string_view dot_postfix) {
g->each_graph_output([&](const Node_pin &pin) {
std::string_view dst_str = "virtual_dst_module";
auto dbits = pin.get_bits();
data += fmt::format(" {}->{}[label=<{}b>];\n", graphviz_legalize_name(pin.get_name()), dst_str, dbits);
data += fmt::format(" {} -> {} [ label = <{}b> ];\n", graphviz_legalize_name(pin.get_name()), dst_str, dbits);
for (const auto &out : pin.out_edges()) {
populate_lg_handle_xedge(pin.get_node(), out, data, verbose);
}
Expand All @@ -309,7 +308,7 @@ void Graphviz::do_from_lnast(const std::shared_ptr<Lnast> &lnast, std::string_vi

auto id = std::to_string(itr.level) + std::to_string(itr.pos);
if (node_data.type.is_ref()) {
data += fmt::format(" {} [label=<{}, {}<I><SUB><font color=\"#ff1020\">{}</font></SUB></I>>];\n",
data += fmt::format(" {} [ label = <{}, {}<I><SUB><font color=\"#ff1020\">{}</font></SUB></I>> ];\n",
id,
node_data.type.debug_name(),
name,
Expand All @@ -319,7 +318,7 @@ void Graphviz::do_from_lnast(const std::shared_ptr<Lnast> &lnast, std::string_vi
data += fmt::format(" {} [label=<{}, {}>];\n", id, "selc", name);
#endif
} else {
data += fmt::format(" {} [label=<{}, {}>];\n", id, node_data.type.debug_name(), name);
data += fmt::format(" {} [ label = <{}, {}> ];\n", id, node_data.type.debug_name(), name);
}

if (node_data.type.is_top()) {
Expand All @@ -330,7 +329,7 @@ void Graphviz::do_from_lnast(const std::shared_ptr<Lnast> &lnast, std::string_vi
auto p = lnast->get_parent(itr);

auto parent_id = std::to_string(p.level) + std::to_string(p.pos);
data += fmt::format(" {}->{};\n", parent_id, id);
data += fmt::format(" {} -> {};\n", parent_id, id);
}

data += "}\n";
Expand Down

0 comments on commit 668cafb

Please sign in to comment.