From 9abd740f5a44d1e414149c453dfdec527bce6deb Mon Sep 17 00:00:00 2001 From: ailrst Date: Mon, 16 Sep 2024 15:02:22 +1000 Subject: [PATCH] makefile --- examples/csmith/Makefile | 29 +++++++++++++++++++++++++++++ examples/csmith/gen.py | 28 +--------------------------- 2 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 examples/csmith/Makefile diff --git a/examples/csmith/Makefile b/examples/csmith/Makefile new file mode 100644 index 000000000..709f4e1e9 --- /dev/null +++ b/examples/csmith/Makefile @@ -0,0 +1,29 @@ + +SOURCES=$(wildcard *.c) +SOURCENAMES=$(basename $(SOURCES)) +RELFS=$(addsuffix .relf,$(SOURCENAMES)) +ADTS=$(addsuffix .adt,$(SOURCENAMES)) +OUTS=$(addsuffix .out,$(SOURCENAMES)) +CHECKSUMS=$(addsuffix .checksum,$(SOURCENAMES)) + +CSMITH_HEADER = "/nix/store/6rawnpny818v7wki6zlr3i0f3phmysyb-csmith-2.3.0/include/csmith-2.3.0/" + +%.out : $(SOURCES) + aarch64-suse-linux-gcc $< -w -I $(CSMITH_HEADER) -o $@ + + +%.relf : $(OUTS) + readelf -s -r -w $< > $@ + +%.adt: $(OUTS) + bap $< -d adt:$@ -d bir:$@ + +%.checksum : $(SOURCES) + clang -w -I $(CSMITH_HEADER) $< -o $<.out && ./$<.out || true + +default : $(ADTS) $(RELFS) + + +.PHONY=checksum +checksum: $(CHECKSUMS) + diff --git a/examples/csmith/gen.py b/examples/csmith/gen.py index b3a2382df..6ff5b1d32 100644 --- a/examples/csmith/gen.py +++ b/examples/csmith/gen.py @@ -11,6 +11,7 @@ # produces programs that we can't handle # cmd = ["csmith", "--seed", str(seed), "--max-block-size", str(max_blocksize), "--max-funcs", str(max_funcs), "--output", f"{fname}.c"] +csmith_header = "/nix/store/6rawnpny818v7wki6zlr3i0f3phmysyb-csmith-2.3.0/include/csmith-2.3.0/" csmith_safe = "--no-arrays --no-bitfields --no-checksum --no-comma-operators --no-longlong --no-int8 --no-uint8 --no-float --no-math64 --no-inline-function --no-safe-math --no-packed-struct --no-pointers --no-structs --no-unions --no-volatile-pointers --no-const-pointers".split(" ") files = [] @@ -41,31 +42,4 @@ def csmith(): gen = subprocess.run(cmd) checksum_cmd = f"gcc {fname}.c -o ${fname}-native.out && ./{fname}.out && rm {fname}-native.out" - -def checksum(): - for fname in files: - print(fname) - checksum_cmd = f"clang {fname}.c -w -o {fname}-native.out -I /usr/include/csmith && ./{fname}-native.out && rm {fname}-native.out" - print(checksum_cmd) - try: - checksum = subprocess.run(checksum_cmd, capture_output=True, text=True, shell=True, timeout=10) - print("checksum" , checksum.stdout, checksum.stderr) - with open(fname + ".checksum", 'w') as f: - f.write(checksum.stdout) - except Exception as e: - print(e) - -def lift(): - for fname in files: - compilecmd = ['clang-15', '-w', '-target', 'aarch64-linux-gnu', fname + ".c", '-I', '/usr/include/csmith', '-o', fname + '.out'] - print(compilecmd) - compile = subprocess.run(compilecmd) - cmd = ["bap", f"{fname}.out", "-d", "adt:" + fname + ".adt", "-d", "bir:"+ fname + ".bir" ] - relfcmd = f"readelf -s -r -w {fname}.out > {fname}.relf" - print(cmd) - subprocess.run(cmd) - print(relfcmd) - subprocess.run(relfcmd, shell=True) - csmith() -lift()