diff options
| author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2004-12-08 11:47:53 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:05:38 -0700 |
| commit | fd5de508cae29bb482513829a64d38e42e8b806e (patch) | |
| tree | 2549543778af379365575b33734fc1a0b2e3ffc9 /example.c | |
| parent | 37a29afc774faf3c0f07e3c06ce8096a1d23d05c (diff) | |
| download | sparse-dev-fd5de508cae29bb482513829a64d38e42e8b806e.tar.gz | |
Make "storage" be part of the sparse library, and split out
the "example output" program from it.
Diffstat (limited to 'example.c')
| -rw-r--r-- | example.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/example.c b/example.c new file mode 100644 index 00000000..284c9ffa --- /dev/null +++ b/example.c @@ -0,0 +1,69 @@ +/* + * Example of how to write a compiler with sparse + */ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +#include "symbol.h" +#include "expression.h" +#include "linearize.h" +#include "storage.h" + +static void output_bb(struct basic_block *bb) +{ + struct storage_hash *entry; + struct storage_hash_list *inputs, *outputs; + + inputs = gather_storage(bb, STOR_IN); + outputs = gather_storage(bb, STOR_OUT); + + FOR_EACH_PTR(inputs, entry) { + printf("\t%s <- %s\n", show_pseudo(entry->pseudo), show_storage(entry->storage)); + } END_FOR_EACH_PTR(entry); + show_bb(bb); + FOR_EACH_PTR(outputs, entry) { + printf("\t%s -> %s\n", show_pseudo(entry->pseudo), show_storage(entry->storage)); + } END_FOR_EACH_PTR(entry); + printf("\n"); + + free_ptr_list(&inputs); + free_ptr_list(&outputs); +} + +static void output(struct entrypoint *ep) +{ + struct basic_block *bb, *prev; + + /* Set up initial inter-bb storage links */ + set_up_storage(ep); + + /* Show the results ... */ + prev = NULL; + FOR_EACH_PTR(ep->bbs, bb) { + output_bb(bb); + } END_FOR_EACH_PTR(bb); + + /* Clear the storage hashes for the next function.. */ + free_storage(); +} + +static int compile(struct symbol_list *list) +{ + struct symbol *sym; + FOR_EACH_PTR(list, sym) { + struct entrypoint *ep; + expand_symbol(sym); + ep = linearize_symbol(sym); + if (ep) + output(ep); + } END_FOR_EACH_PTR(sym); + + return 0; +} + +int main(int argc, char **argv) +{ + return compile(sparse(argc, argv)); +} + |
