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 // Initialize type system
57 fd
= open(filename
, O_RDONLY
);
59 die("No such file: %s", argv
[1]);
61 // Tokenize the input stream
62 token
= tokenize(filename
, fd
, NULL
);
65 // Prepend the initial built-in stream
66 token
= tokenize_buffer(pre_buffer
, pre_buffer_size
, token
);
68 // Pre-process the stream
69 token
= preprocess(token
);
71 // Parse the resulting C code
72 translation_unit(token
, &used_list
);
74 // Do type evaluation and simplification
75 symbol_iterate(used_list
, clean_up_symbol
, NULL
);
78 // Show the end result.
79 show_symbol_list(used_list
, "\n\n");
84 // And show the allocation statistics
88 show_expression_alloc();
89 show_statement_alloc();