2 * Example trivial client program that uses the sparse library
5 * Copyright (C) 2003 Transmeta Corp.
7 * Copyright 2003 Jeff Garzik
9 * Licensed under the Open Software License version 1.1
24 #include "expression.h"
26 extern void emit_unit(const char *basename
, struct symbol_list
*list
);
28 static void clean_up_symbol(struct symbol
*sym
, void *_parent
, int flags
)
34 int main(int argc
, char **argv
)
37 char *basename
, *filename
= NULL
, **args
;
40 // Initialize symbol stream first, so that we can add defines etc
43 create_builtin_stream();
51 args
= handle_switch(arg
+ 1, args
);
57 // Initialize type system
61 die("No file specified");
63 basename
= strrchr(filename
, '/');
66 else if ((basename
== filename
) && (basename
[1] == 0)) {
67 fprintf(stderr
, "um\n");
72 fprintf(stderr
, "um\n");
77 fd
= open(filename
, O_RDONLY
);
79 die("No such file: %s", argv
[1]);
81 // Tokenize the input stream
82 token
= tokenize(filename
, fd
, NULL
);
85 // Prepend the initial built-in stream
86 token
= tokenize_buffer(pre_buffer
, pre_buffer_size
, token
);
88 // Pre-process the stream
89 token
= preprocess(token
);
91 // Parse the resulting C code
92 translation_unit(token
, &used_list
);
94 // Do type evaluation and simplification
95 symbol_iterate(used_list
, clean_up_symbol
, NULL
);
97 // Show the end result.
98 emit_unit(basename
, used_list
);
101 // And show the allocation statistics
105 show_expression_alloc();
106 show_statement_alloc();