[be] comparison, signedness, and operand size update
[smatch.git] / check.c
blobc9883a51344fcf04ea68e13325c3e5184e23bdd6
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 Transmeta Corp.
7 * 2003 Linus Torvalds
9 * Licensed under the Open Software License version 1.1
11 #include <stdarg.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include <unistd.h>
17 #include <fcntl.h>
19 #include "lib.h"
20 #include "token.h"
21 #include "parse.h"
22 #include "symbol.h"
23 #include "expression.h"
25 static void clean_up_symbol(struct symbol *sym, void *_parent, int flags)
27 check_duplicates(sym);
28 evaluate_symbol(sym);
29 expand_symbol(sym);
32 int main(int argc, char **argv)
34 int fd;
35 char *filename = NULL, **args;
36 struct token *token;
38 // Initialize symbol stream first, so that we can add defines etc
39 init_symbols();
41 create_builtin_stream();
43 args = argv;
44 for (;;) {
45 char *arg = *++args;
46 if (!arg)
47 break;
48 if (arg[0] == '-') {
49 args = handle_switch(arg+1, args);
50 continue;
52 filename = arg;
56 fd = open(filename, O_RDONLY);
57 if (fd < 0)
58 die("No such file: %s", filename);
60 // Tokenize the input stream
61 token = tokenize(filename, fd, NULL);
62 close(fd);
64 // Prepend any "include" file to the stream.
65 if (include_fd >= 0)
66 token = tokenize(include, include_fd, token);
68 // Prepend the initial built-in stream
69 token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
71 // Pre-process the stream
72 token = preprocess(token);
74 if (preprocess_only) {
75 while (!eof_token(token)) {
76 int prec = 1;
77 struct token *next = token->next;
78 char * separator = "";
79 if (next->pos.whitespace)
80 separator = " ";
81 if (next->pos.newline) {
82 separator = "\n\t\t\t\t\t";
83 prec = next->pos.pos;
84 if (prec > 4)
85 prec = 4;
87 printf("%s%.*s", show_token(token), prec, separator);
88 token = next;
90 putchar('\n');
92 return 0;
95 // Parse the resulting C code
96 translation_unit(token, &used_list);
98 // Do type evaluation and simplify
99 symbol_iterate(used_list, clean_up_symbol, NULL);
100 return 0;