Split up the printout functions into a file of their own.
[smatch.git] / test-parsing.c
blob154b11af12236a0a442ac1f223d471c7ad1c1260
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 Linus Torvalds, all rights reserved.
7 */
8 #include <stdarg.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <ctype.h>
13 #include <unistd.h>
14 #include <fcntl.h>
16 #include "lib.h"
17 #include "token.h"
18 #include "parse.h"
19 #include "symbol.h"
21 int main(int argc, char **argv)
23 int fd = open(argv[1], O_RDONLY);
24 struct token *token;
25 struct symbol_list *list = NULL;
27 if (fd < 0)
28 die("No such file: %s", argv[1]);
29 init_symbols();
31 // Tokenize the input stream
32 token = tokenize(argv[1], fd, NULL);
33 close(fd);
35 // Pre-process the stream
36 token = preprocess(token);
38 // Parse the resulting C code
39 translation_unit(token, &list);
41 // Show the end result.
42 show_symbol_list(list, "\n\n");
43 printf("\n\n");
45 // And show the allocation statistics
46 show_ident_alloc();
47 show_token_alloc();
48 show_symbol_alloc();
49 show_expression_alloc();
50 show_statement_alloc();
51 show_string_alloc();
52 show_bytes_alloc();
53 return 0;