[PATCH] add support for __builtin_choose_expr()
[smatch.git] / graph.c
blobdb940ae7de0ee8ee9ff397de94fece152054b255
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=\"bb at %p\"]\n", bb, bb);
31 } END_FOR_EACH_PTR(bb);
32 FOR_EACH_PTR(ep->bbs, bb) {
33 struct basic_block *child;
34 FOR_EACH_PTR(bb->children, child) {
35 printf("bb%p -> bb%p;\n", bb, child);
36 } END_FOR_EACH_PTR(child);
37 } END_FOR_EACH_PTR(bb);
38 printf("ep%p -> bb%p;\n", ep, ep->entry->bb);
41 static void graph_symbols(struct symbol_list *list)
43 struct symbol *sym;
45 FOR_EACH_PTR(list, sym) {
46 struct entrypoint *ep;
48 expand_symbol(sym);
49 ep = linearize_symbol(sym);
50 if (ep)
51 graph_ep(ep);
52 } END_FOR_EACH_PTR(sym);
55 int main(int argc, char **argv)
57 printf("digraph control_flow {\n");
58 graph_symbols(sparse_initialize(argc, argv));
59 while (*argv)
60 graph_symbols(sparse(argv));
61 printf("}\n");
62 return 0;