head	1.8;
access;
symbols;
locks
	gtoal:1.8; strict;
comment	@# @;


1.8
date	2026.04.18.02.02.11;	author gtoal;	state Exp;
branches;
next	1.7;

1.7
date	2024.06.25.16.05.09;	author gtoal;	state Exp;
branches;
next	1.6;

1.6
date	2024.06.20.05.55.19;	author gtoal;	state Exp;
branches;
next	1.5;

1.5
date	2024.06.01.02.52.41;	author gtoal;	state Exp;
branches;
next	1.4;

1.4
date	2024.05.28.06.56.36;	author gtoal;	state Exp;
branches;
next	1.3;

1.3
date	2024.05.28.02.12.47;	author gtoal;	state Exp;
branches;
next	1.2;

1.2
date	2024.05.24.21.14.31;	author gtoal;	state Exp;
branches;
next	1.1;

1.1
date	2024.05.23.18.58.20;	author gtoal;	state Exp;
branches;
next	;


desc
@Makefile-imp80
@


1.8
log
@bringing rcs files up to date
@
text
@LANGUAGE := imp80
EXT := imp
# LANGUAGE := project-name      # replace with your own language to be compiled
# EXT := ext

# setting CC to gcc or clang explicitly should be OK.
CC=cc 

REMAKE=-f Makefile-$(LANGUAGE)
# Pick one:
#SAFEOPTS=-Ofast -DFAST   # for a factor of 3 speedup.
SAFEOPTS=-DSUPPLY_DEFAULT_WALK_AST -g -Wall -Wno-unused-but-set-variable 

# Pick one: (Note that two programs fail with runtime-checking options on, so those always use SAFEOPTS )
#OPTS=$(SAFEOPTS)
OPTS=-DSUPPLY_DEFAULT_WALK_AST -Wall -Wno-return-type -Wno-comment -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fsanitize=undefined -fsanitize-undefined-trap-on-error  -fno-sanitize-recover=all -frecord-gcc-switches  -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow  -fstack-protector -O2  -ftrapv -grecord-gcc-switches  -ggdb3 # -fsanitize=address - always fails in getwc.

all: $(LANGUAGE:%=%) regen Makefile $(LANGUAGE:%=%.ng)  # mnemalyse
	@@echo All up to date.


$(LANGUAGE:%=%): $(LANGUAGE:%=%.h) Makefile ../../regexp-lexer.o ../../flex.o ../../uparse.o ../../symtab.o # mnemosyne.o 
	@@echo LINK $(LANGUAGE:%=%)
	@@$(CC) $(OPTS) -o $(LANGUAGE:%=%) ../../uparse.o ../../regexp-lexer.o ../../flex.o ../../symtab.o # mnemosyne.o 
	@@# can't use gdb with gzexe binaries
	@@# which gzexe && gzexe $(LANGUAGE:%=%) || exit 0

../../symtab.o: ../../symtab.c ../../symtab.h ../../symtab_priv.h
	gtcpp ../../symtab.c | fgrep -v "^#line" > ./.symtab.c && $(CC) $(OPTS) -o ../../symtab.o -I../.. -c ./.symtab.c

# This regenerates the skeleton compiler code (CST to AST conversion - just the switch on G_*) from the grammar.
$(LANGUAGE:%=%-ast.h): regen
	@@echo regen $(LANGUAGE:%=%-ast.h)
	@@./regen > $(LANGUAGE:%=%-ast.h)

# This regenerates the skeleton compiler code (AST to application conversion) from the grammar.
$(LANGUAGE:%=%-comp.h): gencomp
	@@echo gencomp $(LANGUAGE:%=%-comp.h)
	@@./gencomp > $(LANGUAGE:%=%-comp.h)

# This builds the tool to regenerate the skeleton compiler code from the grammar.
# It currently only builds the CST to AST conversion.
# -I. below is because regen.c includes imp80.h and gcc does not treat it as relative to gencomp.c's directory...
regen: ../../regen.c $(LANGUAGE:%=%.h) ../../parser.h ../../flex.o Makefile
	@@echo CC regen.c
	@@$(CC) $(SAFEOPTS) -Wno-unused-variable -o regen -I. -DGRAMMAR=\"$(LANGUAGE:%=%.h)\" ../../regen.c ../../flex.o

