
SRC = \
	main.c \
	d4dag.c

# gcc -m32 should compile 32bits version and that does not work on debian linux
all:
	make clean
	make indent
	gcc -Wall -Wextra -pedantic -Wnull-dereference -O0 main.c d4dag.c -o main
	cp main mainc
	rm -v -f *.o main
	g++ -Wall -Wextra -pedantic -O0 main.c d4dag.c -o main++
	rm -v -f *~
	rm -v -f d4dag.bc
	clang-11 -O0 -emit-llvm d4dag.c -c -o d4dag.bc
	llvm-dis-11 d4dag.bc -o d4dag.ll
	python3 OverCG.py -i d4dag.ll -o d4dag.ll.callgraph.gv
	opt-11 -dot-cfg d4dag.bc -o d4dag.bc~
	opt-11 -dot-callgraph d4dag.bc -o d4dag.bc~
	rm -v -f d4dag.bc
	rm -v -f *~
	./mkcallgraph.sh

# smatch sourcecode checker at sourceforge.net using Linux kernel sparse tool
smatch:
	smatch main.c d4dag.c

# compile to llvm binary usinf sparse
sparsellvm:
	sparse-llvm main.c d4dag.c >output.bc

# compile with intel c compiler
icc:
	./icc.sh

# format the source
indent:
	./lindent.sh $(SRC)

# using the complexity program from debian show nesting depth of routines
comp:
	complexity -c -H d4dag.c

# using cunloop from cutils package 1.6 to create C with easier ast
# this needs the cunloop.c with bug fixs
# the resulting ast will only have if() and goto's and goto labels
# the amount of code used in the compiler will be much smaller
unloop:
	cunloop d4dag.c -od4dag-unloop.c -p d4dag__unloop_ d4dag.c
	indent d4dag-unloop.c

simplec:
	rm -v -f lex.yy.c
	rm -v -f simplec
	flex simplec.l
	gcc lex.yy.c -o simplec
	./simplec -od4dag-unloop.c -p d4dag__unloop_ d4dag.c
	indent d4dag-unloop.c

# create some gcc graph data
gccdata:
	gcc -c -fdump-rtl-expand-graph d4dag.c
	gcc -c -fdump-tree-ssa-graph d4dag.c
	gcc -c -fdump-ipa-whole-program-graph d4dag.c
	gcc -g -S -c -fverbose-asm -save-temps d4dag.c
	rm -v -f *.o
	rm -v -f *.i
	rm -v -f *.expand
	rm -v -f *.ssa
	rm -v -f *i.whole-program
	cp d4dag.s d4dag-gcc.s
	gcc -g -c -Wa,-adhnl=d4dag.s d4dag.c
	cp d4dag.s d4dag-gcc-wa.s
	clang-11 -S -g -c -fverbose-asm d4dag.c
	cp d4dag.s d4dag-clang.s
	./icc.sh

clean:
	rm -v -f main
	rm -v -f mainc
	rm -v -f main++
	rm -v -f *.o
	rm -v -f *.bc
	rm -v -f *.output
	rm -v -f *.errors
	rm -v -f *.warnings
	rm -v -f *~
	rm -v -f lex.yy.c
	rm -v -f simplec

cleaner:
	make clean

# end.
