Skip to content

Commit

Permalink
makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
ailrst committed Sep 16, 2024
1 parent 7e075a3 commit 9abd740
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
29 changes: 29 additions & 0 deletions examples/csmith/Makefile
Original file line number Diff line number Diff line change
@@ -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)

28 changes: 1 addition & 27 deletions examples/csmith/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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()

0 comments on commit 9abd740

Please sign in to comment.