Remove the phi node rewriting.
[smatch.git] / test-parsing.c
blob811dfb17777923a6b0f371daa4ae9c8beffb036c
1 /*
2 * Example trivial client program that uses the sparse library
3 * to tokenize, pre-process and parse a C file, and prints out
4 * the results.
6 * Copyright (C) 2003 Transmeta Corp.
7 * 2003 Linus Torvalds
9 * Licensed under the Open Software License version 1.1
11 #include <stdarg.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include <unistd.h>
17 #include <fcntl.h>
19 #include "lib.h"
20 #include "token.h"
21 #include "parse.h"
22 #include "symbol.h"
23 #include "expression.h"
25 static void clean_up_symbols(struct symbol_list *list)
27 struct symbol *sym;
29 FOR_EACH_PTR(list, sym) {
30 expand_symbol(sym);
31 } END_FOR_EACH_PTR(sym);
34 int main(int argc, char **argv)
36 int fd;
37 char *filename = NULL, **args;
38 struct token *token;
39 struct symbol_list *list;
41 // Initialize symbol stream first, so that we can add defines etc
42 init_symbols();
44 create_builtin_stream();
46 args = argv;
47 for (;;) {
48 char *arg = *++args;
49 if (!arg)
50 break;
51 if (arg[0] == '-') {
52 args = handle_switch(arg + 1, args);
53 continue;
55 filename = arg;
58 // Initialize type system
59 init_ctype();
61 fd = open(filename, O_RDONLY);
62 if (fd < 0)
63 die("No such file: %s", filename);
65 // Tokenize the input stream
66 token = tokenize(filename, fd, NULL, includepath);
67 close(fd);
69 // Prepend the initial built-in stream
70 token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
72 // Pre-process the stream
73 token = preprocess(token);
75 // Parse the resulting C code
76 list = translation_unit(token);
78 // Simplification
79 clean_up_symbols(list);
81 #if 1
82 // Show the end result.
83 show_symbol_list(list, "\n\n");
84 printf("\n\n");
85 #endif
87 #if 0
88 // And show the allocation statistics
89 show_ident_alloc();
90 show_token_alloc();
91 show_symbol_alloc();
92 show_expression_alloc();
93 show_statement_alloc();
94 show_string_alloc();
95 show_bytes_alloc();
96 #endif
97 return 0;