Prevent potential NULL pointer dereference in expand_compare
[smatch.git] / graph.c
blob1a26ce0f86a42469fece2b9871aac3ebab33d2e2
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 struct string_list *filelist = NULL;
59 char *file;
61 printf("digraph control_flow {\n");
62 graph_symbols(sparse_initialize(argc, argv, &filelist));
64 FOR_EACH_PTR_NOTAG(filelist, file) {
65 graph_symbols(sparse(file));
66 } END_FOR_EACH_PTR_NOTAG(file);
67 printf("}\n");
68 return 0;