[be] Don't emit move based on value returned from a function's
[smatch.git] / check.c
blob5b919da1df30f4052440d7b899ede92f3176d3a5
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();
42 add_pre_buffer("extern void *__builtin_memcpy(void *, const void *, unsigned long);\n");
43 add_pre_buffer("extern void * __builtin_return_address(int);\n");
45 args = argv;
46 for (;;) {
47 char *arg = *++args;
48 if (!arg)
49 break;
50 if (arg[0] == '-') {
51 args = handle_switch(arg+1, args);
52 continue;
54 filename = arg;
58 fd = open(filename, O_RDONLY);
59 if (fd < 0)
60 die("No such file: %s", filename);
62 // Tokenize the input stream
63 token = tokenize(filename, fd, NULL);
64 close(fd);
66 // Prepend any "include" file to the stream.
67 if (include_fd >= 0)
68 token = tokenize(include, include_fd, token);
70 // Prepend the initial built-in stream
71 token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
73 // Pre-process the stream
74 token = preprocess(token);
76 if (preprocess_only) {
77 while (!eof_token(token)) {
78 int prec = 1;
79 struct token *next = token->next;
80 char * separator = "";
81 if (next->pos.whitespace)
82 separator = " ";
83 if (next->pos.newline) {
84 separator = "\n\t\t\t\t\t";
85 prec = next->pos.pos;
86 if (prec > 4)
87 prec = 4;
89 printf("%s%.*s", show_token(token), prec, separator);
90 token = next;
92 putchar('\n');
94 return 0;
97 // Parse the resulting C code
98 translation_unit(token, &used_list);
100 // Do type evaluation and simplify
101 symbol_iterate(used_list, clean_up_symbol, NULL);
102 return 0;