2 * Example trivial client program that uses the sparse library
3 * to tokenize, pre-process and parse a C file, and prints out
6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
23 #include "expression.h"
25 static void clean_up_symbol(struct symbol
*sym
, void *_parent
, int flags
)
31 int main(int argc
, char **argv
)
34 char *filename
= NULL
, **args
;;
37 // Initialize symbol stream first, so that we can add defines etc
40 create_builtin_stream();
48 args
= handle_switch(arg
+ 1, args
);
54 fd
= open(filename
, O_RDONLY
);
56 die("No such file: %s", argv
[1]);
58 // Tokenize the input stream
59 token
= tokenize(filename
, fd
, NULL
);
62 // Prepend the initial built-in stream
63 token
= tokenize_buffer(pre_buffer
, pre_buffer_size
, token
);
65 // Pre-process the stream
66 token
= preprocess(token
);
68 // Parse the resulting C code
69 translation_unit(token
, &used_list
);
71 // Do type evaluation and simplification
72 symbol_iterate(used_list
, clean_up_symbol
, NULL
);
75 // Show the end result.
76 show_symbol_list(used_list
, "\n\n");
81 // And show the allocation statistics
85 show_expression_alloc();
86 show_statement_alloc();