aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--.gitignore1
-rw-r--r--Makefile6
-rw-r--r--graph.c63
3 files changed, 69 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 32d6e70a..3e12ce74 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@ test-parsing
obfuscate
check
compile
+graph
test-dissect
test-linearize
example
diff --git a/Makefile b/Makefile
index 6755e07e..ccf9f891 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ CFLAGS += -DDEBUG
PREFIX=$(HOME)
BINDIR=$(PREFIX)/bin
-PROGRAMS=test-lexing test-parsing obfuscate check compile test-linearize example test-unssa test-dissect
+PROGRAMS=test-lexing test-parsing obfuscate check compile graph test-linearize example test-unssa test-dissect
LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
@@ -77,6 +77,9 @@ obfuscate: obfuscate.o $(LIBS)
check: check.o $(LIBS)
$(CC) $(LDFLAGS) -o $@ $< $(LIBS)
+graph: graph.o $(LIBS)
+ $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
+
example: example.o $(LIBS)
$(CC) $(LDFLAGS) -o $@ $< $(LIBS)
@@ -123,6 +126,7 @@ obfuscate.o: $(LIB_H)
example.o: $(LIB_H)
storage.o: $(LIB_H) storage.h
dissect.o: $(LIB_H) dissect.h
+graph.o: $(LIB_H)
compat-linux.o: compat/strtold.c compat/mmap-blob.c \
$(LIB_H)
diff --git a/graph.c b/graph.c
new file mode 100644
index 00000000..db940ae7
--- /dev/null
+++ b/graph.c
@@ -0,0 +1,63 @@
+/* Copyright © International Business Machines Corp., 2006
+ *
+ * Author: Josh Triplett <josh@freedesktop.org>
+ *
+ * Licensed under the Open Software License version 1.1
+ */
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "lib.h"
+#include "allocate.h"
+#include "token.h"
+#include "parse.h"
+#include "symbol.h"
+#include "expression.h"
+#include "linearize.h"
+
+static void graph_ep(struct entrypoint *ep)
+{
+ struct basic_block *bb;
+
+ printf("ep%p [label=\"%s\",shape=ellipse];\n",
+ ep, show_ident(ep->name->ident));
+ FOR_EACH_PTR(ep->bbs, bb) {
+ printf("bb%p [shape=record,label=\"bb at %p\"]\n", bb, bb);
+ } END_FOR_EACH_PTR(bb);
+ FOR_EACH_PTR(ep->bbs, bb) {
+ struct basic_block *child;
+ FOR_EACH_PTR(bb->children, child) {
+ printf("bb%p -> bb%p;\n", bb, child);
+ } END_FOR_EACH_PTR(child);
+ } END_FOR_EACH_PTR(bb);
+ printf("ep%p -> bb%p;\n", ep, ep->entry->bb);
+}
+
+static void graph_symbols(struct symbol_list *list)
+{
+ struct symbol *sym;
+
+ FOR_EACH_PTR(list, sym) {
+ struct entrypoint *ep;
+
+ expand_symbol(sym);
+ ep = linearize_symbol(sym);
+ if (ep)
+ graph_ep(ep);
+ } END_FOR_EACH_PTR(sym);
+}
+
+int main(int argc, char **argv)
+{
+ printf("digraph control_flow {\n");
+ graph_symbols(sparse_initialize(argc, argv));
+ while (*argv)
+ graph_symbols(sparse(argv));
+ printf("}\n");
+ return 0;
+}