math: array parameters can be NULL
[smatch.git] / test-unssa.c
blobb81dc47bc0d634bcadabc52aee30d1986244addd
1 #include <stdio.h>
2 #include <assert.h>
4 #include "symbol.h"
5 #include "expression.h"
6 #include "linearize.h"
7 #include "flow.h"
10 static void output_bb(struct basic_block *bb, unsigned long generation)
12 struct instruction *insn;
14 bb->generation = generation;
15 printf("%s\n", show_label(bb));
17 FOR_EACH_PTR(bb->insns, insn) {
18 if (!insn->bb)
19 continue;
20 printf("\t%s\n", show_instruction(insn));
22 END_FOR_EACH_PTR(insn);
24 printf("\n");
27 static void output_fn(struct entrypoint *ep)
29 struct basic_block *bb;
30 unsigned long generation = ++bb_generation;
31 struct symbol *sym = ep->name;
32 const char *name = show_ident(sym->ident);
34 if (sym->ctype.modifiers & MOD_STATIC)
35 printf("\n\n%s:\n", name);
36 else
37 printf("\n\n.globl %s\n%s:\n", name, name);
39 unssa(ep);
41 FOR_EACH_PTR(ep->bbs, bb) {
42 if (bb->generation == generation)
43 continue;
44 output_bb(bb, generation);
46 END_FOR_EACH_PTR(bb);
49 static int output_data(struct symbol *sym)
51 printf("symbol %s:\n", show_ident(sym->ident));
52 printf("\ttype = %d\n", sym->ctype.base_type->type);
53 printf("\tmodif= %lx\n", sym->ctype.modifiers);
55 return 0;
58 static int compile(struct symbol_list *list)
60 struct symbol *sym;
61 FOR_EACH_PTR(list, sym) {
62 struct entrypoint *ep;
63 expand_symbol(sym);
64 ep = linearize_symbol(sym);
65 if (!(fdump_ir & PASS_FINAL))
66 continue;
67 if (ep)
68 output_fn(ep);
69 else
70 output_data(sym);
72 END_FOR_EACH_PTR(sym);
74 return 0;
77 int main(int argc, char **argv)
79 struct string_list * filelist = NULL;
80 char *file;
82 compile(sparse_initialize(argc, argv, &filelist));
83 FOR_EACH_PTR(filelist, file) {
84 compile(sparse(file));
85 } END_FOR_EACH_PTR(file);
87 report_stats();
88 return 0;