Don't get confused about "void *" nodes.
[smatch.git] / test-linearize.c
blob549d0143a65d4372ad806a544ee61e7a58e05fd2
1 /*
2 * Parse and linearize the tree for testing.
4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003-2004 Linus Torvalds
7 * Licensed under the Open Software License version 1.1
8 */
9 #include <stdarg.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <unistd.h>
15 #include <fcntl.h>
17 #include "lib.h"
18 #include "token.h"
19 #include "parse.h"
20 #include "symbol.h"
21 #include "expression.h"
22 #include "linearize.h"
24 static void clean_up_symbol(struct symbol *sym, void *_parent, int flags)
26 struct entrypoint *ep;
28 check_duplicates(sym);
29 evaluate_symbol(sym);
30 expand_symbol(sym);
31 ep = linearize_symbol(sym);
32 if (ep)
33 show_entry(ep);
36 int main(int argc, char **argv)
38 int fd;
39 char *filename = NULL, **args;
40 struct token *token;
42 // Initialize symbol stream first, so that we can add defines etc
43 init_symbols();
45 create_builtin_stream();
46 add_pre_buffer("#define __CHECKER__ 1\n");
47 add_pre_buffer("extern void *__builtin_memcpy(void *, const void *, unsigned long);\n");
48 add_pre_buffer("extern void * __builtin_return_address(int);\n");
50 args = argv;
51 for (;;) {
52 char *arg = *++args;
53 if (!arg)
54 break;
55 if (arg[0] == '-') {
56 args = handle_switch(arg+1, args);
57 continue;
59 filename = arg;
62 // Initialize type system
63 init_ctype();
65 fd = open(filename, O_RDONLY);
66 if (fd < 0)
67 die("No such file: %s", filename);
69 // Tokenize the input stream
70 token = tokenize(filename, fd, NULL);
71 close(fd);
73 // Prepend any "include" file to the stream.
74 if (include_fd >= 0)
75 token = tokenize(include, include_fd, token);
77 // Prepend the initial built-in stream
78 token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
80 // Pre-process the stream
81 token = preprocess(token);
83 // Parse the resulting C code
84 translation_unit(token, &used_list);
86 // Do type evaluation and simplify
87 symbol_iterate(used_list, clean_up_symbol, NULL);
88 return 0;