# This release of the imptoc transpiler does not include the ancilliary software
# required to build the parser tables from the grammar file, so for now do *not*
# make changes to the grammar!

GCC_OPTS_COMMON = -pg -Wunused-result -Wno-div-by-zero 
GCC_OPTS_WARN   = -Wall -Wno-misleading-indentation -Wno-comment -Wno-unused-variable -Wno-unused-but-set-variable -Wno-return-type 
GCC_OPTS_FAST   = ${GCC_OPTS_COMMON} -Ofast -DNDEBUG 
GCC_OPTS_SAFE   = ${GCC_OPTS_COMMON} ${GCC_OPTS_WARN} -g3 

all: imps
	echo All up to date.

imps: compile.h lex.h parser.h regexp-lexer.h symtab.h symtab_priv.h \
      compile.c lex.c parser.c regexp-lexer.c symtab.c \
      datatypes.h \
      show_ast.c ast_to_str.c \
      expressions.c flowcontrol.c \
      lang.c 
	cc -o imps     $(GCC_OPTS_SAFE) parser.c
	cc -o imps-opt $(GCC_OPTS_FAST) parser.c

clean:
	rm -f *~ imps imps-opt bin/*~  bin/#*# gmon.out imps.profile

test: imps
	echo > regression.raw
	echo > regression.log
	./bin/regression-test tests/basic 2>&1 | tee -a regression.log
	./bin/regression-test tests/rebuild -np 2>&1 | tee -a regression.log
	./bin/regression-test tests/single 2>&1 | tee -a regression.log
	./bin/regression-test tests/validation-suite 2>&1 | tee -a regression.log
	./bin/regression-test tests/new-tests 2>&1 | tee -a regression.log
	./bin/regression-test tests/old-tests 2>&1 | tee -a regression.log
	./bin/regression-test tests/imptoc 2>&1 | tee -a regression.log
	./bin/regression-test tests/imp2021 2>&1 | tee -a regression.log
	./bin/regression-test tests/imptests 2>&1 | tee -a regression.log
	./bin/regression-test tests/imp80 2>&1 | tee -a regression.log
	./bin/regression-test tests/i77 2>&1 | tee -a regression.log
	./bin/regression-test tests/imp68k 2>&1 | tee -a regression.log
	mv regression.log regression.raw
	( ecce regression.raw regression.log --command "(v.tests/.f1.: .reb,m)0m-0(v/? /k,m)0m-0(rm,k)0m-0(v/created at/k,m)0m-0(v/C_/k,m)0m-0(v/Type of/k,m)0m-0(v=// COMMENT=k,m)0m-0(v=Backtracking=k,m)0 m-0 (v/@/k,m)0m-0 (v/Debug: /k,m)0m-0 (v/Debug@/k,m)0m-0 (v/Looking up /k,m)0m-0 (v/:=) decl and spec match/k,m)0m-0 (v/MISSING FOLD OPERATOR/k,m)0m-0 (v/Record:/k(v/ /k)0,m)0m-0(v/Good. /k,v/... and the/k,m)0m-0(f/updated in situ./k)0;%c"  2>&1 ) > /dev/null
	echo more regression.log, then make accept when happy.

quicktest: imps
	echo > regression.raw
	echo > regression.log
	./bin/regression-test tests/imptests 2>&1 | tee -a regression.raw
	( ecce regression.raw regression.log --command "(v.tests/.f1.: .reb,m)0m-0(v/? /k,m)0m-0(rm,k)0m-0(v/created at/k,m)0m-0(v/C_/k,m)0m-0(v/Type of/k,m)0m-0(v=// COMMENT=k,m)0m-0(v=Backtracking=k,m)0 m-0 (v/@/k,m)0m-0 (v/Debug: /k,m)0m-0 (v/Debug@/k,m)0m-0 (v/Looking up /k,m)0m-0 (v/:=) decl and spec match/k,m)0m-0 (v/MISSING FOLD OPERATOR/k,m)0m-0 (v/Record:/k(v/ /k)0,m)0m-0(v/Good. /k,v/... and the/k,m)0m-0(f/updated in situ./k)0;%c"  2>&1 ) > /dev/null
	echo more regression.log, then make accept when happy.

accept:
	./bin/accept tests/basic
	./bin/accept tests/rebuild
	./bin/accept tests/single
	./bin/accept tests/validation-suite
	./bin/accept tests/new-tests
	./bin/accept tests/old-tests
	./bin/accept tests/imptoc
	./bin/accept tests/imp2021
	./bin/accept tests/imptests
	./bin/accept tests/imp80
	./bin/accept tests/i77
	./bin/accept tests/imp68k

rcs:
	(echo Edited.|ci ast_to_str.c) && co -l ast_to_str.c
	(echo Edited.|ci compile.c) && co -l compile.c
	(echo Edited.|ci compile.h) && co -l compile.h
	(echo Edited.|ci datatypes.h) && co -l datatypes.h
	(echo Edited.|ci expressions.c) && co -l expressions.c
	(echo Edited.|ci flowcontrol.c) && co -l flowcontrol.c
	(echo Edited.|ci lang.c) && co -l lang.c
	(echo Edited.|ci lex.c) && co -l lex.c
	(echo Edited.|ci lex.h) && co -l lex.h
	(echo Edited.|ci parser.c) && co -l parser.c
	(echo Edited.|ci parser.h) && co -l parser.h
	(echo Edited.|ci regexp-lexer.c) && co -l regexp-lexer.c
	(echo Edited.|ci regexp-lexer.h) && co -l regexp-lexer.h
	(echo Edited.|ci show_ast.c) && co -l show_ast.c
	(echo Edited.|ci symtab.c) && co -l symtab.c
	(echo Edited.|ci symtab.h) && co -l symtab.h
	(echo Edited.|ci symtab_priv.h) && co -l symtab_priv.h
	rlog *.[hc]|grep ^revision|fgrep locked

upload: clean
	rm -f ../imptoc.tar ./imptoc.tar ../imptoc.tgz ./imptoc.tgz
	tar -czf ../imptoc.tgz .
	mv ../imptoc.tgz .
	ctohtml compile.c < compile.c > compile.html
	ctohtml parser.c < parser.c > parser.html
	./gram2html lang.g > grammar.html
	scp grammar.html imptoc.html compile.html lang.html imptoc.tgz gtoal@gtoal.com:gtoal.com/compilers101/new-imp-to-c/
	ssh gtoal@gtoal.com "( cd gtoal.com/compilers101/new-imp-to-c; tar -xzf imptoc.tgz )"
