fix 'weak' attribute loss
[smatch.git] / test-unssa.c
blob88ce025ff1bb55cf506863a846449aa1fd011a18
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(".L%p\n", 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 (ep)
66 output_fn(ep);
67 else
68 output_data(sym);
70 END_FOR_EACH_PTR(sym);
72 return 0;
75 int main(int argc, char **argv)
77 struct string_list * filelist = NULL;
78 char *file;
80 compile(sparse_initialize(argc, argv, &filelist));
81 FOR_EACH_PTR_NOTAG(filelist, file) {
82 compile(sparse(file));
83 } END_FOR_EACH_PTR_NOTAG(file);
85 return 0;