# This builds the tool to regenerate the skeleton compiler code from the grammar.
# It currently only builds the CST to AST conversion.
# -I.. below is because gencomp.c includes parser.h and gcc does not treat it as relative to gencomp.c's directory...
gencomp: ../../gencomp.c $(LANGUAGE:%=%.h) ../../parser.h ../../flex.o Makefile
	@@echo CC gencomp.c
	@@gtcpp ../../gencomp.c | fgrep -v "^#line" > .gencomp.c
	@@$(CC) $(SAFEOPTS) -Wno-unused-variable -o gencomp -I../.. -DGRAMMAR=\"$(LANGUAGE:%=%.h)\" .gencomp.c ../../flex.o

# This is a backup of the grammar extracted from the grammar tables.
# Only the basic rules are saved. Comments and some grammar extensions are dropped.
# It may be useful when making changes to the grammar after the compiler code is written.
# NOTE!!! Does not correctly escape "\\" in strings.
$(LANGUAGE:%=%.ng): $(LANGUAGE:%=%-ast.h)
	@@sed -ne 's|\(.*\)//\\\\ \(.*\)|\2|gp' $(LANGUAGE:%=%-ast.h) > $(LANGUAGE:%=%.ng)

# This is the body of the ../../parser.  It requires the grammar to have been converted to table form.
../../uparse.o: ../../uparse.c ../../uparse-main.c imp80-compile.h imp80-switch.h ../../parser.h ../../flex.h Makefile $(LANGUAGE:%=%.c) $(LANGUAGE:%=%-ast.h) $(LANGUAGE:%=%-comp.h) # $(LANGUAGE:%=%-indent.c)
	@@echo CC uparse.c
	@@gtcpp imp80-compile.h | fgrep -v "^#line" > .imp80-compile.h
	@@gtcpp ../../uparse.c | fgrep -v "^#line" > ./.uparse.c && $(CC) $(OPTS) -I../.. \
	              -DAPPMODULE=\".imp80-compile.h\" \
	              -DAPPCOMMAND=compile \
	              -DGRAMMAR=\"$(LANGUAGE:%=%.h)\" \
	              -DCOMPILER=\"$(LANGUAGE:%=%.c)\" \
	              -DCST2AST=\"$(LANGUAGE:%=%-ast.h)\" \
	              -Wno-unused-variable \
	              -c -o ../../uparse.o ./.uparse.c

# This converts the grammar to table form.  Executing in a pipe was bad because errorcode set to that of whole pipe, ignoring return from ../../takeon.
$(LANGUAGE:%=%.h): $(LANGUAGE:%=%.g) imp80-init.g ../../takeon Makefile
	@@echo ../../takeon $(LANGUAGE:%=%.g)
	@@./../../takeon $(LANGUAGE:%=%.g) > $$.h
	@@gtcpp -P < $$.h | fgrep -v "^#line" > $(LANGUAGE:%=%.h)
	@@rm -f $$.h

# This converts the grammar to table form.
$(LANGUAGE:%=%-switch.h): $(LANGUAGE:%=%-comp.h)
	@@ecce $(LANGUAGE:%=%-comp.h) $(LANGUAGE:%=%-switch.h)  --command "u0.  switch (op).km0f-.//\\\\ E.mk0;%c" > /dev/null 2>/dev/null

# This builds the utility which converts the grammar to table form.
# NOTE: -fsanitize=address causes erroneous trap when running ../../takeon.  Do not use that option here.
../../takeon: ../../takeon.c ../../takeon-output.c ../../takeon-checks.c ../../flex.h Makefile ../../flex.o
	@@echo CC takeon.c
	@@$(CC) $(SAFEOPTS) -o ../../takeon ../../takeon.c ../../flex.o

# This is a utility used in much of the code to support ../../flex arrays, i.e. arrays
# which extend their allocated space as more elements are accessed.  It also
# supplies some checks on array bounds and unassigned variables.  These are
# relatively cheap to implement - the runtime of a program using ../../flex arrays
# and checking is about 3 times that of the same program with static arrays
# and no checks.  Use the "-DFAST" option at the head of this file for a
# faster executable but only once the code is stable and ready for release testing.
../../flex.o: ../../flex.c ../../flex.h Makefile
	@@echo CC flex.c
	@@$(CC) $(SAFEOPTS) -o ../../flex.o -c ../../flex.c

