Python library for building dietcc passes Example of using a pass: The examples/zero_init pass zero-initializes all local variables. It can be run by passing a --dietc-pass flag to dietcc: $ which dietcc [make sure it's on your path!] $ cd examples/zero_init $ make $ ./default Foo return value: 0 Foo return value: 32765 Foo return value: 32765 $ ./instrumented Foo return value: 0 Foo return value: 0 Foo return value: 0 The examples/dynamic_typing pass adds a "dynamic_typeof" feature to C, and uses it to implement pretty-printing in C: $ which dietcc [make sure it's on your path!] $ cd examples/dynamic_typeof $ tail -n13 test.c int main() { struct { char x; int y; int z[3]; } foo = {1, 2, {3, 4, 5}}; pprint(&foo); struct { char a; int b; } bar = {100, 200}; pprint(&bar); } $ make $ ./test { .x = (char)1, .y = (int)2, .z = { (int)3, (int)4, (int)5 } } { .a = (char)100, .b = (int)200 } The examples/refcounting pass adds automated reference counting to C: $ which dietcc [make sure it's on your path!] $ cd examples/refcounting $ cat test.c ... int *foo(void) { int *ptr = 0; for (int i = 0; i < 5; i++) ptr = calloc(1, sizeof(*ptr)); ptr = calloc(1, sizeof(*ptr)); ptr = calloc(1, sizeof(*ptr)); *ptr = 5; return ptr; } ... int *bar(void) { struct bar bar; bar.x = 5; bar.y = calloc(1, sizeof(int)); *bar.y = bar.x; return bar.y; } ... int main(void) { int *x = foo(); printf("Result of foo(): %d\n", *x); x = bar(); printf("Result of bar(): %d\n", *x); return 0; } $ make $ ./test Allocated: 0x55bc2ca6e2a0 ; now tracking 1 regions Allocated: 0x55bc2ca6e700 ; now tracking 2 regions Freeing! Left: 1 Allocated: 0x55bc2ca6e750 ; now tracking 2 regions Freeing! Left: 1 Allocated: 0x55bc2ca6e7a0 ; now tracking 2 regions Freeing! Left: 1 Allocated: 0x55bc2ca6e7f0 ; now tracking 2 regions Freeing! Left: 1 Allocated: 0x55bc2ca6e840 ; now tracking 2 regions Allocated: 0x55bc2ca6e890 ; now tracking 3 regions Freeing! Left: 2 Freeing! Left: 1 Result of foo(): 5 Allocated: 0x55bc2ca6e8e0 ; now tracking 2 regions Result of bar(): 5 Freeing! Left: 1 Freeing! Left: 0