diff options
Diffstat (limited to 'c/examples/zero_init/dietpass.c')
-rw-r--r-- | c/examples/zero_init/dietpass.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/c/examples/zero_init/dietpass.c b/c/examples/zero_init/dietpass.c new file mode 100644 index 0000000..e145a91 --- /dev/null +++ b/c/examples/zero_init/dietpass.c @@ -0,0 +1,25 @@ +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <libdietc.h> + +int main(int argc, char **argv) { + assert(argc == 2); + struct program program = libdietc_parse(argv[1]); + + for (struct function *f = program.functions; f; f = f->next) { + for (struct instruction *i = f->instructions; i; i = i->next) { + if (strncmp(i->line, "\tType_", strlen("\tType_"))) continue; + char *name = libdietc_tokdup(strchrnul(i->line, ' ') + 1); + struct instruction *n = calloc(1, sizeof(*n)); + n->line = malloc(strlen(name) + 512); + sprintf(n->line, "memset(&%s, 0, sizeof(%s));", name, name); + n->next = i->next; + i->next = n; + i = n; + } + } + libdietc_print(program); + return 0; +} |