Shrink "struct token" by moving "noexpand" into the position flags.
[smatch.git] / compile.c
blobaf033910875f856cdcb7b5033f4ba7c658e2a15d
1 /*
2 * Example trivial client program that uses the sparse library
3 * and x86 backend.
5 * Copyright (C) 2003 Transmeta Corp.
6 * 2003 Linus Torvalds
7 * Copyright 2003 Jeff Garzik
9 * Licensed under the Open Software License version 1.1
12 #include <stdarg.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <ctype.h>
17 #include <unistd.h>
18 #include <fcntl.h>
20 #include "lib.h"
21 #include "token.h"
22 #include "parse.h"
23 #include "symbol.h"
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)
30 evaluate_symbol(sym);
31 expand_symbol(sym);
34 int main(int argc, char **argv)
36 int fd;
37 char *basename, *filename = NULL, **args;
38 struct token *token;
40 // Initialize symbol stream first, so that we can add defines etc
41 init_symbols();
43 create_builtin_stream();
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;
57 // Initialize type system
58 init_ctype();
60 if (filename == NULL)
61 die("No file specified");
63 basename = strrchr(filename, '/');
64 if (!basename)
65 basename = filename;
66 else if ((basename == filename) && (basename[1] == 0)) {
67 fprintf(stderr, "um\n");
68 exit(1);
69 } else {
70 basename++;
71 if (*basename == 0) {
72 fprintf(stderr, "um\n");
73 exit(1);
77 fd = open(filename, O_RDONLY);
78 if (fd < 0)
79 die("No such file: %s", argv[1]);
81 // Tokenize the input stream
82 token = tokenize(filename, fd, NULL);
83 close(fd);
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);
100 #if 0
101 // And show the allocation statistics
102 show_ident_alloc();
103 show_token_alloc();
104 show_symbol_alloc();
105 show_expression_alloc();
106 show_statement_alloc();
107 show_string_alloc();
108 show_bytes_alloc();
109 #endif
110 return 0;