# This is an internal regular expression matcher which has been modified
# to support Unicode characters.
../../regexp-lexer.o: ../../regexp-lexer.c Makefile ../../parser.h # ../../tools/mnemosyne.h 
	@@echo CC regexp-lexer.c
	@@$(CC) $(OPTS) -o ../../regexp-lexer.o -c ../../regexp-lexer.c -I../../tools

# This is an old memory leak utility I used to use in the 80's - you can get
# equally good results nowadays by using valgrind instead.  It is off by default.
mnemosyne.o: ../../tools/mnemosyne.c ../../tools/mnemosyne.h Makefile
	$(CC) $(OPTS) -Wno-unused-variable -Wno-pointer-to-int-cast -c ../../tools/mnemosyne.c -I../../tools

# The post-execution analyzer for mnemosyne (the Greek Goddess of memory)
mnemalyse: ../../tools/mnemalyse.c ../../tools/mnemosyne.h Makefile
	$(CC) $(OPTS) -o mnemalyse ../../tools/mnemalyse.c -I../../tools

web:
	make $(REMAKE) clean
	cc -o grammar2html ../../tools/grammar2html.c
	cc -o ctohtml ../../tools/ctohtml.c
	./grammar2html $(LANGUAGE:%=%.g) > $(LANGUAGE:%=%.g.html)
	./ctohtml ../../takeon.c > ../../takeon.c.html
	./ctohtml ../../uparse.c > ../../uparse.c.html
	./ctohtml $(LANGUAGE:%=%.h) > $(LANGUAGE:%=%.h.html)
	./ctohtml ../../regexp-lexer.c > ../../regexp-lexer.c.html
	./ctohtml ../../regexp-lexer.h > ../../regexp-lexer.h.html
	./ctohtml ../../flex.c > ../../flex.c.html
	./ctohtml ../../flex.h > ../../flex.h.html
	./ctohtml ../../parser.h > ../../parser.h.html
	./ctohtml ../../regen.c > ../../regen.c.html
	./ctohtml ../../gencomp.c > ../../gencomp.c.html
	./ctohtml $(LANGUAGE:%=%-ast.h) > $(LANGUAGE:%=%-ast.h.html)
	./ctohtml $(LANGUAGE:%=%-comp.h) > $(LANGUAGE:%=%-comp.h.html)
	# ./ctohtml $(LANGUAGE:%=%-indent.c) > $(LANGUAGE:%=%-indent.c.html)
	rm -f grammar2html ctohtml

