blob: 154b11af12236a0a442ac1f223d471c7ad1c1260 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/*
* Example trivial client program that uses the sparse library
* to tokenize, pre-process and parse a C file, and prints out
* the results.
*
* Copyright (C) 2003 Linus Torvalds, all rights reserved.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include "lib.h"
#include "token.h"
#include "parse.h"
#include "symbol.h"
int main(int argc, char **argv)
{
int fd = open(argv[1], O_RDONLY);
struct token *token;
struct symbol_list *list = NULL;
if (fd < 0)
die("No such file: %s", argv[1]);
init_symbols();
// Tokenize the input stream
token = tokenize(argv[1], fd, NULL);
close(fd);
// Pre-process the stream
token = preprocess(token);
// Parse the resulting C code
translation_unit(token, &list);
// Show the end result.
show_symbol_list(list, "\n\n");
printf("\n\n");
// And show the allocation statistics
show_ident_alloc();
show_token_alloc();
show_symbol_alloc();
show_expression_alloc();
show_statement_alloc();
show_string_alloc();
show_bytes_alloc();
return 0;
}
|