Make "value_pseudo()" always return the same pseudo for
[smatch.git] / compile.c
blob2996465533db7c4f993a2e932f6d9847dd8803b4
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"
25 #include "compile.h"
27 static void clean_up_symbols(struct symbol_list *list)
29 struct symbol *sym;
31 FOR_EACH_PTR(list, sym) {
32 expand_symbol(sym);
33 emit_one_symbol(sym);
34 } END_FOR_EACH_PTR(sym);
37 int main(int argc, char **argv)
39 int fd;
40 char *basename, *filename = NULL, **args;
41 struct token *token;
42 struct symbol_list *list;
44 // Initialize symbol stream first, so that we can add defines etc
45 init_symbols();
47 create_builtin_stream();
49 args = argv;
50 for (;;) {
51 char *arg = *++args;
52 if (!arg)
53 break;
54 if (arg[0] == '-') {
55 args = handle_switch(arg + 1, args);
56 continue;
58 filename = arg;
61 // Initialize type system
62 init_ctype();
64 if (filename == NULL)
65 die("No file specified");
67 basename = strrchr(filename, '/');
68 if (!basename)
69 basename = filename;
70 else if ((basename == filename) && (basename[1] == 0)) {
71 fprintf(stderr, "um\n");
72 exit(1);
73 } else {
74 basename++;
75 if (*basename == 0) {
76 fprintf(stderr, "um\n");
77 exit(1);
81 fd = open(filename, O_RDONLY);
82 if (fd < 0)
83 die("No such file: %s", filename);
85 // Tokenize the input stream
86 token = tokenize(filename, fd, NULL, includepath);
87 close(fd);
89 // Prepend the initial built-in stream
90 token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
92 // Pre-process the stream
93 token = preprocess(token);
95 // Parse the resulting C code
96 list = translation_unit(token);
98 // Do type evaluation and simplification
99 emit_unit_begin(basename);
100 clean_up_symbols(list);
101 emit_unit_end();
103 #if 0
104 // And show the allocation statistics
105 show_ident_alloc();
106 show_token_alloc();
107 show_symbol_alloc();
108 show_expression_alloc();
109 show_statement_alloc();
110 show_string_alloc();
111 show_bytes_alloc();
112 #endif
113 return 0;