diff options
author | Linus Torvalds <torvalds@home.osdl.org> | 2004-02-11 15:04:00 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:01:20 -0700 |
commit | 15ecac69e164c74f899a15208aa204762af5f1c2 (patch) | |
tree | dbd0c05dc7c02037c5772c0c3a166447211669db /test-linearize.c | |
parent | Oops. Fix name clash by renaming the new "copy_ptr_list" to be (diff) | |
download | sparse-15ecac69e164c74f899a15208aa204762af5f1c2.tar.gz sparse-15ecac69e164c74f899a15208aa204762af5f1c2.tar.bz2 sparse-15ecac69e164c74f899a15208aa204762af5f1c2.zip |
Add a "test-linearize" program to test the output of
the linearization phase.
Diffstat (limited to 'test-linearize.c')
-rw-r--r-- | test-linearize.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test-linearize.c b/test-linearize.c new file mode 100644 index 0000000..74b991d --- /dev/null +++ b/test-linearize.c @@ -0,0 +1,83 @@ +/* + * Parse and linearize the tree for testing. + * + * Copyright (C) 2003 Transmeta Corp. + * 2003-2004 Linus Torvalds + * + * Licensed under the Open Software License version 1.1 + */ +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include <unistd.h> +#include <fcntl.h> + +#include "lib.h" +#include "token.h" +#include "parse.h" +#include "symbol.h" +#include "expression.h" +#include "linearize.h" + +static void clean_up_symbol(struct symbol *sym, void *_parent, int flags) +{ + check_duplicates(sym); + evaluate_symbol(sym); + expand_symbol(sym); + linearize_symbol(sym); +} + +int main(int argc, char **argv) +{ + int fd; + char *filename = NULL, **args; + struct token *token; + + // Initialize symbol stream first, so that we can add defines etc + init_symbols(); + + create_builtin_stream(); + add_pre_buffer("#define __CHECKER__ 1\n"); + add_pre_buffer("extern void *__builtin_memcpy(void *, const void *, unsigned long);\n"); + add_pre_buffer("extern void * __builtin_return_address(int);\n"); + + args = argv; + for (;;) { + char *arg = *++args; + if (!arg) + break; + if (arg[0] == '-') { + args = handle_switch(arg+1, args); + continue; + } + filename = arg; + } + + + fd = open(filename, O_RDONLY); + if (fd < 0) + die("No such file: %s", filename); + + // Tokenize the input stream + token = tokenize(filename, fd, NULL); + close(fd); + + // Prepend any "include" file to the stream. + if (include_fd >= 0) + token = tokenize(include, include_fd, token); + + // Prepend the initial built-in stream + token = tokenize_buffer(pre_buffer, pre_buffer_size, token); + + // Pre-process the stream + token = preprocess(token); + + // Parse the resulting C code + translation_unit(token, &used_list); + + // Do type evaluation and simplify + symbol_iterate(used_list, clean_up_symbol, NULL); + return 0; +} |