diff options
author | Matthew Sotoudeh <matthew@masot.net> | 2023-07-26 11:02:15 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthew@masot.net> | 2023-07-26 11:02:15 -0700 |
commit | e29b2b00691b12ae70e97a072664bad073d81c4f (patch) | |
tree | 4cf2c79380baa41369ff8223f70e17d3da2bd812 /python/examples |
initial libdietc
Diffstat (limited to 'python/examples')
-rw-r--r-- | python/examples/test_files/zero_init.c | 20 | ||||
-rwxr-xr-x | python/examples/zero_init | 13 |
2 files changed, 33 insertions, 0 deletions
diff --git a/python/examples/test_files/zero_init.c b/python/examples/test_files/zero_init.c new file mode 100644 index 0000000..5db109a --- /dev/null +++ b/python/examples/test_files/zero_init.c @@ -0,0 +1,20 @@ +#include <stdio.h> + +int set_xyz() { + int xyz = 1; + return xyz; +} + +int foo() { + int xyz; + return xyz; +} + +int main() { + printf("Foo return value: %d\n", foo()); + set_xyz(); + printf("Foo return value: %d\n", foo()); + set_xyz(); + printf("Foo return value: %d\n", foo()); + return 0; +} diff --git a/python/examples/zero_init b/python/examples/zero_init new file mode 100755 index 0000000..e2ab92e --- /dev/null +++ b/python/examples/zero_init @@ -0,0 +1,13 @@ +#!/bin/python3 +import os +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) +import dietc + +prog = dietc.Program(open(sys.argv[1], "rb").read()) +for function in prog.functions: + fn_locals = function.locals() + start_i = function.code_start() + for local in fn_locals: + function.insert(start_i, f"\tMEMZERO ( {local} ) ;") +prog.print() |