# Only for the author. These won't work for anyone else.
upload:
	make web
	tar -cvf $(LANGUAGE:%=%.tar) *.[cgh] *.ng Makefile *.sh README.html ../../tools/mnem*.[ch] ../../tools/grammar2html.c ../../tools/ctohtml.c tests-$(LANGUAGE)/*.$(EXT) *.[chg].html
	make $(REMAKE) clean
	scp Makefile $(LANGUAGE:%=%.tar) gtoal@@gtoal.com:gtoal.com/languages/$(LANGUAGE:%=%)/new-unicode-parser/
	ssh gtoal@@gtoal.com "( cd gtoal.com/languages/$(LANGUAGE:%=%)/new-unicode-parser ; make $(REMAKE) clean )"
	ssh gtoal@@gtoal.com "( cd gtoal.com/languages/$(LANGUAGE:%=%)/new-unicode-parser ; tar -xvf $(LANGUAGE:%=%.tar) )"

# Parse test files
regression-$(LANGUAGE):
	find tests-$(LANGUAGE) -name '*.$(EXT)' |sort > REGRESSION-TESTS-$(LANGUAGE).sh
	# Oops. Does require ecce. Need to avoid that. Use sed instead?
	ecce REGRESSION-TESTS-$(LANGUAGE).sh -command "(rli=./$(LANGUAGE:%=%) =r0i. 2>/dev/null | gtcpp -P | clang-format | ecce - - -command \"f/int _imp_mainep/(v-/ /e-)0m0r0i/-/79b;m-0((v/ /r)0v/;/(v-/ /e-)0m,m)0; m-0(v/\t;/em,m)0; (m-0 (v/;/j-m,m)0)2;%c\" 2> /dev/null.m)0m-0i.#!/bin/sh.b;%c"
	chmod +x REGRESSION-TESTS-$(LANGUAGE).sh
	./REGRESSION-TESTS-$(LANGUAGE).sh -x
#|ecce - - -command '(v/#define/ei/$$/m,m)0;%c' 2>/dev/null | gtcpp

# Mr Sheen.
clean:
	rm -f *~ *.o $(LANGUAGE:%=%) mnemalyse ../../takeon regen gencomp ctohtml grammar2html \#*\# [a-z]*.[chg].html $(LANGUAGE)-ast.h $(LANGUAGE)-comp.h

tidy:
	rm -f *~ *.o $(LANGUAGE:%=%) mnemalyse ../../takeon regen gencomp ctohtml grammar2html \#*\# 
@


1.7
log
@*** empty log message ***
@
text
@d4 1
a4 1
EXT := ext
d150 1
a150 1
	find tests-$(LANGUAGE) -name '*.$(EXT)' > REGRESSION-TESTS-$(LANGUAGE).sh
d152 1
a152 1
	ecce REGRESSION-TESTS-$(LANGUAGE).sh -command "(rli=./$(LANGUAGE:%=%) =m)0m-0i.#!/bin/sh.b;%c"
d155 1
@


1.6
log
@*** empty log message ***
@
text
@d15 2
a16 2
OPTS=$(SAFEOPTS)
#OPTS=-DSUPPLY_DEFAULT_WALK_AST -Wall -Wno-return-type -Wno-comment -fsanitize=undefined -fsanitize-undefined-trap-on-error  -fno-sanitize-recover=all -frecord-gcc-switches  -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow  -fstack-protector -O2  -ftrapv -grecord-gcc-switches  -ggdb3 # -fsanitize=address - always fails in getwc.
d29 1
a29 1
	gtcpp ../../symtab.c > ./.symtab.c && $(CC) $(OPTS) -o ../../symtab.o -I../.. -c ./.symtab.c
d53 1
a53 1
	@@gtcpp ../../gencomp.c > .gencomp.c
d66 2
a67 2
	@@gtcpp imp80-compile.h > .imp80-compile.h
	@@gtcpp ../../uparse.c > ./.uparse.c && $(CC) $(OPTS) -I../.. \
d80 1
a80 1
	@@gtcpp -P < $$.h> $(LANGUAGE:%=%.h)
@


1.5
log
@*** empty log message ***
@
text
@d12 1
a12 1
SAFEOPTS=-DSUPPLY_DEFAULT_WALK_AST -g -Wall         
d21 2
a22 5
# This builds the actual compiler.  The demo only outputs the compiler source
# but with variables converted into upper case as a demonstration.
# Your own code could be an actual compiler, or perhaps a translator
# from your language to C.
$(LANGUAGE:%=%): $(LANGUAGE:%=%.h) Makefile regexp-lexer.o flex.o uparse.o symtab.o # mnemosyne.o 
d24 1
a24 1
	@@$(CC) $(OPTS) -o $(LANGUAGE:%=%) uparse.o regexp-lexer.o flex.o symtab.o # mnemosyne.o 
d28 2
a29 2
symtab.o: symtab.c symtab.h symtab_priv.h
	gtcpp symtab.c > .symtab.c && $(CC) $(OPTS) -o symtab.o -c .symtab.c
d43 2
a44 1
regen: regen.c $(LANGUAGE:%=%.h) parser.h flex.o Makefile
d46 1
a46 1
	@@$(CC) $(SAFEOPTS) -Wno-unused-variable -o regen -DGRAMMAR=\"$(LANGUAGE:%=%.h)\" regen.c flex.o
d50 2
a51 1
gencomp: gencomp.c $(LANGUAGE:%=%.h) parser.h flex.o Makefile
d53 2
a54 2
	@@gtcpp gencomp.c > .gencomp.c
	@@$(CC) $(SAFEOPTS) -Wno-unused-variable -o gencomp -DGRAMMAR=\"$(LANGUAGE:%=%.h)\" .gencomp.c flex.o
d63 2
a64 2
# This is the body of the parser.  It requires the grammar to have been converted to table form.
uparse.o: uparse.c uparse-main.c imp80-compile.h imp80-switch.h parser.h flex.h Makefile $(LANGUAGE:%=%.c) $(LANGUAGE:%=%-ast.h) $(LANGUAGE:%=%-comp.h) # $(LANGUAGE:%=%-indent.c)
d67 1
a67 1
	@@gtcpp uparse.c > .uparse.c && $(CC) $(OPTS) \
d74 1
a74 1
	              -c -o uparse.o .uparse.c
d76 4
a79 4
# This converts the grammar to table form.  Executing in a pipe was bad because errorcode set to that of whole pipe, ignoring return from takeon.
$(LANGUAGE:%=%.h): $(LANGUAGE:%=%.g) imp80-init.g takeon Makefile
	@@echo takeon $(LANGUAGE:%=%.g)
	@@./takeon $(LANGUAGE:%=%.g) > $$.h
d88 2
a89 2
# NOTE: -fsanitize=address causes erroneous trap when running takeon.  Do not use that option here.
takeon: takeon.c takeon-output.c takeon-checks.c flex.h Makefile flex.o
d91 1
a91 1
	@@$(CC) $(SAFEOPTS) -o takeon takeon.c flex.o
d93 1
a93 1
# This is a utility used in much of the code to support flex arrays, i.e. arrays
d96 1
a96 1
# relatively cheap to implement - the runtime of a program using flex arrays
d100 1
a100 1
flex.o: flex.c flex.h Makefile
d102 1
a102 1
	@@$(CC) $(SAFEOPTS) -c flex.c
d106 1
a106 1
regexp-lexer.o: regexp-lexer.c Makefile parser.h # tools/mnemosyne.h 
d108 1
a108 1
	@@$(CC) $(OPTS) -c regexp-lexer.c -Itools
d112 2
a113 2
mnemosyne.o: tools/mnemosyne.c tools/mnemosyne.h Makefile
	$(CC) $(OPTS) -Wno-unused-variable -Wno-pointer-to-int-cast -c tools/mnemosyne.c -Itools
d116 2
a117 2
mnemalyse: tools/mnemalyse.c tools/mnemosyne.h Makefile
	$(CC) $(OPTS) -o mnemalyse tools/mnemalyse.c -Itools
d121 2
a122 2
	cc -o grammar2html tools/grammar2html.c
	cc -o ctohtml tools/ctohtml.c
d124 2
a125 2
	./ctohtml takeon.c > takeon.c.html
	./ctohtml uparse.c > uparse.c.html
d127 7
a133 7
	./ctohtml regexp-lexer.c > regexp-lexer.c.html
	./ctohtml regexp-lexer.h > regexp-lexer.h.html
	./ctohtml flex.c > flex.c.html
	./ctohtml flex.h > flex.h.html
	./ctohtml parser.h > parser.h.html
	./ctohtml regen.c > regen.c.html
	./ctohtml gencomp.c > gencomp.c.html
d142 1
a142 1
	tar -cvf $(LANGUAGE:%=%.tar) *.[cgh] *.ng Makefile *.sh README.html tools/mnem*.[ch] tools/grammar2html.c tools/ctohtml.c tests-$(LANGUAGE)/*.$(EXT) *.[chg].html
d158 1
a158 1
	rm -f *~ *.o $(LANGUAGE:%=%) mnemalyse takeon regen gencomp ctohtml grammar2html \#*\# [a-z]*.[chg].html $(LANGUAGE)-ast.h $(LANGUAGE)-comp.h
d161 1
a161 1
	rm -f *~ *.o $(LANGUAGE:%=%) mnemalyse takeon regen gencomp ctohtml grammar2html \#*\# 
@


1.4
log
@*** empty log message ***
@
text
@d15 2
a16 2
#OPTS=$(SAFEOPTS)
OPTS=-DSUPPLY_DEFAULT_WALK_AST -Wall -Wno-return-type -Wno-comment -fsanitize=undefined -fsanitize-undefined-trap-on-error  -fno-sanitize-recover=all -frecord-gcc-switches  -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow  -fstack-protector -O2  -ftrapv -grecord-gcc-switches  -ggdb3 # -fsanitize=address - always fails in getwc.
@


1.3
log
@*** empty log message ***
@
text
@d68 3
a70 1
	@@gtcpp uparse.c > .uparse.c && $(CC) $(OPTS) -DAPPMODULE=\".imp80-compile.h\" -DAPPCOMMAND=compile \
d74 2
a75 2
	              -Wno-unused-variable -c \
	              -o uparse.o .uparse.c
@


1.2
log
@Working on making more like tacc
@
text
@d19 1
a19 1
	echo All up to date.
d26 4
a29 3
	$(CC) $(OPTS) -o $(LANGUAGE:%=%) uparse.o regexp-lexer.o flex.o symtab.o # mnemosyne.o 
	# can't use gdb with gzexe binaries
	# which gzexe && gzexe $(LANGUAGE:%=%) || exit 0
d32 1
a32 1
	$(CC) $(OPTS) -c symtab.c
d34 1
a34 1
# This regenerates the skeleton compiler code (CST to AST conversion) from the grammar.
d36 2
a37 1
	./regen > $(LANGUAGE:%=%-ast.h)
d39 1
a39 1
# This regenerates the skeleton compiler code (CST to AST conversion) from the grammar.
d41 2
a42 1
	./gencomp > $(LANGUAGE:%=%-comp.h)
d47 2
a48 1
	$(CC) $(SAFEOPTS) -o regen -DGRAMMAR=\"$(LANGUAGE:%=%.h)\" regen.c flex.o
d53 3
a55 1
	$(CC) $(SAFEOPTS) -o gencomp -DGRAMMAR=\"$(LANGUAGE:%=%.h)\" gencomp.c flex.o
d62 1
a62 1
	sed -ne 's|\(.*\)//\\\\ \(.*\)|\2|gp' $(LANGUAGE:%=%-ast.h) > $(LANGUAGE:%=%.ng)
d66 3
a68 1
	$(CC) $(OPTS) -DAPPMODULE=\"imp80-compile.h\" -DAPPCOMMAND=compile \
d73 1
a73 1
	              uparse.c 
d75 6
a80 3
# This converts the grammar to table form.
$(LANGUAGE:%=%.h): $(LANGUAGE:%=%.g) takeon Makefile
	./takeon $(LANGUAGE:%=%.g) > $(LANGUAGE:%=%.h)
d84 1
a84 1
	ecce $(LANGUAGE:%=%-comp.h) $(LANGUAGE:%=%-switch.h)  --command "u0.//\\\\ P<nls> =.m0f-.//\\\\ E.mk0;%c"
d89 2
a90 1
	$(CC) $(SAFEOPTS) -o takeon takeon.c flex.o
d100 2
a101 1
	$(CC) $(SAFEOPTS) -c flex.c
d106 2
a107 1
	$(CC) $(OPTS) -c regexp-lexer.c -Itools
@


1.1
log
@Initial revision
@
text
@d25 2
a26 2
$(LANGUAGE:%=%): $(LANGUAGE:%=%.h) Makefile regexp-lexer.o flex.o uparse.o # mnemosyne.o 
	$(CC) $(OPTS) -o $(LANGUAGE:%=%) uparse.o regexp-lexer.o flex.o # mnemosyne.o 
d30 2
d59 7
a65 2
uparse.o: uparse.c uparse-main.c parser.h flex.h Makefile $(LANGUAGE:%=%.c) $(LANGUAGE:%=%-ast.h) $(LANGUAGE:%=%-comp.h) # $(LANGUAGE:%=%-indent.c)
	$(CC) $(OPTS) -DGRAMMAR=\"$(LANGUAGE:%=%.h)\" -DCOMPILER=\"$(LANGUAGE:%=%.c)\" -DCST2AST=\"$(LANGUAGE:%=%-ast.h)\" -Wno-unused-variable -c uparse.c 
d70 4
@
