summaryrefslogtreecommitdiffstats
path: root/src/graphviz.h
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2010-12-05 00:09:50 (GMT)
committerEvan Martin <martine@danga.com>2010-12-05 00:09:50 (GMT)
commit42d237e7841679b27cd5dcae82d143d86a87a807 (patch)
tree253b0cf88ecf3b0404146a7c7945dd4c660afa04 /src/graphviz.h
parentd0025e234cf3fc0a13f45d179880578285609b59 (diff)
downloadNinja-42d237e7841679b27cd5dcae82d143d86a87a807.zip
Ninja-42d237e7841679b27cd5dcae82d143d86a87a807.tar.gz
Ninja-42d237e7841679b27cd5dcae82d143d86a87a807.tar.bz2
move src into subdir
Diffstat (limited to 'src/graphviz.h')
-rw-r--r--src/graphviz.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/graphviz.h b/src/graphviz.h
new file mode 100644
index 0000000..d688a15
--- /dev/null
+++ b/src/graphviz.h
@@ -0,0 +1,64 @@
+#include <set>
+
+struct Node;
+
+struct GraphViz {
+ void Start();
+ void AddTarget(Node* node);
+ void Finish();
+
+ set<Node*> visited_;
+};
+
+void GraphViz::AddTarget(Node* node) {
+ if (visited_.find(node) != visited_.end())
+ return;
+ printf("\"%p\" [label=\"%s\"]\n", node, node->file_->path_.c_str());
+ visited_.insert(node);
+
+ if (!node->in_edge_) {
+ // Leaf node.
+ // Draw as a rect?
+ return;
+ }
+
+ Edge* edge = node->in_edge_;
+
+ if (edge->inputs_.size() == 1 && edge->outputs_.size() == 1) {
+ // Can draw simply.
+ // Note extra space before label text -- this is cosmetic and feels
+ // like a graphviz bug.
+ printf("\"%p\" -> \"%p\" [label=\" %s\"]\n",
+ edge->inputs_[0], edge->outputs_[0], edge->rule_->name_.c_str());
+ } else {
+ printf("\"%p\" [label=\"%s\", shape=ellipse]\n",
+ edge, edge->rule_->name_.c_str());
+ for (vector<Node*>::iterator out = edge->outputs_.begin();
+ out != edge->outputs_.end(); ++out) {
+ printf("\"%p\" -> \"%p\"\n", edge, *out);
+ }
+ for (vector<Node*>::iterator in = edge->inputs_.begin();
+ in != edge->inputs_.end(); ++in) {
+ const char* order_only = "";
+ if (edge->is_order_only(in - edge->inputs_.begin()))
+ order_only = " style=dotted";
+ printf("\"%p\" -> \"%p\" [arrowhead=none%s]\n", (*in), edge, order_only);
+ }
+ }
+
+ for (vector<Node*>::iterator in = edge->inputs_.begin();
+ in != edge->inputs_.end(); ++in) {
+ AddTarget(*in);
+ }
+}
+
+void GraphViz::Start() {
+ printf("digraph ninja {\n");
+ printf("node [fontsize=10, shape=box, height=0.25]\n");
+ printf("edge [fontsize=10]\n");
+}
+
+void GraphViz::Finish() {
+ printf("}\n");
+}
+