added a bunch of gcc builtins
[smatch.git] / graph.c
blobede3dfa5faedfcdd620e2a527f3f98ea2e06deb9
1 /* Copyright © International Business Machines Corp., 2006
3 * Author: Josh Triplett <josh@freedesktop.org>
5 * Licensed under the Open Software License version 1.1
6 */
7 #include <stdarg.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <unistd.h>
13 #include <fcntl.h>
15 #include "lib.h"
16 #include "allocate.h"
17 #include "token.h"
18 #include "parse.h"
19 #include "symbol.h"
20 #include "expression.h"
21 #include "linearize.h"
23 static void graph_ep(struct entrypoint *ep)
25 struct basic_block *bb;
27 printf("ep%p [label=\"%s\",shape=ellipse];\n",
28 ep, show_ident(ep->name->ident));
29 FOR_EACH_PTR(ep->bbs, bb) {
30 printf("bb%p [shape=record,label=\"%s:%d:%d\"]\n", bb,
31 stream_name(bb->pos.stream), bb->pos.line, bb->pos.pos);
32 } END_FOR_EACH_PTR(bb);
33 FOR_EACH_PTR(ep->bbs, bb) {
34 struct basic_block *child;
35 FOR_EACH_PTR(bb->children, child) {
36 printf("bb%p -> bb%p;\n", bb, child);
37 } END_FOR_EACH_PTR(child);
38 } END_FOR_EACH_PTR(bb);
39 printf("ep%p -> bb%p;\n", ep, ep->entry->bb);
42 static void graph_symbols(struct symbol_list *list)
44 struct symbol *sym;
46 FOR_EACH_PTR(list, sym) {
47 struct entrypoint *ep;
49 expand_symbol(sym);
50 ep = linearize_symbol(sym);
51 if (ep)
52 graph_ep(ep);
53 } END_FOR_EACH_PTR(sym);
56 int main(int argc, char **argv)
58 printf("digraph control_flow {\n");
59 graph_symbols(sparse_initialize(argc, argv));
60 while (*argv)
61 graph_symbols(sparse(argv));
62 printf("}\n");
63 return 0;