From 578531395ecbabd8179e31520c2832ac7d6d3765 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Thu, 27 Jul 2023 12:06:17 -0700 Subject: add dynamic typing example --- python/examples/zero_init | 13 ------------- python/examples/zero_init/.gitignore | 2 ++ python/examples/zero_init/Makefile | 10 ++++++++++ python/examples/zero_init/dietc.py | 1 + python/examples/zero_init/dietpass | 12 ++++++++++++ python/examples/zero_init/test.c | 20 ++++++++++++++++++++ 6 files changed, 45 insertions(+), 13 deletions(-) delete mode 100755 python/examples/zero_init create mode 100644 python/examples/zero_init/.gitignore create mode 100644 python/examples/zero_init/Makefile create mode 120000 python/examples/zero_init/dietc.py create mode 100755 python/examples/zero_init/dietpass create mode 100644 python/examples/zero_init/test.c (limited to 'python/examples/zero_init') diff --git a/python/examples/zero_init b/python/examples/zero_init deleted file mode 100755 index e2ab92e..0000000 --- a/python/examples/zero_init +++ /dev/null @@ -1,13 +0,0 @@ -#!/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() diff --git a/python/examples/zero_init/.gitignore b/python/examples/zero_init/.gitignore new file mode 100644 index 0000000..b74bd7f --- /dev/null +++ b/python/examples/zero_init/.gitignore @@ -0,0 +1,2 @@ +default +instrumented diff --git a/python/examples/zero_init/Makefile b/python/examples/zero_init/Makefile new file mode 100644 index 0000000..92f29b7 --- /dev/null +++ b/python/examples/zero_init/Makefile @@ -0,0 +1,10 @@ +all: default instrumented + +default: test.c + gcc -O0 $^ -o $@ + +instrumented: test.c + dietcc -O0 $^ -o $@ --dietc-pass $(PWD)/dietpass + +clean: + rm -f default instrumented diff --git a/python/examples/zero_init/dietc.py b/python/examples/zero_init/dietc.py new file mode 120000 index 0000000..8cb9097 --- /dev/null +++ b/python/examples/zero_init/dietc.py @@ -0,0 +1 @@ +../../dietc.py \ No newline at end of file diff --git a/python/examples/zero_init/dietpass b/python/examples/zero_init/dietpass new file mode 100755 index 0000000..1984d81 --- /dev/null +++ b/python/examples/zero_init/dietpass @@ -0,0 +1,12 @@ +#!/bin/python3 +import os +import sys +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() diff --git a/python/examples/zero_init/test.c b/python/examples/zero_init/test.c new file mode 100644 index 0000000..5db109a --- /dev/null +++ b/python/examples/zero_init/test.c @@ -0,0 +1,20 @@ +#include + +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; +} -- cgit v1.2.3