summaryrefslogtreecommitdiff
path: root/c/examples/zero_init/dietpass.c
blob: e145a91472ccfd7dd676cf68cf8187cb783cf93b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback