artificial commit to compensate for changes in 93f3093f2b7e from a CVS
vendor branch
This commit is contained in:
commit
abde37e1fc
44
lang/pc/pem/Makefile
Normal file
44
lang/pc/pem/Makefile
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# $Header$
|
||||||
|
d=../../..
|
||||||
|
h=$d/h
|
||||||
|
PEM=$d/lib/pc_pem
|
||||||
|
PEM_OUT=$d/lib/pc_pem.out
|
||||||
|
|
||||||
|
HEAD=$h/em_spec.h $h/em_pseu.h $h/em_mnem.h $h/em_mes.h $h/pc_size.h
|
||||||
|
LDFLAG=-i
|
||||||
|
|
||||||
|
all: pem pem.out
|
||||||
|
|
||||||
|
pem.out: pem.m
|
||||||
|
apc -mint --t -o pem.out pem.m
|
||||||
|
|
||||||
|
pem: pem.m
|
||||||
|
apc $(LDFLAG) -o pem pem.m
|
||||||
|
|
||||||
|
# pem.m is system dependent and may NOT be distributed
|
||||||
|
pem.m: pem.p $(HEAD)
|
||||||
|
-rm -f pem.m
|
||||||
|
-if apc -I$h -O -c.m pem.p ; then :; else \
|
||||||
|
acc -o move move.c ; move ; rm move move.[oskm] ; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmp: pem
|
||||||
|
cmp pem $(PEM)
|
||||||
|
|
||||||
|
install: pem
|
||||||
|
cp pem $(PEM)
|
||||||
|
|
||||||
|
distr:
|
||||||
|
ln pem.p pem22.p ; apc -mpdp -c.m -I$h pem22.p ; rm pem22.p
|
||||||
|
ln pem.p pem24.p ; apc -mvax2 -c.m -I$h pem24.p ; rm pem24.p
|
||||||
|
clean:
|
||||||
|
-rm -f pem pem.out *.[os] *.old
|
||||||
|
|
||||||
|
pr:
|
||||||
|
@pr pem.p
|
||||||
|
|
||||||
|
xref:
|
||||||
|
xref pem.p^pr -h "XREF PEM.P"
|
||||||
|
|
||||||
|
opr:
|
||||||
|
make pr ^ opr
|
||||||
20
lang/pc/pem/move.c
Normal file
20
lang/pc/pem/move.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* A program to move the file pem??.m to pem.m */
|
||||||
|
/* Called when "apc pem.p" fails. It is assumed that the binary
|
||||||
|
file is incorrect in that case and has to be created from the compact
|
||||||
|
code file.
|
||||||
|
This program selects the correct compact code file for each combination
|
||||||
|
of word and pointer size.
|
||||||
|
It will return an error code if the move failed
|
||||||
|
*/
|
||||||
|
main(argc) {
|
||||||
|
char copy[100] ;
|
||||||
|
|
||||||
|
if ( argc!=1 ) {
|
||||||
|
printf("No arguments allowed\n") ;
|
||||||
|
exit(1) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(copy,"cp pem%d%d.m pem.m", EM_WSIZE, EM_PSIZE) ;
|
||||||
|
printf("%s\n",copy) ;
|
||||||
|
return system(copy) ;
|
||||||
|
}
|
||||||
3138
lang/pc/pem/pem.p
Normal file
3138
lang/pc/pem/pem.p
Normal file
File diff suppressed because it is too large
Load Diff
27
lib/6500/descr
Normal file
27
lib/6500/descr
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=m6500
|
||||||
|
var M=6500
|
||||||
|
var LIB=mach/6500/lib/tail_
|
||||||
|
var RT=mach/6500/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_be
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em) -o > (.e:{TAIL}={EM}/{LIB}em)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
31
lib/6809/descr
Normal file
31
lib/6809/descr
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
var w=2
|
||||||
|
var i=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=m6809
|
||||||
|
var M=6809
|
||||||
|
var LIB=mach/6809/lib/tail_
|
||||||
|
var RT=mach/6809/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_be
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c.p:{TAIL}={EM}/{LIB}mon) (.e:{TAIL}={EM}/{LIB}em)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
25
lib/descr/cpm
Normal file
25
lib/descr/cpm
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=4
|
||||||
|
var M=cpm
|
||||||
|
var NAME=CPM
|
||||||
|
var LIB=mach/z80/int/lib/tail_
|
||||||
|
var RT=mach/z80/int/lib/head_
|
||||||
|
var SIZE_F=-sm
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name asld
|
||||||
|
from .k.m.a
|
||||||
|
to e.out
|
||||||
|
program {EM}/lib/em_ass
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
mapflag -+* ASS_F={ASS_F?} -+*
|
||||||
|
mapflag --* ASS_F={ASS_F?} --*
|
||||||
|
mapflag -s* SIZE_F=-s*
|
||||||
|
args {ASS_F?} ({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c.p:{TAIL}={EM}/{LIB}mon)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
60
lib/descr/fe.src
Normal file
60
lib/descr/fe.src
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
name cpp
|
||||||
|
# no from, it's governed by the P property
|
||||||
|
to .i
|
||||||
|
program {EM}/lib/cpp.new
|
||||||
|
mapflag -I* CPP_F={CPP_F?} -I*
|
||||||
|
mapflag -U* CPP_F={CPP_F?} -U*
|
||||||
|
mapflag -D* CPP_F={CPP_F?} -D*
|
||||||
|
args {CPP_F?} {INCLUDES?} -D{NAME} -DEM_WSIZE={w} -DEM_PSIZE={p} \
|
||||||
|
-DEM_SSIZE={s} -DEM_LSIZE={l} -DEM_FSIZE={f} -DEM_DSIZE={d} <
|
||||||
|
prop >P
|
||||||
|
end
|
||||||
|
name cem
|
||||||
|
from .c
|
||||||
|
to .k
|
||||||
|
program {EM}/lib/em_cem
|
||||||
|
mapflag -p CEM_F={CEM_F?} -Xp
|
||||||
|
mapflag -L CEM_F={CEM_F?} -l
|
||||||
|
args -Vw{w}i{w}p{p}f{f}s{s}l{l}d{d} {CEM_F?}
|
||||||
|
prop <>p
|
||||||
|
rts .c
|
||||||
|
need .c
|
||||||
|
end
|
||||||
|
name pc
|
||||||
|
from .p
|
||||||
|
to .k
|
||||||
|
program {EM}/lib/em_pc
|
||||||
|
mapflag -p PC_F={PC_F?} -p
|
||||||
|
mapflag -w PC_F={PC_F?} -w
|
||||||
|
mapflag -E PC_F={PC_F?} -E
|
||||||
|
mapflag -e PC_F={PC_F?} -e
|
||||||
|
mapflag -{*} PC_F={PC_F?} -\{*}
|
||||||
|
mapflag -L PC_F={PC_F?} -\{l-}
|
||||||
|
args -Vw{w}p{p}f{d}l{l} {PC_F?} < > {SOURCE}
|
||||||
|
prop m
|
||||||
|
rts .p
|
||||||
|
need .p
|
||||||
|
end
|
||||||
|
name encode
|
||||||
|
from .e
|
||||||
|
to .k
|
||||||
|
program {EM}/lib/em_encode
|
||||||
|
args <
|
||||||
|
prop >m
|
||||||
|
end
|
||||||
|
name opt
|
||||||
|
from .k
|
||||||
|
to .m
|
||||||
|
program {EM}/lib/em_opt
|
||||||
|
mapflag -LIB OPT_F={OPT_F?} -L
|
||||||
|
args {OPT_F?} <
|
||||||
|
prop >O
|
||||||
|
end
|
||||||
|
name decode
|
||||||
|
from .k.m
|
||||||
|
to .e
|
||||||
|
program {EM}/lib/em_decode
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
end
|
||||||
35
lib/descr/ibm.nosid
Normal file
35
lib/descr/ibm.nosid
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=i8086
|
||||||
|
var M=i86
|
||||||
|
var LIB=mach/i86/lib/tail_
|
||||||
|
var LIBIBM=mach/ibm/lib/tail_
|
||||||
|
var RT=mach/i86/lib/head_
|
||||||
|
var RTIBM=mach/ibm/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I{EM}/mach/ibm/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
mapflag -i IFILE={EM}/{RT}i
|
||||||
|
args {IFILE?} (.e:{HEAD}={EM}/{RTIBM}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.e:{TAIL}={EM}/{LIBIBM}em) \
|
||||||
|
(.c.p:{TAIL}={EM}/{LIBIBM}mon) \
|
||||||
|
(.e:{TAIL}={EM}/{LIBIBM}em.vend)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
34
lib/descr/m68k2.macs
Normal file
34
lib/descr/m68k2.macs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
var w=2
|
||||||
|
var p=4
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=m68k2
|
||||||
|
var M=m68k2
|
||||||
|
var LIBDIR=mach/m68k2/lib
|
||||||
|
var LIB=mach/m68k2/lib/tail_
|
||||||
|
var RT=mach/m68k2/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p.c:{TAIL}={EM}/{LIBDIR}/sys1.s) (.p:{TAIL}={EM}/{LIBDIR}/sys2.s) \
|
||||||
|
(.c:{TAIL}={EM}/{LIBDIR}/write.s) \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c:{TAIL}={EM}/{LIB}mon {EM}/{LIB}fake) \
|
||||||
|
(.e:{TAIL}={EM}/{LIB}em.rt {EM}/{LIB}em.vend)
|
||||||
|
prop Cm
|
||||||
|
end
|
||||||
28
lib/descr/nascom
Normal file
28
lib/descr/nascom
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
var w=1
|
||||||
|
var p=2
|
||||||
|
var s=1
|
||||||
|
var l=2
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=nascom
|
||||||
|
var M=z80a
|
||||||
|
var LIB=mach/z80a/lib/tail_
|
||||||
|
var RT=mach/z80a/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_be
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em) ({RTS}:.c={EM}/{RT}cc) -o > \
|
||||||
|
(.e:{TAIL}={EM}/{LIB}em.1 {EM}/{LIB}em.2)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
32
lib/descr/net86
Normal file
32
lib/descr/net86
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=i8086
|
||||||
|
var M=i86
|
||||||
|
var LIB=mach/i86/lib/tail_
|
||||||
|
var RT=mach/i86/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
mapflag -i IFILE={EM}/{RT}i
|
||||||
|
args {IFILE?} (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c.p.e:{TAIL}={EM}/{LIB}netio) (.c.p.e:{TAIL}={EM}/{LIB}alo) \
|
||||||
|
(.c.p:{TAIL}={EM}/{LIB}mon) (.e:{TAIL}={EM}/{LIB}em)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
33
lib/descr/sat86
Normal file
33
lib/descr/sat86
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=i8086
|
||||||
|
var M=i86
|
||||||
|
var LIB=mach/i86/lib/tail_
|
||||||
|
var ALIB=mach/i86/lib/sat_tail_
|
||||||
|
var RT=mach/i86/lib/head_
|
||||||
|
var ART=mach/i86/lib/sat_head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{ART}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c.p:{TAIL}={EM}/{ALIB}mon) (.c.p.e:{TAIL}={EM}/{LIB}alo) \
|
||||||
|
(.e:{TAIL}={EM}/{LIB}em)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
27
lib/em22/descr
Normal file
27
lib/em22/descr
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var M=int
|
||||||
|
var NAME=int22
|
||||||
|
var LIB=mach/int/lib/tail_
|
||||||
|
var RT=mach/int/lib/head_
|
||||||
|
var SIZE_FLAG=-sm
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name asld
|
||||||
|
from .k.m.a
|
||||||
|
to e.out
|
||||||
|
program {EM}/lib/em_ass
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
mapflag -+* ASS_F={ASS_F?} -+*
|
||||||
|
mapflag --* ASS_F={ASS_F?} --*
|
||||||
|
mapflag -s* SIZE_FLAG=-s*
|
||||||
|
args {SIZE_FLAG} \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) \
|
||||||
|
(.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c.p:{TAIL}={EM}/{LIB}mon)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
27
lib/i80/descr
Normal file
27
lib/i80/descr
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=i8080
|
||||||
|
var M=8080
|
||||||
|
var LIB=mach/8080/lib/tail_
|
||||||
|
var RT=mach/8080/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_be
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args ({RTS}:.c={EM}/{RT}cc) -o > <
|
||||||
|
prop C
|
||||||
|
end
|
||||||
32
lib/i86/descr
Normal file
32
lib/i86/descr
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=i8086
|
||||||
|
var M=i86
|
||||||
|
var LIB=mach/i86/lib/tail_
|
||||||
|
var RT=mach/i86/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
mapflag -i IFILE={EM}/{RT}i
|
||||||
|
args {IFILE?} (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c.p.e:{TAIL}={EM}/{LIB}alo) (.c.p:{TAIL}={EM}/{LIB}mon) \
|
||||||
|
(.e:{TAIL}={EM}/{LIB}em)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
30
lib/m68k2/descr
Normal file
30
lib/m68k2/descr
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
var w=2
|
||||||
|
var p=4
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=m68k2
|
||||||
|
var M=m68k2
|
||||||
|
var LIB=mach/m68k2/lib/tail_
|
||||||
|
var RT=mach/m68k2/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.e:{TAIL}={EM}/{LIB}em.rt {EM}/{LIB}mon {EM}/{LIB}em.vend)
|
||||||
|
prop Cm
|
||||||
|
end
|
||||||
34
lib/m68k4/descr
Normal file
34
lib/m68k4/descr
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
var w=4
|
||||||
|
var p=4
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=m68k4
|
||||||
|
var M=m68k4
|
||||||
|
var LIBDIR=mach/m68k4/lib
|
||||||
|
var LIB=mach/m68k4/lib/tail_
|
||||||
|
var RT=mach/m68k4/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p.c:{TAIL}={EM}/{LIBDIR}/sys1.s) (.p:{TAIL}={EM}/{LIBDIR}/sys2.s) \
|
||||||
|
(.c:{TAIL}={EM}/{LIBDIR}/write.s) \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c:{TAIL}={EM}/{LIB}mon {EM}/{LIB}fake) \
|
||||||
|
(.e:{TAIL}={EM}/{LIB}em.rt {EM}/{LIB}em.vend)
|
||||||
|
prop Cm
|
||||||
|
end
|
||||||
38
lib/pdp/descr
Normal file
38
lib/pdp/descr
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var M=pdp
|
||||||
|
var NAME=pdp
|
||||||
|
var LIB=mach/pdp/lib/tail_
|
||||||
|
var RT=mach/pdp/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name as
|
||||||
|
from .s
|
||||||
|
to .o
|
||||||
|
program /bin/as
|
||||||
|
args - -o > <
|
||||||
|
prop m
|
||||||
|
end
|
||||||
|
name ld
|
||||||
|
from .o.a
|
||||||
|
to a.out
|
||||||
|
program /bin/ld
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) \
|
||||||
|
(.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.e:{TAIL}={EM}/{LIB}em) (.c.p:{TAIL}=/lib/libc.a)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
32
lib/pmds/descr
Normal file
32
lib/pmds/descr
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
var w=2
|
||||||
|
var p=4
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=m68k2
|
||||||
|
var M=m68k2
|
||||||
|
var LIB=mach/m68k2/lib/tail_
|
||||||
|
var RT=mach/m68k2/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .o
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .o.s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
mapflag -i
|
||||||
|
mapflag -n
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em.pmds) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.e:{TAIL}={EM}/{LIB}em.rt {EM}/{LIB}mon.pmds {EM}/{LIB}em.vend)
|
||||||
|
prop Cm
|
||||||
|
end
|
||||||
44
lib/vax4/descr.src
Normal file
44
lib/vax4/descr.src
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
var w=4
|
||||||
|
var p=4
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var M=vax4
|
||||||
|
var NAME=vax4
|
||||||
|
var LIB=mach/vax4/lib/tail_
|
||||||
|
var RT=mach/vax4/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asopt
|
||||||
|
from .s
|
||||||
|
to .so
|
||||||
|
program /bin/sed
|
||||||
|
args -f {EM}/mach/vax4/cg/sedf
|
||||||
|
prop O<>
|
||||||
|
end
|
||||||
|
name as
|
||||||
|
from .s.so
|
||||||
|
to .o
|
||||||
|
program /bin/as
|
||||||
|
args - -o > <
|
||||||
|
prop m
|
||||||
|
end
|
||||||
|
name ld
|
||||||
|
from .o.a
|
||||||
|
to a.out
|
||||||
|
program /bin/ld
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
args (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.c.p:{TAIL}={EM}/{LIB}mon) (.e:{TAIL}={EM}/{LIB}em)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
31
lib/z80/descr
Normal file
31
lib/z80/descr
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=z80
|
||||||
|
var M=z80
|
||||||
|
var LIB=mach/z80/lib/tail_
|
||||||
|
var RT=mach/z80/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
mapflag -i IFILE={EM}/{RT}i
|
||||||
|
args {IFILE?} (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.p.c:{TAIL}={EM}/{LIB}mon) (.e:{TAIL}={EM}/{LIB}em)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
31
lib/z8000/descr
Normal file
31
lib/z8000/descr
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
var w=2
|
||||||
|
var p=2
|
||||||
|
var s=2
|
||||||
|
var l=4
|
||||||
|
var f=4
|
||||||
|
var d=8
|
||||||
|
var NAME=z8000
|
||||||
|
var M=z8000
|
||||||
|
var LIB=mach/z8000/lib/tail_
|
||||||
|
var RT=mach/z8000/lib/head_
|
||||||
|
var INCLUDES=-I{EM}/include -I/usr/include
|
||||||
|
name be
|
||||||
|
from .m
|
||||||
|
to .s
|
||||||
|
program {EM}/lib/{M}_cg
|
||||||
|
args <
|
||||||
|
prop >
|
||||||
|
need .e
|
||||||
|
end
|
||||||
|
name asld
|
||||||
|
from .s.a
|
||||||
|
to a.out
|
||||||
|
program {EM}/lib/{M}_as
|
||||||
|
mapflag -l* LNAME={EM}/{LIB}*
|
||||||
|
mapflag -i IFILE={EM}/{RT}i
|
||||||
|
args {IFILE?} (.e:{HEAD}={EM}/{RT}em) \
|
||||||
|
({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \
|
||||||
|
(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \
|
||||||
|
(.p.c:{TAIL}={EM}/{LIB}mon) (.e:{TAIL}={EM}/{LIB}em)
|
||||||
|
prop C
|
||||||
|
end
|
||||||
178
mach/6500/cg/Makefile
Normal file
178
mach/6500/cg/Makefile
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
# $Header$
|
||||||
|
|
||||||
|
PREFLAGS=-I../../../h -I. -DNDEBUG
|
||||||
|
PFLAGS=
|
||||||
|
CFLAGS=$(PREFLAGS) $(PFLAGS) -O
|
||||||
|
LDFLAGS=-i $(PFLAGS)
|
||||||
|
LINTOPTS=-hbxac
|
||||||
|
LIBS=../../../lib/em_data.a
|
||||||
|
CDIR=../../proto/cg
|
||||||
|
CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \
|
||||||
|
$(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \
|
||||||
|
$(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \
|
||||||
|
$(CDIR)/state.c $(CDIR)/subr.c $(CDIR)/var.c
|
||||||
|
OFILES=codegen.o compute.o equiv.o fillem.o gencode.o glosym.o main.o\
|
||||||
|
move.o nextem.o reg.o regvar.o salloc.o state.o subr.o var.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
make tables.c
|
||||||
|
make cg
|
||||||
|
|
||||||
|
cg: tables.o $(OFILES)
|
||||||
|
cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg
|
||||||
|
|
||||||
|
tables.o: tables.c
|
||||||
|
cc -c $(PREFLAGS) -I$(CDIR) tables.c
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/codegen.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/codegen.c
|
||||||
|
compute.o: $(CDIR)/compute.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/compute.c
|
||||||
|
equiv.o: $(CDIR)/equiv.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/equiv.c
|
||||||
|
fillem.o: $(CDIR)/fillem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/fillem.c
|
||||||
|
gencode.o: $(CDIR)/gencode.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/gencode.c
|
||||||
|
glosym.o: $(CDIR)/glosym.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/glosym.c
|
||||||
|
main.o: $(CDIR)/main.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/main.c
|
||||||
|
move.o: $(CDIR)/move.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/move.c
|
||||||
|
nextem.o: $(CDIR)/nextem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/nextem.c
|
||||||
|
reg.o: $(CDIR)/reg.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/reg.c
|
||||||
|
regvar.o: $(CDIR)/regvar.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/regvar.c
|
||||||
|
salloc.o: $(CDIR)/salloc.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/salloc.c
|
||||||
|
state.o: $(CDIR)/state.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/state.c
|
||||||
|
subr.o: $(CDIR)/subr.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/subr.c
|
||||||
|
var.o: $(CDIR)/var.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/var.c
|
||||||
|
|
||||||
|
install: all
|
||||||
|
../install cg
|
||||||
|
|
||||||
|
cmp: all
|
||||||
|
-../compare cg
|
||||||
|
|
||||||
|
|
||||||
|
tables.c: table
|
||||||
|
-mv tables.h tables.h.save
|
||||||
|
../../../lib/cpp -P table | ../../../lib/cgg > debug.out
|
||||||
|
-if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
-if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
|
||||||
|
lint: $(CFILES)
|
||||||
|
lint $(LINTOPTS) $(PREFLAGS) $(CFILES)
|
||||||
|
clean:
|
||||||
|
rm -f *.o tables.c tables.h debug.out cg tables.h.save
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/assert.h
|
||||||
|
codegen.o: $(CDIR)/data.h
|
||||||
|
codegen.o: $(CDIR)/equiv.h
|
||||||
|
codegen.o: $(CDIR)/extern.h
|
||||||
|
codegen.o: $(CDIR)/param.h
|
||||||
|
codegen.o: $(CDIR)/result.h
|
||||||
|
codegen.o: $(CDIR)/state.h
|
||||||
|
codegen.o: tables.h
|
||||||
|
codegen.o: $(CDIR)/types.h
|
||||||
|
compute.o: $(CDIR)/assert.h
|
||||||
|
compute.o: $(CDIR)/data.h
|
||||||
|
compute.o: $(CDIR)/extern.h
|
||||||
|
compute.o: $(CDIR)/glosym.h
|
||||||
|
compute.o: $(CDIR)/param.h
|
||||||
|
compute.o: $(CDIR)/result.h
|
||||||
|
compute.o: tables.h
|
||||||
|
compute.o: $(CDIR)/types.h
|
||||||
|
equiv.o: $(CDIR)/assert.h
|
||||||
|
equiv.o: $(CDIR)/data.h
|
||||||
|
equiv.o: $(CDIR)/equiv.h
|
||||||
|
equiv.o: $(CDIR)/extern.h
|
||||||
|
equiv.o: $(CDIR)/param.h
|
||||||
|
equiv.o: $(CDIR)/result.h
|
||||||
|
equiv.o: tables.h
|
||||||
|
equiv.o: $(CDIR)/types.h
|
||||||
|
fillem.o: $(CDIR)/assert.h
|
||||||
|
fillem.o: $(CDIR)/data.h
|
||||||
|
fillem.o: $(CDIR)/extern.h
|
||||||
|
fillem.o: mach.c
|
||||||
|
fillem.o: mach.h
|
||||||
|
fillem.o: $(CDIR)/param.h
|
||||||
|
fillem.o: $(CDIR)/regvar.h
|
||||||
|
fillem.o: $(CDIR)/result.h
|
||||||
|
fillem.o: tables.h
|
||||||
|
fillem.o: $(CDIR)/types.h
|
||||||
|
gencode.o: $(CDIR)/assert.h
|
||||||
|
gencode.o: $(CDIR)/data.h
|
||||||
|
gencode.o: $(CDIR)/extern.h
|
||||||
|
gencode.o: $(CDIR)/param.h
|
||||||
|
gencode.o: $(CDIR)/result.h
|
||||||
|
gencode.o: tables.h
|
||||||
|
gencode.o: $(CDIR)/types.h
|
||||||
|
glosym.o: $(CDIR)/glosym.h
|
||||||
|
glosym.o: $(CDIR)/param.h
|
||||||
|
glosym.o: tables.h
|
||||||
|
glosym.o: $(CDIR)/types.h
|
||||||
|
main.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/assert.h
|
||||||
|
move.o: $(CDIR)/data.h
|
||||||
|
move.o: $(CDIR)/extern.h
|
||||||
|
move.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/result.h
|
||||||
|
move.o: tables.h
|
||||||
|
move.o: $(CDIR)/types.h
|
||||||
|
nextem.o: $(CDIR)/assert.h
|
||||||
|
nextem.o: $(CDIR)/data.h
|
||||||
|
nextem.o: $(CDIR)/extern.h
|
||||||
|
nextem.o: $(CDIR)/param.h
|
||||||
|
nextem.o: $(CDIR)/result.h
|
||||||
|
nextem.o: tables.h
|
||||||
|
nextem.o: $(CDIR)/types.h
|
||||||
|
reg.o: $(CDIR)/assert.h
|
||||||
|
reg.o: $(CDIR)/data.h
|
||||||
|
reg.o: $(CDIR)/extern.h
|
||||||
|
reg.o: $(CDIR)/param.h
|
||||||
|
reg.o: $(CDIR)/result.h
|
||||||
|
reg.o: tables.h
|
||||||
|
reg.o: $(CDIR)/types.h
|
||||||
|
regvar.o: $(CDIR)/assert.h
|
||||||
|
regvar.o: $(CDIR)/data.h
|
||||||
|
regvar.o: $(CDIR)/extern.h
|
||||||
|
regvar.o: $(CDIR)/param.h
|
||||||
|
regvar.o: $(CDIR)/regvar.h
|
||||||
|
regvar.o: $(CDIR)/result.h
|
||||||
|
regvar.o: tables.h
|
||||||
|
regvar.o: $(CDIR)/types.h
|
||||||
|
salloc.o: $(CDIR)/assert.h
|
||||||
|
salloc.o: $(CDIR)/data.h
|
||||||
|
salloc.o: $(CDIR)/extern.h
|
||||||
|
salloc.o: $(CDIR)/param.h
|
||||||
|
salloc.o: $(CDIR)/result.h
|
||||||
|
salloc.o: tables.h
|
||||||
|
salloc.o: $(CDIR)/types.h
|
||||||
|
state.o: $(CDIR)/assert.h
|
||||||
|
state.o: $(CDIR)/data.h
|
||||||
|
state.o: $(CDIR)/extern.h
|
||||||
|
state.o: $(CDIR)/param.h
|
||||||
|
state.o: $(CDIR)/result.h
|
||||||
|
state.o: $(CDIR)/state.h
|
||||||
|
state.o: tables.h
|
||||||
|
state.o: $(CDIR)/types.h
|
||||||
|
subr.o: $(CDIR)/assert.h
|
||||||
|
subr.o: $(CDIR)/data.h
|
||||||
|
subr.o: $(CDIR)/extern.h
|
||||||
|
subr.o: $(CDIR)/param.h
|
||||||
|
subr.o: $(CDIR)/result.h
|
||||||
|
subr.o: tables.h
|
||||||
|
subr.o: $(CDIR)/types.h
|
||||||
|
var.o: $(CDIR)/data.h
|
||||||
|
var.o: $(CDIR)/param.h
|
||||||
|
var.o: $(CDIR)/result.h
|
||||||
|
var.o: tables.h
|
||||||
|
var.o: $(CDIR)/types.h
|
||||||
178
mach/pdp/cg/Makefile
Normal file
178
mach/pdp/cg/Makefile
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
# $Header$
|
||||||
|
|
||||||
|
PREFLAGS=-I../../../h -I. -DNDEBUG
|
||||||
|
PFLAGS=
|
||||||
|
CFLAGS=$(PREFLAGS) $(PFLAGS) -O
|
||||||
|
LDFLAGS=-i $(PFLAGS)
|
||||||
|
LINTOPTS=-hbxac
|
||||||
|
LIBS=../../../lib/em_data.a
|
||||||
|
CDIR=../../proto/cg
|
||||||
|
CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \
|
||||||
|
$(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \
|
||||||
|
$(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \
|
||||||
|
$(CDIR)/state.c $(CDIR)/subr.c $(CDIR)/var.c
|
||||||
|
OFILES=codegen.o compute.o equiv.o fillem.o gencode.o glosym.o main.o\
|
||||||
|
move.o nextem.o reg.o regvar.o salloc.o state.o subr.o var.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
make tables.c
|
||||||
|
make cg
|
||||||
|
|
||||||
|
cg: tables.o $(OFILES)
|
||||||
|
cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg
|
||||||
|
|
||||||
|
tables.o: tables.c
|
||||||
|
cc -c $(PREFLAGS) -I$(CDIR) tables.c
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/codegen.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/codegen.c
|
||||||
|
compute.o: $(CDIR)/compute.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/compute.c
|
||||||
|
equiv.o: $(CDIR)/equiv.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/equiv.c
|
||||||
|
fillem.o: $(CDIR)/fillem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/fillem.c
|
||||||
|
gencode.o: $(CDIR)/gencode.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/gencode.c
|
||||||
|
glosym.o: $(CDIR)/glosym.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/glosym.c
|
||||||
|
main.o: $(CDIR)/main.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/main.c
|
||||||
|
move.o: $(CDIR)/move.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/move.c
|
||||||
|
nextem.o: $(CDIR)/nextem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/nextem.c
|
||||||
|
reg.o: $(CDIR)/reg.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/reg.c
|
||||||
|
regvar.o: $(CDIR)/regvar.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/regvar.c
|
||||||
|
salloc.o: $(CDIR)/salloc.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/salloc.c
|
||||||
|
state.o: $(CDIR)/state.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/state.c
|
||||||
|
subr.o: $(CDIR)/subr.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/subr.c
|
||||||
|
var.o: $(CDIR)/var.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/var.c
|
||||||
|
|
||||||
|
install: all
|
||||||
|
../install cg
|
||||||
|
|
||||||
|
cmp: all
|
||||||
|
-../compare cg
|
||||||
|
|
||||||
|
|
||||||
|
tables.c: table
|
||||||
|
-mv tables.h tables.h.save
|
||||||
|
../../../lib/cpp -P table | ../../../lib/cgg > debug.out
|
||||||
|
-if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
-if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
|
||||||
|
lint: $(CFILES)
|
||||||
|
lint $(LINTOPTS) $(PREFLAGS) $(CFILES)
|
||||||
|
clean:
|
||||||
|
rm -f *.o tables.c tables.h debug.out cg tables.h.save
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/assert.h
|
||||||
|
codegen.o: $(CDIR)/data.h
|
||||||
|
codegen.o: $(CDIR)/equiv.h
|
||||||
|
codegen.o: $(CDIR)/extern.h
|
||||||
|
codegen.o: $(CDIR)/param.h
|
||||||
|
codegen.o: $(CDIR)/result.h
|
||||||
|
codegen.o: $(CDIR)/state.h
|
||||||
|
codegen.o: tables.h
|
||||||
|
codegen.o: $(CDIR)/types.h
|
||||||
|
compute.o: $(CDIR)/assert.h
|
||||||
|
compute.o: $(CDIR)/data.h
|
||||||
|
compute.o: $(CDIR)/extern.h
|
||||||
|
compute.o: $(CDIR)/glosym.h
|
||||||
|
compute.o: $(CDIR)/param.h
|
||||||
|
compute.o: $(CDIR)/result.h
|
||||||
|
compute.o: tables.h
|
||||||
|
compute.o: $(CDIR)/types.h
|
||||||
|
equiv.o: $(CDIR)/assert.h
|
||||||
|
equiv.o: $(CDIR)/data.h
|
||||||
|
equiv.o: $(CDIR)/equiv.h
|
||||||
|
equiv.o: $(CDIR)/extern.h
|
||||||
|
equiv.o: $(CDIR)/param.h
|
||||||
|
equiv.o: $(CDIR)/result.h
|
||||||
|
equiv.o: tables.h
|
||||||
|
equiv.o: $(CDIR)/types.h
|
||||||
|
fillem.o: $(CDIR)/assert.h
|
||||||
|
fillem.o: $(CDIR)/data.h
|
||||||
|
fillem.o: $(CDIR)/extern.h
|
||||||
|
fillem.o: mach.c
|
||||||
|
fillem.o: mach.h
|
||||||
|
fillem.o: $(CDIR)/param.h
|
||||||
|
fillem.o: $(CDIR)/regvar.h
|
||||||
|
fillem.o: $(CDIR)/result.h
|
||||||
|
fillem.o: tables.h
|
||||||
|
fillem.o: $(CDIR)/types.h
|
||||||
|
gencode.o: $(CDIR)/assert.h
|
||||||
|
gencode.o: $(CDIR)/data.h
|
||||||
|
gencode.o: $(CDIR)/extern.h
|
||||||
|
gencode.o: $(CDIR)/param.h
|
||||||
|
gencode.o: $(CDIR)/result.h
|
||||||
|
gencode.o: tables.h
|
||||||
|
gencode.o: $(CDIR)/types.h
|
||||||
|
glosym.o: $(CDIR)/glosym.h
|
||||||
|
glosym.o: $(CDIR)/param.h
|
||||||
|
glosym.o: tables.h
|
||||||
|
glosym.o: $(CDIR)/types.h
|
||||||
|
main.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/assert.h
|
||||||
|
move.o: $(CDIR)/data.h
|
||||||
|
move.o: $(CDIR)/extern.h
|
||||||
|
move.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/result.h
|
||||||
|
move.o: tables.h
|
||||||
|
move.o: $(CDIR)/types.h
|
||||||
|
nextem.o: $(CDIR)/assert.h
|
||||||
|
nextem.o: $(CDIR)/data.h
|
||||||
|
nextem.o: $(CDIR)/extern.h
|
||||||
|
nextem.o: $(CDIR)/param.h
|
||||||
|
nextem.o: $(CDIR)/result.h
|
||||||
|
nextem.o: tables.h
|
||||||
|
nextem.o: $(CDIR)/types.h
|
||||||
|
reg.o: $(CDIR)/assert.h
|
||||||
|
reg.o: $(CDIR)/data.h
|
||||||
|
reg.o: $(CDIR)/extern.h
|
||||||
|
reg.o: $(CDIR)/param.h
|
||||||
|
reg.o: $(CDIR)/result.h
|
||||||
|
reg.o: tables.h
|
||||||
|
reg.o: $(CDIR)/types.h
|
||||||
|
regvar.o: $(CDIR)/assert.h
|
||||||
|
regvar.o: $(CDIR)/data.h
|
||||||
|
regvar.o: $(CDIR)/extern.h
|
||||||
|
regvar.o: $(CDIR)/param.h
|
||||||
|
regvar.o: $(CDIR)/regvar.h
|
||||||
|
regvar.o: $(CDIR)/result.h
|
||||||
|
regvar.o: tables.h
|
||||||
|
regvar.o: $(CDIR)/types.h
|
||||||
|
salloc.o: $(CDIR)/assert.h
|
||||||
|
salloc.o: $(CDIR)/data.h
|
||||||
|
salloc.o: $(CDIR)/extern.h
|
||||||
|
salloc.o: $(CDIR)/param.h
|
||||||
|
salloc.o: $(CDIR)/result.h
|
||||||
|
salloc.o: tables.h
|
||||||
|
salloc.o: $(CDIR)/types.h
|
||||||
|
state.o: $(CDIR)/assert.h
|
||||||
|
state.o: $(CDIR)/data.h
|
||||||
|
state.o: $(CDIR)/extern.h
|
||||||
|
state.o: $(CDIR)/param.h
|
||||||
|
state.o: $(CDIR)/result.h
|
||||||
|
state.o: $(CDIR)/state.h
|
||||||
|
state.o: tables.h
|
||||||
|
state.o: $(CDIR)/types.h
|
||||||
|
subr.o: $(CDIR)/assert.h
|
||||||
|
subr.o: $(CDIR)/data.h
|
||||||
|
subr.o: $(CDIR)/extern.h
|
||||||
|
subr.o: $(CDIR)/param.h
|
||||||
|
subr.o: $(CDIR)/result.h
|
||||||
|
subr.o: tables.h
|
||||||
|
subr.o: $(CDIR)/types.h
|
||||||
|
var.o: $(CDIR)/data.h
|
||||||
|
var.o: $(CDIR)/param.h
|
||||||
|
var.o: $(CDIR)/result.h
|
||||||
|
var.o: tables.h
|
||||||
|
var.o: $(CDIR)/types.h
|
||||||
171
mach/pdp/cg/mach.c
Normal file
171
mach/pdp/cg/mach.c
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* machine dependent back end routines for the PDP-11
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define REGPATCH
|
||||||
|
|
||||||
|
con_part(sz,w) register sz; word w; {
|
||||||
|
|
||||||
|
while (part_size % sz)
|
||||||
|
part_size++;
|
||||||
|
if (part_size == EM_WSIZE)
|
||||||
|
part_flush();
|
||||||
|
if (sz == 1) {
|
||||||
|
w &= 0xFF;
|
||||||
|
if (part_size)
|
||||||
|
w <<= 8;
|
||||||
|
part_word |= w;
|
||||||
|
} else {
|
||||||
|
assert(sz == 2);
|
||||||
|
part_word = w;
|
||||||
|
}
|
||||||
|
part_size += sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
con_mult(sz) word sz; {
|
||||||
|
long l;
|
||||||
|
|
||||||
|
if (sz != 4)
|
||||||
|
fatal("bad icon/ucon size");
|
||||||
|
l = atol(str);
|
||||||
|
fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
|
||||||
|
}
|
||||||
|
|
||||||
|
con_float() {
|
||||||
|
double f;
|
||||||
|
register short *p,i;
|
||||||
|
|
||||||
|
if (argval != 4 && argval != 8)
|
||||||
|
fatal("bad fcon size");
|
||||||
|
f = atof(str);
|
||||||
|
p = (short *) &f;
|
||||||
|
i = *p++;
|
||||||
|
if (argval == 8) {
|
||||||
|
fprintf(codefile,"\t%o;%o;",i,*p++);
|
||||||
|
i = *p++;
|
||||||
|
}
|
||||||
|
fprintf(codefile,"\t%o;%o\n",i,*p++);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef REGVARS
|
||||||
|
|
||||||
|
char Rstring[10] = "RT";
|
||||||
|
|
||||||
|
regscore(off,size,typ,score,totyp) long off; {
|
||||||
|
|
||||||
|
if (size != 2)
|
||||||
|
return(-1);
|
||||||
|
score -= 1; /* allow for save/restore */
|
||||||
|
if (off>=0)
|
||||||
|
score -= 2;
|
||||||
|
if (typ==reg_pointer)
|
||||||
|
score *= 17;
|
||||||
|
else if (typ==reg_loop)
|
||||||
|
score = 10*score+50; /* Guestimate */
|
||||||
|
else
|
||||||
|
score *= 10;
|
||||||
|
return(score); /* estimated # of words of profit */
|
||||||
|
}
|
||||||
|
|
||||||
|
i_regsave() {
|
||||||
|
|
||||||
|
Rstring[2] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_regsave() {}
|
||||||
|
|
||||||
|
regsave(regstr,off,size) char *regstr; long off; {
|
||||||
|
|
||||||
|
fprintf(codefile,"/ Local %ld into %s\n",off,regstr);
|
||||||
|
#ifndef REGPATCH
|
||||||
|
fprintf(codefile,"mov %s,-(sp)\n",regstr);
|
||||||
|
#endif
|
||||||
|
strcat(Rstring,regstr);
|
||||||
|
if (off>=0)
|
||||||
|
fprintf(codefile,"mov 0%lo(r5),%s\n",off,regstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
regreturn() {
|
||||||
|
|
||||||
|
#ifdef REGPATCH
|
||||||
|
fprintf(codefile,"jmp eret\n");
|
||||||
|
#else
|
||||||
|
fprintf(codefile,"jmp %s\n",Rstring);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
prolog(nlocals) full nlocals; {
|
||||||
|
|
||||||
|
#ifdef REGPATCH
|
||||||
|
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
|
||||||
|
#endif
|
||||||
|
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
||||||
|
if (nlocals == 0)
|
||||||
|
return;
|
||||||
|
if (nlocals == 2)
|
||||||
|
fprintf(codefile,"tst -(sp)\n");
|
||||||
|
else
|
||||||
|
fprintf(codefile,"sub $0%o,sp\n",nlocals);
|
||||||
|
}
|
||||||
|
|
||||||
|
dlbdlb(as,ls) string as,ls; {
|
||||||
|
|
||||||
|
if (strlen(as)+strlen(ls)+2<sizeof(labstr)) {
|
||||||
|
strcat(ls,":");
|
||||||
|
strcat(ls,as);
|
||||||
|
} else
|
||||||
|
fatal("too many consecutive labels");
|
||||||
|
}
|
||||||
|
|
||||||
|
mes(type) word type; {
|
||||||
|
int argt ;
|
||||||
|
|
||||||
|
switch ( (int)type ) {
|
||||||
|
case ms_ext :
|
||||||
|
for (;;) {
|
||||||
|
switch ( argt=getarg(
|
||||||
|
ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
|
||||||
|
case sp_cend :
|
||||||
|
return ;
|
||||||
|
default:
|
||||||
|
strarg(argt) ;
|
||||||
|
fprintf(codefile,".globl %s\n",argstr) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default :
|
||||||
|
while ( getarg(any_ptyp) != sp_cend ) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *segname[] = {
|
||||||
|
".text", /* SEGTXT */
|
||||||
|
".data", /* SEGCON */
|
||||||
|
".data", /* SEGROM */
|
||||||
|
".bss" /* SEGBSS */
|
||||||
|
};
|
||||||
23
mach/pdp/cg/mach.h
Normal file
23
mach/pdp/cg/mach.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#define ex_ap(y) fprintf(codefile,"\t.globl %s\n",y)
|
||||||
|
#define in_ap(y) /* nothing */
|
||||||
|
|
||||||
|
#define newilb(x) fprintf(codefile,"%s:\n",x)
|
||||||
|
#define newdlb(x) fprintf(codefile,"%s:\n",x)
|
||||||
|
#define newlbss(l,x) fprintf(codefile,"%s:.=.+0%o\n",l,x);
|
||||||
|
|
||||||
|
#define cst_fmt "$0%o"
|
||||||
|
#define off_fmt "0%o"
|
||||||
|
#define ilb_fmt "I%02x%x"
|
||||||
|
#define dlb_fmt "_%d"
|
||||||
|
#define hol_fmt "hol%d"
|
||||||
|
|
||||||
|
#define hol_off "0%o+hol%d"
|
||||||
|
|
||||||
|
#define con_cst(x) fprintf(codefile,"0%o\n",x)
|
||||||
|
#define con_ilb(x) fprintf(codefile,"%s\n",x)
|
||||||
|
#define con_dlb(x) fprintf(codefile,"%s\n",x)
|
||||||
|
|
||||||
|
#define id_first '_'
|
||||||
|
#define BSS_INIT 0
|
||||||
2450
mach/pdp/cg/table
Normal file
2450
mach/pdp/cg/table
Normal file
File diff suppressed because it is too large
Load Diff
178
mach/proto/cg/Makefile
Normal file
178
mach/proto/cg/Makefile
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
# $Header$
|
||||||
|
|
||||||
|
PREFLAGS=-I../../../h -I. -DNDEBUG
|
||||||
|
PFLAGS=
|
||||||
|
CFLAGS=$(PREFLAGS) $(PFLAGS) -O
|
||||||
|
LDFLAGS=-i $(PFLAGS)
|
||||||
|
LINTOPTS=-hbxac
|
||||||
|
LIBS=../../../lib/em_data.a
|
||||||
|
CDIR=../../proto/cg
|
||||||
|
CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \
|
||||||
|
$(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \
|
||||||
|
$(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \
|
||||||
|
$(CDIR)/state.c $(CDIR)/subr.c $(CDIR)/var.c
|
||||||
|
OFILES=codegen.o compute.o equiv.o fillem.o gencode.o glosym.o main.o\
|
||||||
|
move.o nextem.o reg.o regvar.o salloc.o state.o subr.o var.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
make tables.c
|
||||||
|
make cg
|
||||||
|
|
||||||
|
cg: tables.o $(OFILES)
|
||||||
|
cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg
|
||||||
|
|
||||||
|
tables.o: tables.c
|
||||||
|
cc -c $(PREFLAGS) -I$(CDIR) tables.c
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/codegen.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/codegen.c
|
||||||
|
compute.o: $(CDIR)/compute.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/compute.c
|
||||||
|
equiv.o: $(CDIR)/equiv.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/equiv.c
|
||||||
|
fillem.o: $(CDIR)/fillem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/fillem.c
|
||||||
|
gencode.o: $(CDIR)/gencode.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/gencode.c
|
||||||
|
glosym.o: $(CDIR)/glosym.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/glosym.c
|
||||||
|
main.o: $(CDIR)/main.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/main.c
|
||||||
|
move.o: $(CDIR)/move.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/move.c
|
||||||
|
nextem.o: $(CDIR)/nextem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/nextem.c
|
||||||
|
reg.o: $(CDIR)/reg.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/reg.c
|
||||||
|
regvar.o: $(CDIR)/regvar.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/regvar.c
|
||||||
|
salloc.o: $(CDIR)/salloc.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/salloc.c
|
||||||
|
state.o: $(CDIR)/state.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/state.c
|
||||||
|
subr.o: $(CDIR)/subr.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/subr.c
|
||||||
|
var.o: $(CDIR)/var.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/var.c
|
||||||
|
|
||||||
|
install: all
|
||||||
|
../install cg
|
||||||
|
|
||||||
|
cmp: all
|
||||||
|
-../compare cg
|
||||||
|
|
||||||
|
|
||||||
|
tables.c: table
|
||||||
|
-mv tables.h tables.h.save
|
||||||
|
../../../lib/cpp -P table | ../../../lib/cgg > debug.out
|
||||||
|
-if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
-if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
|
||||||
|
lint: $(CFILES)
|
||||||
|
lint $(LINTOPTS) $(PREFLAGS) $(CFILES)
|
||||||
|
clean:
|
||||||
|
rm -f *.o tables.c tables.h debug.out cg tables.h.save
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/assert.h
|
||||||
|
codegen.o: $(CDIR)/data.h
|
||||||
|
codegen.o: $(CDIR)/equiv.h
|
||||||
|
codegen.o: $(CDIR)/extern.h
|
||||||
|
codegen.o: $(CDIR)/param.h
|
||||||
|
codegen.o: $(CDIR)/result.h
|
||||||
|
codegen.o: $(CDIR)/state.h
|
||||||
|
codegen.o: tables.h
|
||||||
|
codegen.o: $(CDIR)/types.h
|
||||||
|
compute.o: $(CDIR)/assert.h
|
||||||
|
compute.o: $(CDIR)/data.h
|
||||||
|
compute.o: $(CDIR)/extern.h
|
||||||
|
compute.o: $(CDIR)/glosym.h
|
||||||
|
compute.o: $(CDIR)/param.h
|
||||||
|
compute.o: $(CDIR)/result.h
|
||||||
|
compute.o: tables.h
|
||||||
|
compute.o: $(CDIR)/types.h
|
||||||
|
equiv.o: $(CDIR)/assert.h
|
||||||
|
equiv.o: $(CDIR)/data.h
|
||||||
|
equiv.o: $(CDIR)/equiv.h
|
||||||
|
equiv.o: $(CDIR)/extern.h
|
||||||
|
equiv.o: $(CDIR)/param.h
|
||||||
|
equiv.o: $(CDIR)/result.h
|
||||||
|
equiv.o: tables.h
|
||||||
|
equiv.o: $(CDIR)/types.h
|
||||||
|
fillem.o: $(CDIR)/assert.h
|
||||||
|
fillem.o: $(CDIR)/data.h
|
||||||
|
fillem.o: $(CDIR)/extern.h
|
||||||
|
fillem.o: mach.c
|
||||||
|
fillem.o: mach.h
|
||||||
|
fillem.o: $(CDIR)/param.h
|
||||||
|
fillem.o: $(CDIR)/regvar.h
|
||||||
|
fillem.o: $(CDIR)/result.h
|
||||||
|
fillem.o: tables.h
|
||||||
|
fillem.o: $(CDIR)/types.h
|
||||||
|
gencode.o: $(CDIR)/assert.h
|
||||||
|
gencode.o: $(CDIR)/data.h
|
||||||
|
gencode.o: $(CDIR)/extern.h
|
||||||
|
gencode.o: $(CDIR)/param.h
|
||||||
|
gencode.o: $(CDIR)/result.h
|
||||||
|
gencode.o: tables.h
|
||||||
|
gencode.o: $(CDIR)/types.h
|
||||||
|
glosym.o: $(CDIR)/glosym.h
|
||||||
|
glosym.o: $(CDIR)/param.h
|
||||||
|
glosym.o: tables.h
|
||||||
|
glosym.o: $(CDIR)/types.h
|
||||||
|
main.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/assert.h
|
||||||
|
move.o: $(CDIR)/data.h
|
||||||
|
move.o: $(CDIR)/extern.h
|
||||||
|
move.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/result.h
|
||||||
|
move.o: tables.h
|
||||||
|
move.o: $(CDIR)/types.h
|
||||||
|
nextem.o: $(CDIR)/assert.h
|
||||||
|
nextem.o: $(CDIR)/data.h
|
||||||
|
nextem.o: $(CDIR)/extern.h
|
||||||
|
nextem.o: $(CDIR)/param.h
|
||||||
|
nextem.o: $(CDIR)/result.h
|
||||||
|
nextem.o: tables.h
|
||||||
|
nextem.o: $(CDIR)/types.h
|
||||||
|
reg.o: $(CDIR)/assert.h
|
||||||
|
reg.o: $(CDIR)/data.h
|
||||||
|
reg.o: $(CDIR)/extern.h
|
||||||
|
reg.o: $(CDIR)/param.h
|
||||||
|
reg.o: $(CDIR)/result.h
|
||||||
|
reg.o: tables.h
|
||||||
|
reg.o: $(CDIR)/types.h
|
||||||
|
regvar.o: $(CDIR)/assert.h
|
||||||
|
regvar.o: $(CDIR)/data.h
|
||||||
|
regvar.o: $(CDIR)/extern.h
|
||||||
|
regvar.o: $(CDIR)/param.h
|
||||||
|
regvar.o: $(CDIR)/regvar.h
|
||||||
|
regvar.o: $(CDIR)/result.h
|
||||||
|
regvar.o: tables.h
|
||||||
|
regvar.o: $(CDIR)/types.h
|
||||||
|
salloc.o: $(CDIR)/assert.h
|
||||||
|
salloc.o: $(CDIR)/data.h
|
||||||
|
salloc.o: $(CDIR)/extern.h
|
||||||
|
salloc.o: $(CDIR)/param.h
|
||||||
|
salloc.o: $(CDIR)/result.h
|
||||||
|
salloc.o: tables.h
|
||||||
|
salloc.o: $(CDIR)/types.h
|
||||||
|
state.o: $(CDIR)/assert.h
|
||||||
|
state.o: $(CDIR)/data.h
|
||||||
|
state.o: $(CDIR)/extern.h
|
||||||
|
state.o: $(CDIR)/param.h
|
||||||
|
state.o: $(CDIR)/result.h
|
||||||
|
state.o: $(CDIR)/state.h
|
||||||
|
state.o: tables.h
|
||||||
|
state.o: $(CDIR)/types.h
|
||||||
|
subr.o: $(CDIR)/assert.h
|
||||||
|
subr.o: $(CDIR)/data.h
|
||||||
|
subr.o: $(CDIR)/extern.h
|
||||||
|
subr.o: $(CDIR)/param.h
|
||||||
|
subr.o: $(CDIR)/result.h
|
||||||
|
subr.o: tables.h
|
||||||
|
subr.o: $(CDIR)/types.h
|
||||||
|
var.o: $(CDIR)/data.h
|
||||||
|
var.o: $(CDIR)/param.h
|
||||||
|
var.o: $(CDIR)/result.h
|
||||||
|
var.o: tables.h
|
||||||
|
var.o: $(CDIR)/types.h
|
||||||
7
mach/proto/cg/assert.h
Normal file
7
mach/proto/cg/assert.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define assert(x) if(!(x)) badassertion("x",__FILE__,__LINE__)
|
||||||
|
#else
|
||||||
|
#define assert(x) /* nothing */
|
||||||
|
#endif
|
||||||
672
mach/proto/cg/codegen.c
Normal file
672
mach/proto/cg/codegen.c
Normal file
@ -0,0 +1,672 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "state.h"
|
||||||
|
#include "equiv.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SHORTCUT /* Stop searching at distance 0 */
|
||||||
|
|
||||||
|
#if NREGS >= MAXRULE
|
||||||
|
#define MAXPOS NREGS
|
||||||
|
#else
|
||||||
|
#define MAXPOS MAXRULE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAXPATTERN 5
|
||||||
|
#define MAXREPLLEN 5 /* Max length of EM-replacement, should come from boot */
|
||||||
|
|
||||||
|
byte startupcode[] = { DO_NEXTEM };
|
||||||
|
|
||||||
|
byte *nextem();
|
||||||
|
unsigned costcalc();
|
||||||
|
unsigned docoerc();
|
||||||
|
unsigned stackupto();
|
||||||
|
string tostring();
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define DEBUG()
|
||||||
|
#else
|
||||||
|
#include <stdio.h>
|
||||||
|
#define DEBUG(string) {if(Debug) fprintf(stderr,"%-*d%s\n",4*level,level,string);}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BROKE() {assert(origcp!=startupcode);DEBUG("BROKE");goto doreturn;}
|
||||||
|
#define CHKCOST() {if (totalcost>=costlimit) BROKE();}
|
||||||
|
|
||||||
|
unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned costlimit; {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
byte *origcp=codep;
|
||||||
|
static int level=0;
|
||||||
|
#endif
|
||||||
|
unsigned totalcost = 0;
|
||||||
|
byte *bp;
|
||||||
|
int n;
|
||||||
|
unsigned mindistance,dist;
|
||||||
|
register i;
|
||||||
|
int cindex;
|
||||||
|
int npos,npos2,pos[MAXPOS],pos2[MAXPOS];
|
||||||
|
#ifdef STONSTACK
|
||||||
|
state_t state;
|
||||||
|
#define SAVEST savestatus(&state)
|
||||||
|
#define RESTST restorestatus(&state)
|
||||||
|
#define FREEST /* nothing */
|
||||||
|
#else
|
||||||
|
state_p state;
|
||||||
|
#define SAVEST state=savestatus()
|
||||||
|
#define RESTST restorestatus(state)
|
||||||
|
#define FREEST freestatus(state)
|
||||||
|
#endif
|
||||||
|
unsigned mincost,t;
|
||||||
|
int texpno,nodeno;
|
||||||
|
token_p tp;
|
||||||
|
tkdef_p tdp;
|
||||||
|
int tinstno;
|
||||||
|
struct reginfo *rp,**rpp;
|
||||||
|
token_t token,mtoken,token2;
|
||||||
|
int propno;
|
||||||
|
int exactmatch;
|
||||||
|
int j;
|
||||||
|
int decision;
|
||||||
|
int stringno;
|
||||||
|
result_t result;
|
||||||
|
cost_t cost;
|
||||||
|
int size,lsize,repllen;
|
||||||
|
int tokexp[MAXPATTERN];
|
||||||
|
int nregneeded;
|
||||||
|
token_p regtp[MAXCREG];
|
||||||
|
c3_p regcp[MAXCREG];
|
||||||
|
rl_p regls[MAXCREG];
|
||||||
|
c3_p cp,findcoerc();
|
||||||
|
int sret;
|
||||||
|
token_t reptoken[MAXREPLLEN];
|
||||||
|
int emrepllen,eminstr;
|
||||||
|
int inscoerc=0;
|
||||||
|
int stackpad;
|
||||||
|
struct perm *tup,*ntup,*besttup,*tuples();
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
level++;
|
||||||
|
DEBUG("Entering codegen");
|
||||||
|
#endif
|
||||||
|
for (;;) {
|
||||||
|
switch( (*codep++)&037 ) {
|
||||||
|
default:
|
||||||
|
assert(FALSE);
|
||||||
|
/* NOTREACHED */
|
||||||
|
case DO_NEXTEM:
|
||||||
|
DEBUG("NEXTEM");
|
||||||
|
tokpatlen = 0;
|
||||||
|
nallreg=0;
|
||||||
|
if (toplevel) {
|
||||||
|
garbage_collect();
|
||||||
|
totalcost=0;
|
||||||
|
} else {
|
||||||
|
if (--ply <= 0)
|
||||||
|
goto doreturn;
|
||||||
|
}
|
||||||
|
if (stackheight>MAXFSTACK-7)
|
||||||
|
totalcost += stackupto(&fakestack[6],ply,toplevel);
|
||||||
|
bp = nextem(toplevel);
|
||||||
|
if (bp == 0) {
|
||||||
|
/*
|
||||||
|
* No pattern found, can be pseudo or error
|
||||||
|
* in table.
|
||||||
|
*/
|
||||||
|
if (toplevel) {
|
||||||
|
codep--;
|
||||||
|
DEBUG("pseudo");
|
||||||
|
dopseudo();
|
||||||
|
} else
|
||||||
|
goto doreturn;
|
||||||
|
} else {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
chkregs();
|
||||||
|
#endif
|
||||||
|
n = *bp++;
|
||||||
|
assert(n>0 && n<=MAXRULE);
|
||||||
|
if (n>1) {
|
||||||
|
mindistance = MAXINT; npos=0;
|
||||||
|
for(i=0;i<n;i++) {
|
||||||
|
getint(cindex,bp);
|
||||||
|
dist=distance(cindex);
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (Debug)
|
||||||
|
fprintf(stderr,"distance of pos %d is %u\n",i,dist);
|
||||||
|
#endif
|
||||||
|
if (dist<=mindistance) {
|
||||||
|
if (dist<mindistance) {
|
||||||
|
#ifdef SHORTCUT
|
||||||
|
if(dist==0)
|
||||||
|
goto gotit;
|
||||||
|
#endif
|
||||||
|
npos=0;
|
||||||
|
mindistance = dist;
|
||||||
|
}
|
||||||
|
pos[npos++] = cindex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(mindistance<MAXINT);
|
||||||
|
if (npos>1) {
|
||||||
|
/*
|
||||||
|
* More than 1 tokenpattern is a candidate.
|
||||||
|
* Decision has to be made by lookahead.
|
||||||
|
*/
|
||||||
|
SAVEST;
|
||||||
|
mincost = costlimit-totalcost+1;
|
||||||
|
for(i=0;i<npos;i++) {
|
||||||
|
t=codegen(&coderules[pos[i]],ply,FALSE,mincost,0);
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (Debug)
|
||||||
|
fprintf(stderr,"mincost %u,cost %u,pos %d\n",mincost,t,i);
|
||||||
|
#endif
|
||||||
|
if (t<mincost) {
|
||||||
|
mincost = t;
|
||||||
|
cindex = pos[i];
|
||||||
|
}
|
||||||
|
RESTST;
|
||||||
|
}
|
||||||
|
FREEST;
|
||||||
|
if (totalcost+mincost>costlimit) {
|
||||||
|
totalcost += mincost;
|
||||||
|
BROKE();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cindex = pos[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getint(cindex,bp);
|
||||||
|
}
|
||||||
|
|
||||||
|
gotit:
|
||||||
|
/*
|
||||||
|
* Now cindex contains the code-index of the best candidate
|
||||||
|
* so proceed to use it.
|
||||||
|
*/
|
||||||
|
codep = &coderules[cindex];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DO_COERC:
|
||||||
|
DEBUG("COERC");
|
||||||
|
tokpatlen=1;
|
||||||
|
inscoerc=1;
|
||||||
|
break;
|
||||||
|
case DO_XXMATCH:
|
||||||
|
DEBUG("XXMATCH");
|
||||||
|
case DO_XMATCH:
|
||||||
|
DEBUG("XMATCH");
|
||||||
|
tokpatlen=(codep[-1]>>5)&07;
|
||||||
|
for (i=0;i<tokpatlen;i++)
|
||||||
|
getint(tokexp[i],codep);
|
||||||
|
tokexp[i]=0;
|
||||||
|
break; /* match already checked by distance() */
|
||||||
|
case DO_MATCH:
|
||||||
|
DEBUG("MATCH");
|
||||||
|
tokpatlen=(codep[-1]>>5)&07;
|
||||||
|
for(i=0;i<tokpatlen;i++)
|
||||||
|
getint(tokexp[i],codep);
|
||||||
|
tokexp[i] = 0;
|
||||||
|
tp = &fakestack[stackheight-1];
|
||||||
|
i=0;
|
||||||
|
while (i<tokpatlen && tp>=fakestack) {
|
||||||
|
size=tsize(tp);
|
||||||
|
while (i<tokpatlen && (lsize=ssize(tokexp[i]))<=size) {
|
||||||
|
size -= lsize;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i<tokpatlen && size!=0) {
|
||||||
|
totalcost += stackupto(tp,ply,toplevel);
|
||||||
|
CHKCOST();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tp--;
|
||||||
|
}
|
||||||
|
tp = &fakestack[stackheight-1];
|
||||||
|
i=0;
|
||||||
|
while (i<tokpatlen && tp >= fakestack) {
|
||||||
|
size = tsize(tp);
|
||||||
|
lsize= ssize(tokexp[i]);
|
||||||
|
if (size != lsize) { /* find coercion */
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
sret = split(tp,&tokexp[i],ply,toplevel);
|
||||||
|
if (sret==0) {
|
||||||
|
#endif MAXSPLIT
|
||||||
|
totalcost += stackupto(tp,ply,toplevel);
|
||||||
|
CHKCOST();
|
||||||
|
break;
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
}
|
||||||
|
i += sret;
|
||||||
|
#endif MAXSPLIT
|
||||||
|
} else
|
||||||
|
i += 1;
|
||||||
|
tp--;
|
||||||
|
}
|
||||||
|
nextmatch:
|
||||||
|
tp = &fakestack[stackheight-1];
|
||||||
|
i=0; nregneeded = 0;
|
||||||
|
while (i<tokpatlen && tp>=fakestack) {
|
||||||
|
if (!match(tp,&machsets[tokexp[i]],0)) {
|
||||||
|
cp = findcoerc(tp, &machsets[tokexp[i]]);
|
||||||
|
if (cp==0) {
|
||||||
|
for (j=0;j<nregneeded;j++)
|
||||||
|
regtp[j] -= (tp-fakestack+1);
|
||||||
|
totalcost += stackupto(tp,ply,toplevel);
|
||||||
|
CHKCOST();
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if (cp->c3_prop==0) {
|
||||||
|
totalcost+=docoerc(tp,cp,ply,toplevel,0);
|
||||||
|
CHKCOST();
|
||||||
|
} else {
|
||||||
|
assert(nregneeded<MAXCREG);
|
||||||
|
regtp[nregneeded] = tp;
|
||||||
|
regcp[nregneeded] = cp;
|
||||||
|
regls[nregneeded] = curreglist;
|
||||||
|
nregneeded++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++; tp--;
|
||||||
|
}
|
||||||
|
if (tokpatlen>stackheight) {
|
||||||
|
stackpad = tokpatlen-stackheight;
|
||||||
|
for (j=stackheight-1;j>=0;j--)
|
||||||
|
fakestack[j+stackpad] = fakestack[j];
|
||||||
|
for (j=0;j<stackpad;j++)
|
||||||
|
fakestack[j].t_token=0;
|
||||||
|
stackheight += stackpad;
|
||||||
|
for (j=0;j<nregneeded;j++)
|
||||||
|
regtp[j] += stackpad;
|
||||||
|
tp = &fakestack[stackpad-1];
|
||||||
|
while (i<tokpatlen && tp>=fakestack) {
|
||||||
|
cp = findcoerc((token_p) 0, &machsets[tokexp[i]]);
|
||||||
|
if (cp==0) {
|
||||||
|
assert(!toplevel);
|
||||||
|
for (j=0;j<nregneeded;j++)
|
||||||
|
myfree(regls[j]);
|
||||||
|
totalcost=INFINITY;
|
||||||
|
BROKE();
|
||||||
|
}
|
||||||
|
if (cp->c3_prop==0) {
|
||||||
|
totalcost+=docoerc(tp,cp,ply,toplevel,0);
|
||||||
|
CHKCOST();
|
||||||
|
} else {
|
||||||
|
assert(nregneeded<MAXCREG);
|
||||||
|
regtp[nregneeded] = tp;
|
||||||
|
regcp[nregneeded] = cp;
|
||||||
|
regls[nregneeded] = curreglist;
|
||||||
|
nregneeded++;
|
||||||
|
}
|
||||||
|
i++; tp--;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
stackpad=0;
|
||||||
|
assert(i==tokpatlen);
|
||||||
|
if (nregneeded==0)
|
||||||
|
break;
|
||||||
|
SAVEST;
|
||||||
|
mincost=costlimit-totalcost+1;
|
||||||
|
tup = tuples(regls,nregneeded);
|
||||||
|
besttup=0;
|
||||||
|
for (; tup != 0; tup = ntup) {
|
||||||
|
ntup = tup->p_next;
|
||||||
|
for (i=0,t=0;i<nregneeded && t<mincost; i++)
|
||||||
|
t += docoerc(regtp[i],regcp[i],ply,FALSE,tup->p_rar[i]);
|
||||||
|
if (t<mincost)
|
||||||
|
t += codegen(codep,ply,FALSE,mincost-t,0);
|
||||||
|
if (t<mincost) {
|
||||||
|
mincost = t;
|
||||||
|
besttup = tup;
|
||||||
|
} else
|
||||||
|
myfree(tup);
|
||||||
|
RESTST;
|
||||||
|
}
|
||||||
|
FREEST;
|
||||||
|
for (i=0;i<nregneeded;i++)
|
||||||
|
myfree(regls[i]);
|
||||||
|
if (totalcost+mincost>costlimit) {
|
||||||
|
if (besttup)
|
||||||
|
myfree(besttup);
|
||||||
|
if (stackpad!=tokpatlen) {
|
||||||
|
if (stackpad) {
|
||||||
|
if (costlimit<MAXINT) {
|
||||||
|
totalcost = costlimit+1;
|
||||||
|
BROKE();
|
||||||
|
}
|
||||||
|
for (i=0;i<stackheight-stackpad;i++)
|
||||||
|
fakestack[i] = fakestack[i+stackpad];
|
||||||
|
stackheight -= stackpad;
|
||||||
|
totalcost += stackupto(&fakestack[stackheight-1],ply,toplevel);
|
||||||
|
} else
|
||||||
|
totalcost += stackupto(fakestack,ply,toplevel);
|
||||||
|
CHKCOST();
|
||||||
|
goto nextmatch;
|
||||||
|
}
|
||||||
|
totalcost += mincost;
|
||||||
|
BROKE();
|
||||||
|
}
|
||||||
|
for (i=0;i<nregneeded;i++)
|
||||||
|
totalcost += docoerc(regtp[i],regcp[i],ply,toplevel,besttup->p_rar[i]);
|
||||||
|
myfree(besttup);
|
||||||
|
break;
|
||||||
|
case DO_REMOVE:
|
||||||
|
DEBUG("REMOVE");
|
||||||
|
if (codep[-1]&32) {
|
||||||
|
getint(texpno,codep);
|
||||||
|
getint(nodeno,codep);
|
||||||
|
} else {
|
||||||
|
getint(texpno,codep);
|
||||||
|
nodeno=0;
|
||||||
|
}
|
||||||
|
for (tp= &fakestack[stackheight-tokpatlen-1];tp>=&fakestack[0];tp--)
|
||||||
|
if (match(tp,&machsets[texpno],nodeno)) {
|
||||||
|
/* investigate possible coercion to register */
|
||||||
|
totalcost += stackupto(tp,ply,toplevel);
|
||||||
|
CHKCOST();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (rp=machregs+2;rp<machregs+NREGS;rp++)
|
||||||
|
if (match(&rp->r_contents,&machsets[texpno],nodeno))
|
||||||
|
rp->r_contents.t_token=0;
|
||||||
|
break;
|
||||||
|
case DO_RREMOVE: /* register remove */
|
||||||
|
getint(nodeno,codep);
|
||||||
|
result=compute(&enodes[nodeno]);
|
||||||
|
assert(result.e_typ==EV_REG);
|
||||||
|
for (tp= &fakestack[stackheight-tokpatlen-1];tp>=&fakestack[0];tp--)
|
||||||
|
if (tp->t_token==-1) {
|
||||||
|
if(tp->t_att[0].ar==result.e_v.e_con)
|
||||||
|
goto gotone;
|
||||||
|
} else {
|
||||||
|
tdp = &tokens[tp->t_token];
|
||||||
|
for(i=0;i<TOKENSIZE;i++)
|
||||||
|
if (tdp->t_type[i]==EV_REG &&
|
||||||
|
tp->t_att[i].ar==result.e_v.e_con)
|
||||||
|
goto gotone;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
gotone:
|
||||||
|
/* investigate possible coercion to register */
|
||||||
|
totalcost += stackupto(tp,ply,toplevel);
|
||||||
|
CHKCOST();
|
||||||
|
break;
|
||||||
|
case DO_DEALLOCATE:
|
||||||
|
DEBUG("DEALLOCATE");
|
||||||
|
getint(tinstno,codep);
|
||||||
|
instance(tinstno,&token);
|
||||||
|
if (token.t_token==-1)
|
||||||
|
chrefcount(token.t_att[0].ar,-1,TRUE);
|
||||||
|
else {
|
||||||
|
tdp= &tokens[token.t_token];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
if (tdp->t_type[i]==EV_REG)
|
||||||
|
chrefcount(token.t_att[i].ar,-1,TRUE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DO_REALLOCATE:
|
||||||
|
DEBUG("REALLOCATE");
|
||||||
|
for(rp=machregs;rp<machregs+NREGS;rp++)
|
||||||
|
if(rp->r_tcount) {
|
||||||
|
rp->r_refcount -= rp->r_tcount;
|
||||||
|
rp->r_tcount = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DO_ALLOCATE:
|
||||||
|
DEBUG("ALLOCATE");
|
||||||
|
if (codep[-1]&32) {
|
||||||
|
getint(propno,codep);
|
||||||
|
getint(tinstno,codep);
|
||||||
|
} else {
|
||||||
|
getint(propno,codep);
|
||||||
|
tinstno=0;
|
||||||
|
}
|
||||||
|
instance(tinstno,&token);
|
||||||
|
if (!forced) {
|
||||||
|
do {
|
||||||
|
npos=exactmatch=0;
|
||||||
|
for(rpp=reglist[propno];rp= *rpp; rpp++)
|
||||||
|
if (getrefcount(rp-machregs)==0) {
|
||||||
|
pos[npos++] = rp-machregs;
|
||||||
|
if (eqtoken(&rp->r_contents,&token))
|
||||||
|
exactmatch++;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Now pos[] contains all free registers with desired
|
||||||
|
* property. If none then some stacking has to take place.
|
||||||
|
*/
|
||||||
|
if (npos==0) {
|
||||||
|
if (stackheight<=tokpatlen) {
|
||||||
|
if (!toplevel) {
|
||||||
|
totalcost = INFINITY;
|
||||||
|
BROKE();
|
||||||
|
} else {
|
||||||
|
fatal("No regs available");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalcost += stackupto( &fakestack[0],ply,toplevel);
|
||||||
|
CHKCOST();
|
||||||
|
}
|
||||||
|
} while (npos==0);
|
||||||
|
if (!exactmatch) {
|
||||||
|
npos2=npos;
|
||||||
|
for(i=0;i<npos;i++)
|
||||||
|
pos2[i]=pos[i];
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Now we are reducing the number of possible registers.
|
||||||
|
* We take only one equally likely register out of every
|
||||||
|
* equivalence class as given by set of properties.
|
||||||
|
*/
|
||||||
|
mtoken = token;
|
||||||
|
npos2=0;
|
||||||
|
for(i=0;i<npos;i++)
|
||||||
|
if (eqtoken(&machregs[pos[i]].r_contents,&mtoken)) {
|
||||||
|
pos2[npos2++] = pos[i];
|
||||||
|
for(j=0;j<npos2-1;j++)
|
||||||
|
if (eqregclass(pos2[j],pos[i])) {
|
||||||
|
npos2--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Now pos2[] contains all possibilities to try, if more than
|
||||||
|
* one, lookahead is necessary.
|
||||||
|
*/
|
||||||
|
token2.t_token= -1;
|
||||||
|
for (i=1;i<TOKENSIZE;i++)
|
||||||
|
token2.t_att[i].aw=0;
|
||||||
|
if (npos2==1)
|
||||||
|
decision=pos2[0];
|
||||||
|
else {
|
||||||
|
SAVEST;
|
||||||
|
mincost=costlimit-totalcost+1;
|
||||||
|
for(j=0;j<npos2;j++) {
|
||||||
|
chrefcount(pos2[j],1,FALSE);
|
||||||
|
token2.t_att[0].ar=pos2[j];
|
||||||
|
allreg[nallreg++] = pos2[j];
|
||||||
|
if (token.t_token != 0)
|
||||||
|
t=move(&token,&token2,ply,FALSE,mincost);
|
||||||
|
else {
|
||||||
|
t = 0;
|
||||||
|
erasereg(pos2[j]);
|
||||||
|
}
|
||||||
|
if (t<mincost)
|
||||||
|
t += codegen(codep,ply,FALSE,mincost-t,0);
|
||||||
|
if (t<mincost) {
|
||||||
|
mincost=t;
|
||||||
|
decision=pos2[j];
|
||||||
|
}
|
||||||
|
RESTST;
|
||||||
|
}
|
||||||
|
FREEST;
|
||||||
|
if (totalcost+mincost>costlimit) {
|
||||||
|
totalcost = INFINITY;
|
||||||
|
BROKE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
decision = forced;
|
||||||
|
if (getrefcount(decision)!=0) {
|
||||||
|
totalcost = INFINITY;
|
||||||
|
BROKE();
|
||||||
|
}
|
||||||
|
token2.t_token = -1;
|
||||||
|
}
|
||||||
|
chrefcount(decision,1,FALSE);
|
||||||
|
token2.t_att[0].ar=decision;
|
||||||
|
if (token.t_token != 0) {
|
||||||
|
totalcost+=move(&token,&token2,ply,toplevel,MAXINT);
|
||||||
|
CHKCOST();
|
||||||
|
} else
|
||||||
|
erasereg(decision);
|
||||||
|
allreg[nallreg++]=decision;
|
||||||
|
break;
|
||||||
|
case DO_LOUTPUT:
|
||||||
|
DEBUG("LOUTPUT");
|
||||||
|
getint(stringno,codep);
|
||||||
|
getint(nodeno,codep);
|
||||||
|
if (toplevel) {
|
||||||
|
gencode(codestrings[stringno]);
|
||||||
|
genexpr(nodeno);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DO_ROUTPUT:
|
||||||
|
DEBUG("ROUTPUT");
|
||||||
|
i=((codep[-1]>>5)&07);
|
||||||
|
do {
|
||||||
|
getint(stringno,codep);
|
||||||
|
if (toplevel) {
|
||||||
|
gencode(codestrings[stringno]);
|
||||||
|
gennl();
|
||||||
|
}
|
||||||
|
} while (i--);
|
||||||
|
break;
|
||||||
|
case DO_MOVE:
|
||||||
|
DEBUG("MOVE");
|
||||||
|
getint(tinstno,codep);
|
||||||
|
instance(tinstno,&token);
|
||||||
|
getint(tinstno,codep);
|
||||||
|
instance(tinstno,&token2);
|
||||||
|
totalcost += move(&token,&token2,ply,toplevel,costlimit-totalcost+1);
|
||||||
|
CHKCOST();
|
||||||
|
break;
|
||||||
|
case DO_ERASE:
|
||||||
|
DEBUG("ERASE");
|
||||||
|
getint(nodeno,codep);
|
||||||
|
result=compute(&enodes[nodeno]);
|
||||||
|
assert(result.e_typ==EV_REG);
|
||||||
|
erasereg(result.e_v.e_reg);
|
||||||
|
break;
|
||||||
|
case DO_TOKREPLACE:
|
||||||
|
DEBUG("TOKREPLACE");
|
||||||
|
assert(stackheight>=tokpatlen);
|
||||||
|
repllen=(codep[-1]>>5)&07;
|
||||||
|
for(i=0;i<repllen;i++) {
|
||||||
|
getint(tinstno,codep);
|
||||||
|
instance(tinstno,&reptoken[i]);
|
||||||
|
tref(&reptoken[i],1);
|
||||||
|
}
|
||||||
|
for(i=0;i<tokpatlen;i++) {
|
||||||
|
if (!inscoerc)
|
||||||
|
tref(&fakestack[stackheight-1],-1);
|
||||||
|
stackheight--;
|
||||||
|
}
|
||||||
|
for (i=0;i<repllen;i++) {
|
||||||
|
assert(stackheight<MAXFSTACK);
|
||||||
|
fakestack[stackheight++] = reptoken[i];
|
||||||
|
}
|
||||||
|
for(i=0;i<nallreg;i++)
|
||||||
|
chrefcount(allreg[i],-1,FALSE);
|
||||||
|
break;
|
||||||
|
case DO_EMREPLACE:
|
||||||
|
DEBUG("EMREPLACE");
|
||||||
|
emrepllen=(codep[-1]>>5)&07;
|
||||||
|
j=emp-emlines;
|
||||||
|
if (emrepllen>j) {
|
||||||
|
assert(nemlines+emrepllen-j<MAXEMLINES);
|
||||||
|
for (i=nemlines;i>=0;i--)
|
||||||
|
emlines[i+emrepllen-j] = emlines[i];
|
||||||
|
nemlines += emrepllen-j;
|
||||||
|
emp += emrepllen-j;
|
||||||
|
}
|
||||||
|
emp -= emrepllen;
|
||||||
|
for (i=0;i<emrepllen;i++) {
|
||||||
|
getint(eminstr,codep);
|
||||||
|
getint(nodeno,codep);
|
||||||
|
emp[i].em_instr = eminstr;
|
||||||
|
result = compute(&enodes[nodeno]);
|
||||||
|
switch(result.e_typ) {
|
||||||
|
default:
|
||||||
|
assert(FALSE);
|
||||||
|
case 0:
|
||||||
|
emp[i].em_optyp = OPNO;
|
||||||
|
emp[i].em_soper = 0;
|
||||||
|
break;
|
||||||
|
case EV_INT:
|
||||||
|
emp[i].em_optyp = OPINT;
|
||||||
|
emp[i].em_soper = tostring(result.e_v.e_con);
|
||||||
|
emp[i].em_u.em_ioper = result.e_v.e_con;
|
||||||
|
break;
|
||||||
|
case EV_STR:
|
||||||
|
emp[i].em_optyp = OPSYMBOL;
|
||||||
|
emp[i].em_soper = result.e_v.e_str;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!toplevel)
|
||||||
|
ply += emrepllen;
|
||||||
|
break;
|
||||||
|
case DO_COST:
|
||||||
|
DEBUG("COST");
|
||||||
|
getint(cost.c_size,codep);
|
||||||
|
getint(cost.c_time,codep);
|
||||||
|
totalcost += costcalc(cost);
|
||||||
|
CHKCOST();
|
||||||
|
break;
|
||||||
|
#ifdef REGVARS
|
||||||
|
case DO_PRETURN:
|
||||||
|
if (toplevel) {
|
||||||
|
swtxt();
|
||||||
|
regreturn(); /* in mach.c */
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case DO_RETURN:
|
||||||
|
DEBUG("RETURN");
|
||||||
|
assert(origcp!=startupcode);
|
||||||
|
doreturn:
|
||||||
|
#ifndef NDEBUG
|
||||||
|
level--;
|
||||||
|
#endif
|
||||||
|
return(totalcost);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
364
mach/proto/cg/compute.c
Normal file
364
mach/proto/cg/compute.c
Normal file
@ -0,0 +1,364 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "glosym.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LLEAF 01
|
||||||
|
#define LDEF 02
|
||||||
|
#define RLEAF 04
|
||||||
|
#define RDEF 010
|
||||||
|
#define LLDEF LLEAF|LDEF
|
||||||
|
#define RLDEF RLEAF|RDEF
|
||||||
|
|
||||||
|
char opdesc[] = {
|
||||||
|
0, /* EX_TOKFIELD */
|
||||||
|
0, /* EX_ARG */
|
||||||
|
0, /* EX_CON */
|
||||||
|
0, /* EX_ALLREG */
|
||||||
|
LLDEF|RLDEF, /* EX_SAMESIGN */
|
||||||
|
LLDEF|RLDEF, /* EX_SFIT */
|
||||||
|
LLDEF|RLDEF, /* EX_UFIT */
|
||||||
|
0, /* EX_ROM */
|
||||||
|
LLDEF|RLDEF, /* EX_NCPEQ */
|
||||||
|
LLDEF|RLDEF, /* EX_SCPEQ */
|
||||||
|
LLDEF|RLDEF, /* EX_RCPEQ */
|
||||||
|
LLDEF|RLDEF, /* EX_NCPNE */
|
||||||
|
LLDEF|RLDEF, /* EX_SCPNE */
|
||||||
|
LLDEF|RLDEF, /* EX_RCPNE */
|
||||||
|
LLDEF|RLDEF, /* EX_NCPGT */
|
||||||
|
LLDEF|RLDEF, /* EX_NCPGE */
|
||||||
|
LLDEF|RLDEF, /* EX_NCPLT */
|
||||||
|
LLDEF|RLDEF, /* EX_NCPLE */
|
||||||
|
LLDEF, /* EX_OR2 */
|
||||||
|
LLDEF, /* EX_AND2 */
|
||||||
|
LLDEF|RLDEF, /* EX_PLUS */
|
||||||
|
LLDEF|RLDEF, /* EX_CAT */
|
||||||
|
LLDEF|RLDEF, /* EX_MINUS */
|
||||||
|
LLDEF|RLDEF, /* EX_TIMES */
|
||||||
|
LLDEF|RLDEF, /* EX_DIVIDE */
|
||||||
|
LLDEF|RLDEF, /* EX_MOD */
|
||||||
|
LLDEF|RLDEF, /* EX_LSHIFT */
|
||||||
|
LLDEF|RLDEF, /* EX_RSHIFT */
|
||||||
|
LLDEF, /* EX_NOT */
|
||||||
|
LLDEF, /* EX_COMP */
|
||||||
|
0, /* EX_COST */
|
||||||
|
0, /* EX_STRING */
|
||||||
|
LLEAF, /* EX_DEFINED */
|
||||||
|
0, /* EX_SUBREG */
|
||||||
|
LLDEF, /* EX_TOSTRING */
|
||||||
|
LLDEF, /* EX_UMINUS */
|
||||||
|
0, /* EX_REG */
|
||||||
|
0, /* EX_LOWW */
|
||||||
|
0, /* EX_HIGHW */
|
||||||
|
LLDEF, /* EX_INREG */
|
||||||
|
LLDEF, /* EX_REGVAR */
|
||||||
|
};
|
||||||
|
|
||||||
|
string salloc(),strcpy(),strcat();
|
||||||
|
|
||||||
|
string mycat(s1,s2) string s1,s2; {
|
||||||
|
register string s;
|
||||||
|
|
||||||
|
s=salloc(strlen(s1)+strlen(s2));
|
||||||
|
strcpy(s,s1);
|
||||||
|
strcat(s,s2);
|
||||||
|
return(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
string mystrcpy(s) string s; {
|
||||||
|
register string r;
|
||||||
|
|
||||||
|
r=salloc(strlen(s));
|
||||||
|
strcpy(r,s);
|
||||||
|
return(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
char digstr[21][15];
|
||||||
|
|
||||||
|
string tostring(n) word n; {
|
||||||
|
char buf[25];
|
||||||
|
|
||||||
|
if (n>=-20 && n<=20 && (n&1)==0) {
|
||||||
|
if (digstr[(n>>1)+10][0]==0)
|
||||||
|
sprintf(digstr[(n>>1)+10],WRD_FMT,n);
|
||||||
|
return(digstr[(n>>1)+10]);
|
||||||
|
}
|
||||||
|
sprintf(buf,WRD_FMT,n);
|
||||||
|
return(mystrcpy(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
result_t undefres= {EV_UNDEF};
|
||||||
|
|
||||||
|
result_t compute(node) node_p node; {
|
||||||
|
result_t leaf1,leaf2,result;
|
||||||
|
token_p tp;
|
||||||
|
int desc;
|
||||||
|
long mask,tmp;
|
||||||
|
int i,tmpreg;
|
||||||
|
glosym_p gp;
|
||||||
|
|
||||||
|
desc=opdesc[node->ex_operator];
|
||||||
|
if (desc&LLEAF) {
|
||||||
|
leaf1 = compute(&enodes[node->ex_lnode]);
|
||||||
|
if (desc&LDEF && leaf1.e_typ==EV_UNDEF)
|
||||||
|
return(undefres);
|
||||||
|
}
|
||||||
|
if (desc&RLEAF) {
|
||||||
|
leaf2 = compute(&enodes[node->ex_rnode]);
|
||||||
|
if (desc&RDEF && leaf2.e_typ==EV_UNDEF)
|
||||||
|
return(undefres);
|
||||||
|
}
|
||||||
|
result.e_typ=EV_INT;
|
||||||
|
switch(node->ex_operator) {
|
||||||
|
default: assert(FALSE);
|
||||||
|
case EX_TOKFIELD:
|
||||||
|
if (node->ex_lnode!=0)
|
||||||
|
tp = &fakestack[stackheight-node->ex_lnode];
|
||||||
|
else
|
||||||
|
tp = curtoken;
|
||||||
|
switch(result.e_typ = tokens[tp->t_token].t_type[node->ex_rnode-1]) {
|
||||||
|
default:
|
||||||
|
assert(FALSE);
|
||||||
|
case EV_INT:
|
||||||
|
result.e_v.e_con = tp->t_att[node->ex_rnode-1].aw;
|
||||||
|
break;
|
||||||
|
case EV_STR:
|
||||||
|
result.e_v.e_str = tp->t_att[node->ex_rnode-1].as;
|
||||||
|
break;
|
||||||
|
case EV_REG:
|
||||||
|
result.e_v.e_reg = tp->t_att[node->ex_rnode-1].ar;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
case EX_ARG:
|
||||||
|
return(dollar[node->ex_lnode-1]);
|
||||||
|
case EX_CON:
|
||||||
|
result.e_typ = EV_INT;
|
||||||
|
result.e_v.e_con = ((long) node->ex_rnode << 16) | ((long)node->ex_lnode&0xffff);
|
||||||
|
return(result);
|
||||||
|
case EX_REG:
|
||||||
|
result.e_typ = EV_REG;
|
||||||
|
result.e_v.e_reg = node->ex_lnode;
|
||||||
|
return(result);
|
||||||
|
case EX_ALLREG:
|
||||||
|
result.e_typ = EV_REG;
|
||||||
|
result.e_v.e_reg = allreg[node->ex_lnode-1];
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (node->ex_rnode!=0)
|
||||||
|
result.e_v.e_reg = machregs[result.e_v.e_reg].
|
||||||
|
r_members[node->ex_rnode-1];
|
||||||
|
#endif
|
||||||
|
return(result);
|
||||||
|
case EX_SAMESIGN:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_typ = EV_INT;
|
||||||
|
if (leaf1.e_v.e_con>=0)
|
||||||
|
result.e_v.e_con= leaf2.e_v.e_con>=0;
|
||||||
|
else
|
||||||
|
result.e_v.e_con= leaf2.e_v.e_con<0;
|
||||||
|
return(result);
|
||||||
|
case EX_SFIT:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
mask = 0xFFFFFFFFL;
|
||||||
|
for (i=0;i<leaf2.e_v.e_con-1;i++)
|
||||||
|
mask &= ~(1<<i);
|
||||||
|
tmp = leaf1.e_v.e_con&mask;
|
||||||
|
result.e_v.e_con = tmp==0||tmp==mask;
|
||||||
|
return(result);
|
||||||
|
case EX_UFIT:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
mask = 0xFFFFFFFFL;
|
||||||
|
for (i=0;i<leaf2.e_v.e_con;i++)
|
||||||
|
mask &= ~(1<<i);
|
||||||
|
result.e_v.e_con = (leaf1.e_v.e_con&mask)==0;
|
||||||
|
return(result);
|
||||||
|
case EX_ROM:
|
||||||
|
assert(node->ex_rnode>=0 &&node->ex_rnode<MAXROM);
|
||||||
|
leaf2=dollar[node->ex_lnode];
|
||||||
|
if (leaf2.e_typ != EV_STR)
|
||||||
|
return(undefres);
|
||||||
|
gp = lookglo(leaf2.e_v.e_str);
|
||||||
|
if (gp == (glosym_p) 0)
|
||||||
|
return(undefres);
|
||||||
|
if ((gp->gl_rom[MAXROM]&(1<<node->ex_rnode))==0)
|
||||||
|
return(undefres);
|
||||||
|
result.e_v.e_con = gp->gl_rom[node->ex_rnode];
|
||||||
|
return(result);
|
||||||
|
case EX_LOWW:
|
||||||
|
result.e_v.e_con = saveemp[node->ex_lnode].em_u.em_loper&0xFFFF;
|
||||||
|
return(result);
|
||||||
|
case EX_HIGHW:
|
||||||
|
result.e_v.e_con = saveemp[node->ex_lnode].em_u.em_loper>>16;
|
||||||
|
return(result);
|
||||||
|
case EX_NCPEQ:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con==leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_SCPEQ:
|
||||||
|
assert(leaf1.e_typ == EV_STR && leaf2.e_typ == EV_STR);
|
||||||
|
result.e_v.e_con = !strcmp(leaf1.e_v.e_str,leaf2.e_v.e_str);
|
||||||
|
return(result);
|
||||||
|
case EX_RCPEQ:
|
||||||
|
assert(leaf1.e_typ == EV_REG && leaf2.e_typ == EV_REG);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_reg==leaf2.e_v.e_reg;
|
||||||
|
return(result);
|
||||||
|
case EX_NCPNE:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con!=leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_SCPNE:
|
||||||
|
assert(leaf1.e_typ == EV_STR && leaf2.e_typ == EV_STR);
|
||||||
|
result.e_v.e_con = strcmp(leaf1.e_v.e_str,leaf2.e_v.e_str);
|
||||||
|
return(result);
|
||||||
|
case EX_RCPNE:
|
||||||
|
assert(leaf1.e_typ == EV_REG && leaf2.e_typ == EV_REG);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_reg!=leaf2.e_v.e_reg;
|
||||||
|
return(result);
|
||||||
|
case EX_NCPGT:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con>leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_NCPGE:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con>=leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_NCPLT:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con<leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_NCPLE:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con<=leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_OR2:
|
||||||
|
assert(leaf1.e_typ == EV_INT);
|
||||||
|
if (leaf1.e_v.e_con==0)
|
||||||
|
return(compute(&enodes[node->ex_rnode]));
|
||||||
|
return(leaf1);
|
||||||
|
case EX_AND2:
|
||||||
|
assert(leaf1.e_typ == EV_INT);
|
||||||
|
if (leaf1.e_v.e_con!=0)
|
||||||
|
return(compute(&enodes[node->ex_rnode]));
|
||||||
|
return(leaf1);
|
||||||
|
case EX_PLUS:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con=leaf1.e_v.e_con+leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_CAT:
|
||||||
|
assert(leaf1.e_typ == EV_STR && leaf2.e_typ == EV_STR);
|
||||||
|
result.e_typ = EV_STR;
|
||||||
|
result.e_v.e_str = mycat(leaf1.e_v.e_str,leaf2.e_v.e_str);
|
||||||
|
return(result);
|
||||||
|
case EX_MINUS:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con - leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_TIMES:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con * leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_DIVIDE:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con / leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_MOD:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con % leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_LSHIFT:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con << leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_RSHIFT:
|
||||||
|
assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = leaf1.e_v.e_con >> leaf2.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_NOT:
|
||||||
|
assert(leaf1.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = !leaf1.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_COMP:
|
||||||
|
assert(leaf1.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = ~leaf1.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
case EX_COST:
|
||||||
|
if (node->ex_rnode==0)
|
||||||
|
return(compute(&enodes[tokens[node->ex_lnode].t_cost.c_size]));
|
||||||
|
else
|
||||||
|
return(compute(&enodes[tokens[node->ex_lnode].t_cost.c_time]));
|
||||||
|
case EX_STRING:
|
||||||
|
result.e_typ = EV_STR;
|
||||||
|
result.e_v.e_str = codestrings[node->ex_lnode];
|
||||||
|
return(result);
|
||||||
|
case EX_DEFINED:
|
||||||
|
result.e_v.e_con=leaf1.e_typ!=EV_UNDEF;
|
||||||
|
return(result);
|
||||||
|
case EX_SUBREG:
|
||||||
|
result.e_typ = EV_REG;
|
||||||
|
tp= &fakestack[stackheight-node->ex_lnode];
|
||||||
|
assert(tp->t_token == -1);
|
||||||
|
tmpreg= tp->t_att[0].ar;
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (node->ex_rnode)
|
||||||
|
tmpreg=machregs[tmpreg].r_members[node->ex_rnode-1];
|
||||||
|
#endif
|
||||||
|
result.e_v.e_reg=tmpreg;
|
||||||
|
return(result);
|
||||||
|
case EX_TOSTRING:
|
||||||
|
assert(leaf1.e_typ == EV_INT);
|
||||||
|
result.e_typ = EV_STR;
|
||||||
|
result.e_v.e_str = tostring(leaf1.e_v.e_con);
|
||||||
|
return(result);
|
||||||
|
#ifdef REGVARS
|
||||||
|
case EX_INREG:
|
||||||
|
assert(leaf1.e_typ == EV_INT);
|
||||||
|
i = isregvar((long) leaf1.e_v.e_con);
|
||||||
|
if (i<0)
|
||||||
|
result.e_v.e_con = 0;
|
||||||
|
else if (i==0)
|
||||||
|
result.e_v.e_con = 1;
|
||||||
|
else
|
||||||
|
result.e_v.e_con = 2;
|
||||||
|
return(result);
|
||||||
|
case EX_REGVAR:
|
||||||
|
assert(leaf1.e_typ == EV_INT);
|
||||||
|
i = isregvar((long) leaf1.e_v.e_con);
|
||||||
|
if (i<=0)
|
||||||
|
return(undefres);
|
||||||
|
result.e_typ = EV_REG;
|
||||||
|
result.e_v.e_reg=i;
|
||||||
|
return(result);
|
||||||
|
#endif
|
||||||
|
case EX_UMINUS:
|
||||||
|
assert(leaf1.e_typ == EV_INT);
|
||||||
|
result.e_v.e_con = -leaf1.e_v.e_con;
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
54
mach/proto/cg/data.h
Normal file
54
mach/proto/cg/data.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int t_token; /* kind of token, -1 for register */
|
||||||
|
union {
|
||||||
|
word aw; /* integer type */
|
||||||
|
string as; /* string type */
|
||||||
|
int ar; /* register type */
|
||||||
|
} t_att[TOKENSIZE];
|
||||||
|
} token_t,*token_p;
|
||||||
|
|
||||||
|
struct reginfo {
|
||||||
|
int r_repr; /* index in string table */
|
||||||
|
int r_size; /* size in bytes */
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
int r_members[MAXMEMBERS]; /* register contained within this reg */
|
||||||
|
short r_clash[REGSETSIZE]; /* set of clashing registers */
|
||||||
|
#endif
|
||||||
|
int r_refcount; /* Times in use */
|
||||||
|
token_t r_contents; /* Current contents */
|
||||||
|
int r_tcount; /* Temporary count difference */
|
||||||
|
};
|
||||||
|
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
#define clash(a,b) ((machregs[a].r_clash[(b)>>4]&(1<<((b)&017)))!=0)
|
||||||
|
#else
|
||||||
|
#define clash(a,b) ((a)==(b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int t_size; /* size in bytes */
|
||||||
|
cost_t t_cost; /* cost in bytes and time */
|
||||||
|
byte t_type[TOKENSIZE]; /* types of attributes, TT_??? */
|
||||||
|
int t_format; /* index of formatstring */
|
||||||
|
} tkdef_t,*tkdef_p;
|
||||||
|
|
||||||
|
struct emline {
|
||||||
|
int em_instr;
|
||||||
|
int em_optyp;
|
||||||
|
string em_soper;
|
||||||
|
union {
|
||||||
|
word em_ioper;
|
||||||
|
long em_loper;
|
||||||
|
} em_u;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define OPNO 0
|
||||||
|
#define OPINT 1
|
||||||
|
#define OPSYMBOL 2
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int rl_n; /* number in list */
|
||||||
|
int rl_list[NREGS];
|
||||||
|
} rl_t,*rl_p;
|
||||||
105
mach/proto/cg/equiv.c
Normal file
105
mach/proto/cg/equiv.c
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include "equiv.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern string myalloc();
|
||||||
|
|
||||||
|
int rar[MAXCREG];
|
||||||
|
rl_p *lar;
|
||||||
|
int maxindex;
|
||||||
|
int regclass[NREGS];
|
||||||
|
struct perm *perms;
|
||||||
|
|
||||||
|
struct perm *
|
||||||
|
tuples(regls,nregneeded) rl_p *regls; {
|
||||||
|
int class=0;
|
||||||
|
register i,j;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* First compute equivalence classes of registers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (i=0;i<NREGS;i++) {
|
||||||
|
regclass[i] = class++;
|
||||||
|
if (getrefcount(i) == 0) {
|
||||||
|
for (j=0;j<i;j++) {
|
||||||
|
if (eqregclass(i,j) &&
|
||||||
|
eqtoken(&machregs[i].r_contents,
|
||||||
|
&machregs[j].r_contents)) {
|
||||||
|
regclass[i] = regclass[j];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now create tuples through a recursive function
|
||||||
|
*/
|
||||||
|
|
||||||
|
maxindex = nregneeded;
|
||||||
|
lar = regls;
|
||||||
|
perms = 0;
|
||||||
|
permute(0);
|
||||||
|
return(perms);
|
||||||
|
}
|
||||||
|
|
||||||
|
permute(index) {
|
||||||
|
register struct perm *pp;
|
||||||
|
register rl_p rlp;
|
||||||
|
register i,j;
|
||||||
|
|
||||||
|
if (index == maxindex) {
|
||||||
|
for (pp=perms; pp != 0; pp=pp->p_next) {
|
||||||
|
for (i=0; i<maxindex; i++)
|
||||||
|
if (regclass[rar[i]] != regclass[pp->p_rar[i]])
|
||||||
|
goto diff;
|
||||||
|
for (i=0; i<maxindex; i++)
|
||||||
|
for (j=0; j<i; j++)
|
||||||
|
if (clash(rar[i],rar[j]) !=
|
||||||
|
clash(pp->p_rar[i],pp->p_rar[j]))
|
||||||
|
goto diff;
|
||||||
|
return;
|
||||||
|
diff: ;
|
||||||
|
}
|
||||||
|
pp = (struct perm *) myalloc(sizeof ( *pp ));
|
||||||
|
pp->p_next = perms;
|
||||||
|
for (i=0; i<maxindex; i++)
|
||||||
|
pp->p_rar[i] = rar[i];
|
||||||
|
perms = pp;
|
||||||
|
} else {
|
||||||
|
rlp=lar[index];
|
||||||
|
for (i=rlp->rl_n-1; i>=0; i--) {
|
||||||
|
rar[index] = rlp->rl_list[i];
|
||||||
|
permute(index+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
mach/proto/cg/equiv.h
Normal file
8
mach/proto/cg/equiv.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#define MAXCREG 4
|
||||||
|
|
||||||
|
struct perm {
|
||||||
|
struct perm *p_next;
|
||||||
|
int p_rar[MAXCREG];
|
||||||
|
};
|
||||||
49
mach/proto/cg/extern.h
Normal file
49
mach/proto/cg/extern.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
extern int maxply; /* amount of lookahead allowed */
|
||||||
|
extern int stackheight; /* # of tokens on fakestack */
|
||||||
|
extern token_t fakestack[]; /* fakestack itself */
|
||||||
|
extern int nallreg; /* number of allocated registers */
|
||||||
|
extern int allreg[]; /* array of allocated registers */
|
||||||
|
extern token_p curtoken; /* pointer to current token */
|
||||||
|
extern result_t dollar[]; /* Values of $1,$2 etc.. */
|
||||||
|
extern int nemlines; /* # of EM instructions in core */
|
||||||
|
extern struct emline emlines[]; /* EM instructions itself */
|
||||||
|
extern struct emline *emp; /* pointer to current instr */
|
||||||
|
extern struct emline *saveemp; /* pointer to start of pattern */
|
||||||
|
extern int tokpatlen; /* length of current stackpattern */
|
||||||
|
extern rl_p curreglist; /* side effect of findcoerc() */
|
||||||
|
#ifndef NDEBUG
|
||||||
|
extern int Debug; /* on/off debug printout */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Next descriptions are external declarations for tables created
|
||||||
|
* by bootgram.
|
||||||
|
* All definitions are to be found in tables.c (Not for humans)
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern byte coderules[]; /* pseudo code for cg itself */
|
||||||
|
extern char stregclass[]; /* static register class */
|
||||||
|
extern struct reginfo machregs[]; /* register info */
|
||||||
|
extern tkdef_t tokens[]; /* token info */
|
||||||
|
extern node_t enodes[]; /* expression nodes */
|
||||||
|
extern string codestrings[]; /* table of strings */
|
||||||
|
extern set_t machsets[]; /* token expression table */
|
||||||
|
extern inst_t tokeninstances[]; /* token instance description table */
|
||||||
|
extern move_t moves[]; /* move descriptors */
|
||||||
|
extern byte pattern[]; /* EM patterns */
|
||||||
|
extern int pathash[256]; /* Indices into previous */
|
||||||
|
extern c1_t c1coercs[]; /* coercions type 1 */
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
extern c2_t c2coercs[]; /* coercions type 2 */
|
||||||
|
#endif MAXSPLIT
|
||||||
|
extern c3_t c3coercs[]; /* coercions type 3 */
|
||||||
|
extern struct reginfo **reglist[]; /* lists of registers per property */
|
||||||
|
|
||||||
|
#define eqregclass(r1,r2) (stregclass[r1]==stregclass[r2])
|
||||||
|
|
||||||
|
#ifdef REGVARS
|
||||||
|
extern int nregvar[]; /* # of register variables per type */
|
||||||
|
extern int *rvnumbers[]; /* lists of numbers */
|
||||||
|
#endif
|
||||||
644
mach/proto/cg/fillem.c
Normal file
644
mach/proto/cg/fillem.c
Normal file
@ -0,0 +1,644 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid2[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "assert.h"
|
||||||
|
#include <em_spec.h>
|
||||||
|
#include <em_pseu.h>
|
||||||
|
#include <em_flag.h>
|
||||||
|
#include <em_ptyp.h>
|
||||||
|
#include <em_mes.h>
|
||||||
|
#include "mach.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#ifdef REGVARS
|
||||||
|
#include "regvar.h"
|
||||||
|
#include <em_reg.h>
|
||||||
|
#endif
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* segment types for switchseg() */
|
||||||
|
#define SEGTXT 0
|
||||||
|
#define SEGCON 1
|
||||||
|
#define SEGROM 2
|
||||||
|
#define SEGBSS 3
|
||||||
|
|
||||||
|
long con();
|
||||||
|
|
||||||
|
#define get8() getc(emfile)
|
||||||
|
|
||||||
|
#define MAXSTR 256
|
||||||
|
|
||||||
|
FILE *emfile;
|
||||||
|
extern FILE *codefile;
|
||||||
|
|
||||||
|
int nextispseu,savetab1;
|
||||||
|
int opcode;
|
||||||
|
int offtyp;
|
||||||
|
long argval;
|
||||||
|
int dlbval;
|
||||||
|
char str[MAXSTR],argstr[32],labstr[32];
|
||||||
|
int strsiz;
|
||||||
|
int holno=0;
|
||||||
|
int procno=0;
|
||||||
|
int curseg= -1;
|
||||||
|
int part_size=0;
|
||||||
|
word part_word=0;
|
||||||
|
int endofprog=0;
|
||||||
|
#ifdef REGVARS
|
||||||
|
int regallowed=0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern char em_flag[];
|
||||||
|
extern short em_ptyp[];
|
||||||
|
extern long atol();
|
||||||
|
extern double atof();
|
||||||
|
|
||||||
|
#define sp_cstx sp_cst2
|
||||||
|
|
||||||
|
string tostring();
|
||||||
|
string holstr();
|
||||||
|
string strarg();
|
||||||
|
string mystrcpy();
|
||||||
|
long get32();
|
||||||
|
|
||||||
|
in_init(filename) char *filename; {
|
||||||
|
|
||||||
|
if ((emfile=freopen(filename,"r",stdin))==NULL)
|
||||||
|
error("Can't open %s",filename);
|
||||||
|
if (get16()!=sp_magic)
|
||||||
|
error("Bad format %s",filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
in_finish() {
|
||||||
|
}
|
||||||
|
|
||||||
|
fillemlines() {
|
||||||
|
int t,i;
|
||||||
|
register struct emline *lp;
|
||||||
|
|
||||||
|
while ((emlines+nemlines)-emp<MAXEMLINES-5) {
|
||||||
|
assert(nemlines<MAXEMLINES);
|
||||||
|
if (nextispseu) {
|
||||||
|
emlines[nemlines].em_instr=0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lp = &emlines[nemlines++];
|
||||||
|
|
||||||
|
switch(t=table1()) {
|
||||||
|
default:
|
||||||
|
error("unknown instruction byte");
|
||||||
|
case sp_ilb1:
|
||||||
|
case sp_ilb2:
|
||||||
|
case sp_fpseu:
|
||||||
|
case sp_dlb1:
|
||||||
|
case sp_dlb2:
|
||||||
|
case sp_dnam:
|
||||||
|
nextispseu=1; savetab1=t;
|
||||||
|
nemlines--;
|
||||||
|
lp->em_instr = 0;
|
||||||
|
return;
|
||||||
|
case EOF:
|
||||||
|
nextispseu=1; savetab1=t;
|
||||||
|
endofprog=1;
|
||||||
|
nemlines--;
|
||||||
|
lp->em_instr = 0;
|
||||||
|
return;
|
||||||
|
case sp_fmnem:
|
||||||
|
lp->em_instr = opcode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i=em_flag[lp->em_instr-sp_fmnem] & EM_PAR;
|
||||||
|
if ( i == PAR_NO ) {
|
||||||
|
lp->em_optyp = OPNO;
|
||||||
|
lp->em_soper = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
t= em_ptyp[i];
|
||||||
|
t= getarg(t);
|
||||||
|
switch(i) {
|
||||||
|
case PAR_L:
|
||||||
|
assert(t == sp_cstx);
|
||||||
|
if (argval >= 0)
|
||||||
|
argval += EM_BSIZE;
|
||||||
|
lp->em_optyp = OPINT;
|
||||||
|
lp->em_u.em_ioper = argval;
|
||||||
|
lp->em_soper = tostring((word) argval);
|
||||||
|
continue;
|
||||||
|
case PAR_G:
|
||||||
|
if (t != sp_cstx)
|
||||||
|
break;
|
||||||
|
lp->em_optyp = OPSYMBOL;
|
||||||
|
lp->em_soper = holstr((word) argval);
|
||||||
|
continue;
|
||||||
|
case PAR_B:
|
||||||
|
t = sp_ilb2;
|
||||||
|
break;
|
||||||
|
case PAR_D:
|
||||||
|
assert(t == sp_cstx);
|
||||||
|
lp->em_optyp = OPSYMBOL;
|
||||||
|
lp->em_soper = strarg(t);
|
||||||
|
lp->em_u.em_loper = argval;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lp->em_soper = strarg(t);
|
||||||
|
if (t==sp_cend)
|
||||||
|
lp->em_optyp = OPNO;
|
||||||
|
else if (t==sp_cstx) {
|
||||||
|
lp->em_optyp = OPINT;
|
||||||
|
lp->em_u.em_ioper = argval;
|
||||||
|
} else
|
||||||
|
lp->em_optyp = OPSYMBOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dopseudo() {
|
||||||
|
register b,t;
|
||||||
|
register full n;
|
||||||
|
register long save;
|
||||||
|
word romcont[MAXROM+1];
|
||||||
|
int nromwords;
|
||||||
|
int rombit,rommask;
|
||||||
|
unsigned dummy,stackupto();
|
||||||
|
|
||||||
|
if (nextispseu==0 || nemlines>0)
|
||||||
|
error("No table entry for %d",emlines[0].em_instr);
|
||||||
|
nextispseu=0;
|
||||||
|
switch(savetab1) {
|
||||||
|
case sp_ilb1:
|
||||||
|
case sp_ilb2:
|
||||||
|
swtxt();
|
||||||
|
dummy = stackupto(&fakestack[stackheight-1],maxply,TRUE);
|
||||||
|
cleanregs();
|
||||||
|
strarg(savetab1);
|
||||||
|
newilb(argstr);
|
||||||
|
return;
|
||||||
|
case sp_dlb1:
|
||||||
|
case sp_dlb2:
|
||||||
|
case sp_dnam:
|
||||||
|
strarg(savetab1);
|
||||||
|
savelab();
|
||||||
|
return;
|
||||||
|
case sp_fpseu:
|
||||||
|
break;
|
||||||
|
case EOF:
|
||||||
|
swtxt();
|
||||||
|
popstr(0);
|
||||||
|
tstoutput();
|
||||||
|
exit(0);
|
||||||
|
default:
|
||||||
|
error("Unknown opcode %d",savetab1);
|
||||||
|
}
|
||||||
|
switch (opcode) {
|
||||||
|
case ps_hol:
|
||||||
|
sprintf(labstr,hol_fmt,++holno);
|
||||||
|
case ps_bss:
|
||||||
|
getarg(cst_ptyp);
|
||||||
|
n = (full) argval;
|
||||||
|
t = getarg(val_ptyp);
|
||||||
|
save = argval;
|
||||||
|
getarg(cst_ptyp);
|
||||||
|
b = (int) argval;
|
||||||
|
argval = save;
|
||||||
|
bss(n,t,b);
|
||||||
|
break;
|
||||||
|
case ps_con:
|
||||||
|
switchseg(SEGCON);
|
||||||
|
dumplab();
|
||||||
|
con(getarg(val_ptyp));
|
||||||
|
while ((t = getarg(any_ptyp)) != sp_cend)
|
||||||
|
con(t);
|
||||||
|
break;
|
||||||
|
case ps_rom:
|
||||||
|
switchseg(SEGROM);
|
||||||
|
xdumplab();
|
||||||
|
nromwords=0;
|
||||||
|
rommask=0;
|
||||||
|
rombit=1;
|
||||||
|
t=getarg(val_ptyp);
|
||||||
|
while (t!=sp_cend) {
|
||||||
|
if (t==sp_cstx && nromwords<MAXROM) {
|
||||||
|
romcont[nromwords] = (word) argval;
|
||||||
|
rommask |= rombit;
|
||||||
|
}
|
||||||
|
nromwords++;
|
||||||
|
rombit <<= 1;
|
||||||
|
con(t);
|
||||||
|
t=getarg(any_ptyp);
|
||||||
|
}
|
||||||
|
if (rommask != 0) {
|
||||||
|
romcont[MAXROM]=rommask;
|
||||||
|
enterglo(labstr,romcont);
|
||||||
|
}
|
||||||
|
labstr[0]=0;
|
||||||
|
break;
|
||||||
|
case ps_mes:
|
||||||
|
getarg(ptyp(sp_cst2));
|
||||||
|
if (argval == ms_emx) {
|
||||||
|
getarg(ptyp(sp_cst2));
|
||||||
|
if (argval != EM_WSIZE)
|
||||||
|
fatal("bad word size");
|
||||||
|
getarg(ptyp(sp_cst2));
|
||||||
|
if (argval != EM_PSIZE)
|
||||||
|
fatal("bad pointer size");
|
||||||
|
if ( getarg(any_ptyp)!=sp_cend )
|
||||||
|
fatal("too many parameters");
|
||||||
|
#ifdef REGVARS
|
||||||
|
} else if (argval == ms_gto) {
|
||||||
|
getarg(ptyp(sp_cend));
|
||||||
|
if (!regallowed)
|
||||||
|
error("mes 3 not allowed here");
|
||||||
|
fixregvars(TRUE);
|
||||||
|
regallowed=0;
|
||||||
|
} else if (argval == ms_reg) {
|
||||||
|
long r_off;
|
||||||
|
int r_size,r_type,r_score;
|
||||||
|
struct regvar *linkreg();
|
||||||
|
|
||||||
|
if (!regallowed)
|
||||||
|
error("mes 3 not allowed here");
|
||||||
|
if(getarg(ptyp(sp_cst2)|ptyp(sp_cend)) == sp_cend) {
|
||||||
|
fixregvars(FALSE);
|
||||||
|
regallowed=0;
|
||||||
|
} else {
|
||||||
|
r_off = argval;
|
||||||
|
#ifdef EM_BSIZE
|
||||||
|
if (r_off >= 0)
|
||||||
|
r_off += EM_BSIZE;
|
||||||
|
#endif
|
||||||
|
getarg(ptyp(sp_cst2));
|
||||||
|
r_size = argval;
|
||||||
|
getarg(ptyp(sp_cst2));
|
||||||
|
r_type = argval;
|
||||||
|
if (r_type<reg_any || r_type>reg_float)
|
||||||
|
fatal("Bad type in register message");
|
||||||
|
if(getarg(ptyp(sp_cst2)|ptyp(sp_cend)) == sp_cend)
|
||||||
|
r_score = 0;
|
||||||
|
else {
|
||||||
|
r_score = argval;
|
||||||
|
if ( getarg(any_ptyp)!=sp_cend )
|
||||||
|
fatal("too many parameters");
|
||||||
|
}
|
||||||
|
tryreg(linkreg(r_off,r_size,r_type,r_score),r_type);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else
|
||||||
|
mes((word)argval);
|
||||||
|
break;
|
||||||
|
case ps_exa:
|
||||||
|
strarg(getarg(sym_ptyp));
|
||||||
|
ex_ap(argstr);
|
||||||
|
break;
|
||||||
|
case ps_ina:
|
||||||
|
strarg(getarg(sym_ptyp));
|
||||||
|
in_ap(argstr);
|
||||||
|
break;
|
||||||
|
case ps_exp:
|
||||||
|
strarg(getarg(ptyp(sp_pnam)));
|
||||||
|
ex_ap(argstr);
|
||||||
|
break;
|
||||||
|
case ps_inp:
|
||||||
|
strarg(getarg(ptyp(sp_pnam)));
|
||||||
|
in_ap(argstr);
|
||||||
|
break;
|
||||||
|
case ps_pro:
|
||||||
|
switchseg(SEGTXT);
|
||||||
|
procno++;
|
||||||
|
strarg(getarg(ptyp(sp_pnam)));
|
||||||
|
newilb(argstr);
|
||||||
|
getarg(cst_ptyp);
|
||||||
|
prolog((full)argval);
|
||||||
|
#ifdef REGVARS
|
||||||
|
regallowed++;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case ps_end:
|
||||||
|
getarg(cst_ptyp | ptyp(sp_cend));
|
||||||
|
cleanregs();
|
||||||
|
#ifdef REGVARS
|
||||||
|
unlinkregs();
|
||||||
|
#endif
|
||||||
|
tstoutput();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error("No table entry for %d",savetab1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----- input ----- */
|
||||||
|
|
||||||
|
int getarg(typset) {
|
||||||
|
register t,argtyp;
|
||||||
|
|
||||||
|
argtyp = t = table2();
|
||||||
|
if (t == EOF)
|
||||||
|
fatal("unexpected EOF");
|
||||||
|
t -= sp_fspec;
|
||||||
|
t = 1 << t;
|
||||||
|
if ((typset & t) == 0)
|
||||||
|
error("bad argument type %d",argtyp);
|
||||||
|
return(argtyp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int table1() {
|
||||||
|
register i;
|
||||||
|
|
||||||
|
i = get8();
|
||||||
|
if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
|
||||||
|
opcode = i;
|
||||||
|
return(sp_fmnem);
|
||||||
|
}
|
||||||
|
if (i < sp_fpseu+sp_npseu && i >= sp_fpseu) {
|
||||||
|
opcode = i;
|
||||||
|
return(sp_fpseu);
|
||||||
|
}
|
||||||
|
if (i < sp_filb0+sp_nilb0 && i >= sp_filb0) {
|
||||||
|
argval = i - sp_filb0;
|
||||||
|
return(sp_ilb2);
|
||||||
|
}
|
||||||
|
return(table3(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
int table2() {
|
||||||
|
register i;
|
||||||
|
|
||||||
|
i = get8();
|
||||||
|
if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
|
||||||
|
argval = i - sp_zcst0;
|
||||||
|
return(sp_cstx);
|
||||||
|
}
|
||||||
|
return(table3(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
int table3(i) {
|
||||||
|
word consiz;
|
||||||
|
|
||||||
|
switch(i) {
|
||||||
|
case sp_ilb1:
|
||||||
|
argval = get8();
|
||||||
|
break;
|
||||||
|
case sp_dlb1:
|
||||||
|
dlbval = get8();
|
||||||
|
break;
|
||||||
|
case sp_dlb2:
|
||||||
|
dlbval = get16();
|
||||||
|
break;
|
||||||
|
case sp_cst2:
|
||||||
|
i = sp_cstx;
|
||||||
|
case sp_ilb2:
|
||||||
|
argval = get16();
|
||||||
|
break;
|
||||||
|
case sp_cst4:
|
||||||
|
i = sp_cstx;
|
||||||
|
argval = get32();
|
||||||
|
break;
|
||||||
|
case sp_dnam:
|
||||||
|
case sp_pnam:
|
||||||
|
case sp_scon:
|
||||||
|
getstring();
|
||||||
|
break;
|
||||||
|
case sp_doff:
|
||||||
|
offtyp = getarg(sym_ptyp);
|
||||||
|
getarg(cst_ptyp);
|
||||||
|
break;
|
||||||
|
case sp_icon:
|
||||||
|
case sp_ucon:
|
||||||
|
case sp_fcon:
|
||||||
|
getarg(cst_ptyp);
|
||||||
|
consiz = (word) argval;
|
||||||
|
getstring();
|
||||||
|
argval = consiz;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get16() {
|
||||||
|
register int l_byte, h_byte;
|
||||||
|
|
||||||
|
l_byte = get8();
|
||||||
|
h_byte = get8();
|
||||||
|
if ( h_byte>=128 ) h_byte -= 256 ;
|
||||||
|
return l_byte | (h_byte*256) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
long get32() {
|
||||||
|
register long l;
|
||||||
|
register int h_byte;
|
||||||
|
|
||||||
|
l = get8();
|
||||||
|
l |= ((unsigned) get8())*256 ;
|
||||||
|
l |= get8()*256L*256L ;
|
||||||
|
h_byte = get8() ;
|
||||||
|
if ( h_byte>=128 ) h_byte -= 256 ;
|
||||||
|
return l | (h_byte*256L*256*256L) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
getstring() {
|
||||||
|
register char *p;
|
||||||
|
register n;
|
||||||
|
|
||||||
|
getarg(cst_ptyp);
|
||||||
|
if (argval < 0 || argval > MAXSTR-1)
|
||||||
|
fatal("string/identifier too long");
|
||||||
|
strsiz = n = (int) argval;
|
||||||
|
p = str;
|
||||||
|
while (--n >= 0)
|
||||||
|
*p++ = get8();
|
||||||
|
*p++ = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
char *strarg(t) {
|
||||||
|
register char *p;
|
||||||
|
|
||||||
|
switch (t) {
|
||||||
|
case sp_ilb1:
|
||||||
|
case sp_ilb2:
|
||||||
|
sprintf(argstr,ilb_fmt,procno,(int)argval);
|
||||||
|
break;
|
||||||
|
case sp_dlb1:
|
||||||
|
case sp_dlb2:
|
||||||
|
sprintf(argstr,dlb_fmt,dlbval);
|
||||||
|
break;
|
||||||
|
case sp_cstx:
|
||||||
|
sprintf(argstr,cst_fmt,(full)argval);
|
||||||
|
break;
|
||||||
|
case sp_dnam:
|
||||||
|
case sp_pnam:
|
||||||
|
p = argstr;
|
||||||
|
if (strsiz < 8 || str[0] == id_first)
|
||||||
|
*p++ = id_first;
|
||||||
|
sprintf(p,"%.*s",strsiz,str);
|
||||||
|
break;
|
||||||
|
case sp_doff:
|
||||||
|
strarg(offtyp);
|
||||||
|
for (p = argstr; *p; p++)
|
||||||
|
;
|
||||||
|
if (argval >= 0)
|
||||||
|
*p++ = '+';
|
||||||
|
sprintf(p,off_fmt,(full)argval);
|
||||||
|
break;
|
||||||
|
case sp_cend:
|
||||||
|
return("");
|
||||||
|
}
|
||||||
|
return(mystrcpy(argstr));
|
||||||
|
}
|
||||||
|
|
||||||
|
bss(n,t,b) full n; {
|
||||||
|
register long s;
|
||||||
|
|
||||||
|
if (n % EM_WSIZE)
|
||||||
|
fatal("bad BSS size");
|
||||||
|
if (b==0
|
||||||
|
#ifdef BSS_INIT
|
||||||
|
|| (t==sp_cstx && argval==BSS_INIT)
|
||||||
|
#endif BSS_INIT
|
||||||
|
) {
|
||||||
|
switchseg(SEGBSS);
|
||||||
|
newlbss(labstr,n);
|
||||||
|
labstr[0]=0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switchseg(SEGCON);
|
||||||
|
dumplab();
|
||||||
|
while (n > 0)
|
||||||
|
n -= (s = con(t));
|
||||||
|
if (s % EM_WSIZE)
|
||||||
|
fatal("bad BSS initializer");
|
||||||
|
}
|
||||||
|
|
||||||
|
long con(t) {
|
||||||
|
register i;
|
||||||
|
|
||||||
|
strarg(t);
|
||||||
|
switch (t) {
|
||||||
|
case sp_ilb1:
|
||||||
|
case sp_ilb2:
|
||||||
|
case sp_pnam:
|
||||||
|
part_flush();
|
||||||
|
con_ilb(argstr);
|
||||||
|
return((long)EM_PSIZE);
|
||||||
|
case sp_dlb1:
|
||||||
|
case sp_dlb2:
|
||||||
|
case sp_dnam:
|
||||||
|
case sp_doff:
|
||||||
|
part_flush();
|
||||||
|
con_dlb(argstr);
|
||||||
|
return((long)EM_PSIZE);
|
||||||
|
case sp_cstx:
|
||||||
|
con_part(EM_WSIZE,(word)argval);
|
||||||
|
return((long)EM_WSIZE);
|
||||||
|
case sp_scon:
|
||||||
|
for (i = 0; i < strsiz; i++)
|
||||||
|
con_part(1,(word) str[i]);
|
||||||
|
return((long)strsiz);
|
||||||
|
case sp_icon:
|
||||||
|
case sp_ucon:
|
||||||
|
if (argval > EM_WSIZE) {
|
||||||
|
part_flush();
|
||||||
|
con_mult((word)argval);
|
||||||
|
} else {
|
||||||
|
con_part((int)argval,(word)atol(str));
|
||||||
|
}
|
||||||
|
return(argval);
|
||||||
|
case sp_fcon:
|
||||||
|
part_flush();
|
||||||
|
con_float();
|
||||||
|
return(argval);
|
||||||
|
}
|
||||||
|
assert(FALSE);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
extern char *segname[];
|
||||||
|
|
||||||
|
swtxt() {
|
||||||
|
switchseg(SEGTXT);
|
||||||
|
}
|
||||||
|
|
||||||
|
switchseg(s) {
|
||||||
|
|
||||||
|
if (s == curseg)
|
||||||
|
return;
|
||||||
|
part_flush();
|
||||||
|
if ((curseg = s) >= 0)
|
||||||
|
fprintf(codefile,"%s\n",segname[s]);
|
||||||
|
}
|
||||||
|
|
||||||
|
savelab() {
|
||||||
|
register char *p,*q;
|
||||||
|
|
||||||
|
part_flush();
|
||||||
|
if (labstr[0]) {
|
||||||
|
dlbdlb(argstr,labstr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
p = argstr;
|
||||||
|
q = labstr;
|
||||||
|
while (*q++ = *p++)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
dumplab() {
|
||||||
|
|
||||||
|
if (labstr[0] == 0)
|
||||||
|
return;
|
||||||
|
assert(part_size == 0);
|
||||||
|
newdlb(labstr);
|
||||||
|
labstr[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
xdumplab() {
|
||||||
|
|
||||||
|
if (labstr[0] == 0)
|
||||||
|
return;
|
||||||
|
assert(part_size == 0);
|
||||||
|
newdlb(labstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
part_flush() {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Each new data fragment and each data label starts at
|
||||||
|
* a new target machine word
|
||||||
|
*/
|
||||||
|
if (part_size == 0)
|
||||||
|
return;
|
||||||
|
con_cst(part_word);
|
||||||
|
part_size = 0;
|
||||||
|
part_word = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
string holstr(n) word n; {
|
||||||
|
|
||||||
|
sprintf(str,hol_off,n,holno);
|
||||||
|
return(mystrcpy(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- machine dependent routines ----- */
|
||||||
|
|
||||||
|
#include "mach.c"
|
||||||
194
mach/proto/cg/gencode.c
Normal file
194
mach/proto/cg/gencode.c
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE *codefile;
|
||||||
|
|
||||||
|
out_init(filename) char *filename; {
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
static char stderrbuff[512];
|
||||||
|
|
||||||
|
if (Debug) {
|
||||||
|
codefile = stderr;
|
||||||
|
if (!isatty(2))
|
||||||
|
setbuf(stderr,stderrbuff);
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
|
if (filename == (char *) 0)
|
||||||
|
codefile = stdout;
|
||||||
|
else
|
||||||
|
if ((codefile=freopen(filename,"w",stdout))==NULL)
|
||||||
|
error("Can't create %s",filename);
|
||||||
|
#ifndef NDEBUG
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
out_finish() {
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (Debug)
|
||||||
|
fflush(stderr);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
fclose(codefile);
|
||||||
|
}
|
||||||
|
|
||||||
|
tstoutput() {
|
||||||
|
|
||||||
|
if (ferror(codefile))
|
||||||
|
error("Write error on output");
|
||||||
|
}
|
||||||
|
|
||||||
|
gencode(code) register char *code; {
|
||||||
|
register c;
|
||||||
|
int tokno,fldno,insno,regno,subno;
|
||||||
|
register token_p tp;
|
||||||
|
|
||||||
|
swtxt();
|
||||||
|
while ((c= *code++)!=0) switch(c) {
|
||||||
|
default:
|
||||||
|
fputc(c,codefile);
|
||||||
|
break;
|
||||||
|
case PR_TOK:
|
||||||
|
tokno = *code++;
|
||||||
|
tp = &fakestack[stackheight-tokno];
|
||||||
|
if (tp->t_token==-1)
|
||||||
|
fprintf(codefile,"%s",codestrings[machregs[tp->t_att[0].ar].r_repr]);
|
||||||
|
else
|
||||||
|
prtoken(tp);
|
||||||
|
break;
|
||||||
|
case PR_TOKFLD:
|
||||||
|
tokno = *code++;
|
||||||
|
fldno = *code++;
|
||||||
|
tp = &fakestack[stackheight-tokno];
|
||||||
|
assert(tp->t_token != -1);
|
||||||
|
switch(tokens[tp->t_token].t_type[fldno-1]) {
|
||||||
|
default:
|
||||||
|
assert(FALSE);
|
||||||
|
case EV_INT:
|
||||||
|
fprintf(codefile,WRD_FMT,tp->t_att[fldno-1].aw);
|
||||||
|
break;
|
||||||
|
case EV_STR:
|
||||||
|
fprintf(codefile,"%s",tp->t_att[fldno-1].as);
|
||||||
|
break;
|
||||||
|
case EV_REG:
|
||||||
|
assert(tp->t_att[fldno-1].ar>0 && tp->t_att[fldno-1].ar<NREGS);
|
||||||
|
fprintf(codefile,"%s",codestrings[machregs[tp->t_att[fldno-1].ar].r_repr]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PR_EMINT:
|
||||||
|
insno = *code++;
|
||||||
|
fprintf(codefile,WRD_FMT,dollar[insno-1].e_v.e_con);
|
||||||
|
break;
|
||||||
|
case PR_EMSTR:
|
||||||
|
insno = *code++;
|
||||||
|
fprintf(codefile,"%s",dollar[insno-1].e_v.e_str);
|
||||||
|
break;
|
||||||
|
case PR_ALLREG:
|
||||||
|
regno = *code++;
|
||||||
|
subno = (*code++)&0377;
|
||||||
|
assert(regno>=1 && regno<=nallreg);
|
||||||
|
regno = allreg[regno-1];
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (subno!=255) {
|
||||||
|
assert(subno>=1 && subno<=MAXMEMBERS);
|
||||||
|
regno = machregs[regno].r_members[subno-1];
|
||||||
|
assert(regno!=0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
fprintf(codefile,"%s",codestrings[machregs[regno].r_repr]);
|
||||||
|
break;
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
case PR_SUBREG:
|
||||||
|
tokno = *code++;
|
||||||
|
subno = *code++;
|
||||||
|
tp = &fakestack[stackheight-tokno];
|
||||||
|
assert(tp->t_token == -1);
|
||||||
|
fprintf(codefile,"%s",codestrings[machregs[machregs[tp->t_att[0].ar].r_members[subno-1]].r_repr]);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
genexpr(nodeno) {
|
||||||
|
result_t result;
|
||||||
|
|
||||||
|
result= compute(&enodes[nodeno]);
|
||||||
|
switch(result.e_typ) {
|
||||||
|
default: assert(FALSE);
|
||||||
|
case EV_INT:
|
||||||
|
fprintf(codefile,WRD_FMT,result.e_v.e_con);
|
||||||
|
break;
|
||||||
|
case EV_REG:
|
||||||
|
fprintf(codefile,"%s", codestrings[machregs[result.e_v.e_reg].r_repr]);
|
||||||
|
break;
|
||||||
|
case EV_STR:
|
||||||
|
fprintf(codefile,"%s",result.e_v.e_str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gennl() {
|
||||||
|
fputc('\n',codefile);
|
||||||
|
}
|
||||||
|
|
||||||
|
prtoken(tp) token_p tp; {
|
||||||
|
register c;
|
||||||
|
register char *code;
|
||||||
|
register tkdef_p tdp;
|
||||||
|
|
||||||
|
tdp = &tokens[tp->t_token];
|
||||||
|
assert(tdp->t_format != -1);
|
||||||
|
code = codestrings[tdp->t_format];
|
||||||
|
while ((c = *code++) != 0) {
|
||||||
|
if (c>=' ' && c<='~')
|
||||||
|
fputc(c,codefile);
|
||||||
|
else {
|
||||||
|
assert(c>0 && c<=TOKENSIZE);
|
||||||
|
switch(tdp->t_type[c-1]) {
|
||||||
|
default:
|
||||||
|
assert(FALSE);
|
||||||
|
case EV_INT:
|
||||||
|
fprintf(codefile,WRD_FMT,tp->t_att[c-1].aw);
|
||||||
|
break;
|
||||||
|
case EV_STR:
|
||||||
|
fprintf(codefile,"%s",tp->t_att[c-1].as);
|
||||||
|
break;
|
||||||
|
case EV_REG:
|
||||||
|
fprintf(codefile,"%s",codestrings[machregs[tp->t_att[c-1].ar].r_repr]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
52
mach/proto/cg/glosym.c
Normal file
52
mach/proto/cg/glosym.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "glosym.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern string myalloc();
|
||||||
|
|
||||||
|
glosym_p glolist= (glosym_p) 0;
|
||||||
|
|
||||||
|
enterglo(name,romp) string name; word *romp; {
|
||||||
|
register glosym_p gp;
|
||||||
|
register i;
|
||||||
|
|
||||||
|
gp = (glosym_p) myalloc(sizeof *gp);
|
||||||
|
gp->gl_next = glolist;
|
||||||
|
gp->gl_name = (string) myalloc(strlen(name)+1);
|
||||||
|
strcpy(gp->gl_name,name);
|
||||||
|
for (i=0;i<=MAXROM;i++)
|
||||||
|
gp->gl_rom[i] = romp[i];
|
||||||
|
glolist = gp;
|
||||||
|
}
|
||||||
|
|
||||||
|
glosym_p lookglo(name) string name; {
|
||||||
|
register glosym_p gp;
|
||||||
|
|
||||||
|
for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next)
|
||||||
|
if (strcmp(gp->gl_name,name)==0)
|
||||||
|
return(gp);
|
||||||
|
return((glosym_p) 0);
|
||||||
|
}
|
||||||
9
mach/proto/cg/glosym.h
Normal file
9
mach/proto/cg/glosym.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
typedef struct glosym {
|
||||||
|
struct glosym *gl_next;
|
||||||
|
string gl_name;
|
||||||
|
word gl_rom[MAXROM+1];
|
||||||
|
} glosym_t,*glosym_p;
|
||||||
|
|
||||||
|
glosym_p lookglo();
|
||||||
84
mach/proto/cg/main.c
Normal file
84
mach/proto/cg/main.c
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *progname;
|
||||||
|
extern char startupcode[];
|
||||||
|
int maxply=1;
|
||||||
|
#ifndef NDEBUG
|
||||||
|
int Debug=0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern int endofprog;
|
||||||
|
|
||||||
|
main(argc,argv) char **argv; {
|
||||||
|
register unsigned n;
|
||||||
|
extern unsigned cc1,cc2,cc3,cc4;
|
||||||
|
unsigned ggd();
|
||||||
|
|
||||||
|
progname = argv[0];
|
||||||
|
while (--argc && **++argv == '-') {
|
||||||
|
switch(argv[0][1]) {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
case 'd':
|
||||||
|
Debug=1; break;
|
||||||
|
#endif
|
||||||
|
case 'p':
|
||||||
|
maxply = atoi(argv[0]+2);
|
||||||
|
break;
|
||||||
|
case 'w': /* weight percentage for size */
|
||||||
|
n=atoi(argv[0]+2);
|
||||||
|
cc1 *= n;
|
||||||
|
cc2 *= 50;
|
||||||
|
cc3 *= (100-n);
|
||||||
|
cc4 *= 50;
|
||||||
|
n=ggd(cc1,cc2);
|
||||||
|
cc1 /= n;
|
||||||
|
cc2 /= n;
|
||||||
|
n=ggd(cc3,cc4);
|
||||||
|
cc3 /= n;
|
||||||
|
cc4 /= n;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error("Unknown flag %c",argv[0][1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (argc < 1 || argc > 2)
|
||||||
|
error("Usage: %s EMfile [ asfile ]",progname);
|
||||||
|
in_init(argv[0]);
|
||||||
|
out_init(argv[1]);
|
||||||
|
codegen(startupcode,maxply,TRUE,MAXINT,0);
|
||||||
|
in_finish();
|
||||||
|
if (!endofprog)
|
||||||
|
error("Bombed out of codegen");
|
||||||
|
out_finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned ggd(a,b) register unsigned a,b; {
|
||||||
|
register unsigned c;
|
||||||
|
|
||||||
|
do {
|
||||||
|
c = a%b; a=b; b=c;
|
||||||
|
} while (c!=0);
|
||||||
|
return(a);
|
||||||
|
}
|
||||||
110
mach/proto/cg/move.c
Normal file
110
mach/proto/cg/move.c
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned costcalc();
|
||||||
|
|
||||||
|
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
|
||||||
|
register move_p mp;
|
||||||
|
register unsigned t;
|
||||||
|
register struct reginfo *rp;
|
||||||
|
tkdef_p tdp;
|
||||||
|
int i;
|
||||||
|
unsigned codegen();
|
||||||
|
|
||||||
|
if (eqtoken(tp1,tp2))
|
||||||
|
return(0);
|
||||||
|
if (tp2->t_token == -1) {
|
||||||
|
if (tp1->t_token == -1) {
|
||||||
|
if (eqtoken(&machregs[tp1->t_att[0].ar].r_contents,
|
||||||
|
&machregs[tp2->t_att[0].ar].r_contents) &&
|
||||||
|
machregs[tp1->t_att[0].ar].r_contents.t_token!=0)
|
||||||
|
return(0);
|
||||||
|
if (tp1->t_att[0].ar!=1) { /* COCO reg; tmp kludge */
|
||||||
|
erasereg(tp2->t_att[0].ar);
|
||||||
|
machregs[tp2->t_att[0].ar].r_contents =
|
||||||
|
machregs[tp1->t_att[0].ar].r_contents ;
|
||||||
|
} else
|
||||||
|
machregs[tp1->t_att[0].ar].r_contents =
|
||||||
|
machregs[tp2->t_att[0].ar].r_contents ;
|
||||||
|
} else {
|
||||||
|
if (eqtoken(&machregs[tp2->t_att[0].ar].r_contents,tp1))
|
||||||
|
return(0);
|
||||||
|
machregs[tp2->t_att[0].ar].r_contents = *tp1;
|
||||||
|
}
|
||||||
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||||
|
if (rp->r_contents.t_token == 0)
|
||||||
|
continue;
|
||||||
|
assert(rp->r_contents.t_token > 0);
|
||||||
|
tdp = &tokens[rp->r_contents.t_token];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
if (tdp->t_type[i] == EV_REG &&
|
||||||
|
clash(rp->r_contents.t_att[i].ar,tp2->t_att[0].ar)) {
|
||||||
|
erasereg(rp-machregs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (tp1->t_token == -1) {
|
||||||
|
if (eqtoken(tp2,&machregs[tp1->t_att[0].ar].r_contents))
|
||||||
|
return(0);
|
||||||
|
machregs[tp1->t_att[0].ar].r_contents = *tp2;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* If we arrive here the move must really be executed
|
||||||
|
*/
|
||||||
|
for (mp=moves;mp<moves+NMOVES;mp++) {
|
||||||
|
if (!match(tp1,&machsets[mp->m_set1],mp->m_expr1))
|
||||||
|
continue;
|
||||||
|
if (match(tp2,&machsets[mp->m_set2],mp->m_expr2))
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* Correct move rule is found
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
assert(mp<moves+NMOVES);
|
||||||
|
/*
|
||||||
|
* To get correct interpretation of things like %[1]
|
||||||
|
* in move code we stack tp2 and tp1. This little trick
|
||||||
|
* saves a lot of testing in other places.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (mp->m_cindex!=0) {
|
||||||
|
fakestack[stackheight] = *tp2;
|
||||||
|
fakestack[stackheight+1] = *tp1;
|
||||||
|
stackheight += 2;
|
||||||
|
t = codegen(&coderules[mp->m_cindex],ply,toplevel,maxcost,0);
|
||||||
|
if (t <= maxcost)
|
||||||
|
t += costcalc(mp->m_cost);
|
||||||
|
stackheight -= 2;
|
||||||
|
} else {
|
||||||
|
t = 0;
|
||||||
|
}
|
||||||
|
return(t);
|
||||||
|
}
|
||||||
131
mach/proto/cg/nextem.c
Normal file
131
mach/proto/cg/nextem.c
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <em_spec.h>
|
||||||
|
#include <em_flag.h>
|
||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#include <stdio.h>
|
||||||
|
extern char em_mnem[][4];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
byte *trypat(bp,len) register byte *bp; {
|
||||||
|
register patlen,i;
|
||||||
|
result_t result;
|
||||||
|
|
||||||
|
getint(patlen,bp);
|
||||||
|
if (len == 3) {
|
||||||
|
if (patlen < 3)
|
||||||
|
return(0);
|
||||||
|
} else {
|
||||||
|
if (patlen != len)
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
for(i=0;i<patlen;i++)
|
||||||
|
if (emp[i].em_instr != (*bp++&BMASK))
|
||||||
|
return(0);
|
||||||
|
for (i=0;i<patlen;i++)
|
||||||
|
if (emp[i].em_optyp==OPNO)
|
||||||
|
dollar[i].e_typ=EV_UNDEF;
|
||||||
|
else if ((dollar[i].e_typ=argtyp(emp[i].em_instr))==EV_INT)
|
||||||
|
dollar[i].e_v.e_con=emp[i].em_u.em_ioper;
|
||||||
|
else
|
||||||
|
dollar[i].e_v.e_str=emp[i].em_soper;
|
||||||
|
getint(i,bp);
|
||||||
|
if (i!=0) {
|
||||||
|
result = compute(&enodes[i]);
|
||||||
|
if (result.e_typ != EV_INT || result.e_v.e_con == 0)
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (Debug) {
|
||||||
|
fprintf(stderr,"Matched:");
|
||||||
|
for (i=0;i<patlen;i++)
|
||||||
|
fprintf(stderr," %3.3s",em_mnem[emp[i].em_instr-sp_fmnem]);
|
||||||
|
fprintf(stderr,"\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
saveemp = emp;
|
||||||
|
emp += patlen;
|
||||||
|
return(bp);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern char em_flag[];
|
||||||
|
|
||||||
|
argtyp(mn) {
|
||||||
|
|
||||||
|
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
|
||||||
|
case PAR_W:
|
||||||
|
case PAR_S:
|
||||||
|
case PAR_Z:
|
||||||
|
case PAR_O:
|
||||||
|
case PAR_N:
|
||||||
|
case PAR_L:
|
||||||
|
case PAR_F:
|
||||||
|
case PAR_R:
|
||||||
|
case PAR_C:
|
||||||
|
return(EV_INT);
|
||||||
|
default:
|
||||||
|
return(EV_STR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte *nextem(toplevel) {
|
||||||
|
register i;
|
||||||
|
short hash[3];
|
||||||
|
register byte *bp;
|
||||||
|
byte *cp;
|
||||||
|
int index;
|
||||||
|
register struct emline *ep;
|
||||||
|
|
||||||
|
if (toplevel) {
|
||||||
|
if (nemlines && emp>emlines) {
|
||||||
|
nemlines -= emp-emlines;
|
||||||
|
for (i=0,ep=emlines;i<nemlines;i++)
|
||||||
|
*ep++ = *emp++;
|
||||||
|
emp=emlines;
|
||||||
|
}
|
||||||
|
fillemlines();
|
||||||
|
}
|
||||||
|
hash[0] = emp[0].em_instr;
|
||||||
|
hash[1] = (hash[0]<<4) ^ emp[1].em_instr;
|
||||||
|
hash[2] = (hash[1]<<4) ^ emp[2].em_instr;
|
||||||
|
for (i=2;i>=0;i--) {
|
||||||
|
index = pathash[hash[i]&BMASK];
|
||||||
|
while (index != 0) {
|
||||||
|
bp = &pattern[index];
|
||||||
|
if ( bp[PO_HASH] == (hash[i]>>8))
|
||||||
|
if ((cp=trypat(&bp[PO_MATCH],i+1)) != 0)
|
||||||
|
return(cp);
|
||||||
|
index = (bp[PO_NEXT]&BMASK) | (bp[PO_NEXT+1]<<8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
19
mach/proto/cg/param.h
Normal file
19
mach/proto/cg/param.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#define BMASK 0377
|
||||||
|
#define BSHIFT 8
|
||||||
|
|
||||||
|
#define TRUE 1
|
||||||
|
#define FALSE 0
|
||||||
|
|
||||||
|
#define MAXINT 32767
|
||||||
|
#define INFINITY (MAXINT+100)
|
||||||
|
|
||||||
|
#define MAXROM 3
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tunable constants
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAXEMLINES 20
|
||||||
|
#define MAXFSTACK 20
|
||||||
175
mach/proto/cg/reg.c
Normal file
175
mach/proto/cg/reg.c
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
chrefcount(regno,amount,tflag) {
|
||||||
|
register struct reginfo *rp;
|
||||||
|
register i;
|
||||||
|
|
||||||
|
rp= &machregs[regno];
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (rp->r_members[0]==0) {
|
||||||
|
#endif
|
||||||
|
rp->r_refcount += amount;
|
||||||
|
if (tflag)
|
||||||
|
rp->r_tcount += amount;
|
||||||
|
assert(rp->r_refcount >= 0);
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
} else
|
||||||
|
for (i=0;i<MAXMEMBERS;i++)
|
||||||
|
if (rp->r_members[i]!=0)
|
||||||
|
chrefcount(rp->r_members[i],amount,tflag);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
getrefcount(regno) {
|
||||||
|
register struct reginfo *rp;
|
||||||
|
register i,maxcount;
|
||||||
|
|
||||||
|
rp= &machregs[regno];
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (rp->r_members[0]==0)
|
||||||
|
#endif
|
||||||
|
return(rp->r_refcount);
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
else {
|
||||||
|
maxcount=0;
|
||||||
|
for (i=0;i<MAXMEMBERS;i++)
|
||||||
|
if (rp->r_members[i]!=0)
|
||||||
|
maxcount=max(maxcount,getrefcount(rp->r_members[i]));
|
||||||
|
return(maxcount);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
erasereg(regno) {
|
||||||
|
register struct reginfo *rp;
|
||||||
|
|
||||||
|
#if MAXMEMBERS==0
|
||||||
|
awayreg(regno);
|
||||||
|
#else
|
||||||
|
for (rp=machregs;rp<machregs+NREGS;rp++)
|
||||||
|
if (rp->r_clash[regno>>4]&(1<<(regno&017)))
|
||||||
|
awayreg(rp-machregs);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
awayreg(regno) {
|
||||||
|
register struct reginfo *rp;
|
||||||
|
register tkdef_p tdp;
|
||||||
|
register i;
|
||||||
|
|
||||||
|
rp = &machregs[regno];
|
||||||
|
rp->r_contents.t_token = 0;
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
rp->r_contents.t_att[i].aw = 0;
|
||||||
|
|
||||||
|
/* Now erase recursively all registers containing
|
||||||
|
* something using this one
|
||||||
|
*/
|
||||||
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||||
|
if (rp->r_contents.t_token == -1) {
|
||||||
|
if (rp->r_contents.t_att[0].ar == regno)
|
||||||
|
erasereg(rp-machregs);
|
||||||
|
} else {
|
||||||
|
tdp= & tokens[rp->r_contents.t_token];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
if (tdp->t_type[i] == EV_REG &&
|
||||||
|
rp->r_contents.t_att[i].ar == regno) {
|
||||||
|
erasereg(rp-machregs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanregs() {
|
||||||
|
register struct reginfo *rp;
|
||||||
|
register i;
|
||||||
|
|
||||||
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||||
|
rp->r_contents.t_token = 0;
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
rp->r_contents.t_att[i].aw = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
inctcount(regno) {
|
||||||
|
register struct reginfo *rp;
|
||||||
|
register i;
|
||||||
|
|
||||||
|
rp = &machregs[regno];
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (rp->r_members[0] == 0) {
|
||||||
|
#endif
|
||||||
|
rp->r_tcount++;
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
} else {
|
||||||
|
for (i=0;i<MAXMEMBERS;i++)
|
||||||
|
if (rp->r_members[i] != 0)
|
||||||
|
inctcount(rp->r_members[i]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
chkregs() {
|
||||||
|
register struct reginfo *rp;
|
||||||
|
register token_p tp;
|
||||||
|
register tkdef_p tdp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||||
|
assert(rp->r_tcount==0);
|
||||||
|
}
|
||||||
|
for (tp=fakestack;tp<fakestack+stackheight;tp++) {
|
||||||
|
if (tp->t_token == -1)
|
||||||
|
inctcount(tp->t_att[0].ar);
|
||||||
|
else {
|
||||||
|
tdp = &tokens[tp->t_token];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
if (tdp->t_type[i]==EV_REG)
|
||||||
|
inctcount(tp->t_att[i].ar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef REGVARS
|
||||||
|
#include <em_reg.h>
|
||||||
|
for(i=reg_any;i<=reg_float;i++) {
|
||||||
|
int j;
|
||||||
|
for(j=0;j<nregvar[i];j++)
|
||||||
|
inctcount(rvnumbers[i][j]);
|
||||||
|
}
|
||||||
|
#endif REGVARS
|
||||||
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||||
|
assert(rp->r_refcount==rp->r_tcount);
|
||||||
|
rp->r_tcount=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
151
mach/proto/cg/regvar.c
Normal file
151
mach/proto/cg/regvar.c
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
|
||||||
|
#ifdef REGVARS
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "regvar.h"
|
||||||
|
#include <em_reg.h>
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct regvar *rvlist;
|
||||||
|
|
||||||
|
struct regvar *
|
||||||
|
linkreg(of,sz,tp,sc) long of; {
|
||||||
|
struct regvar *rvlp;
|
||||||
|
|
||||||
|
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
|
||||||
|
rvlp->rv_next = rvlist;
|
||||||
|
rvlist=rvlp;
|
||||||
|
rvlp->rv_off = of;
|
||||||
|
rvlp->rv_size = sz;
|
||||||
|
rvlp->rv_type = tp;
|
||||||
|
rvlp->rv_score = sc;
|
||||||
|
rvlp->rv_reg = 0; /* no register assigned yet */
|
||||||
|
return(rvlp);
|
||||||
|
}
|
||||||
|
|
||||||
|
tryreg(rvlp,typ) struct regvar *rvlp; {
|
||||||
|
int score;
|
||||||
|
register i;
|
||||||
|
struct regassigned *ra;
|
||||||
|
struct regvar *save;
|
||||||
|
|
||||||
|
if (typ != reg_any && nregvar[typ]!=0) {
|
||||||
|
if (machregs[rvnumbers[typ][0]].r_size!=rvlp->rv_size)
|
||||||
|
score = -1;
|
||||||
|
else
|
||||||
|
score = regscore(rvlp->rv_off,
|
||||||
|
rvlp->rv_size,
|
||||||
|
rvlp->rv_type,
|
||||||
|
rvlp->rv_score,
|
||||||
|
typ); /* machine dependent */
|
||||||
|
ra = regassigned[typ];
|
||||||
|
if (score>ra[nregvar[typ]-1].ra_score) {
|
||||||
|
save = ra[nregvar[typ]-1].ra_rv;
|
||||||
|
for (i=nregvar[typ]-1;i>0 && ra[i-1].ra_score<score;i--)
|
||||||
|
ra[i] = ra[i-1];
|
||||||
|
ra[i].ra_rv = rvlp;
|
||||||
|
ra[i].ra_score = score;
|
||||||
|
if((rvlp=save)==0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nregvar[reg_any]==0)
|
||||||
|
return;
|
||||||
|
if (machregs[rvnumbers[reg_any][0]].r_size!=rvlp->rv_size)
|
||||||
|
score = -1;
|
||||||
|
else
|
||||||
|
score = regscore(rvlp->rv_off,
|
||||||
|
rvlp->rv_size,
|
||||||
|
rvlp->rv_type,
|
||||||
|
rvlp->rv_score,
|
||||||
|
reg_any); /* machine dependent */
|
||||||
|
ra = regassigned[reg_any];
|
||||||
|
if (score>ra[nregvar[reg_any]-1].ra_score) {
|
||||||
|
for (i=nregvar[reg_any]-1;i>0 && ra[i-1].ra_score<score;i--)
|
||||||
|
ra[i] = ra[i-1];
|
||||||
|
ra[i].ra_rv = rvlp;
|
||||||
|
ra[i].ra_score = score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixregvars(saveall) {
|
||||||
|
register struct regvar *rv;
|
||||||
|
register rvtyp,i;
|
||||||
|
|
||||||
|
swtxt();
|
||||||
|
i_regsave(); /* machine dependent initialization */
|
||||||
|
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
|
||||||
|
for(i=0;i<nregvar[rvtyp];i++)
|
||||||
|
if (saveall) {
|
||||||
|
struct reginfo *rp;
|
||||||
|
rp= &machregs[rvnumbers[rvtyp][i]];
|
||||||
|
regsave(codestrings[rp->r_repr],-EM_WSIZE,rp->r_size);
|
||||||
|
} else if(regassigned[rvtyp][i].ra_score>0) {
|
||||||
|
rv=regassigned[rvtyp][i].ra_rv;
|
||||||
|
rv->rv_reg=rvnumbers[rvtyp][i];
|
||||||
|
regsave(codestrings[machregs[rv->rv_reg].r_repr],
|
||||||
|
rv->rv_off,rv->rv_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f_regsave();
|
||||||
|
#ifndef EM_BSIZE
|
||||||
|
for(rv=rvlist;rv!=0;rv=rv->rv_next)
|
||||||
|
if (rv->rv_off >= 0) rv->rv_off += EM_BSIZE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
isregvar(off) long off; {
|
||||||
|
register struct regvar *rvlp;
|
||||||
|
|
||||||
|
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
||||||
|
if(rvlp->rv_off == off)
|
||||||
|
return(rvlp->rv_reg);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unlinkregs() {
|
||||||
|
register struct regvar *rvlp,*t;
|
||||||
|
register struct regassigned *ra;
|
||||||
|
int rvtyp,i;
|
||||||
|
|
||||||
|
for(rvlp=rvlist;rvlp!=0;rvlp=t) {
|
||||||
|
t=rvlp->rv_next;
|
||||||
|
myfree(rvlp);
|
||||||
|
}
|
||||||
|
rvlist=0;
|
||||||
|
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
|
||||||
|
for(i=0;i<nregvar[rvtyp];i++) {
|
||||||
|
ra= ®assigned[rvtyp][i];
|
||||||
|
ra->ra_rv = 0;
|
||||||
|
ra->ra_score = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif REGVARS
|
||||||
|
|
||||||
|
/* nothing after this */
|
||||||
19
mach/proto/cg/regvar.h
Normal file
19
mach/proto/cg/regvar.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
struct regvar {
|
||||||
|
struct regvar *rv_next;
|
||||||
|
long rv_off;
|
||||||
|
int rv_size;
|
||||||
|
int rv_type;
|
||||||
|
int rv_score;
|
||||||
|
int rv_reg;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct regassigned {
|
||||||
|
struct regvar *ra_rv;
|
||||||
|
int ra_score;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct regvar *rvlist;
|
||||||
|
extern int nregvar[];
|
||||||
|
extern struct regassigned *regassigned[];
|
||||||
19
mach/proto/cg/result.h
Normal file
19
mach/proto/cg/result.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
struct result {
|
||||||
|
int e_typ; /* EV_INT,EV_REG,EV_STR */
|
||||||
|
union {
|
||||||
|
word e_con;
|
||||||
|
int e_reg;
|
||||||
|
string e_str;
|
||||||
|
} e_v; /* value */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define EV_UNDEF 0
|
||||||
|
#define EV_INT 1
|
||||||
|
#define EV_REG 2
|
||||||
|
#define EV_STR 3
|
||||||
|
|
||||||
|
typedef struct result result_t;
|
||||||
|
|
||||||
|
extern result_t compute();
|
||||||
150
mach/proto/cg/salloc.c
Normal file
150
mach/proto/cg/salloc.c
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Package for string allocation and garbage collection.
|
||||||
|
* Call salloc(size) to get room for string.
|
||||||
|
* Every now and then call garbage_collect() from toplevel.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAXSTAB 500
|
||||||
|
#define THRESHOLD 200
|
||||||
|
|
||||||
|
char *stab[MAXSTAB];
|
||||||
|
int nstab=0;
|
||||||
|
string malloc();
|
||||||
|
|
||||||
|
string myalloc(size) {
|
||||||
|
register string p;
|
||||||
|
|
||||||
|
p = (string) malloc(size);
|
||||||
|
if (p==0)
|
||||||
|
fatal("Out of memory");
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
myfree(p) string p; {
|
||||||
|
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
popstr(nnstab) {
|
||||||
|
register i;
|
||||||
|
|
||||||
|
for (i=nnstab;i<nstab;i++)
|
||||||
|
myfree(stab[i]);
|
||||||
|
nstab = nnstab;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *salloc(size) {
|
||||||
|
register char *p;
|
||||||
|
|
||||||
|
if (nstab==MAXSTAB)
|
||||||
|
fatal("String table overflow");
|
||||||
|
p = myalloc(size+1); /* extra room for terminating zero */
|
||||||
|
stab[nstab++] = p;
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
compar(p1,p2) char **p1,**p2; {
|
||||||
|
|
||||||
|
assert(*p1 != *p2);
|
||||||
|
if (*p1 < *p2)
|
||||||
|
return(-1);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
garbage_collect() {
|
||||||
|
register i;
|
||||||
|
struct emline *emlp;
|
||||||
|
token_p tp;
|
||||||
|
tkdef_p tdp;
|
||||||
|
struct reginfo *rp;
|
||||||
|
register char **fillp,**scanp;
|
||||||
|
char used[MAXSTAB]; /* could be bitarray */
|
||||||
|
|
||||||
|
if (nstab<THRESHOLD)
|
||||||
|
return;
|
||||||
|
qsort(stab,nstab,sizeof (char *),compar);
|
||||||
|
for (i=0;i<nstab;i++)
|
||||||
|
used[i]= FALSE;
|
||||||
|
for(emlp=emlines;emlp<emlines+nemlines;emlp++)
|
||||||
|
chkstr(emlp->em_soper,used);
|
||||||
|
for (tp= fakestack;tp<&fakestack[stackheight];tp++) {
|
||||||
|
if (tp->t_token== -1)
|
||||||
|
continue;
|
||||||
|
tdp = &tokens[tp->t_token];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
if (tdp->t_type[i] == EV_STR)
|
||||||
|
chkstr(tp->t_att[i].as,used);
|
||||||
|
}
|
||||||
|
for (rp= machregs; rp<machregs+NREGS; rp++) {
|
||||||
|
tp = &rp->r_contents;
|
||||||
|
assert(tp->t_token != -1);
|
||||||
|
tdp= &tokens[tp->t_token];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
if (tdp->t_type[i] == EV_STR)
|
||||||
|
chkstr(tp->t_att[i].as,used);
|
||||||
|
}
|
||||||
|
for (i=0;i<nstab;i++)
|
||||||
|
if (!used[i]) {
|
||||||
|
myfree(stab[i]);
|
||||||
|
stab[i]=0;
|
||||||
|
}
|
||||||
|
fillp=stab;
|
||||||
|
for (scanp=stab;scanp<stab+nstab;scanp++)
|
||||||
|
if (*scanp != 0)
|
||||||
|
*fillp++ = *scanp;
|
||||||
|
nstab = fillp-stab;
|
||||||
|
}
|
||||||
|
|
||||||
|
chkstr(str,used) string str; char used[]; {
|
||||||
|
register low,middle,high;
|
||||||
|
|
||||||
|
low=0; high=nstab-1;
|
||||||
|
while (high>low) {
|
||||||
|
middle= (low+high)>>1;
|
||||||
|
if (str==stab[middle]) {
|
||||||
|
used[middle]=1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (str<stab[middle])
|
||||||
|
high = middle-1;
|
||||||
|
else
|
||||||
|
low = middle+1;
|
||||||
|
}
|
||||||
|
if (low==high) {
|
||||||
|
if (str==stab[low]) {
|
||||||
|
used[low]=1;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
104
mach/proto/cg/state.c
Normal file
104
mach/proto/cg/state.c
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "state.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int nstab; /* salloc.c */
|
||||||
|
|
||||||
|
#ifndef STONSTACK
|
||||||
|
extern string myalloc();
|
||||||
|
|
||||||
|
state_p stlist=0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STONSTACK
|
||||||
|
savestatus(sp) register state_p sp; {
|
||||||
|
#else
|
||||||
|
state_p savestatus() {
|
||||||
|
register state_p sp;
|
||||||
|
|
||||||
|
if ((sp=stlist)==0)
|
||||||
|
sp = (state_p) myalloc( sizeof( *sp ) );
|
||||||
|
else
|
||||||
|
stlist=sp->st_next;
|
||||||
|
#endif
|
||||||
|
sp->st_sh = stackheight;
|
||||||
|
bmove((short *)fakestack,(short *)sp->st_fs,stackheight*sizeof(token_t));
|
||||||
|
sp->st_na = nallreg;
|
||||||
|
bmove((short *)allreg,(short *)sp->st_ar,nallreg*sizeof(int));
|
||||||
|
sp->st_ct = curtoken;
|
||||||
|
bmove((short *)dollar,(short *)sp->st_do,LONGESTPATTERN*sizeof(result_t));
|
||||||
|
bmove((short *)machregs,(short *)sp->st_mr,NREGS*sizeof(struct reginfo));
|
||||||
|
sp->st_ne = nemlines;
|
||||||
|
bmove((short *)emlines,(short *)sp->st_el,nemlines*sizeof(struct emline));
|
||||||
|
sp->st_em = emp;
|
||||||
|
sp->st_se = saveemp;
|
||||||
|
sp->st_tl = tokpatlen;
|
||||||
|
sp->st_ns = nstab;
|
||||||
|
#ifndef STONSTACK
|
||||||
|
return(sp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
restorestatus(sp) register state_p sp; {
|
||||||
|
|
||||||
|
stackheight = sp->st_sh;
|
||||||
|
bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
|
||||||
|
nallreg = sp->st_na;
|
||||||
|
bmove((short *)sp->st_ar,(short *)allreg,nallreg*sizeof(int));
|
||||||
|
curtoken = sp->st_ct;
|
||||||
|
bmove((short *)sp->st_do,(short *)dollar,LONGESTPATTERN*sizeof(result_t));
|
||||||
|
bmove((short *)sp->st_mr,(short *)machregs,NREGS*sizeof(struct reginfo));
|
||||||
|
nemlines = sp->st_ne;
|
||||||
|
bmove((short *)sp->st_el,(short *)emlines,nemlines*sizeof(struct emline));
|
||||||
|
emp = sp->st_em;
|
||||||
|
saveemp = sp->st_se;
|
||||||
|
tokpatlen = sp->st_tl;
|
||||||
|
popstr(sp->st_ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef STONSTACK
|
||||||
|
freestatus(sp) state_p sp; {
|
||||||
|
|
||||||
|
sp->st_next = stlist;
|
||||||
|
stlist = sp;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bmove(from,to,nbytes) register short *from,*to; register nbytes; {
|
||||||
|
|
||||||
|
if (nbytes<=0)
|
||||||
|
return;
|
||||||
|
assert(sizeof(short)==2 && (nbytes&1)==0);
|
||||||
|
nbytes>>=1;
|
||||||
|
do
|
||||||
|
*to++ = *from++;
|
||||||
|
while (--nbytes);
|
||||||
|
}
|
||||||
24
mach/proto/cg/state.h
Normal file
24
mach/proto/cg/state.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#define STONSTACK /* if defined state is saved in stackframe */
|
||||||
|
|
||||||
|
typedef struct state {
|
||||||
|
struct state *st_next; /* for linked list */
|
||||||
|
int st_sh; /* stackheight */
|
||||||
|
token_t st_fs[MAXFSTACK]; /* fakestack */
|
||||||
|
int st_na; /* nallreg */
|
||||||
|
int st_ar[MAXALLREG]; /* allreg[] */
|
||||||
|
token_p st_ct; /* curtoken */
|
||||||
|
result_t st_do[LONGESTPATTERN]; /* dollar[] */
|
||||||
|
struct reginfo st_mr[NREGS]; /* machregs[] */
|
||||||
|
int st_ne; /* nemlines */
|
||||||
|
struct emline st_el[MAXEMLINES]; /* emlines[] */
|
||||||
|
struct emline *st_em; /* emp */
|
||||||
|
struct emline *st_se; /* saveemp */
|
||||||
|
int st_tl; /* tokpatlen */
|
||||||
|
int st_ns; /* nstab */
|
||||||
|
} state_t,*state_p;
|
||||||
|
|
||||||
|
#ifndef STONSTACK
|
||||||
|
state_p savestatus();
|
||||||
|
#endif
|
||||||
547
mach/proto/cg/subr.c
Normal file
547
mach/proto/cg/subr.c
Normal file
@ -0,0 +1,547 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
string myalloc();
|
||||||
|
unsigned codegen();
|
||||||
|
|
||||||
|
match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
||||||
|
register bitno;
|
||||||
|
token_p ct;
|
||||||
|
result_t result;
|
||||||
|
|
||||||
|
if (tp->t_token == -1) { /* register frame */
|
||||||
|
bitno = tp->t_att[0].ar+1;
|
||||||
|
if (tep->set_val[bitno>>4]&(1<<(bitno&017)))
|
||||||
|
if (tep->set_val[0]&1 || getrefcount(tp->t_att[0].ar)<=1)
|
||||||
|
goto oklabel;
|
||||||
|
return(0);
|
||||||
|
} else { /* token frame */
|
||||||
|
bitno = tp->t_token+NREGS+1;
|
||||||
|
if ((tep->set_val[bitno>>4]&(1<<(bitno&017)))==0)
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
oklabel:
|
||||||
|
if (optexp==0)
|
||||||
|
return(1);
|
||||||
|
ct=curtoken;
|
||||||
|
curtoken=tp;
|
||||||
|
result=compute(&enodes[optexp]);
|
||||||
|
curtoken=ct;
|
||||||
|
return(result.e_v.e_con);
|
||||||
|
}
|
||||||
|
|
||||||
|
instance(instno,token) token_p token; {
|
||||||
|
inst_p inp;
|
||||||
|
int i;
|
||||||
|
token_p tp;
|
||||||
|
struct reginfo *rp;
|
||||||
|
int regno;
|
||||||
|
result_t result;
|
||||||
|
|
||||||
|
if (instno==0) {
|
||||||
|
token->t_token = 0;
|
||||||
|
for(i=0;i<TOKENSIZE;i++)
|
||||||
|
token->t_att[i].aw=0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
inp= &tokeninstances[instno];
|
||||||
|
switch(inp->in_which) {
|
||||||
|
default:
|
||||||
|
assert(FALSE);
|
||||||
|
case IN_COPY:
|
||||||
|
tp= &fakestack[stackheight-inp->in_info[0]];
|
||||||
|
if (inp->in_info[1]==0) {
|
||||||
|
*token = *tp;
|
||||||
|
} else {
|
||||||
|
token->t_token= -1;
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (tp->t_token == -1) {
|
||||||
|
rp = &machregs[tp->t_att[0].ar];
|
||||||
|
token->t_att[0].ar=rp->r_members[inp->in_info[1]-1];
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
|
assert(tokens[tp->t_token].t_type[inp->in_info[1]-1] == EV_REG);
|
||||||
|
token->t_att[0].ar=tp->t_att[inp->in_info[1]-1].ar;
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case IN_RIDENT:
|
||||||
|
token->t_token= -1;
|
||||||
|
token->t_att[0].ar= inp->in_info[0];
|
||||||
|
return;
|
||||||
|
#ifdef REGVARS
|
||||||
|
case IN_REGVAR:
|
||||||
|
result=compute(&enodes[inp->in_info[0]]);
|
||||||
|
i=isregvar((long)result.e_v.e_con);
|
||||||
|
assert(i>0);
|
||||||
|
token->t_token= -1;
|
||||||
|
token->t_att[0].ar = i;
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
case IN_ALLOC:
|
||||||
|
token->t_token= -1;
|
||||||
|
regno=allreg[inp->in_info[0]];
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (inp->in_info[1])
|
||||||
|
regno=machregs[regno].r_members[inp->in_info[1]-1];
|
||||||
|
#endif
|
||||||
|
token->t_att[0].ar = regno;
|
||||||
|
return;
|
||||||
|
case IN_DESCR:
|
||||||
|
token->t_token=inp->in_info[0];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
if (inp->in_info[i+1]==0) {
|
||||||
|
assert(tokens[token->t_token].t_type[i]==0);
|
||||||
|
token->t_att[i].aw=0;
|
||||||
|
} else {
|
||||||
|
result=compute(&enodes[inp->in_info[i+1]]);
|
||||||
|
assert(tokens[token->t_token].t_type[i]==result.e_typ);
|
||||||
|
if (result.e_typ==EV_INT)
|
||||||
|
token->t_att[i].aw=result.e_v.e_con;
|
||||||
|
else if (result.e_typ==EV_STR)
|
||||||
|
token->t_att[i].as= result.e_v.e_str;
|
||||||
|
else
|
||||||
|
token->t_att[i].ar=result.e_v.e_reg;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cinstance(instno,token,tp,regno) token_p token,tp; {
|
||||||
|
inst_p inp;
|
||||||
|
int i;
|
||||||
|
struct reginfo *rp;
|
||||||
|
result_t result;
|
||||||
|
int sh; /* saved stackheight */
|
||||||
|
|
||||||
|
assert(instno!=0);
|
||||||
|
inp= &tokeninstances[instno];
|
||||||
|
switch(inp->in_which) {
|
||||||
|
default:
|
||||||
|
assert(FALSE);
|
||||||
|
case IN_COPY:
|
||||||
|
assert(inp->in_info[0] == 1);
|
||||||
|
if (inp->in_info[1]==0) {
|
||||||
|
*token = *tp;
|
||||||
|
} else {
|
||||||
|
token->t_token= -1;
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (tp->t_token == -1) {
|
||||||
|
rp = &machregs[tp->t_att[0].ar];
|
||||||
|
token->t_att[0].ar=rp->r_members[inp->in_info[1]-1];
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
|
assert(tokens[tp->t_token].t_type[inp->in_info[1]-1] == EV_REG);
|
||||||
|
token->t_att[0].ar=tp->t_att[inp->in_info[1]-1].ar;
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case IN_RIDENT:
|
||||||
|
token->t_token= -1;
|
||||||
|
token->t_att[0].ar= inp->in_info[0];
|
||||||
|
return;
|
||||||
|
case IN_ALLOC:
|
||||||
|
token->t_token= -1;
|
||||||
|
assert(inp->in_info[0]==0);
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (inp->in_info[1])
|
||||||
|
regno=machregs[regno].r_members[inp->in_info[1]-1];
|
||||||
|
#endif
|
||||||
|
token->t_att[0].ar = regno;
|
||||||
|
return;
|
||||||
|
case IN_DESCR:
|
||||||
|
sh = stackheight;
|
||||||
|
stackheight = tp - fakestack + 1;
|
||||||
|
token->t_token=inp->in_info[0];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
if (inp->in_info[i+1]==0) {
|
||||||
|
assert(tokens[token->t_token].t_type[i]==0);
|
||||||
|
token->t_att[i].aw=0;
|
||||||
|
} else {
|
||||||
|
result=compute(&enodes[inp->in_info[i+1]]);
|
||||||
|
assert(tokens[token->t_token].t_type[i]==result.e_typ);
|
||||||
|
if (result.e_typ==EV_INT)
|
||||||
|
token->t_att[i].aw=result.e_v.e_con;
|
||||||
|
else if (result.e_typ==EV_STR)
|
||||||
|
token->t_att[i].as= result.e_v.e_str;
|
||||||
|
else
|
||||||
|
token->t_att[i].ar=result.e_v.e_reg;
|
||||||
|
}
|
||||||
|
stackheight = sh;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eqtoken(tp1,tp2) token_p tp1,tp2; {
|
||||||
|
register i;
|
||||||
|
register tkdef_p tdp;
|
||||||
|
|
||||||
|
if (tp1->t_token!=tp2->t_token)
|
||||||
|
return(0);
|
||||||
|
if (tp1->t_token==0)
|
||||||
|
return(1);
|
||||||
|
if (tp1->t_token==-1) {
|
||||||
|
if (tp1->t_att[0].ar!=tp2->t_att[0].ar)
|
||||||
|
return(0);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
tdp = &tokens[tp1->t_token];
|
||||||
|
for (i=0;i<TOKENSIZE;i++)
|
||||||
|
switch(tdp->t_type[i]) {
|
||||||
|
default:
|
||||||
|
return(1);
|
||||||
|
case EV_INT:
|
||||||
|
if (tp1->t_att[i].aw != tp2->t_att[i].aw)
|
||||||
|
return(0);
|
||||||
|
break;
|
||||||
|
case EV_REG:
|
||||||
|
if (tp1->t_att[i].ar != tp2->t_att[i].ar)
|
||||||
|
return(0);
|
||||||
|
break;
|
||||||
|
case EV_STR:
|
||||||
|
if (strcmp(tp1->t_att[i].as, tp2->t_att[i].as))
|
||||||
|
return(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
distance(cindex) {
|
||||||
|
register char *bp;
|
||||||
|
register i;
|
||||||
|
register token_p tp;
|
||||||
|
int tokexp,tpl;
|
||||||
|
int expsize,toksize,exact;
|
||||||
|
int xsekt=0;
|
||||||
|
|
||||||
|
bp = &coderules[cindex];
|
||||||
|
switch( (*bp)&037 ) {
|
||||||
|
default:
|
||||||
|
return(stackheight==0 ? 0 : 100);
|
||||||
|
case DO_MATCH:
|
||||||
|
break;
|
||||||
|
case DO_XXMATCH:
|
||||||
|
xsekt++;
|
||||||
|
case DO_XMATCH:
|
||||||
|
xsekt++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tpl= ((*bp++)>>5)&07;
|
||||||
|
if (stackheight < tpl) {
|
||||||
|
if (xsekt)
|
||||||
|
return(MAXINT);
|
||||||
|
tpl = stackheight;
|
||||||
|
} else
|
||||||
|
if (stackheight != tpl && xsekt==2)
|
||||||
|
return(MAXINT);
|
||||||
|
exact=0;
|
||||||
|
tp= &fakestack[stackheight-1];
|
||||||
|
for (i=0;i<tpl;i++,tp--) {
|
||||||
|
getint(tokexp,bp);
|
||||||
|
if (!match(tp, &machsets[tokexp], 0)) {
|
||||||
|
if (xsekt)
|
||||||
|
return(MAXINT);
|
||||||
|
expsize = ssize(tokexp);
|
||||||
|
toksize = tsize(tp);
|
||||||
|
if (expsize>toksize)
|
||||||
|
return(100);
|
||||||
|
if (expsize<toksize)
|
||||||
|
return(99-i);
|
||||||
|
} else
|
||||||
|
exact++;
|
||||||
|
}
|
||||||
|
if (exact==tpl) {
|
||||||
|
if (xsekt)
|
||||||
|
return(0);
|
||||||
|
return(10-exact);
|
||||||
|
}
|
||||||
|
return(20-exact);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned costcalc(cost) cost_t cost; {
|
||||||
|
result_t result1,result2;
|
||||||
|
extern unsigned cc1,cc2,cc3,cc4;
|
||||||
|
|
||||||
|
result1=compute(&enodes[cost.c_size]);
|
||||||
|
result2=compute(&enodes[cost.c_time]);
|
||||||
|
assert(result1.e_typ == EV_INT && result2.e_typ == EV_INT);
|
||||||
|
return(result1.e_v.e_con*cc1/cc2 + result2.e_v.e_con*cc3/cc4);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize(tokexpno) {
|
||||||
|
|
||||||
|
return(machsets[tokexpno].set_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
tsize(tp) register token_p tp; {
|
||||||
|
|
||||||
|
if (tp->t_token==-1)
|
||||||
|
return(machregs[tp->t_att[0].ar].r_size);
|
||||||
|
return(tokens[tp->t_token].t_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
instsize(tinstno,tp) token_p tp; {
|
||||||
|
inst_p inp;
|
||||||
|
struct reginfo *rp;
|
||||||
|
|
||||||
|
inp = &tokeninstances[tinstno];
|
||||||
|
switch(inp->in_which) {
|
||||||
|
default:
|
||||||
|
assert(FALSE);
|
||||||
|
case IN_COPY:
|
||||||
|
assert(inp->in_info[0]==1);
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
if (inp->in_info[1]==0)
|
||||||
|
#endif
|
||||||
|
return(tsize(tp));
|
||||||
|
#if MAXMEMBERS!=0
|
||||||
|
else {
|
||||||
|
assert(tp->t_token == -1);
|
||||||
|
rp = &machregs[tp->t_att[0].ar];
|
||||||
|
return(machregs[rp->r_members[inp->in_info[1]-1]].r_size);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
case IN_RIDENT:
|
||||||
|
return(machregs[inp->in_info[0]].r_size);
|
||||||
|
case IN_ALLOC:
|
||||||
|
assert(FALSE); /* cannot occur in splitting coercion */
|
||||||
|
case IN_DESCR:
|
||||||
|
return(tokens[inp->in_info[0]].t_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif MAXSPLIT
|
||||||
|
|
||||||
|
tref(tp,amount) register token_p tp; {
|
||||||
|
register i;
|
||||||
|
register tkdef_p tdp;
|
||||||
|
|
||||||
|
if (tp->t_token==-1)
|
||||||
|
chrefcount(tp->t_att[0].ar,amount,FALSE);
|
||||||
|
else {
|
||||||
|
tdp= &tokens[tp->t_token];
|
||||||
|
for(i=0;i<TOKENSIZE;i++)
|
||||||
|
if (tdp->t_type[i]==EV_REG)
|
||||||
|
chrefcount(tp->t_att[i].ar,amount,FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MAXSAVE 10
|
||||||
|
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
split(tp,ip,ply,toplevel) token_p tp; int *ip; {
|
||||||
|
c2_p cp;
|
||||||
|
token_t savestack[MAXSAVE];
|
||||||
|
int ok;
|
||||||
|
register i;
|
||||||
|
int diff;
|
||||||
|
token_p stp;
|
||||||
|
int tpl;
|
||||||
|
|
||||||
|
for (cp=c2coercs;cp< &c2coercs[NC2]; cp++) {
|
||||||
|
if (!match(tp,&machsets[cp->c2_texpno],0))
|
||||||
|
continue;
|
||||||
|
ok=1;
|
||||||
|
for (i=0; ok && i<cp->c2_nsplit;i++) {
|
||||||
|
if (ip[i]==0)
|
||||||
|
goto found;
|
||||||
|
if (instsize(cp->c2_repl[i],tp) != ssize(ip[i]))
|
||||||
|
ok=0;
|
||||||
|
}
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
found:
|
||||||
|
assert(stackheight+cp->c2_nsplit-1<MAXFSTACK);
|
||||||
|
stp = &fakestack[stackheight-1];
|
||||||
|
diff = stp - tp;
|
||||||
|
assert(diff<=MAXSAVE);
|
||||||
|
for (i=1;i<=diff;i++)
|
||||||
|
savestack[i-1] = tp[i]; /* save top of stack */
|
||||||
|
stackheight -= diff;
|
||||||
|
tpl = tokpatlen;
|
||||||
|
tokpatlen = 1;
|
||||||
|
codegen(&coderules[cp->c2_codep],ply,toplevel,MAXINT,0);
|
||||||
|
tokpatlen = tpl;
|
||||||
|
for (i=0;i<diff;i++) /* restore top of stack */
|
||||||
|
fakestack[stackheight++] = savestack[i];
|
||||||
|
return(cp->c2_nsplit);
|
||||||
|
}
|
||||||
|
#endif MAXSPLIT
|
||||||
|
|
||||||
|
unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; c3_p cp; {
|
||||||
|
token_t savestack[MAXSAVE];
|
||||||
|
token_p stp;
|
||||||
|
int i,diff;
|
||||||
|
unsigned cost;
|
||||||
|
int tpl; /* saved tokpatlen */
|
||||||
|
|
||||||
|
stp = &fakestack[stackheight-1];
|
||||||
|
diff = stp -tp;
|
||||||
|
assert(diff<=MAXSAVE);
|
||||||
|
for (i=1;i<=diff;i++)
|
||||||
|
savestack[i-1] = tp[i];
|
||||||
|
stackheight -= diff;
|
||||||
|
tpl = tokpatlen;
|
||||||
|
tokpatlen = 1;
|
||||||
|
cost = codegen(&coderules[cp->c3_codep],ply,toplevel,MAXINT,forced);
|
||||||
|
tokpatlen = tpl;
|
||||||
|
for (i=0;i<diff;i++)
|
||||||
|
fakestack[stackheight++] = savestack[i];
|
||||||
|
nallreg = 0;
|
||||||
|
return(cost);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
||||||
|
token_t savestack[MAXFSTACK];
|
||||||
|
token_p stp;
|
||||||
|
int i,diff;
|
||||||
|
int tpl; /* saved tokpatlen */
|
||||||
|
int nareg; /* saved nareg */
|
||||||
|
int areg[MAXALLREG];
|
||||||
|
c1_p cp;
|
||||||
|
register token_p tp;
|
||||||
|
unsigned totalcost=0;
|
||||||
|
struct reginfo *rp,**rpp;
|
||||||
|
|
||||||
|
for (tp=fakestack;tp<=limit;limit--) {
|
||||||
|
for (cp=c1coercs;cp< &c1coercs[NC1]; cp++) {
|
||||||
|
if (match(tp,&machsets[cp->c1_texpno],cp->c1_expr)) {
|
||||||
|
if (cp->c1_prop>=0) {
|
||||||
|
for (rpp=reglist[cp->c1_prop];
|
||||||
|
(rp = *rpp)!=0 &&
|
||||||
|
getrefcount(rp-machregs)!=0;
|
||||||
|
rpp++)
|
||||||
|
;
|
||||||
|
if (rp==0)
|
||||||
|
continue;
|
||||||
|
/* look for other possibility */
|
||||||
|
}
|
||||||
|
stp = &fakestack[stackheight-1];
|
||||||
|
diff = stp -tp;
|
||||||
|
assert(diff<=MAXFSTACK);
|
||||||
|
for (i=1;i<=diff;i++)
|
||||||
|
savestack[i-1] = tp[i];
|
||||||
|
stackheight -= diff;
|
||||||
|
tpl = tokpatlen;
|
||||||
|
tokpatlen = 1;
|
||||||
|
nareg = nallreg;
|
||||||
|
for (i=0;i<nareg;i++)
|
||||||
|
areg[i] = allreg[i];
|
||||||
|
if (cp->c1_prop>=0) {
|
||||||
|
nallreg=1; allreg[0] = rp-machregs;
|
||||||
|
chrefcount(allreg[0],1,FALSE);
|
||||||
|
} else
|
||||||
|
nallreg=0;
|
||||||
|
totalcost+= codegen(&coderules[cp->c1_codep],ply,toplevel,MAXINT,0);
|
||||||
|
totalcost+= costcalc(cp->c1_cost);
|
||||||
|
tokpatlen = tpl;
|
||||||
|
for (i=0;i<diff;i++)
|
||||||
|
fakestack[stackheight++] = savestack[i];
|
||||||
|
nallreg=nareg;
|
||||||
|
for (i=0;i<nareg;i++)
|
||||||
|
allreg[i] = areg[i];
|
||||||
|
goto contin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(FALSE);
|
||||||
|
contin: ;
|
||||||
|
}
|
||||||
|
return(totalcost);
|
||||||
|
}
|
||||||
|
|
||||||
|
c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
||||||
|
register c3_p cp;
|
||||||
|
token_t rtoken;
|
||||||
|
register i;
|
||||||
|
register struct reginfo **rpp;
|
||||||
|
|
||||||
|
for (cp=c3coercs;cp< &c3coercs[NC3]; cp++) {
|
||||||
|
if (tp!=(token_p) 0) {
|
||||||
|
if (!match(tp,&machsets[cp->c3_texpno],0))
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if (cp->c3_texpno!=0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (cp->c3_prop==0) { /* no reg needed */
|
||||||
|
cinstance(cp->c3_repl,&rtoken,tp,0);
|
||||||
|
if (match(&rtoken,tep,0))
|
||||||
|
return(cp);
|
||||||
|
} else {
|
||||||
|
curreglist = (rl_p) myalloc(sizeof (rl_t));
|
||||||
|
curreglist->rl_n = 0;
|
||||||
|
for (rpp=reglist[cp->c3_prop];*rpp;rpp++) {
|
||||||
|
i = *rpp - machregs;
|
||||||
|
cinstance(cp->c3_repl,&rtoken,tp,i);
|
||||||
|
if (match(&rtoken,tep,0))
|
||||||
|
curreglist->rl_list[curreglist->rl_n++] = i;
|
||||||
|
}
|
||||||
|
if (curreglist->rl_n != 0)
|
||||||
|
return(cp);
|
||||||
|
myfree(curreglist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(0); /* nothing found */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
error(s,a1,a2,a3,a4) char *s; {
|
||||||
|
|
||||||
|
fatal(s,a1,a2,a3,a4);
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal(s,a1,a2,a3,a4) char *s; {
|
||||||
|
|
||||||
|
fprintf(stderr,"Error: ");
|
||||||
|
fprintf(stderr,s,a1,a2,a3,a4);
|
||||||
|
fprintf(stderr,"\n");
|
||||||
|
out_finish();
|
||||||
|
abort();
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
badassertion(asstr,file,line) char *asstr, *file; {
|
||||||
|
|
||||||
|
fatal("Assertion \"%s\" failed %s(%d)",asstr,file,line);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
max(a,b) {
|
||||||
|
|
||||||
|
return(a>b ? a : b);
|
||||||
|
}
|
||||||
33
mach/proto/cg/types.h
Normal file
33
mach/proto/cg/types.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#ifndef EM_WSIZE
|
||||||
|
EM_WSIZE should be defined at this point
|
||||||
|
#endif
|
||||||
|
#ifndef EM_PSIZE
|
||||||
|
EM_PSIZE should be defined at this point
|
||||||
|
#endif
|
||||||
|
#if EM_WSIZE>4 || EM_PSIZE>4
|
||||||
|
Implementation will not be correct unless a long integer
|
||||||
|
has more then 4 bytes of precision.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef char byte;
|
||||||
|
typedef char * string;
|
||||||
|
|
||||||
|
#if EM_WSIZE>2 || EM_PSIZE>2
|
||||||
|
#define full long
|
||||||
|
#else
|
||||||
|
#define full int
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if EM_WSIZE>2
|
||||||
|
#define word long
|
||||||
|
#ifndef WRD_FMT
|
||||||
|
#define WRD_FMT "%D"
|
||||||
|
#endif WRD_FMT
|
||||||
|
#else
|
||||||
|
#define word int
|
||||||
|
#ifndef WRD_FMT
|
||||||
|
#define WRD_FMT "%d"
|
||||||
|
#endif WRD_FMT
|
||||||
|
#endif
|
||||||
41
mach/proto/cg/var.c
Normal file
41
mach/proto/cg/var.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "result.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
int stackheight = 0;
|
||||||
|
token_t fakestack[MAXFSTACK];
|
||||||
|
int nallreg = 0;
|
||||||
|
int allreg[MAXALLREG];
|
||||||
|
token_p curtoken = (token_p) 0;
|
||||||
|
result_t dollar[LONGESTPATTERN];
|
||||||
|
int nemlines =0;
|
||||||
|
struct emline emlines[MAXEMLINES];
|
||||||
|
struct emline *emp=emlines;
|
||||||
|
struct emline *saveemp;
|
||||||
|
int tokpatlen;
|
||||||
|
rl_p curreglist;
|
||||||
178
mach/vax4/cg/Makefile
Normal file
178
mach/vax4/cg/Makefile
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
# $Header$
|
||||||
|
|
||||||
|
PREFLAGS=-I../../../h -I. -DNDEBUG
|
||||||
|
PFLAGS=
|
||||||
|
CFLAGS=$(PREFLAGS) $(PFLAGS) -O
|
||||||
|
LDFLAGS=-i $(PFLAGS)
|
||||||
|
LINTOPTS=-hbxac
|
||||||
|
LIBS=../../../lib/em_data.a
|
||||||
|
CDIR=../../proto/cg
|
||||||
|
CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \
|
||||||
|
$(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \
|
||||||
|
$(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \
|
||||||
|
$(CDIR)/state.c $(CDIR)/subr.c $(CDIR)/var.c
|
||||||
|
OFILES=codegen.o compute.o equiv.o fillem.o gencode.o glosym.o main.o\
|
||||||
|
move.o nextem.o reg.o regvar.o salloc.o state.o subr.o var.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
make tables.c
|
||||||
|
make cg
|
||||||
|
|
||||||
|
cg: tables.o $(OFILES)
|
||||||
|
cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg
|
||||||
|
|
||||||
|
tables.o: tables.c
|
||||||
|
cc -c $(PREFLAGS) -I$(CDIR) tables.c
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/codegen.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/codegen.c
|
||||||
|
compute.o: $(CDIR)/compute.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/compute.c
|
||||||
|
equiv.o: $(CDIR)/equiv.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/equiv.c
|
||||||
|
fillem.o: $(CDIR)/fillem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/fillem.c
|
||||||
|
gencode.o: $(CDIR)/gencode.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/gencode.c
|
||||||
|
glosym.o: $(CDIR)/glosym.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/glosym.c
|
||||||
|
main.o: $(CDIR)/main.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/main.c
|
||||||
|
move.o: $(CDIR)/move.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/move.c
|
||||||
|
nextem.o: $(CDIR)/nextem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/nextem.c
|
||||||
|
reg.o: $(CDIR)/reg.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/reg.c
|
||||||
|
regvar.o: $(CDIR)/regvar.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/regvar.c
|
||||||
|
salloc.o: $(CDIR)/salloc.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/salloc.c
|
||||||
|
state.o: $(CDIR)/state.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/state.c
|
||||||
|
subr.o: $(CDIR)/subr.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/subr.c
|
||||||
|
var.o: $(CDIR)/var.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/var.c
|
||||||
|
|
||||||
|
install: all
|
||||||
|
../install cg
|
||||||
|
|
||||||
|
cmp: all
|
||||||
|
-../compare cg
|
||||||
|
|
||||||
|
|
||||||
|
tables.c: table
|
||||||
|
-mv tables.h tables.h.save
|
||||||
|
../../../lib/cpp -P table | ../../../lib/cgg > debug.out
|
||||||
|
-if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
-if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
|
||||||
|
lint: $(CFILES)
|
||||||
|
lint $(LINTOPTS) $(PREFLAGS) $(CFILES)
|
||||||
|
clean:
|
||||||
|
rm -f *.o tables.c tables.h debug.out cg tables.h.save
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/assert.h
|
||||||
|
codegen.o: $(CDIR)/data.h
|
||||||
|
codegen.o: $(CDIR)/equiv.h
|
||||||
|
codegen.o: $(CDIR)/extern.h
|
||||||
|
codegen.o: $(CDIR)/param.h
|
||||||
|
codegen.o: $(CDIR)/result.h
|
||||||
|
codegen.o: $(CDIR)/state.h
|
||||||
|
codegen.o: tables.h
|
||||||
|
codegen.o: $(CDIR)/types.h
|
||||||
|
compute.o: $(CDIR)/assert.h
|
||||||
|
compute.o: $(CDIR)/data.h
|
||||||
|
compute.o: $(CDIR)/extern.h
|
||||||
|
compute.o: $(CDIR)/glosym.h
|
||||||
|
compute.o: $(CDIR)/param.h
|
||||||
|
compute.o: $(CDIR)/result.h
|
||||||
|
compute.o: tables.h
|
||||||
|
compute.o: $(CDIR)/types.h
|
||||||
|
equiv.o: $(CDIR)/assert.h
|
||||||
|
equiv.o: $(CDIR)/data.h
|
||||||
|
equiv.o: $(CDIR)/equiv.h
|
||||||
|
equiv.o: $(CDIR)/extern.h
|
||||||
|
equiv.o: $(CDIR)/param.h
|
||||||
|
equiv.o: $(CDIR)/result.h
|
||||||
|
equiv.o: tables.h
|
||||||
|
equiv.o: $(CDIR)/types.h
|
||||||
|
fillem.o: $(CDIR)/assert.h
|
||||||
|
fillem.o: $(CDIR)/data.h
|
||||||
|
fillem.o: $(CDIR)/extern.h
|
||||||
|
fillem.o: mach.c
|
||||||
|
fillem.o: mach.h
|
||||||
|
fillem.o: $(CDIR)/param.h
|
||||||
|
fillem.o: $(CDIR)/regvar.h
|
||||||
|
fillem.o: $(CDIR)/result.h
|
||||||
|
fillem.o: tables.h
|
||||||
|
fillem.o: $(CDIR)/types.h
|
||||||
|
gencode.o: $(CDIR)/assert.h
|
||||||
|
gencode.o: $(CDIR)/data.h
|
||||||
|
gencode.o: $(CDIR)/extern.h
|
||||||
|
gencode.o: $(CDIR)/param.h
|
||||||
|
gencode.o: $(CDIR)/result.h
|
||||||
|
gencode.o: tables.h
|
||||||
|
gencode.o: $(CDIR)/types.h
|
||||||
|
glosym.o: $(CDIR)/glosym.h
|
||||||
|
glosym.o: $(CDIR)/param.h
|
||||||
|
glosym.o: tables.h
|
||||||
|
glosym.o: $(CDIR)/types.h
|
||||||
|
main.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/assert.h
|
||||||
|
move.o: $(CDIR)/data.h
|
||||||
|
move.o: $(CDIR)/extern.h
|
||||||
|
move.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/result.h
|
||||||
|
move.o: tables.h
|
||||||
|
move.o: $(CDIR)/types.h
|
||||||
|
nextem.o: $(CDIR)/assert.h
|
||||||
|
nextem.o: $(CDIR)/data.h
|
||||||
|
nextem.o: $(CDIR)/extern.h
|
||||||
|
nextem.o: $(CDIR)/param.h
|
||||||
|
nextem.o: $(CDIR)/result.h
|
||||||
|
nextem.o: tables.h
|
||||||
|
nextem.o: $(CDIR)/types.h
|
||||||
|
reg.o: $(CDIR)/assert.h
|
||||||
|
reg.o: $(CDIR)/data.h
|
||||||
|
reg.o: $(CDIR)/extern.h
|
||||||
|
reg.o: $(CDIR)/param.h
|
||||||
|
reg.o: $(CDIR)/result.h
|
||||||
|
reg.o: tables.h
|
||||||
|
reg.o: $(CDIR)/types.h
|
||||||
|
regvar.o: $(CDIR)/assert.h
|
||||||
|
regvar.o: $(CDIR)/data.h
|
||||||
|
regvar.o: $(CDIR)/extern.h
|
||||||
|
regvar.o: $(CDIR)/param.h
|
||||||
|
regvar.o: $(CDIR)/regvar.h
|
||||||
|
regvar.o: $(CDIR)/result.h
|
||||||
|
regvar.o: tables.h
|
||||||
|
regvar.o: $(CDIR)/types.h
|
||||||
|
salloc.o: $(CDIR)/assert.h
|
||||||
|
salloc.o: $(CDIR)/data.h
|
||||||
|
salloc.o: $(CDIR)/extern.h
|
||||||
|
salloc.o: $(CDIR)/param.h
|
||||||
|
salloc.o: $(CDIR)/result.h
|
||||||
|
salloc.o: tables.h
|
||||||
|
salloc.o: $(CDIR)/types.h
|
||||||
|
state.o: $(CDIR)/assert.h
|
||||||
|
state.o: $(CDIR)/data.h
|
||||||
|
state.o: $(CDIR)/extern.h
|
||||||
|
state.o: $(CDIR)/param.h
|
||||||
|
state.o: $(CDIR)/result.h
|
||||||
|
state.o: $(CDIR)/state.h
|
||||||
|
state.o: tables.h
|
||||||
|
state.o: $(CDIR)/types.h
|
||||||
|
subr.o: $(CDIR)/assert.h
|
||||||
|
subr.o: $(CDIR)/data.h
|
||||||
|
subr.o: $(CDIR)/extern.h
|
||||||
|
subr.o: $(CDIR)/param.h
|
||||||
|
subr.o: $(CDIR)/result.h
|
||||||
|
subr.o: tables.h
|
||||||
|
subr.o: $(CDIR)/types.h
|
||||||
|
var.o: $(CDIR)/data.h
|
||||||
|
var.o: $(CDIR)/param.h
|
||||||
|
var.o: $(CDIR)/result.h
|
||||||
|
var.o: tables.h
|
||||||
|
var.o: $(CDIR)/types.h
|
||||||
178
mach/z80/cg/Makefile
Normal file
178
mach/z80/cg/Makefile
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
# $Header$
|
||||||
|
|
||||||
|
PREFLAGS=-I../../../h -I. -DNDEBUG
|
||||||
|
PFLAGS=
|
||||||
|
CFLAGS=$(PREFLAGS) $(PFLAGS) -O
|
||||||
|
LDFLAGS=-i $(PFLAGS)
|
||||||
|
LINTOPTS=-hbxac
|
||||||
|
LIBS=../../../lib/em_data.a
|
||||||
|
CDIR=../../proto/cg
|
||||||
|
CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \
|
||||||
|
$(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \
|
||||||
|
$(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \
|
||||||
|
$(CDIR)/state.c $(CDIR)/subr.c $(CDIR)/var.c
|
||||||
|
OFILES=codegen.o compute.o equiv.o fillem.o gencode.o glosym.o main.o\
|
||||||
|
move.o nextem.o reg.o regvar.o salloc.o state.o subr.o var.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
make tables.c
|
||||||
|
make cg
|
||||||
|
|
||||||
|
cg: tables.o $(OFILES)
|
||||||
|
cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg
|
||||||
|
|
||||||
|
tables.o: tables.c
|
||||||
|
cc -c $(PREFLAGS) -I$(CDIR) tables.c
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/codegen.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/codegen.c
|
||||||
|
compute.o: $(CDIR)/compute.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/compute.c
|
||||||
|
equiv.o: $(CDIR)/equiv.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/equiv.c
|
||||||
|
fillem.o: $(CDIR)/fillem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/fillem.c
|
||||||
|
gencode.o: $(CDIR)/gencode.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/gencode.c
|
||||||
|
glosym.o: $(CDIR)/glosym.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/glosym.c
|
||||||
|
main.o: $(CDIR)/main.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/main.c
|
||||||
|
move.o: $(CDIR)/move.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/move.c
|
||||||
|
nextem.o: $(CDIR)/nextem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/nextem.c
|
||||||
|
reg.o: $(CDIR)/reg.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/reg.c
|
||||||
|
regvar.o: $(CDIR)/regvar.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/regvar.c
|
||||||
|
salloc.o: $(CDIR)/salloc.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/salloc.c
|
||||||
|
state.o: $(CDIR)/state.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/state.c
|
||||||
|
subr.o: $(CDIR)/subr.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/subr.c
|
||||||
|
var.o: $(CDIR)/var.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/var.c
|
||||||
|
|
||||||
|
install: all
|
||||||
|
../install cg
|
||||||
|
|
||||||
|
cmp: all
|
||||||
|
-../compare cg
|
||||||
|
|
||||||
|
|
||||||
|
tables.c: table
|
||||||
|
-mv tables.h tables.h.save
|
||||||
|
../../../lib/cpp -P table | ../../../lib/cgg > debug.out
|
||||||
|
-if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
-if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
|
||||||
|
lint: $(CFILES)
|
||||||
|
lint $(LINTOPTS) $(PREFLAGS) $(CFILES)
|
||||||
|
clean:
|
||||||
|
rm -f *.o tables.c tables.h debug.out cg tables.h.save
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/assert.h
|
||||||
|
codegen.o: $(CDIR)/data.h
|
||||||
|
codegen.o: $(CDIR)/equiv.h
|
||||||
|
codegen.o: $(CDIR)/extern.h
|
||||||
|
codegen.o: $(CDIR)/param.h
|
||||||
|
codegen.o: $(CDIR)/result.h
|
||||||
|
codegen.o: $(CDIR)/state.h
|
||||||
|
codegen.o: tables.h
|
||||||
|
codegen.o: $(CDIR)/types.h
|
||||||
|
compute.o: $(CDIR)/assert.h
|
||||||
|
compute.o: $(CDIR)/data.h
|
||||||
|
compute.o: $(CDIR)/extern.h
|
||||||
|
compute.o: $(CDIR)/glosym.h
|
||||||
|
compute.o: $(CDIR)/param.h
|
||||||
|
compute.o: $(CDIR)/result.h
|
||||||
|
compute.o: tables.h
|
||||||
|
compute.o: $(CDIR)/types.h
|
||||||
|
equiv.o: $(CDIR)/assert.h
|
||||||
|
equiv.o: $(CDIR)/data.h
|
||||||
|
equiv.o: $(CDIR)/equiv.h
|
||||||
|
equiv.o: $(CDIR)/extern.h
|
||||||
|
equiv.o: $(CDIR)/param.h
|
||||||
|
equiv.o: $(CDIR)/result.h
|
||||||
|
equiv.o: tables.h
|
||||||
|
equiv.o: $(CDIR)/types.h
|
||||||
|
fillem.o: $(CDIR)/assert.h
|
||||||
|
fillem.o: $(CDIR)/data.h
|
||||||
|
fillem.o: $(CDIR)/extern.h
|
||||||
|
fillem.o: mach.c
|
||||||
|
fillem.o: mach.h
|
||||||
|
fillem.o: $(CDIR)/param.h
|
||||||
|
fillem.o: $(CDIR)/regvar.h
|
||||||
|
fillem.o: $(CDIR)/result.h
|
||||||
|
fillem.o: tables.h
|
||||||
|
fillem.o: $(CDIR)/types.h
|
||||||
|
gencode.o: $(CDIR)/assert.h
|
||||||
|
gencode.o: $(CDIR)/data.h
|
||||||
|
gencode.o: $(CDIR)/extern.h
|
||||||
|
gencode.o: $(CDIR)/param.h
|
||||||
|
gencode.o: $(CDIR)/result.h
|
||||||
|
gencode.o: tables.h
|
||||||
|
gencode.o: $(CDIR)/types.h
|
||||||
|
glosym.o: $(CDIR)/glosym.h
|
||||||
|
glosym.o: $(CDIR)/param.h
|
||||||
|
glosym.o: tables.h
|
||||||
|
glosym.o: $(CDIR)/types.h
|
||||||
|
main.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/assert.h
|
||||||
|
move.o: $(CDIR)/data.h
|
||||||
|
move.o: $(CDIR)/extern.h
|
||||||
|
move.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/result.h
|
||||||
|
move.o: tables.h
|
||||||
|
move.o: $(CDIR)/types.h
|
||||||
|
nextem.o: $(CDIR)/assert.h
|
||||||
|
nextem.o: $(CDIR)/data.h
|
||||||
|
nextem.o: $(CDIR)/extern.h
|
||||||
|
nextem.o: $(CDIR)/param.h
|
||||||
|
nextem.o: $(CDIR)/result.h
|
||||||
|
nextem.o: tables.h
|
||||||
|
nextem.o: $(CDIR)/types.h
|
||||||
|
reg.o: $(CDIR)/assert.h
|
||||||
|
reg.o: $(CDIR)/data.h
|
||||||
|
reg.o: $(CDIR)/extern.h
|
||||||
|
reg.o: $(CDIR)/param.h
|
||||||
|
reg.o: $(CDIR)/result.h
|
||||||
|
reg.o: tables.h
|
||||||
|
reg.o: $(CDIR)/types.h
|
||||||
|
regvar.o: $(CDIR)/assert.h
|
||||||
|
regvar.o: $(CDIR)/data.h
|
||||||
|
regvar.o: $(CDIR)/extern.h
|
||||||
|
regvar.o: $(CDIR)/param.h
|
||||||
|
regvar.o: $(CDIR)/regvar.h
|
||||||
|
regvar.o: $(CDIR)/result.h
|
||||||
|
regvar.o: tables.h
|
||||||
|
regvar.o: $(CDIR)/types.h
|
||||||
|
salloc.o: $(CDIR)/assert.h
|
||||||
|
salloc.o: $(CDIR)/data.h
|
||||||
|
salloc.o: $(CDIR)/extern.h
|
||||||
|
salloc.o: $(CDIR)/param.h
|
||||||
|
salloc.o: $(CDIR)/result.h
|
||||||
|
salloc.o: tables.h
|
||||||
|
salloc.o: $(CDIR)/types.h
|
||||||
|
state.o: $(CDIR)/assert.h
|
||||||
|
state.o: $(CDIR)/data.h
|
||||||
|
state.o: $(CDIR)/extern.h
|
||||||
|
state.o: $(CDIR)/param.h
|
||||||
|
state.o: $(CDIR)/result.h
|
||||||
|
state.o: $(CDIR)/state.h
|
||||||
|
state.o: tables.h
|
||||||
|
state.o: $(CDIR)/types.h
|
||||||
|
subr.o: $(CDIR)/assert.h
|
||||||
|
subr.o: $(CDIR)/data.h
|
||||||
|
subr.o: $(CDIR)/extern.h
|
||||||
|
subr.o: $(CDIR)/param.h
|
||||||
|
subr.o: $(CDIR)/result.h
|
||||||
|
subr.o: tables.h
|
||||||
|
subr.o: $(CDIR)/types.h
|
||||||
|
var.o: $(CDIR)/data.h
|
||||||
|
var.o: $(CDIR)/param.h
|
||||||
|
var.o: $(CDIR)/result.h
|
||||||
|
var.o: tables.h
|
||||||
|
var.o: $(CDIR)/types.h
|
||||||
178
mach/z8000/cg/Makefile
Normal file
178
mach/z8000/cg/Makefile
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
# $Header$
|
||||||
|
|
||||||
|
PREFLAGS=-I../../../h -I. -DNDEBUG
|
||||||
|
PFLAGS=
|
||||||
|
CFLAGS=$(PREFLAGS) $(PFLAGS) -O
|
||||||
|
LDFLAGS=-i $(PFLAGS)
|
||||||
|
LINTOPTS=-hbxac
|
||||||
|
LIBS=../../../lib/em_data.a
|
||||||
|
CDIR=../../proto/cg
|
||||||
|
CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \
|
||||||
|
$(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \
|
||||||
|
$(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \
|
||||||
|
$(CDIR)/state.c $(CDIR)/subr.c $(CDIR)/var.c
|
||||||
|
OFILES=codegen.o compute.o equiv.o fillem.o gencode.o glosym.o main.o\
|
||||||
|
move.o nextem.o reg.o regvar.o salloc.o state.o subr.o var.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
make tables.c
|
||||||
|
make cg
|
||||||
|
|
||||||
|
cg: tables.o $(OFILES)
|
||||||
|
cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg
|
||||||
|
|
||||||
|
tables.o: tables.c
|
||||||
|
cc -c $(PREFLAGS) -I$(CDIR) tables.c
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/codegen.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/codegen.c
|
||||||
|
compute.o: $(CDIR)/compute.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/compute.c
|
||||||
|
equiv.o: $(CDIR)/equiv.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/equiv.c
|
||||||
|
fillem.o: $(CDIR)/fillem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/fillem.c
|
||||||
|
gencode.o: $(CDIR)/gencode.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/gencode.c
|
||||||
|
glosym.o: $(CDIR)/glosym.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/glosym.c
|
||||||
|
main.o: $(CDIR)/main.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/main.c
|
||||||
|
move.o: $(CDIR)/move.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/move.c
|
||||||
|
nextem.o: $(CDIR)/nextem.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/nextem.c
|
||||||
|
reg.o: $(CDIR)/reg.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/reg.c
|
||||||
|
regvar.o: $(CDIR)/regvar.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/regvar.c
|
||||||
|
salloc.o: $(CDIR)/salloc.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/salloc.c
|
||||||
|
state.o: $(CDIR)/state.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/state.c
|
||||||
|
subr.o: $(CDIR)/subr.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/subr.c
|
||||||
|
var.o: $(CDIR)/var.c
|
||||||
|
cc -c $(CFLAGS) $(CDIR)/var.c
|
||||||
|
|
||||||
|
install: all
|
||||||
|
../install cg
|
||||||
|
|
||||||
|
cmp: all
|
||||||
|
-../compare cg
|
||||||
|
|
||||||
|
|
||||||
|
tables.c: table
|
||||||
|
-mv tables.h tables.h.save
|
||||||
|
../../../lib/cpp -P table | ../../../lib/cgg > debug.out
|
||||||
|
-if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
-if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi
|
||||||
|
|
||||||
|
lint: $(CFILES)
|
||||||
|
lint $(LINTOPTS) $(PREFLAGS) $(CFILES)
|
||||||
|
clean:
|
||||||
|
rm -f *.o tables.c tables.h debug.out cg tables.h.save
|
||||||
|
|
||||||
|
codegen.o: $(CDIR)/assert.h
|
||||||
|
codegen.o: $(CDIR)/data.h
|
||||||
|
codegen.o: $(CDIR)/equiv.h
|
||||||
|
codegen.o: $(CDIR)/extern.h
|
||||||
|
codegen.o: $(CDIR)/param.h
|
||||||
|
codegen.o: $(CDIR)/result.h
|
||||||
|
codegen.o: $(CDIR)/state.h
|
||||||
|
codegen.o: tables.h
|
||||||
|
codegen.o: $(CDIR)/types.h
|
||||||
|
compute.o: $(CDIR)/assert.h
|
||||||
|
compute.o: $(CDIR)/data.h
|
||||||
|
compute.o: $(CDIR)/extern.h
|
||||||
|
compute.o: $(CDIR)/glosym.h
|
||||||
|
compute.o: $(CDIR)/param.h
|
||||||
|
compute.o: $(CDIR)/result.h
|
||||||
|
compute.o: tables.h
|
||||||
|
compute.o: $(CDIR)/types.h
|
||||||
|
equiv.o: $(CDIR)/assert.h
|
||||||
|
equiv.o: $(CDIR)/data.h
|
||||||
|
equiv.o: $(CDIR)/equiv.h
|
||||||
|
equiv.o: $(CDIR)/extern.h
|
||||||
|
equiv.o: $(CDIR)/param.h
|
||||||
|
equiv.o: $(CDIR)/result.h
|
||||||
|
equiv.o: tables.h
|
||||||
|
equiv.o: $(CDIR)/types.h
|
||||||
|
fillem.o: $(CDIR)/assert.h
|
||||||
|
fillem.o: $(CDIR)/data.h
|
||||||
|
fillem.o: $(CDIR)/extern.h
|
||||||
|
fillem.o: mach.c
|
||||||
|
fillem.o: mach.h
|
||||||
|
fillem.o: $(CDIR)/param.h
|
||||||
|
fillem.o: $(CDIR)/regvar.h
|
||||||
|
fillem.o: $(CDIR)/result.h
|
||||||
|
fillem.o: tables.h
|
||||||
|
fillem.o: $(CDIR)/types.h
|
||||||
|
gencode.o: $(CDIR)/assert.h
|
||||||
|
gencode.o: $(CDIR)/data.h
|
||||||
|
gencode.o: $(CDIR)/extern.h
|
||||||
|
gencode.o: $(CDIR)/param.h
|
||||||
|
gencode.o: $(CDIR)/result.h
|
||||||
|
gencode.o: tables.h
|
||||||
|
gencode.o: $(CDIR)/types.h
|
||||||
|
glosym.o: $(CDIR)/glosym.h
|
||||||
|
glosym.o: $(CDIR)/param.h
|
||||||
|
glosym.o: tables.h
|
||||||
|
glosym.o: $(CDIR)/types.h
|
||||||
|
main.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/assert.h
|
||||||
|
move.o: $(CDIR)/data.h
|
||||||
|
move.o: $(CDIR)/extern.h
|
||||||
|
move.o: $(CDIR)/param.h
|
||||||
|
move.o: $(CDIR)/result.h
|
||||||
|
move.o: tables.h
|
||||||
|
move.o: $(CDIR)/types.h
|
||||||
|
nextem.o: $(CDIR)/assert.h
|
||||||
|
nextem.o: $(CDIR)/data.h
|
||||||
|
nextem.o: $(CDIR)/extern.h
|
||||||
|
nextem.o: $(CDIR)/param.h
|
||||||
|
nextem.o: $(CDIR)/result.h
|
||||||
|
nextem.o: tables.h
|
||||||
|
nextem.o: $(CDIR)/types.h
|
||||||
|
reg.o: $(CDIR)/assert.h
|
||||||
|
reg.o: $(CDIR)/data.h
|
||||||
|
reg.o: $(CDIR)/extern.h
|
||||||
|
reg.o: $(CDIR)/param.h
|
||||||
|
reg.o: $(CDIR)/result.h
|
||||||
|
reg.o: tables.h
|
||||||
|
reg.o: $(CDIR)/types.h
|
||||||
|
regvar.o: $(CDIR)/assert.h
|
||||||
|
regvar.o: $(CDIR)/data.h
|
||||||
|
regvar.o: $(CDIR)/extern.h
|
||||||
|
regvar.o: $(CDIR)/param.h
|
||||||
|
regvar.o: $(CDIR)/regvar.h
|
||||||
|
regvar.o: $(CDIR)/result.h
|
||||||
|
regvar.o: tables.h
|
||||||
|
regvar.o: $(CDIR)/types.h
|
||||||
|
salloc.o: $(CDIR)/assert.h
|
||||||
|
salloc.o: $(CDIR)/data.h
|
||||||
|
salloc.o: $(CDIR)/extern.h
|
||||||
|
salloc.o: $(CDIR)/param.h
|
||||||
|
salloc.o: $(CDIR)/result.h
|
||||||
|
salloc.o: tables.h
|
||||||
|
salloc.o: $(CDIR)/types.h
|
||||||
|
state.o: $(CDIR)/assert.h
|
||||||
|
state.o: $(CDIR)/data.h
|
||||||
|
state.o: $(CDIR)/extern.h
|
||||||
|
state.o: $(CDIR)/param.h
|
||||||
|
state.o: $(CDIR)/result.h
|
||||||
|
state.o: $(CDIR)/state.h
|
||||||
|
state.o: tables.h
|
||||||
|
state.o: $(CDIR)/types.h
|
||||||
|
subr.o: $(CDIR)/assert.h
|
||||||
|
subr.o: $(CDIR)/data.h
|
||||||
|
subr.o: $(CDIR)/extern.h
|
||||||
|
subr.o: $(CDIR)/param.h
|
||||||
|
subr.o: $(CDIR)/result.h
|
||||||
|
subr.o: tables.h
|
||||||
|
subr.o: $(CDIR)/types.h
|
||||||
|
var.o: $(CDIR)/data.h
|
||||||
|
var.o: $(CDIR)/param.h
|
||||||
|
var.o: $(CDIR)/result.h
|
||||||
|
var.o: tables.h
|
||||||
|
var.o: $(CDIR)/types.h
|
||||||
23
util/ack/.distr
Normal file
23
util/ack/.distr
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Makefile
|
||||||
|
ack.h
|
||||||
|
data.c
|
||||||
|
data.h
|
||||||
|
dmach.c
|
||||||
|
dmach.h
|
||||||
|
files.c
|
||||||
|
grows.c
|
||||||
|
grows.h
|
||||||
|
intable.c
|
||||||
|
list.c
|
||||||
|
list.h
|
||||||
|
main.c
|
||||||
|
malloc.c
|
||||||
|
mktables.c
|
||||||
|
pc
|
||||||
|
rmach.c
|
||||||
|
run.c
|
||||||
|
scan.c
|
||||||
|
svars.c
|
||||||
|
trans.c
|
||||||
|
trans.h
|
||||||
|
util.c
|
||||||
63
util/ack/Makefile
Normal file
63
util/ack/Makefile
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
HFILES=ack.h list.h trans.h data.h dmach.h grows.h
|
||||||
|
DSRC=list.c data.c main.c scan.c svars.c trans.c util.c rmach.c run.c grows.c\
|
||||||
|
files.c
|
||||||
|
ISRC=dmach.c intable.c
|
||||||
|
OBJ=list.o data.o main.o scan.o svars.o trans.o util.o rmach.o run.o \
|
||||||
|
dmach.o intable.o grows.o files.o
|
||||||
|
ACKDIR=../../lib/ack
|
||||||
|
FE=fe
|
||||||
|
INTABLES=pdp int
|
||||||
|
LNTABLES=6500 m68k2 m68k4 6809 8080 acc apc nascom vax2 vax4 z80 i86
|
||||||
|
CFLAGS=-O -n
|
||||||
|
BINDIR=../../bin
|
||||||
|
|
||||||
|
head: ack
|
||||||
|
|
||||||
|
install: ack
|
||||||
|
cp ack $(BINDIR)/ack
|
||||||
|
-cd $(BINDIR) ; \
|
||||||
|
for i in $(INTABLES) $(LNTABLES) ; do ln ack $$i ; done
|
||||||
|
(cd pc ; make install )
|
||||||
|
|
||||||
|
cmp: ack
|
||||||
|
cmp ack $(BINDIR)/ack
|
||||||
|
(cd pc ; make cmp )
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f *.old *.o ack
|
||||||
|
(cd pc ; make clean )
|
||||||
|
|
||||||
|
ack: $(OBJ)
|
||||||
|
$(CC) -o ack $(CFLAGS) $(OBJ)
|
||||||
|
|
||||||
|
grows.o files.o list.o run.o \
|
||||||
|
data.o main.o scan.o trans.o rmach.o util.o : ack.h list.h
|
||||||
|
|
||||||
|
files.o data.o main.o scan.o run.o trans.o rmach.o: trans.h data.h
|
||||||
|
|
||||||
|
files.o rmach.o trans.o grows.c : grows.h
|
||||||
|
|
||||||
|
rmach.c: dmach.h
|
||||||
|
|
||||||
|
files.o main.o rmach.o : ../../h/em_path.h
|
||||||
|
|
||||||
|
main.o : ../../h/local.h
|
||||||
|
|
||||||
|
malloc.o svars.o: ack.h
|
||||||
|
|
||||||
|
dmach.c intable.c: mktables dmach.h
|
||||||
|
: mktables $(ACKDIR) # $(FE) $(INTABLES)
|
||||||
|
mktables $(ACKDIR)
|
||||||
|
|
||||||
|
mktables: mktables.c
|
||||||
|
cc -o mktables mktables.c
|
||||||
|
|
||||||
|
pr:
|
||||||
|
@pr Makefile $(HFILES) $(DSRC) $(ACKDIR)/*
|
||||||
|
@(cd pc ; make pr)
|
||||||
|
|
||||||
|
opr:
|
||||||
|
make pr | opr
|
||||||
|
|
||||||
|
lint: $(ISRC)
|
||||||
|
lint -hbx $(DSRC) $(ISRC)
|
||||||
88
util/ack/ack.h
Normal file
88
util/ack/ack.h
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/****************************************************************************/
|
||||||
|
/* User settable options */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
#define FRONTENDS "fe" /* The front-end definitions */
|
||||||
|
#define ACKNAME "AckXXXXXX" /* Handed to mktemp for temp. files */
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Internal mnemonics, should not be tinkered with */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/* The names of some string variables */
|
||||||
|
|
||||||
|
#define HOME "EM"
|
||||||
|
#define RTS "RTS"
|
||||||
|
#define NEEDS "NEEDS"
|
||||||
|
#define HEAD "HEAD"
|
||||||
|
#define TAIL "TAIL"
|
||||||
|
#define SRC "SOURCE"
|
||||||
|
#define LIBVAR "LNAME"
|
||||||
|
|
||||||
|
/* Intended for flags, possibly in bit fields */
|
||||||
|
|
||||||
|
#define YES 1
|
||||||
|
#define NO 0
|
||||||
|
#define MAYBE 2
|
||||||
|
|
||||||
|
#define EXTERN extern
|
||||||
|
|
||||||
|
#define SUFCHAR '.' /* Start of SUFFIX in file name */
|
||||||
|
#define SPACE ' '
|
||||||
|
#define TAB '\t'
|
||||||
|
#define EQUAL '='
|
||||||
|
#define S_VAR '{' /* Start of variable */
|
||||||
|
#define C_VAR '}' /* End of variable */
|
||||||
|
#define A_VAR '?' /* Variable alternative */
|
||||||
|
#define BSLASH '\\' /* Backslash */
|
||||||
|
#define STAR '*' /* STAR */
|
||||||
|
#define C_IN '<' /* Token specifying input */
|
||||||
|
#define C_OUT '>' /* Token specifying output */
|
||||||
|
#define S_EXPR '(' /* Start of expression */
|
||||||
|
#define C_EXPR ')' /* End of expression */
|
||||||
|
#define M_EXPR ':' /* Middle of two suffix lists */
|
||||||
|
#define T_EXPR '=' /* Start of tail */
|
||||||
|
|
||||||
|
#define NO_SCAN 0200 /* Bit set in character to defeat recogn. */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *p_path; /* points to the full pathname */
|
||||||
|
int p_keeps:1; /* The string should be thrown when unused */
|
||||||
|
int p_keep:1; /* The file should be thrown away after use */
|
||||||
|
} path ;
|
||||||
|
|
||||||
|
/* Return values of setpath() */
|
||||||
|
enum f_path { F_OK, F_NOMATCH, F_NOPATH } ;
|
||||||
|
|
||||||
|
/* Library routines */
|
||||||
|
|
||||||
|
extern char *index();
|
||||||
|
extern char *rindex();
|
||||||
|
extern char *strcpy();
|
||||||
|
extern char *strcat();
|
||||||
|
extern char *mktemp();
|
||||||
|
extern int unlink();
|
||||||
|
extern int close();
|
||||||
|
extern int open();
|
||||||
|
extern int creat();
|
||||||
|
|
||||||
|
/* Own routines */
|
||||||
|
enum f_path setpath();
|
||||||
|
enum f_path scan_end();
|
||||||
|
extern int noodstop();
|
||||||
|
extern char *getvar();
|
||||||
|
extern char *keeps();
|
||||||
|
extern char *basename();
|
||||||
|
extern char *skipblank();
|
||||||
|
extern char *firstblank();
|
||||||
|
extern char *getcore();
|
||||||
|
extern char *changecore();
|
||||||
|
#define freecore(area) free(area)
|
||||||
|
|
||||||
|
/* #define DEBUG 1 /* Allow debugging of Ack */
|
||||||
|
|
||||||
|
#ifndef DEBUG
|
||||||
|
# define debug 0 /* To surprise all these 'if ( debug ) 's */
|
||||||
|
#else
|
||||||
|
extern int debug ;
|
||||||
|
#endif
|
||||||
9
util/ack/data.c
Normal file
9
util/ack/data.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "ack.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "trans.h"
|
||||||
|
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#define EXTERN
|
||||||
|
|
||||||
|
#include "data.h"
|
||||||
43
util/ack/data.h
Normal file
43
util/ack/data.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
EXTERN char *stopsuffix; /* Suffix to stop at */
|
||||||
|
EXTERN char *machine; /* The machine id */
|
||||||
|
EXTERN char *rts; /* The runtime-system id */
|
||||||
|
|
||||||
|
EXTERN list_head arguments; /* List of arguments */
|
||||||
|
EXTERN list_head flags; /* List of flags */
|
||||||
|
|
||||||
|
EXTERN list_head c_arguments; /* List of linker arguments */
|
||||||
|
|
||||||
|
EXTERN list_head tr_list; /* List of transformations */
|
||||||
|
|
||||||
|
EXTERN list_head R_list; /* List of -R flags */
|
||||||
|
EXTERN list_head head_list; /* List of suffices for headers */
|
||||||
|
EXTERN list_head tail_list; /* List of suffices for tails */
|
||||||
|
|
||||||
|
EXTERN int k_flag; /* Like -k of lint */
|
||||||
|
EXTERN int g_flag; /* do_run() */
|
||||||
|
EXTERN int t_flag; /* Preserve intermediate files */
|
||||||
|
EXTERN int v_flag; /* Verbose */
|
||||||
|
EXTERN int w_flag; /* Don't print warnings */
|
||||||
|
EXTERN int nill_flag; /* Don't file names */
|
||||||
|
EXTERN int Optflag; /* Optimizing */
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
EXTERN int debug; /* Debugging control */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
EXTERN int n_error; /* Number of errors encountered */
|
||||||
|
|
||||||
|
EXTERN char *progname; /* The program call name */
|
||||||
|
|
||||||
|
EXTERN char *outfile; /* The result file e.g. a.out */
|
||||||
|
EXTERN char *template; /* The template for temporary file
|
||||||
|
names */
|
||||||
|
|
||||||
|
EXTERN trf *combiner; /* Pointer to the Loader/Linker */
|
||||||
|
EXTERN trf *cpp_trafo; /* Pointer to C-preprocessor */
|
||||||
|
|
||||||
|
EXTERN path in; /* The current input pathname */
|
||||||
|
EXTERN path out; /* The current output pathname */
|
||||||
|
EXTERN path orig; /* The original input path */
|
||||||
|
EXTERN char *p_basename; /* The current basename */
|
||||||
|
EXTERN char *p_suffix; /* The current input suffix */
|
||||||
15
util/ack/dmach.h
Normal file
15
util/ack/dmach.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/***************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Definition for table that maps a name on an intable index */
|
||||||
|
/* */
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *ma_name ; /* The name of the machine */
|
||||||
|
int ma_index ;
|
||||||
|
} dmach ;
|
||||||
|
|
||||||
|
extern dmach massoc[] ;
|
||||||
|
|
||||||
|
extern char intable[] ;
|
||||||
94
util/ack/files.c
Normal file
94
util/ack/files.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "trans.h"
|
||||||
|
#include "grows.h"
|
||||||
|
#include "data.h"
|
||||||
|
#include "../../h/em_path.h"
|
||||||
|
|
||||||
|
setfiles(phase) register trf *phase ; {
|
||||||
|
/* Set the out structure according to the in structure,
|
||||||
|
the transformation and some global data */
|
||||||
|
growstring pathname ;
|
||||||
|
register list_elem *elem ;
|
||||||
|
|
||||||
|
if ( phase->t_combine ) {
|
||||||
|
out.p_keep=YES ;
|
||||||
|
out.p_path=outfile ;
|
||||||
|
out.p_keeps=NO ;
|
||||||
|
in.p_path= (char *)0 ;
|
||||||
|
in.p_keep=YES ;
|
||||||
|
in.p_keeps=NO ;
|
||||||
|
} else {
|
||||||
|
gr_init(&pathname) ;
|
||||||
|
if ( !phase->t_keep && !t_flag ) {
|
||||||
|
gr_cat(&pathname,TMP_DIR) ;
|
||||||
|
gr_cat(&pathname,"/") ;
|
||||||
|
gr_cat(&pathname,template) ;
|
||||||
|
out.p_keep=NO ;
|
||||||
|
} else {
|
||||||
|
gr_cat(&pathname,p_basename) ;
|
||||||
|
out.p_keep=YES ;
|
||||||
|
}
|
||||||
|
gr_cat(&pathname,phase->t_out) ;
|
||||||
|
out.p_path= gr_final(&pathname) ;
|
||||||
|
out.p_keeps= YES ;
|
||||||
|
}
|
||||||
|
scanlist( l_first(arguments), elem) {
|
||||||
|
if ( strcmp(l_content(*elem),out.p_path)==0 ) {
|
||||||
|
error("attempt to overwrite argument file") ;
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
disc_files() {
|
||||||
|
if ( in.p_path ) {
|
||||||
|
if ( !in.p_keep ) {
|
||||||
|
if ( unlink(in.p_path)!=0 ) {
|
||||||
|
werror("couldn't unlink %s",in.p_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( in.p_keeps ) throws(in.p_path) ;
|
||||||
|
}
|
||||||
|
in=out ;
|
||||||
|
out.p_path= (char *)0 ;
|
||||||
|
out.p_keeps=NO ;
|
||||||
|
out.p_keep=NO ;
|
||||||
|
}
|
||||||
|
|
||||||
|
rmtemps() {
|
||||||
|
/* Called in case of disaster, always remove the current output file!
|
||||||
|
*/
|
||||||
|
if ( out.p_path ) {
|
||||||
|
unlink(out.p_path) ;
|
||||||
|
if ( out.p_keeps ) throws(out.p_path) ;
|
||||||
|
out.p_path= (char *)0 ;
|
||||||
|
out.p_keeps=NO ;
|
||||||
|
out.p_keep=NO ;
|
||||||
|
}
|
||||||
|
if ( !in.p_keep && in.p_path ) {
|
||||||
|
unlink(in.p_path) ;
|
||||||
|
if ( in.p_keeps ) throws(in.p_path) ;
|
||||||
|
in.p_path= (char *)0 ;
|
||||||
|
out.p_keeps= NO ;
|
||||||
|
out.p_keep=NO ;
|
||||||
|
}
|
||||||
|
}
|
||||||
79
util/ack/grows.c
Normal file
79
util/ack/grows.c
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Bookkeeping for growing strings */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#include "grows.h"
|
||||||
|
|
||||||
|
gr_add(id,c) register growstring *id ; char c ; {
|
||||||
|
if ( id->gr_size==id->gr_max) {
|
||||||
|
if ( id->gr_size==0 ) { /* The first time */
|
||||||
|
id->gr_max= 2*GR_MORE ;
|
||||||
|
id->gr_string= getcore(id->gr_max) ;
|
||||||
|
} else {
|
||||||
|
id->gr_max += GR_MORE ;
|
||||||
|
id->gr_string= changecore(id->gr_string,id->gr_max ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*(id->gr_string+id->gr_size++)= c ;
|
||||||
|
}
|
||||||
|
|
||||||
|
gr_cat(id,string) growstring *id ; char *string ; {
|
||||||
|
register char *ptr ;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( id->gr_size && *(id->gr_string+id->gr_size-1) ) {
|
||||||
|
vprint("Non-zero terminated %*s\n",
|
||||||
|
id->gr_size, id->gr_string ) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if ( id->gr_size ) id->gr_size-- ;
|
||||||
|
ptr=string ;
|
||||||
|
for (;;) {
|
||||||
|
gr_add(id,*ptr) ;
|
||||||
|
if ( *ptr++ ) continue ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gr_throw(id) register growstring *id ; {
|
||||||
|
/* Throw the string away */
|
||||||
|
if ( id->gr_max==0 ) return ;
|
||||||
|
freecore(id->gr_string) ;
|
||||||
|
id->gr_max=0 ;
|
||||||
|
id->gr_size=0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
gr_init(id) growstring *id ; {
|
||||||
|
id->gr_size=0 ; id->gr_max=0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *gr_final(id) growstring *id ; {
|
||||||
|
/* Throw away the bookkeeping, adjust the string to its final
|
||||||
|
length and return a pointer to a string to be get rid of with
|
||||||
|
throws
|
||||||
|
*/
|
||||||
|
register char *retval ;
|
||||||
|
retval= keeps(gr_start(*id)) ;
|
||||||
|
gr_throw(id) ;
|
||||||
|
return retval ;
|
||||||
|
}
|
||||||
19
util/ack/grows.h
Normal file
19
util/ack/grows.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* struct used to identify and do bookkeeping for growing strings */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *gr_string ; /* Points to start of string */
|
||||||
|
unsigned gr_size ; /* Current string size */
|
||||||
|
unsigned gr_max ; /* Maximum string size */
|
||||||
|
} growstring ;
|
||||||
|
|
||||||
|
#define GR_MORE 50 /* Steps to grow */
|
||||||
|
|
||||||
|
#define gr_start(id) (id).gr_string /* The start of the string */
|
||||||
|
|
||||||
|
/* Routines used */
|
||||||
|
|
||||||
|
extern int gr_throw() ; /* To free the core */
|
||||||
|
extern int gr_add() ; /* To add one character */
|
||||||
|
extern int gr_cat() ; /* concatenate the contents and the string */
|
||||||
|
extern int gr_init() ; /* Initialize the bookkeeping */
|
||||||
|
extern char *gr_final() ; /* Transform to a stable storage string */
|
||||||
73
util/ack/list.c
Normal file
73
util/ack/list.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
|
/* List handling, operations allowed:
|
||||||
|
adding strings to the list,
|
||||||
|
throwing away whole lists,
|
||||||
|
linearize a list.
|
||||||
|
|
||||||
|
Routines:
|
||||||
|
l_add(header,string) Add an element to a list.
|
||||||
|
header List header, list_head *
|
||||||
|
string String pointer, char *
|
||||||
|
the string is NOT copied
|
||||||
|
|
||||||
|
l_clear(header) Delete an whole list.
|
||||||
|
header List header, list_head *
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
l_add(header,string) list_head *header ; char *string ; {
|
||||||
|
register list_elem *new;
|
||||||
|
|
||||||
|
/* NOSTRICT */
|
||||||
|
new= (list_elem *)getcore(sizeof *new);
|
||||||
|
l_content(*new)= string ;
|
||||||
|
/* NOSTRICT */
|
||||||
|
l_next(*new)= (list_elem *)0 ;
|
||||||
|
if ( !header->ca_first ) {
|
||||||
|
header->ca_first= new ;
|
||||||
|
} else {
|
||||||
|
header->ca_last->ca_next= new ;
|
||||||
|
}
|
||||||
|
header->ca_last= new ;
|
||||||
|
}
|
||||||
|
|
||||||
|
l_clear(header) list_head *header ; {
|
||||||
|
register list_elem *old, *next;
|
||||||
|
for ( old=header->ca_first ; old ; old= next ) {
|
||||||
|
next= old->ca_next ;
|
||||||
|
freecore((char *)old) ;
|
||||||
|
}
|
||||||
|
header->ca_first= (list_elem *) 0 ;
|
||||||
|
header->ca_last = (list_elem *) 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
l_throw(header) list_head *header ; {
|
||||||
|
register list_elem *old, *next;
|
||||||
|
for ( old=header->ca_first ; old ; old= next ) {
|
||||||
|
throws(l_content(*old)) ;
|
||||||
|
next= old->ca_next ;
|
||||||
|
freecore((char *)old) ;
|
||||||
|
}
|
||||||
|
header->ca_first= (list_elem *) 0 ;
|
||||||
|
header->ca_last = (list_elem *) 0 ;
|
||||||
|
}
|
||||||
23
util/ack/list.h
Normal file
23
util/ack/list.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
struct ca_elem {
|
||||||
|
struct ca_elem *ca_next; /* The link */
|
||||||
|
char *ca_cont; /* The contents */
|
||||||
|
} ;
|
||||||
|
|
||||||
|
struct ca_list {
|
||||||
|
struct ca_elem *ca_first; /* The head */
|
||||||
|
struct ca_elem *ca_last; /* The tail */
|
||||||
|
} ;
|
||||||
|
|
||||||
|
typedef struct ca_list list_head ; /* The decl. for headers */
|
||||||
|
typedef struct ca_elem list_elem ; /* The decl. for elements */
|
||||||
|
|
||||||
|
/* Some operations */
|
||||||
|
|
||||||
|
/* Access */
|
||||||
|
#define l_first(header) (header).ca_first
|
||||||
|
#define l_next(elem) (elem).ca_next
|
||||||
|
#define l_content(elem) (elem).ca_cont
|
||||||
|
|
||||||
|
/* To be used for scanning lists, ptr is the running variable */
|
||||||
|
#define scanlist(elem,ptr) \
|
||||||
|
for ( ptr= elem ; ptr; ptr= l_next(*ptr) )
|
||||||
340
util/ack/main.c
Normal file
340
util/ack/main.c
Normal file
@ -0,0 +1,340 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "trans.h"
|
||||||
|
#include "../../h/em_path.h"
|
||||||
|
#include "../../h/local.h"
|
||||||
|
#include "data.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
static int sigs[] = { SIGINT, SIGHUP, SIGTERM, 0 } ;
|
||||||
|
|
||||||
|
extern char *getenv();
|
||||||
|
|
||||||
|
main(argc,argv) char **argv ; {
|
||||||
|
register list_elem *elem ;
|
||||||
|
register char *frontend ;
|
||||||
|
register int *n_sig ;
|
||||||
|
|
||||||
|
progname=argv[0];
|
||||||
|
varinit();
|
||||||
|
vieuwargs(argc,argv);
|
||||||
|
if ( (frontend=getenv("ACKFE")) ) {
|
||||||
|
setlist(frontend) ;
|
||||||
|
} else {
|
||||||
|
setlist(FRONTENDS);
|
||||||
|
}
|
||||||
|
setlist(machine);
|
||||||
|
transini();
|
||||||
|
scanneeds();
|
||||||
|
template= mktemp(ACKNAME) ;
|
||||||
|
if ( n_error && !k_flag ) return n_error ;
|
||||||
|
|
||||||
|
for ( n_sig=sigs ; *n_sig ; n_sig++ ) {
|
||||||
|
if ( signal(*n_sig,noodstop)==SIG_IGN ) {
|
||||||
|
signal(*n_sig,SIG_IGN) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scanlist ( l_first(arguments), elem ) {
|
||||||
|
if ( !process(l_content(*elem)) && !k_flag ) return 1 ;
|
||||||
|
}
|
||||||
|
orig.p_path= (char *)0 ;
|
||||||
|
|
||||||
|
if ( !combiner && !stopsuffix ) {
|
||||||
|
/* Call combiner directly without any transformation */
|
||||||
|
scanlist(l_first(tr_list),elem) {
|
||||||
|
if ( t_cont(*elem)->t_combine ) {
|
||||||
|
combiner= t_cont(*elem) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !combiner || n_error ) return n_error ;
|
||||||
|
|
||||||
|
if ( !do_combine() ) return 1 ;
|
||||||
|
|
||||||
|
if ( g_flag ) {
|
||||||
|
return do_run();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *srcvar() {
|
||||||
|
return orig.p_path ;
|
||||||
|
}
|
||||||
|
|
||||||
|
varinit() {
|
||||||
|
/* initialize the string variables */
|
||||||
|
setsvar(keeps(HOME),keeps(EM_DIR)) ;
|
||||||
|
setpvar(keeps(SRC),srcvar) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************* flag processing ***********************/
|
||||||
|
|
||||||
|
vieuwargs(argc,argv) char **argv ; {
|
||||||
|
register char *argp;
|
||||||
|
register int nextarg ;
|
||||||
|
register int eaten ;
|
||||||
|
|
||||||
|
firstarg(argv[0]) ;
|
||||||
|
|
||||||
|
nextarg= 1 ;
|
||||||
|
|
||||||
|
while ( nextarg<argc ) {
|
||||||
|
argp= argv[nextarg] ;
|
||||||
|
nextarg++ ;
|
||||||
|
if ( argp[0]!='-' || argp[1]=='l' ) {
|
||||||
|
/* Not a flag, or a library */
|
||||||
|
l_add(&arguments,argp) ;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Flags */
|
||||||
|
eaten=0 ; /* Did not 'eat' tail of flag yet */
|
||||||
|
switch ( argp[1] ) {
|
||||||
|
case 'm': if ( machine ) fuerror("Two machines?") ;
|
||||||
|
machine= &argp[2];
|
||||||
|
eaten=1 ;
|
||||||
|
break ;
|
||||||
|
case 'o': if ( nextarg>=argc ) {
|
||||||
|
fuerror("-o can't be the last flag") ;
|
||||||
|
}
|
||||||
|
if ( outfile ) fuerror("Two results?") ;
|
||||||
|
outfile= argv[nextarg++] ;
|
||||||
|
break ;
|
||||||
|
case 'O': Optflag++ ;
|
||||||
|
break ;
|
||||||
|
case 'v': v_flag++ ;
|
||||||
|
break ;
|
||||||
|
case 'g': g_flag++ ;
|
||||||
|
break ;
|
||||||
|
case 'c': if ( stopsuffix ) fuerror("Two -c flags") ;
|
||||||
|
stopsuffix= &argp[2]; eaten=1;
|
||||||
|
if ( *stopsuffix && *stopsuffix!=SUFCHAR ) {
|
||||||
|
fuerror("-c flag has invalid tail") ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
case 'k': k_flag++ ;
|
||||||
|
break ;
|
||||||
|
case 't': t_flag++ ;
|
||||||
|
break ;
|
||||||
|
case 'R': do_Rflag(argp); eaten=1;
|
||||||
|
break ;
|
||||||
|
case 'r': if ( argp[2]!=SUFCHAR ) {
|
||||||
|
error("-r must be followed by %c",SUFCHAR) ;
|
||||||
|
}
|
||||||
|
keeptail(&argp[2]); eaten=1 ;
|
||||||
|
break ;
|
||||||
|
case '.': if ( rts ) fuerror("Two run-time systems?") ;
|
||||||
|
rts= &argp[1] ; eaten=1;
|
||||||
|
keephead(rts) ; keeptail(rts) ;
|
||||||
|
break ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
case 'd': debug++ ;
|
||||||
|
break ;
|
||||||
|
#endif
|
||||||
|
case 0 : nill_flag++ ; eaten++ ;
|
||||||
|
break;
|
||||||
|
case 'w': { register char *tokeep ;
|
||||||
|
w_flag++;
|
||||||
|
tokeep=keeps(argp) ;
|
||||||
|
*tokeep |= NO_SCAN ;
|
||||||
|
l_add(&flags,tokeep) ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
default: /* The flag is not recognized,
|
||||||
|
put it on the list for the sub-processes
|
||||||
|
*/
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug ) {
|
||||||
|
vprint("Flag %s: phase dependent\n",argp) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
l_add(&flags,keeps(argp)) ;
|
||||||
|
eaten=1 ;
|
||||||
|
}
|
||||||
|
if ( argp[2] && !eaten ) {
|
||||||
|
werror("Unexpected characters at end of %s",argp) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( !machine && ! (machine=getenv("ACKM")) ) {
|
||||||
|
#ifdef ACKM
|
||||||
|
machine= ACKM; /* The default machine */
|
||||||
|
#else
|
||||||
|
fuerror("No machine specified") ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
firstarg(argp) register char *argp ; {
|
||||||
|
register char *name ;
|
||||||
|
|
||||||
|
name=rindex(argp,'/') ;
|
||||||
|
if ( name && *(name+1) ) {
|
||||||
|
name++ ;
|
||||||
|
} else {
|
||||||
|
name= argp ;
|
||||||
|
}
|
||||||
|
if ( strcmp(name,"ack")==0 ) return ;
|
||||||
|
if ( strcmp(name,"acc")==0 || strcmp(name,"cc")==0 ) {
|
||||||
|
rts= ".c" ; keephead(rts) ; keeptail(rts) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if ( strcmp(name,"apc")==0 || strcmp(name,"pc")==0 ) {
|
||||||
|
rts= ".p" ; keephead(rts) ; keeptail(rts) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
machine= name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************* argument processing ***********************/
|
||||||
|
|
||||||
|
process(arg) char *arg ; {
|
||||||
|
/* Process files & library arguments */
|
||||||
|
register list_elem *elem ;
|
||||||
|
register trf *phase ;
|
||||||
|
int first=YES ;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug ) vprint("Processing %s\n",arg) ;
|
||||||
|
#endif
|
||||||
|
if ( arg[0]=='-' ) { l_add(&c_arguments,keeps(arg)) ; return 1 ; }
|
||||||
|
p_suffix= rindex(arg,SUFCHAR) ;
|
||||||
|
if ( p_basename ) throws(p_basename) ;
|
||||||
|
orig.p_keep= YES ; /* Don't throw away the original ! */
|
||||||
|
orig.p_path= arg ;
|
||||||
|
p_basename= keeps(basename(arg)) ;
|
||||||
|
if ( !p_suffix ) { l_add(&c_arguments,keeps(arg)) ; return 1 ; }
|
||||||
|
/* Try to find a path through the transformations */
|
||||||
|
switch( setpath() ) {
|
||||||
|
case F_NOPATH :
|
||||||
|
error("Cannot produce the desired file from %s",arg) ;
|
||||||
|
l_add(&c_arguments,keeps(arg)) ;
|
||||||
|
return 1 ;
|
||||||
|
case F_NOMATCH :
|
||||||
|
if ( stopsuffix ) werror("Unknown suffix in %s",arg) ;
|
||||||
|
l_add(&c_arguments,keeps(arg)) ;
|
||||||
|
return 1 ;
|
||||||
|
case F_OK :
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
orig.p_keeps= NO;
|
||||||
|
in= orig ;
|
||||||
|
scanlist(l_first(tr_list), elem) {
|
||||||
|
phase= t_cont(*elem) ;
|
||||||
|
if ( phase->t_do ) { /* perform this transformation */
|
||||||
|
if ( first ) {
|
||||||
|
if ( !nill_flag ) {
|
||||||
|
printf("%s\n",arg) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch ( phase->t_prep ) {
|
||||||
|
default : if ( !mayprep() ) break ;
|
||||||
|
case YES: if ( !transform(cpp_trafo) ) {
|
||||||
|
n_error++ ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
vprint("Pre-processor failed\n") ;
|
||||||
|
#endif
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
case NO :
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
if ( cpp_trafo && stopsuffix &&
|
||||||
|
strcmp(cpp_trafo->t_out,stopsuffix)==0 ) {
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
if ( !transform(phase) ) {
|
||||||
|
n_error++ ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug ) {
|
||||||
|
vprint("phase %s for %s failed\n",
|
||||||
|
phase->t_name,orig.p_path) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
first=NO ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug ) vprint("Transformation complete for %s\n",orig.p_path) ;
|
||||||
|
#endif
|
||||||
|
if ( !in.p_keep ) fatal("attempt to discard the result file") ;
|
||||||
|
l_add(&c_arguments,keeps(in.p_path));
|
||||||
|
disc_files() ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
mayprep() {
|
||||||
|
int file ;
|
||||||
|
char fc ;
|
||||||
|
file=open(in.p_path,0);
|
||||||
|
if ( file<0 ) return 0 ;
|
||||||
|
if ( read(file,&fc,1)!=1 ) fc=0 ;
|
||||||
|
close(file) ;
|
||||||
|
return fc=='#' ;
|
||||||
|
}
|
||||||
|
|
||||||
|
keephead(suffix) char *suffix ; {
|
||||||
|
l_add(&head_list, suffix) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
keeptail(suffix) char *suffix ; {
|
||||||
|
l_add(&tail_list, suffix) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
scanneeds() {
|
||||||
|
register list_elem *elem ;
|
||||||
|
scanlist(l_first(head_list), elem) { setneeds(l_content(*elem),0) ; }
|
||||||
|
l_clear(&head_list) ;
|
||||||
|
scanlist(l_first(tail_list), elem) { setneeds(l_content(*elem),1) ; }
|
||||||
|
l_clear(&tail_list) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
setneeds(suffix,tail) char *suffix ; {
|
||||||
|
register list_elem *elem ;
|
||||||
|
register trf *phase ;
|
||||||
|
|
||||||
|
p_suffix= suffix ;
|
||||||
|
switch ( setpath() ) {
|
||||||
|
case F_OK :
|
||||||
|
scanlist( l_first(tr_list), elem ) {
|
||||||
|
phase = t_cont(*elem) ;
|
||||||
|
if ( phase->t_do ) {
|
||||||
|
if ( phase->t_needed ) {
|
||||||
|
if ( tail )
|
||||||
|
add_tail(phase->t_needed) ;
|
||||||
|
else
|
||||||
|
add_head(phase->t_needed) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
case F_NOMATCH :
|
||||||
|
werror("\"%s\": unrecognized suffix",suffix) ;
|
||||||
|
break ;
|
||||||
|
case F_NOPATH :
|
||||||
|
werror("incomplete internal specification for %s files",
|
||||||
|
suffix) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
208
util/ack/malloc.c
Normal file
208
util/ack/malloc.c
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define ASSERT(p) if(!(p))botch("p");else
|
||||||
|
botch(s)
|
||||||
|
char *s;
|
||||||
|
{
|
||||||
|
printf("malloc/free botched: %s\n",s);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define ASSERT(p)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* avoid break bug */
|
||||||
|
#ifdef pdp11
|
||||||
|
#define GRANULE 64
|
||||||
|
#else
|
||||||
|
#define GRANULE 0
|
||||||
|
#endif
|
||||||
|
/* C storage allocator
|
||||||
|
* circular first-fit strategy
|
||||||
|
* works with noncontiguous, but monotonically linked, arena
|
||||||
|
* each block is preceded by a ptr to the (pointer of)
|
||||||
|
* the next following block
|
||||||
|
* blocks are exact number of words long
|
||||||
|
* aligned to the data type requirements of ALIGN
|
||||||
|
* pointers to blocks must have BUSY bit 0
|
||||||
|
* bit in ptr is 1 for busy, 0 for idle
|
||||||
|
* gaps in arena are merely noted as busy blocks
|
||||||
|
* last block of arena (pointed to by alloct) is empty and
|
||||||
|
* has a pointer to first
|
||||||
|
* idle blocks are coalesced during space search
|
||||||
|
*
|
||||||
|
* a different implementation may need to redefine
|
||||||
|
* ALIGN, NALIGN, BLOCK, BUSY, INT
|
||||||
|
* where INT is integer type to which a pointer can be cast
|
||||||
|
*/
|
||||||
|
#define INT int
|
||||||
|
#define ALIGN int
|
||||||
|
#define NALIGN 1
|
||||||
|
#define WORD sizeof(union store)
|
||||||
|
#define BLOCK 1024 /* a multiple of WORD*/
|
||||||
|
#define BUSY 1
|
||||||
|
#define NULL 0
|
||||||
|
#define testbusy(p) ((INT)(p)&BUSY)
|
||||||
|
#define setbusy(p) (union store *)((INT)(p)|BUSY)
|
||||||
|
#define clearbusy(p) (union store *)((INT)(p)&~BUSY)
|
||||||
|
|
||||||
|
union store { union store *ptr;
|
||||||
|
ALIGN dummy[NALIGN];
|
||||||
|
int calloc; /*calloc clears an array of integers*/
|
||||||
|
};
|
||||||
|
|
||||||
|
static union store allocs[2]; /*initial arena*/
|
||||||
|
static union store *allocp; /*search ptr*/
|
||||||
|
static union store *alloct; /*arena top*/
|
||||||
|
static union store *allocx; /*for benefit of realloc*/
|
||||||
|
char *sbrk();
|
||||||
|
|
||||||
|
char *
|
||||||
|
malloc(nbytes)
|
||||||
|
unsigned nbytes;
|
||||||
|
{
|
||||||
|
register union store *p, *q;
|
||||||
|
register nw;
|
||||||
|
static temp; /*coroutines assume no auto*/
|
||||||
|
|
||||||
|
if(allocs[0].ptr==0) { /*first time*/
|
||||||
|
allocs[0].ptr = setbusy(&allocs[1]);
|
||||||
|
allocs[1].ptr = setbusy(&allocs[0]);
|
||||||
|
alloct = &allocs[1];
|
||||||
|
allocp = &allocs[0];
|
||||||
|
}
|
||||||
|
nw = (nbytes+WORD+WORD-1)/WORD;
|
||||||
|
ASSERT(allocp>=allocs && allocp<=alloct);
|
||||||
|
ASSERT(allock());
|
||||||
|
for(p=allocp; ; ) {
|
||||||
|
for(temp=0; ; ) {
|
||||||
|
if(!testbusy(p->ptr)) {
|
||||||
|
while(!testbusy((q=p->ptr)->ptr)) {
|
||||||
|
ASSERT(q>p&&q<alloct);
|
||||||
|
p->ptr = q->ptr;
|
||||||
|
}
|
||||||
|
if(q>=p+nw && p+nw>=p)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
q = p;
|
||||||
|
p = clearbusy(p->ptr);
|
||||||
|
if(p>q)
|
||||||
|
ASSERT(p<=alloct);
|
||||||
|
else if(q!=alloct || p!=allocs) {
|
||||||
|
ASSERT(q==alloct&&p==allocs);
|
||||||
|
return(NULL);
|
||||||
|
} else if(++temp>1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
temp = ((nw+BLOCK/WORD)/(BLOCK/WORD))*(BLOCK/WORD);
|
||||||
|
q = (union store *)sbrk(0);
|
||||||
|
if(q+temp+GRANULE < q) {
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
q = (union store *)sbrk(temp*WORD);
|
||||||
|
if((INT)q == -1) {
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
ASSERT(q>alloct);
|
||||||
|
alloct->ptr = q;
|
||||||
|
if(q!=alloct+1)
|
||||||
|
alloct->ptr = setbusy(alloct->ptr);
|
||||||
|
alloct = q->ptr = q+temp-1;
|
||||||
|
alloct->ptr = setbusy(allocs);
|
||||||
|
}
|
||||||
|
found:
|
||||||
|
allocp = p + nw;
|
||||||
|
ASSERT(allocp<=alloct);
|
||||||
|
if(q>allocp) {
|
||||||
|
allocx = allocp->ptr;
|
||||||
|
allocp->ptr = p->ptr;
|
||||||
|
}
|
||||||
|
p->ptr = setbusy(allocp);
|
||||||
|
return((char *)(p+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* freeing strategy tuned for LIFO allocation
|
||||||
|
*/
|
||||||
|
free(ap)
|
||||||
|
register char *ap;
|
||||||
|
{
|
||||||
|
register union store *p = (union store *)ap;
|
||||||
|
|
||||||
|
ASSERT(p>clearbusy(allocs[1].ptr)&&p<=alloct);
|
||||||
|
ASSERT(allock());
|
||||||
|
allocp = --p;
|
||||||
|
ASSERT(testbusy(p->ptr));
|
||||||
|
p->ptr = clearbusy(p->ptr);
|
||||||
|
ASSERT(p->ptr > allocp && p->ptr <= alloct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* realloc(p, nbytes) reallocates a block obtained from malloc()
|
||||||
|
* and freed since last call of malloc()
|
||||||
|
* to have new size nbytes, and old content
|
||||||
|
* returns new location, or 0 on failure
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *
|
||||||
|
realloc(p, nbytes)
|
||||||
|
register union store *p;
|
||||||
|
unsigned nbytes;
|
||||||
|
{
|
||||||
|
register union store *q;
|
||||||
|
union store *s, *t;
|
||||||
|
register unsigned nw;
|
||||||
|
unsigned onw;
|
||||||
|
|
||||||
|
if(testbusy(p[-1].ptr))
|
||||||
|
free((char *)p);
|
||||||
|
onw = p[-1].ptr - p;
|
||||||
|
q = (union store *)malloc(nbytes);
|
||||||
|
if(q==NULL || q==p)
|
||||||
|
return((char *)q);
|
||||||
|
s = p;
|
||||||
|
t = q;
|
||||||
|
nw = (nbytes+WORD-1)/WORD;
|
||||||
|
if(nw<onw)
|
||||||
|
onw = nw;
|
||||||
|
while(onw--!=0)
|
||||||
|
*t++ = *s++;
|
||||||
|
if(q<p && q+nw>=p)
|
||||||
|
(q+(q+nw-p))->ptr = allocx;
|
||||||
|
return((char *)q);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
allock()
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
register union store *p;
|
||||||
|
int x;
|
||||||
|
x = 0;
|
||||||
|
for(p= &allocs[0]; clearbusy(p->ptr) > p; p=clearbusy(p->ptr)) {
|
||||||
|
if(p==allocp)
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
ASSERT(p==alloct);
|
||||||
|
return(x==1|p==allocp);
|
||||||
|
#else
|
||||||
|
return(1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
121
util/ack/mktables.c
Normal file
121
util/ack/mktables.c
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
char *fname = 0 ;
|
||||||
|
char dname[200] ;
|
||||||
|
char *tail ;
|
||||||
|
|
||||||
|
FILE *intab ;
|
||||||
|
FILE *dmach ;
|
||||||
|
|
||||||
|
int index ;
|
||||||
|
|
||||||
|
main(argc,argv) char **argv ; {
|
||||||
|
register i ;
|
||||||
|
|
||||||
|
start(argv[1]) ;
|
||||||
|
for ( i=2 ; i<argc ; i++ ) {
|
||||||
|
fname= argv[i] ;
|
||||||
|
readm() ;
|
||||||
|
}
|
||||||
|
stop(argc>2) ;
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
start(dir) char *dir ; {
|
||||||
|
tail= dname ;
|
||||||
|
while ( *dir ) {
|
||||||
|
*tail++ = *dir ++ ;
|
||||||
|
}
|
||||||
|
if ( tail!=dname ) *tail++= '/' ;
|
||||||
|
index=0 ;
|
||||||
|
intab= fopen("intable.c","w");
|
||||||
|
dmach= fopen("dmach.c","w");
|
||||||
|
if ( intab==NULL || dmach==NULL ) {
|
||||||
|
fprintf(stderr,"Couln't create output file(s)\n");
|
||||||
|
exit ( 1) ;
|
||||||
|
}
|
||||||
|
fprintf(dmach,"#include \"dmach.h\"\n\ndmach\tmassoc[] = {\n") ;
|
||||||
|
fprintf(intab,"char intable[] = {\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
stop(filled) {
|
||||||
|
fprintf(dmach,"\t{\"\",\t-1\t}\n} ;\n") ;
|
||||||
|
if ( !filled ) fprintf(intab,"\t0\n") ;
|
||||||
|
fprintf(intab,"\n} ;\n") ;
|
||||||
|
fclose(dmach); fclose(intab) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *do_open(file) char *file ; {
|
||||||
|
strcpy(tail,file) ;
|
||||||
|
return fopen(dname,"r") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
readm() {
|
||||||
|
register int i ;
|
||||||
|
register int token ;
|
||||||
|
register FILE *in ;
|
||||||
|
|
||||||
|
in=do_open(fname) ;
|
||||||
|
if ( in==NULL ) {
|
||||||
|
fprintf(stderr,"Cannot open %s\n",fname) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
i=0 ;
|
||||||
|
fprintf(dmach,"\t{\"%s\",\t%d\t},\n",fname,index) ;
|
||||||
|
fprintf(intab,"\n/* %s */\n\t",fname) ;
|
||||||
|
for (;;) {
|
||||||
|
token=getc(in) ;
|
||||||
|
index++ ;
|
||||||
|
if ( ++i == 10 ) {
|
||||||
|
fprintf(intab,"\n\t") ;
|
||||||
|
i=0 ;
|
||||||
|
} else {
|
||||||
|
fprintf(intab," ") ;
|
||||||
|
}
|
||||||
|
if ( !isascii(token) || !(isprint(token) || isspace(token)) ){
|
||||||
|
if ( token!=EOF ) {
|
||||||
|
fprintf(stderr,"warning: non-ascii in %s\n",fname) ;
|
||||||
|
fprintf(intab,"%4d,",token) ;
|
||||||
|
} else {
|
||||||
|
fprintf(intab," 0,",token) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
} else if ( isprint(token) ) {
|
||||||
|
switch ( token ) {
|
||||||
|
case '\'': fprintf(intab,"'\\''") ; break ;
|
||||||
|
case '\\': fprintf(intab,"'\\\\'") ; break ;
|
||||||
|
default: fprintf(intab," '%c'",token) ; break ;
|
||||||
|
}
|
||||||
|
} else switch ( token ) {
|
||||||
|
case '\n' : fprintf(intab,"'\\n'") ; break ;
|
||||||
|
case '\t' : fprintf(intab,"'\\t'") ; break ;
|
||||||
|
case '\r' : fprintf(intab,"'\\r'") ; break ;
|
||||||
|
case '\f' : fprintf(intab,"'\\f'") ; break ;
|
||||||
|
case ' ' : fprintf(intab," ' '") ; break ;
|
||||||
|
default : fprintf(stderr,"warning: unrec. %d\n",
|
||||||
|
token) ;
|
||||||
|
fprintf(intab,"%4d",token) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
fprintf(intab,",") ;
|
||||||
|
}
|
||||||
|
fclose(in) ;
|
||||||
|
}
|
||||||
2
util/ack/pc/.distr
Normal file
2
util/ack/pc/.distr
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Makefile
|
||||||
|
em_pc.c
|
||||||
25
util/ack/pc/Makefile
Normal file
25
util/ack/pc/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
d=../../..
|
||||||
|
h=$d/h
|
||||||
|
|
||||||
|
PC_PATH=$d/lib/em_pc
|
||||||
|
|
||||||
|
em_pc: em_pc.c $h/local.h $h/em_path.h
|
||||||
|
cc -n -o em_pc -O -I$h em_pc.c
|
||||||
|
|
||||||
|
cmp: em_pc
|
||||||
|
cmp em_pc $(PC_PATH)
|
||||||
|
|
||||||
|
install: em_pc
|
||||||
|
cp em_pc $(PC_PATH)
|
||||||
|
|
||||||
|
lint:
|
||||||
|
lint -hpxc -I$h em_pc.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o *.old em_pc
|
||||||
|
|
||||||
|
opr:
|
||||||
|
make pr ^ opr
|
||||||
|
|
||||||
|
pr:
|
||||||
|
pr -n em_pc.c
|
||||||
681
util/ack/pc/em_pc.c
Normal file
681
util/ack/pc/em_pc.c
Normal file
@ -0,0 +1,681 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* put all the pieces of the pascal part of the EM project together
|
||||||
|
* original author: Johan Stevenson, Vrije Universiteit, Amsterdam
|
||||||
|
* heavily modified by: Ed Keizer, Vrije Universiteit, Amsterdam
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/dir.h>
|
||||||
|
#include <em_path.h>
|
||||||
|
#include <pc_size.h>
|
||||||
|
#include <local.h>
|
||||||
|
|
||||||
|
#define MAX_FLAG 40 /* The Max. no of '{' flags allowed */
|
||||||
|
|
||||||
|
#define void int
|
||||||
|
|
||||||
|
char *pc_path = PEM_PATH ;
|
||||||
|
char *err_path = ERR_PATH;
|
||||||
|
|
||||||
|
int toterr;
|
||||||
|
int parent;
|
||||||
|
|
||||||
|
char *eeflag;
|
||||||
|
char *vvflag = "-V";
|
||||||
|
int no_pemflag = 0 ;
|
||||||
|
char *pemflag[MAX_FLAG];
|
||||||
|
char *eflag;
|
||||||
|
char *wflag;
|
||||||
|
|
||||||
|
int sizes[sz_last+1] = {
|
||||||
|
2, /* sz_addr */
|
||||||
|
8, /* sz_real */
|
||||||
|
0, /* sz_head */
|
||||||
|
512, /* sz_buff */
|
||||||
|
4096, /* sz_mset */
|
||||||
|
2, /* sz_iset */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CALLSIZE 60
|
||||||
|
char *callvector[CALLSIZE];
|
||||||
|
char **av;
|
||||||
|
int ac;
|
||||||
|
int fileargs; /* number of recognized, processed args */
|
||||||
|
int flagargs;
|
||||||
|
char *progname;
|
||||||
|
char *source;
|
||||||
|
|
||||||
|
#define CHARSIZE 2500
|
||||||
|
#define CHARMARG 50
|
||||||
|
char charbuf[CHARSIZE];
|
||||||
|
char *charp = charbuf;
|
||||||
|
|
||||||
|
char *tmp_dir = TMP_DIR;
|
||||||
|
char *unique = "pcXXXXXX";
|
||||||
|
|
||||||
|
char sigs[] = {
|
||||||
|
SIGHUP,
|
||||||
|
SIGINT,
|
||||||
|
SIGTERM,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* forward function declarations
|
||||||
|
*/
|
||||||
|
void finish();
|
||||||
|
void pem();
|
||||||
|
int list();
|
||||||
|
char *flag();
|
||||||
|
char *tempfile();
|
||||||
|
char **initvector();
|
||||||
|
char *basename();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* used library routines and data
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern char *sys_errlist[];
|
||||||
|
extern int errno;
|
||||||
|
|
||||||
|
int atoi();
|
||||||
|
void exit();
|
||||||
|
void sleep();
|
||||||
|
void execv();
|
||||||
|
char *sbrk();
|
||||||
|
int chdir();
|
||||||
|
int fork();
|
||||||
|
int wait();
|
||||||
|
int getpid();
|
||||||
|
int open();
|
||||||
|
int close();
|
||||||
|
int read();
|
||||||
|
|
||||||
|
main(argc,argv) char **argv; {
|
||||||
|
register char *p;
|
||||||
|
char *files[3] ;
|
||||||
|
|
||||||
|
for (p = sigs; *p; p++)
|
||||||
|
if (signal(*p,finish) == SIG_IGN)
|
||||||
|
signal(*p,SIG_IGN);
|
||||||
|
ac = argc;
|
||||||
|
av = argv;
|
||||||
|
progname = *av++;
|
||||||
|
init();
|
||||||
|
while ( --ac>0 ) {
|
||||||
|
p = *av++;
|
||||||
|
if (*p == '-') {
|
||||||
|
flagargs++;
|
||||||
|
p = flag(p);
|
||||||
|
} else {
|
||||||
|
if ( fileargs>=3 ) fatal("Too many file arguments") ;
|
||||||
|
files[fileargs++]= p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( fileargs!=3 ) fatal("Not enough arguments") ;
|
||||||
|
source=files[2] ;
|
||||||
|
pem(files[0],files[1]) ;
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
char *flag(f) char *f; {
|
||||||
|
register char *p;
|
||||||
|
|
||||||
|
p = f+1;
|
||||||
|
switch (*p++) {
|
||||||
|
case 'e':
|
||||||
|
eflag = f;
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
eeflag = f;
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
wflag = f;
|
||||||
|
break;
|
||||||
|
case 'V':
|
||||||
|
vvflag = f;
|
||||||
|
return(0);
|
||||||
|
case '{':
|
||||||
|
if ( no_pemflag>=MAX_FLAG ) {
|
||||||
|
ermess("too many flags, ignored %s",f) ;
|
||||||
|
} else {
|
||||||
|
pemflag[no_pemflag++] = p;
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
case 'R':
|
||||||
|
pc_path= p ;
|
||||||
|
return 0 ;
|
||||||
|
case 'r' :
|
||||||
|
err_path= p ;
|
||||||
|
return 0 ;
|
||||||
|
default:
|
||||||
|
return(f);
|
||||||
|
}
|
||||||
|
if (*p)
|
||||||
|
fatal("bad flag %s",f);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
initsizes(f) FILE *f; {
|
||||||
|
register c, i;
|
||||||
|
register char *p;
|
||||||
|
|
||||||
|
p = vvflag + 2;
|
||||||
|
while (c = *p++) {
|
||||||
|
i = atoi(p);
|
||||||
|
while (*p >= '0' && *p <= '9')
|
||||||
|
p++;
|
||||||
|
switch (c) {
|
||||||
|
case 'p': sz_addr = i; continue;
|
||||||
|
case 'f': sz_real = i; continue;
|
||||||
|
case 'h': sz_head = i; continue;
|
||||||
|
case 'b': sz_buff = i; continue;
|
||||||
|
case 'm': sz_mset = i; continue;
|
||||||
|
case 'j': sz_iset = i; continue;
|
||||||
|
case 'w':
|
||||||
|
case 'i': if (i == 2) continue; break;
|
||||||
|
case 'l': if (i == 4) continue; break;
|
||||||
|
}
|
||||||
|
fatal("bad V-flag %s",vvflag);
|
||||||
|
}
|
||||||
|
if (sz_head == 0)
|
||||||
|
sz_head = 6*sz_word + 2*sz_addr;
|
||||||
|
for (i = 0; i <= sz_last; i++)
|
||||||
|
fprintf(f, "%d\n",sizes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------ calling sequences -------------------- */
|
||||||
|
|
||||||
|
pem(p,q) char *p,*q; {
|
||||||
|
register char **v,*d;
|
||||||
|
int i;
|
||||||
|
FILE *erfil;
|
||||||
|
|
||||||
|
v = initvector(pc_path);
|
||||||
|
d = tempfile('d');
|
||||||
|
if ((erfil = fopen(d,"w")) == NULL)
|
||||||
|
syserr(d);
|
||||||
|
initsizes(erfil);
|
||||||
|
fprintf(erfil,"%s\n",basename(source));
|
||||||
|
for ( i=0 ; i<no_pemflag ; i++ ) fprintf(erfil,"%s\n",pemflag[i]);
|
||||||
|
fclose(erfil);
|
||||||
|
*v++ = q;
|
||||||
|
*v++ = d;
|
||||||
|
call(v,p,(char *)0);
|
||||||
|
if (toterr == 0)
|
||||||
|
if (list(p,d) < 0)
|
||||||
|
toterr++;
|
||||||
|
donewith(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------- miscellaneous routines --------------- */
|
||||||
|
|
||||||
|
char *basename(p) char *p; {
|
||||||
|
register char *q;
|
||||||
|
|
||||||
|
q = p;
|
||||||
|
while (*q)
|
||||||
|
if (*q++ == '/')
|
||||||
|
p = q;
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *tempfile(suf) {
|
||||||
|
register char *p,*q;
|
||||||
|
register i;
|
||||||
|
|
||||||
|
p = charp; q = tmp_dir;
|
||||||
|
while (*p = *q++)
|
||||||
|
p++;
|
||||||
|
*p++ = '/';
|
||||||
|
q = unique;
|
||||||
|
while (*p = *q++)
|
||||||
|
p++;
|
||||||
|
i = fileargs;
|
||||||
|
do
|
||||||
|
*p++ = i % 10 + '0';
|
||||||
|
while (i /= 10);
|
||||||
|
*p++ = '.'; *p++ = suf; *p++ = '\0';
|
||||||
|
q = charp; charp = p;
|
||||||
|
return(q);
|
||||||
|
}
|
||||||
|
|
||||||
|
call(v,in,out) char **v,*in,*out; {
|
||||||
|
register pid;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
while ((parent = fork()) < 0)
|
||||||
|
sleep(1);
|
||||||
|
if (parent == 0) {
|
||||||
|
if (in) {
|
||||||
|
close(0);
|
||||||
|
if (open(in,0) != 0)
|
||||||
|
syserr(in);
|
||||||
|
}
|
||||||
|
if (out) {
|
||||||
|
close(1);
|
||||||
|
if (creat(out,0666) != 1)
|
||||||
|
syserr(out);
|
||||||
|
}
|
||||||
|
*v = 0;
|
||||||
|
execv(callvector[0],callvector+1);
|
||||||
|
syserr(callvector[0]);
|
||||||
|
}
|
||||||
|
while ((pid = wait(&status)) != parent) {
|
||||||
|
if (pid == -1)
|
||||||
|
fatal("process %d disappeared",parent);
|
||||||
|
fatal("unknown child %d died",pid);
|
||||||
|
}
|
||||||
|
if ((status & 0177) > 3) {
|
||||||
|
/*
|
||||||
|
if ((status & 0200) && tflag==0)
|
||||||
|
unlink("core");
|
||||||
|
*/
|
||||||
|
fatal("signal %d in %s. Ask an expert for help",
|
||||||
|
status&0177,callvector[0]);
|
||||||
|
}
|
||||||
|
if (status & 0177400)
|
||||||
|
toterr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
char **initvector(path) char *path; {
|
||||||
|
register char *p,**v;
|
||||||
|
|
||||||
|
v = callvector;
|
||||||
|
p = path;
|
||||||
|
*v++ = p;
|
||||||
|
*v++ = basename(p);
|
||||||
|
return(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
finish() {
|
||||||
|
register char *p,*q;
|
||||||
|
register fd;
|
||||||
|
struct direct dir;
|
||||||
|
|
||||||
|
signal(SIGINT,SIG_IGN);
|
||||||
|
if (parent != 0) {
|
||||||
|
chdir(tmp_dir);
|
||||||
|
fd = open(".",0);
|
||||||
|
while (read(fd,(char *) &dir,sizeof dir) == sizeof dir) {
|
||||||
|
if (dir.d_ino == 0)
|
||||||
|
continue;
|
||||||
|
p = unique;
|
||||||
|
q = dir.d_name;
|
||||||
|
while (*p++ == *q++)
|
||||||
|
if (*p == '\0') {
|
||||||
|
unlink(dir.d_name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
exit(toterr ? -1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
donewith(p) char *p; {
|
||||||
|
|
||||||
|
if (p >= charbuf && p < &charbuf[CHARSIZE])
|
||||||
|
unlink(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
register char *p;
|
||||||
|
register i,fd;
|
||||||
|
|
||||||
|
if ((fd = open(tmp_dir,0)) < 0)
|
||||||
|
tmp_dir = ".";
|
||||||
|
close(fd);
|
||||||
|
p = unique+2;
|
||||||
|
parent = i = getpid();
|
||||||
|
do
|
||||||
|
*p++ = i % 10 + '0';
|
||||||
|
while (i /= 10);
|
||||||
|
*p++ = '.'; *p = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------- pascal listing ----------------------- */
|
||||||
|
|
||||||
|
#define MAXERNO 300
|
||||||
|
#define MAXERRLIST 10
|
||||||
|
#define IDMAX 8
|
||||||
|
|
||||||
|
struct errec {
|
||||||
|
int erno;
|
||||||
|
char mess[IDMAX+1];
|
||||||
|
int mesi;
|
||||||
|
int chno;
|
||||||
|
int lino;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct errec curr;
|
||||||
|
struct errec next;
|
||||||
|
|
||||||
|
int *index = 0;
|
||||||
|
int maxerno;
|
||||||
|
|
||||||
|
int errerr;
|
||||||
|
int errfat;
|
||||||
|
|
||||||
|
int listlino;
|
||||||
|
int listorig;
|
||||||
|
int listrela;
|
||||||
|
char *listfnam;
|
||||||
|
|
||||||
|
FILE *inpfil;
|
||||||
|
FILE *mesfil;
|
||||||
|
FILE *errfil;
|
||||||
|
|
||||||
|
int errorline();
|
||||||
|
int geterrec();
|
||||||
|
int nexterror();
|
||||||
|
|
||||||
|
int list(p,q) char *p,*q; {
|
||||||
|
|
||||||
|
if ((errfil = fopen(q,"r")) == NULL)
|
||||||
|
syserr(q);
|
||||||
|
if (geterrec() == 0)
|
||||||
|
if (eeflag==0) {
|
||||||
|
fclose(errfil);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
if (index == 0) {
|
||||||
|
index = (int *) sbrk(MAXERNO * sizeof index[0]);
|
||||||
|
fillindex();
|
||||||
|
}
|
||||||
|
if ((inpfil = fopen(p,"r")) == NULL)
|
||||||
|
syserr(p);
|
||||||
|
errerr = 0;
|
||||||
|
errfat = 0;
|
||||||
|
listlino = 0;
|
||||||
|
listorig = 0;
|
||||||
|
listrela = 0;
|
||||||
|
listfnam = source;
|
||||||
|
if (eeflag)
|
||||||
|
listfull();
|
||||||
|
else if (eflag)
|
||||||
|
listpartial();
|
||||||
|
else
|
||||||
|
listshort();
|
||||||
|
fclose(errfil);
|
||||||
|
fclose(inpfil);
|
||||||
|
fflush(stdout);
|
||||||
|
return(errfat ? -1 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
listshort() {
|
||||||
|
|
||||||
|
while (nexterror()) {
|
||||||
|
while (listlino < curr.lino)
|
||||||
|
nextline(0);
|
||||||
|
printf("%s, line %d: ",listfnam,listrela);
|
||||||
|
string(&curr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listfull() {
|
||||||
|
|
||||||
|
if (nexterror())
|
||||||
|
do {
|
||||||
|
do {
|
||||||
|
nextline(1);
|
||||||
|
} while (listlino < curr.lino);
|
||||||
|
} while (errorline());
|
||||||
|
while (nextline(1))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
listpartial() {
|
||||||
|
|
||||||
|
if (nexterror())
|
||||||
|
do {
|
||||||
|
do {
|
||||||
|
nextline(listlino >= curr.lino-2);
|
||||||
|
} while (listlino < curr.lino);
|
||||||
|
} while (errorline());
|
||||||
|
}
|
||||||
|
|
||||||
|
int nextline(printing) {
|
||||||
|
register ch;
|
||||||
|
|
||||||
|
listlino++;
|
||||||
|
ch = getc(inpfil);
|
||||||
|
if (ch == '#') {
|
||||||
|
if (lineline(printing) == 0)
|
||||||
|
fatal("bad line directive");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
listrela++;
|
||||||
|
if (listfnam == source)
|
||||||
|
listorig++;
|
||||||
|
if (ch != EOF) {
|
||||||
|
if (printing)
|
||||||
|
printf("%5d\t",listorig);
|
||||||
|
do {
|
||||||
|
if (printing)
|
||||||
|
putchar(ch);
|
||||||
|
if (ch == '\n')
|
||||||
|
return(1);
|
||||||
|
} while ((ch = getc(inpfil)) != EOF);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
lineline(printing) {
|
||||||
|
register ch;
|
||||||
|
register char *p,*q;
|
||||||
|
static char line[100];
|
||||||
|
|
||||||
|
p = line;
|
||||||
|
while ((ch = getc(inpfil)) != '\n') {
|
||||||
|
if (ch == EOF || p == &line[100-1])
|
||||||
|
return(0);
|
||||||
|
*p++ = ch;
|
||||||
|
}
|
||||||
|
*p = '\0'; p = line;
|
||||||
|
if (printing)
|
||||||
|
printf("\t#%s\n",p);
|
||||||
|
if ((listrela = atoi(p)-1) < 0)
|
||||||
|
return(0);
|
||||||
|
while ((ch = *p++) != '"')
|
||||||
|
if (ch == '\0')
|
||||||
|
return(0);
|
||||||
|
q = p;
|
||||||
|
while (ch = *p++) {
|
||||||
|
if (ch == '"') {
|
||||||
|
*--p = '\0';
|
||||||
|
if ( source ) {
|
||||||
|
listfnam = strcmp(q,source)==0 ? source : q;
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
source=q ; listfnam=q ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
if (ch == '/')
|
||||||
|
q = p;
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int errorline() {
|
||||||
|
register c;
|
||||||
|
register struct errec *p,*q;
|
||||||
|
struct errec lerr[MAXERRLIST];
|
||||||
|
int goon;
|
||||||
|
|
||||||
|
printf("*** ***");
|
||||||
|
p = lerr;
|
||||||
|
c = 0;
|
||||||
|
do {
|
||||||
|
if (c < curr.chno) {
|
||||||
|
printf("%*c",curr.chno-c,'^');
|
||||||
|
c = curr.chno;
|
||||||
|
}
|
||||||
|
if (p < &lerr[MAXERRLIST])
|
||||||
|
*p++ = curr;
|
||||||
|
goon = nexterror();
|
||||||
|
} while (goon && curr.lino==listlino);
|
||||||
|
putchar('\n');
|
||||||
|
for (q = lerr; q < p; q++)
|
||||||
|
string(q);
|
||||||
|
putchar('\n');
|
||||||
|
return(goon);
|
||||||
|
}
|
||||||
|
|
||||||
|
int geterrec() {
|
||||||
|
register ch;
|
||||||
|
register char *p;
|
||||||
|
|
||||||
|
ch = getc(errfil);
|
||||||
|
next.erno = 0;
|
||||||
|
next.mesi = -1;
|
||||||
|
next.mess[0] = '\0';
|
||||||
|
if (ch == EOF)
|
||||||
|
return(0);
|
||||||
|
if (ch >= '0' && ch <= '9') {
|
||||||
|
ch = getnum(ch,&next.mesi);
|
||||||
|
} else if (ch == '\'') {
|
||||||
|
p = next.mess;
|
||||||
|
while ((ch = getc(errfil)) != ' ' && ch != EOF)
|
||||||
|
if (p < &next.mess[IDMAX])
|
||||||
|
*p++ = ch;
|
||||||
|
*p = '\0';
|
||||||
|
}
|
||||||
|
ch = getnum(ch, &next.erno);
|
||||||
|
ch = getnum(ch, &next.lino);
|
||||||
|
ch = getnum(ch, &next.chno);
|
||||||
|
if (ch != '\n')
|
||||||
|
fatal("bad error line");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getnum(ch, ip) register ch; register *ip; {
|
||||||
|
register neg;
|
||||||
|
|
||||||
|
*ip = 0;
|
||||||
|
while (ch == ' ')
|
||||||
|
ch = getc(errfil);
|
||||||
|
if (neg = ch=='-')
|
||||||
|
ch = getc(errfil);
|
||||||
|
while (ch >= '0' && ch <= '9') {
|
||||||
|
*ip = *ip * 10 - '0' + ch;
|
||||||
|
ch = getc(errfil);
|
||||||
|
}
|
||||||
|
if (neg)
|
||||||
|
*ip = -(*ip);
|
||||||
|
return(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nexterror() {
|
||||||
|
|
||||||
|
do { /* skip warnings if wflag */
|
||||||
|
curr = next;
|
||||||
|
if (curr.erno == 0)
|
||||||
|
return(0);
|
||||||
|
for (;;) {
|
||||||
|
if (geterrec() == 0)
|
||||||
|
break;
|
||||||
|
if (next.lino != curr.lino || next.chno != curr.chno)
|
||||||
|
break;
|
||||||
|
if (curr.erno < 0 && next.erno > 0)
|
||||||
|
/* promote warnings if they cause fatals */
|
||||||
|
curr.erno = -curr.erno;
|
||||||
|
if (next.mess[0] != '\0' || next.mesi != -1)
|
||||||
|
/* give all parameterized errors */
|
||||||
|
break;
|
||||||
|
if (curr.mess[0] != '\0' || curr.mesi != -1)
|
||||||
|
/* and at least a non-parameterized one */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (curr.erno < 0 && wflag != 0);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fillindex() {
|
||||||
|
register *ip,n,c;
|
||||||
|
|
||||||
|
if ((mesfil = fopen(err_path,"r")) == NULL)
|
||||||
|
syserr(err_path);
|
||||||
|
ip = index;
|
||||||
|
*ip++ = 0;
|
||||||
|
n = 0;
|
||||||
|
while ((c = getc(mesfil)) != EOF) {
|
||||||
|
n++;
|
||||||
|
if (c == '\n') {
|
||||||
|
*ip++ = n;
|
||||||
|
if (ip > &index[MAXERNO])
|
||||||
|
fatal("too many errors on %s",err_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maxerno = ip - index;
|
||||||
|
}
|
||||||
|
|
||||||
|
string(ep) register struct errec *ep; {
|
||||||
|
register i,n;
|
||||||
|
|
||||||
|
errerr++;
|
||||||
|
if ((i = ep->erno) < 0) {
|
||||||
|
i = -i;
|
||||||
|
printf("Warning: ");
|
||||||
|
} else
|
||||||
|
errfat++;
|
||||||
|
if (i == 0 || i >= maxerno)
|
||||||
|
fatal("bad error number %d",i);
|
||||||
|
n = index[i] - index[i-1];
|
||||||
|
fseek(mesfil,(long)index[i-1],0);
|
||||||
|
while (--n >= 0) {
|
||||||
|
i = getc(mesfil);
|
||||||
|
if (i == '%' && --n>=0) {
|
||||||
|
i = getc(mesfil);
|
||||||
|
if (i == 'i')
|
||||||
|
printf("%d", ep->mesi);
|
||||||
|
else if (i == 's')
|
||||||
|
printf("%s", ep->mess);
|
||||||
|
else
|
||||||
|
putchar(i);
|
||||||
|
} else
|
||||||
|
putchar(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------- error routines -------------------------- */
|
||||||
|
|
||||||
|
/* VARARGS1 */
|
||||||
|
void ermess(s,a1,a2,a3,a4) char *s; {
|
||||||
|
|
||||||
|
fprintf(stderr,"%s: ",progname);
|
||||||
|
fprintf(stderr,s,a1,a2,a3,a4);
|
||||||
|
fprintf(stderr,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
syserr(s) char *s; {
|
||||||
|
fatal("%s: %s",s,sys_errlist[errno]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* VARARGS1 */
|
||||||
|
void fatal(s,a1,a2,a3,a4) char *s; {
|
||||||
|
|
||||||
|
ermess(s,a1,a2,a3,a4);
|
||||||
|
toterr++;
|
||||||
|
finish();
|
||||||
|
}
|
||||||
154
util/ack/run.c
Normal file
154
util/ack/run.c
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "trans.h"
|
||||||
|
#include "data.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#define ARG_MORE 40 /* The size of args chunks to allocate */
|
||||||
|
|
||||||
|
static char **arglist ; /* The first argument */
|
||||||
|
static unsigned argcount ; /* The current number of arguments */
|
||||||
|
static unsigned argmax; /* The maximum number of arguments so far */
|
||||||
|
|
||||||
|
int do_run() {
|
||||||
|
fatal("-g flag not implemeted") ;
|
||||||
|
/*NOTREACHED*/
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int runphase(phase) register trf *phase ; {
|
||||||
|
register list_elem *elem ;
|
||||||
|
|
||||||
|
if ( v_flag || debug ) {
|
||||||
|
if ( v_flag==1 && !debug ) {
|
||||||
|
vprint("%s",phase->t_name) ;
|
||||||
|
if ( !phase->t_combine ) {
|
||||||
|
vprint(" %s%s\n",p_basename,
|
||||||
|
rindex(in.p_path,SUFCHAR) ) ;
|
||||||
|
} else {
|
||||||
|
scanlist(l_first(c_arguments), elem) {
|
||||||
|
vprint(" %s",l_content(*elem)) ;
|
||||||
|
}
|
||||||
|
vprint("\n") ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* list all args */
|
||||||
|
vprint("%s",phase->t_prog) ;
|
||||||
|
scanlist(l_first(phase->t_flags), elem) {
|
||||||
|
vprint(" %s",l_content(*elem)) ;
|
||||||
|
}
|
||||||
|
scanlist(l_first(phase->t_args), elem) {
|
||||||
|
vprint(" %s",l_content(*elem)) ;
|
||||||
|
}
|
||||||
|
vprint("\n") ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argcount=0 ;
|
||||||
|
x_arg(phase->t_name) ;
|
||||||
|
scanlist(l_first(phase->t_flags), elem) {
|
||||||
|
x_arg(l_content(*elem)) ;
|
||||||
|
}
|
||||||
|
scanlist(l_first(phase->t_args), elem) {
|
||||||
|
x_arg(l_content(*elem)) ;
|
||||||
|
}
|
||||||
|
x_arg( (char *)0 ) ;
|
||||||
|
return run_exec(phase) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int run_exec(phase) trf *phase ; {
|
||||||
|
int status, child, waitchild ;
|
||||||
|
|
||||||
|
do_flush();
|
||||||
|
while ( (child=fork())== -1 ) ;
|
||||||
|
if ( child ) {
|
||||||
|
/* The parent */
|
||||||
|
do {
|
||||||
|
waitchild= wait(&status) ;
|
||||||
|
if ( waitchild== -1 ) {
|
||||||
|
fatal("missing child") ;
|
||||||
|
}
|
||||||
|
} while ( waitchild!=child) ;
|
||||||
|
if ( status ) {
|
||||||
|
if ( status&0200 && (status&0177)!=SIGQUIT &&
|
||||||
|
!t_flag ) unlink("core") ;
|
||||||
|
switch ( status&0177 ) {
|
||||||
|
case 0 :
|
||||||
|
break ;
|
||||||
|
case SIGHUP:
|
||||||
|
case SIGINT:
|
||||||
|
case SIGQUIT:
|
||||||
|
case SIGTERM:
|
||||||
|
quit(-5) ;
|
||||||
|
default:
|
||||||
|
error("%s died with signal %d",
|
||||||
|
phase->t_prog,status&0177) ;
|
||||||
|
}
|
||||||
|
/* The assumption is that processes voluntarely
|
||||||
|
dying with a non-zero status already produced
|
||||||
|
some sort of error message to the outside world.
|
||||||
|
*/
|
||||||
|
n_error++ ;
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
return 1 ; /* From the parent */
|
||||||
|
}
|
||||||
|
/* The child */
|
||||||
|
if ( phase->t_stdin ) {
|
||||||
|
if ( !in.p_path ) {
|
||||||
|
fatal("no input file for %s",phase->t_name) ;
|
||||||
|
}
|
||||||
|
close(0) ;
|
||||||
|
if ( open(in.p_path,0)!=0 ) {
|
||||||
|
error("cannot open %s",in.p_path) ;
|
||||||
|
exit(1) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( phase->t_stdout ) {
|
||||||
|
if ( !out.p_path ) {
|
||||||
|
fatal("no output file for %s",phase->t_name) ;
|
||||||
|
}
|
||||||
|
close(1) ;
|
||||||
|
if ( creat(out.p_path,0666)!=1 ) {
|
||||||
|
close(1); dup(2);
|
||||||
|
error("cannot open %s",out.p_path) ;
|
||||||
|
exit(1) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
execv(phase->t_prog,arglist) ;
|
||||||
|
if ( phase->t_stdout ) { close(1) ; dup(2) ; }
|
||||||
|
error("Cannot execute %s",phase->t_prog) ;
|
||||||
|
exit(1) ;
|
||||||
|
/*NOTREACHED*/
|
||||||
|
}
|
||||||
|
|
||||||
|
x_arg(string) char *string ; {
|
||||||
|
/* Add one execute argument to the argument vector */
|
||||||
|
if ( argcount==argmax ) {
|
||||||
|
if ( argmax==0 ) {
|
||||||
|
argmax= 2*ARG_MORE ;
|
||||||
|
arglist= (char **)getcore(argmax*sizeof (char *)) ;
|
||||||
|
} else {
|
||||||
|
argmax += ARG_MORE ;
|
||||||
|
arglist= (char **)changecore((char *)arglist,
|
||||||
|
argmax*sizeof (char *)) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*(arglist+argcount++) = string ;
|
||||||
|
}
|
||||||
244
util/ack/scan.c
Normal file
244
util/ack/scan.c
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "trans.h"
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
enum f_path setpath() { /* Try to find a transformation path */
|
||||||
|
|
||||||
|
start_scan();
|
||||||
|
/*
|
||||||
|
The end result is the setting of the t_do flags
|
||||||
|
in the transformation list.
|
||||||
|
The list is scanned for possible transformations
|
||||||
|
stopping at stopsuffix or a combine transformation.
|
||||||
|
The scan flags are set by this process.
|
||||||
|
When a transformation is found, it is compared with
|
||||||
|
the last transformation found, if better (or the first)
|
||||||
|
the scan bits are copied to the t_do bits, except for
|
||||||
|
the combiner which is remembered in a global pointer.
|
||||||
|
At the end of all transformations for all files, the combiner
|
||||||
|
is called, unless errors occurred.
|
||||||
|
*/
|
||||||
|
try(l_first(tr_list),p_suffix);
|
||||||
|
return scan_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************** data used only while scanning *******************/
|
||||||
|
|
||||||
|
static int last_ncount; /* The # of non-optimizing transformations
|
||||||
|
in the best path sofar */
|
||||||
|
|
||||||
|
static int last_ocount; /* The # of optimizing transformations in the
|
||||||
|
best path sofar */
|
||||||
|
static int com_err; /* Complain only once about multiple linkers*/
|
||||||
|
|
||||||
|
static trf *final; /* The last non-combining transformation */
|
||||||
|
|
||||||
|
static int suf_found; /* Was the suffix at least recognized ? */
|
||||||
|
|
||||||
|
/******************** The hard work ********************/
|
||||||
|
|
||||||
|
start_scan() {
|
||||||
|
register list_elem *scan ;
|
||||||
|
|
||||||
|
scanlist(l_first(tr_list),scan) {
|
||||||
|
t_cont(*scan)->t_do=NO ; t_cont(*scan)->t_scan=NO ;
|
||||||
|
t_cont(*scan)->t_keep=NO ;
|
||||||
|
}
|
||||||
|
final= (trf *)0 ;
|
||||||
|
suf_found= 0 ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=3 ) vprint("Scan_start\n");
|
||||||
|
#endif
|
||||||
|
last_ncount= -1 ;
|
||||||
|
last_ocount= 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
try(f_scan,suffix) list_elem *f_scan; char *suffix; {
|
||||||
|
register list_elem *scan ;
|
||||||
|
register trf *trafo ;
|
||||||
|
/* Try to find a transformation path starting at f_scan for a
|
||||||
|
file with the indicated suffix.
|
||||||
|
If the suffix is already reached or the combiner is found
|
||||||
|
call scan_found() to OK the scan.
|
||||||
|
If a transformation is found it calls itself recursively
|
||||||
|
with as starting point the next transformation in the list.
|
||||||
|
*/
|
||||||
|
if ( stopsuffix && *stopsuffix && strcmp(stopsuffix,suffix)==0 ) {
|
||||||
|
scan_found();
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
scanlist(f_scan, scan) {
|
||||||
|
trafo= t_cont(*scan) ;
|
||||||
|
if ( satisfy(trafo,suffix) ) {
|
||||||
|
/* Found a transformation */
|
||||||
|
suf_found= 1;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=4 ) {
|
||||||
|
vprint("Found %s for %s: result %s\n",
|
||||||
|
trafo->t_name,suffix,trafo->t_out);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
trafo->t_scan=YES ;
|
||||||
|
if ( trafo->t_prep ) {
|
||||||
|
if ( !cpp_trafo ) {
|
||||||
|
find_cpp() ;
|
||||||
|
}
|
||||||
|
if ( stopsuffix &&
|
||||||
|
strcmp(stopsuffix,
|
||||||
|
cpp_trafo->t_out)==0 )
|
||||||
|
{
|
||||||
|
scan_found() ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( trafo->t_combine ) {
|
||||||
|
if ( stopsuffix ) {
|
||||||
|
trafo->t_scan=NO;
|
||||||
|
if ( *stopsuffix ) return ;
|
||||||
|
} else {
|
||||||
|
if( combiner &&
|
||||||
|
combiner!=trafo && !com_err ){
|
||||||
|
com_err++ ;
|
||||||
|
werror("Multiple linkers present %s and %s",
|
||||||
|
trafo->t_name,combiner->t_name) ;
|
||||||
|
} else {
|
||||||
|
combiner=trafo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scan_found() ;
|
||||||
|
} else {
|
||||||
|
try(l_next(*scan),trafo->t_out);
|
||||||
|
}
|
||||||
|
trafo->t_scan= NO ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scan_found() {
|
||||||
|
register list_elem *scan;
|
||||||
|
int ncount, ocount ;
|
||||||
|
register trf *keepit ;
|
||||||
|
|
||||||
|
keepit= (trf *)0 ;
|
||||||
|
suf_found= 1;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=3 ) vprint("Scan found\n") ;
|
||||||
|
#endif
|
||||||
|
/* Gather data used in comparison */
|
||||||
|
ncount=0; ocount=0;
|
||||||
|
scanlist(l_first(tr_list),scan) {
|
||||||
|
if (t_cont(*scan)->t_scan) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=4 ) vprint("%s-",t_cont(*scan)->t_name) ;
|
||||||
|
#endif
|
||||||
|
if( t_cont(*scan)->t_optim ) ocount++ ;else ncount++ ;
|
||||||
|
if ( !(t_cont(*scan)->t_combine) ) {
|
||||||
|
keepit= t_cont(*scan) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=4 ) vprint("\n");
|
||||||
|
#endif
|
||||||
|
/* Is this transformation better then any found yet ? */
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=3 ) {
|
||||||
|
vprint("old n:%d, o:%d - new n:%d, o:%d\n",
|
||||||
|
last_ncount,last_ocount,ncount,ocount) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if ( last_ncount== -1 || /* None found yet */
|
||||||
|
last_ncount>ncount || /* Shorter nec. path */
|
||||||
|
(last_ncount==ncount && /* Same nec. path, optimize?*/
|
||||||
|
(Optflag? last_ocount<ocount : last_ocount>ocount ) ) ) {
|
||||||
|
/* Yes it is */
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=3 ) vprint("Better\n");
|
||||||
|
#endif
|
||||||
|
scanlist(l_first(tr_list),scan) {
|
||||||
|
t_cont(*scan)->t_do=t_cont(*scan)->t_scan;
|
||||||
|
}
|
||||||
|
last_ncount=ncount; last_ocount=ocount;
|
||||||
|
if ( keepit ) final=keepit ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int satisfy(trafo,suffix) register trf *trafo; char *suffix ; {
|
||||||
|
register char *f_char, *l_char ;
|
||||||
|
/* Check whether this transformation is present for
|
||||||
|
the current machine and the parameter suffix is among
|
||||||
|
the input suffices. If so, return 1. 0 otherwise
|
||||||
|
*/
|
||||||
|
if ( trafo->t_isprep ) return 0 ;
|
||||||
|
l_char=trafo->t_in ;
|
||||||
|
while ( l_char ) {
|
||||||
|
f_char= l_char ;
|
||||||
|
if ( *f_char!=SUFCHAR || ! *(f_char+1) ) {
|
||||||
|
fuerror("Illegal input suffix entry for %s",
|
||||||
|
trafo->t_name) ;
|
||||||
|
}
|
||||||
|
l_char=index(f_char+1,SUFCHAR);
|
||||||
|
if ( l_char ? strncmp(f_char,suffix,l_char-f_char)==0 :
|
||||||
|
strcmp(f_char,suffix)==0 ) {
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum f_path scan_end() { /* Finalization */
|
||||||
|
/* Return value indicating whether a transformation was found */
|
||||||
|
/* Set the flags for the transformation up to, but not including,
|
||||||
|
the combiner
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=3 ) vprint("End_scan\n");
|
||||||
|
#endif
|
||||||
|
if ( last_ncount== -1 ) return suf_found ? F_NOPATH : F_NOMATCH ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=2 ) vprint("Transformation found\n");
|
||||||
|
#endif
|
||||||
|
if ( cpp_trafo && stopsuffix &&
|
||||||
|
strcmp(stopsuffix,cpp_trafo->t_out)==0 ) {
|
||||||
|
final= cpp_trafo ;
|
||||||
|
}
|
||||||
|
/* There might not be a final when the file can be eaten
|
||||||
|
by the combiner
|
||||||
|
*/
|
||||||
|
if ( final ) final->t_keep=YES ;
|
||||||
|
if ( combiner ) {
|
||||||
|
if ( !combiner->t_do ) error("Combiner YES/NO");
|
||||||
|
combiner->t_do=NO ;
|
||||||
|
}
|
||||||
|
return F_OK ;
|
||||||
|
}
|
||||||
|
|
||||||
|
find_cpp() {
|
||||||
|
register list_elem *elem ;
|
||||||
|
scanlist( l_first(tr_list), elem ) {
|
||||||
|
if ( t_cont(*elem)->t_isprep ) {
|
||||||
|
if ( cpp_trafo ) fuerror("Multiple cpp's present") ;
|
||||||
|
cpp_trafo= t_cont(*elem) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( !cpp_trafo ) fuerror("No cpp present") ;
|
||||||
|
}
|
||||||
125
util/ack/svars.c
Normal file
125
util/ack/svars.c
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
|
||||||
|
/* The processing of string valued variables,
|
||||||
|
this is an almost self contained module.
|
||||||
|
|
||||||
|
Five externally visible routines:
|
||||||
|
|
||||||
|
setsvar(name,result)
|
||||||
|
Associate the name with the result.
|
||||||
|
|
||||||
|
name a string pointer
|
||||||
|
result a string pointer
|
||||||
|
|
||||||
|
setpvar(name,routine)
|
||||||
|
Associate the name with the routine.
|
||||||
|
|
||||||
|
name a string pointer
|
||||||
|
routine a routine id
|
||||||
|
|
||||||
|
The parameters name and result are supposed to be pointing to
|
||||||
|
non-volatile string storage used only for this call.
|
||||||
|
|
||||||
|
char *getvar(name)
|
||||||
|
returns the pointer to a string associated with name,
|
||||||
|
the pointer is produced by returning result or the
|
||||||
|
value returned by calling the routine.
|
||||||
|
|
||||||
|
name a string pointer
|
||||||
|
|
||||||
|
Other routines called
|
||||||
|
|
||||||
|
fatal(args*) When something goes wrong
|
||||||
|
getcore(size) Core allocation
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern char *getcore();
|
||||||
|
extern fatal();
|
||||||
|
|
||||||
|
struct vars {
|
||||||
|
char *v_name;
|
||||||
|
enum { routine, string } v_type;
|
||||||
|
|
||||||
|
union {
|
||||||
|
char *v_string;
|
||||||
|
char *(*v_routine)();
|
||||||
|
} v_value ;
|
||||||
|
struct vars *v_next ;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct vars *v_first ;
|
||||||
|
|
||||||
|
static struct vars *newvar(name) char *name; {
|
||||||
|
register struct vars *new ;
|
||||||
|
|
||||||
|
for ( new=v_first ; new ; new= new->v_next ) {
|
||||||
|
if ( strcmp(name,new->v_name)==0 ) {
|
||||||
|
throws(name) ;
|
||||||
|
if ( new->v_type== string ) {
|
||||||
|
throws(new->v_value.v_string) ;
|
||||||
|
}
|
||||||
|
return new ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new= (struct vars *)getcore( (unsigned)sizeof (struct vars));
|
||||||
|
new->v_name= name ;
|
||||||
|
new->v_next= v_first ;
|
||||||
|
v_first= new ;
|
||||||
|
return new ;
|
||||||
|
}
|
||||||
|
|
||||||
|
setsvar(name,str) char *name, *str ; {
|
||||||
|
register struct vars *new ;
|
||||||
|
|
||||||
|
new= newvar(name);
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=2 ) vprint("%s=%s\n", name, str) ;
|
||||||
|
#endif
|
||||||
|
new->v_type= string;
|
||||||
|
new->v_value.v_string= str;
|
||||||
|
}
|
||||||
|
|
||||||
|
setpvar(name,rout) char *name, *(*rout)() ; {
|
||||||
|
register struct vars *new ;
|
||||||
|
|
||||||
|
new= newvar(name);
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=2 ) vprint("%s= (*%o)()\n",name,rout) ;
|
||||||
|
#endif
|
||||||
|
new->v_type= routine;
|
||||||
|
new->v_value.v_routine= rout;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *getvar(name) char *name ; {
|
||||||
|
register struct vars *scan ;
|
||||||
|
|
||||||
|
for ( scan=v_first ; scan ; scan= scan->v_next ) {
|
||||||
|
if ( strcmp(name,scan->v_name)==0 ) {
|
||||||
|
switch ( scan->v_type ) {
|
||||||
|
case string:
|
||||||
|
return scan->v_value.v_string ;
|
||||||
|
case routine:
|
||||||
|
return (*scan->v_value.v_routine)() ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (char *)0 ;
|
||||||
|
}
|
||||||
672
util/ack/trans.c
Normal file
672
util/ack/trans.c
Normal file
@ -0,0 +1,672 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "trans.h"
|
||||||
|
#include "grows.h"
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Routines for transforming from one file type to another */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
static growstring head ;
|
||||||
|
static int touch_head= NO ;
|
||||||
|
static growstring tail ;
|
||||||
|
static int touch_tail= NO ;
|
||||||
|
|
||||||
|
char *headvar(),*tailvar() ;
|
||||||
|
|
||||||
|
int transform(phase) register trf *phase ; {
|
||||||
|
int ok ;
|
||||||
|
|
||||||
|
if ( !setfiles(phase) ) return 0 ;
|
||||||
|
if ( !phase->t_visited ) {
|
||||||
|
/* The flags are set up once.
|
||||||
|
At the first time the phase is used.
|
||||||
|
The program name and flags may already be touched
|
||||||
|
by vieuwargs.
|
||||||
|
*/
|
||||||
|
phase->t_visited=YES ;
|
||||||
|
if ( !rts && phase->t_rts ) rts= phase->t_rts ;
|
||||||
|
if ( phase->t_needed ) {
|
||||||
|
add_head(phase->t_needed) ;
|
||||||
|
add_tail(phase->t_needed) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getcallargs(phase) ;
|
||||||
|
ok= runphase(phase) ;
|
||||||
|
if ( !ok ) rmtemps() ;
|
||||||
|
/* Free the space occupied by the arguments,
|
||||||
|
except for the combiner, since we are bound to exit soon
|
||||||
|
and do not foresee further need of memory space */
|
||||||
|
if ( !phase->t_combine ) discardargs(phase) ;
|
||||||
|
disc_files() ;
|
||||||
|
return ok ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_combine() {
|
||||||
|
setsvar(keeps(RTS), keeps(rts? rts : "") ) ;
|
||||||
|
if ( !outfile ) outfile= combiner->t_out ;
|
||||||
|
getmapflags(combiner);
|
||||||
|
return transform(combiner) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
getmapflags(phase) register trf *phase ; {
|
||||||
|
register list_elem *elem ;
|
||||||
|
int scanned ;
|
||||||
|
register char *ptr ;
|
||||||
|
|
||||||
|
scanlist(l_first(flags),elem) {
|
||||||
|
scanned= *(l_content(*elem))&NO_SCAN ;
|
||||||
|
*(l_content(*elem)) &= ~NO_SCAN ;
|
||||||
|
if ( mapflag(&(phase->t_mapf),l_content(*elem)) ) {
|
||||||
|
scanned=NO_SCAN ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug >=4 ) {
|
||||||
|
vprint("phase %s, added mapflag for %s\n",
|
||||||
|
phase->t_name,
|
||||||
|
l_content(*elem) ) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
*(l_content(*elem)) |= scanned ;
|
||||||
|
}
|
||||||
|
if ( phase->t_combine ) {
|
||||||
|
scanlist(l_first(c_arguments),elem) {
|
||||||
|
if ( mapflag(&(phase->t_mapf),l_content(*elem)) ) {
|
||||||
|
throws(l_content(*elem)) ;
|
||||||
|
ptr= keeps(getvar(LIBVAR)) ;
|
||||||
|
clr_noscan(ptr) ;
|
||||||
|
l_content(*elem)= ptr ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scanlist(l_first(flags),elem) {
|
||||||
|
/* Get the flags remaining for the loader,
|
||||||
|
That is: all the flags neither eaten by ack nor
|
||||||
|
one of the subprograms called so-far.
|
||||||
|
The last fact is indicated by the NO_SCAN bit
|
||||||
|
in the first character of the flag.
|
||||||
|
*/
|
||||||
|
if ( !( *(l_content(*elem))&NO_SCAN ) ) {
|
||||||
|
l_add(&(phase->t_flags),l_content(*elem)) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
do_Rflag(argp) char *argp ; {
|
||||||
|
l_add(&R_list,argp) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *needvar() {
|
||||||
|
static growstring needed ;
|
||||||
|
static int been_here = NO ;
|
||||||
|
|
||||||
|
if ( !been_here ) {
|
||||||
|
gr_init(&needed) ;
|
||||||
|
been_here=YES ;
|
||||||
|
gr_cat(&needed,headvar()) ;
|
||||||
|
gr_cat(&needed,tailvar()) ;
|
||||||
|
}
|
||||||
|
return gr_start(needed) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *headvar() {
|
||||||
|
if ( !touch_head) return "" ;
|
||||||
|
return gr_start(head) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_head(str) char *str; {
|
||||||
|
if ( !touch_head) {
|
||||||
|
gr_init(&head) ;
|
||||||
|
touch_head=YES ;
|
||||||
|
}
|
||||||
|
gr_cat(&head,str) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *tailvar() {
|
||||||
|
if ( !touch_tail ) return "" ;
|
||||||
|
return gr_start(tail) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_tail(str) char *str ; {
|
||||||
|
if ( !touch_tail ) {
|
||||||
|
gr_init(&tail) ;
|
||||||
|
touch_tail=YES ;
|
||||||
|
}
|
||||||
|
gr_cat(&tail,str) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
transini() {
|
||||||
|
register list_elem *elem ;
|
||||||
|
register trf *phase ;
|
||||||
|
|
||||||
|
scanlist(l_first(R_list), elem) {
|
||||||
|
set_Rflag(l_content(*elem)) ;
|
||||||
|
}
|
||||||
|
l_clear(&R_list) ;
|
||||||
|
scanlist(l_first(tr_list), elem) {
|
||||||
|
phase = t_cont(*elem) ;
|
||||||
|
if ( !phase->t_combine ) getmapflags(phase);
|
||||||
|
}
|
||||||
|
setpvar(keeps(NEEDS),needvar) ;
|
||||||
|
setpvar(keeps(HEAD),headvar) ;
|
||||||
|
setpvar(keeps(TAIL),tailvar) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_Rflag(argp) register char *argp ; {
|
||||||
|
int seen ;
|
||||||
|
register char *eos ;
|
||||||
|
register list_elem *prog ;
|
||||||
|
register int length ;
|
||||||
|
char *eq ;
|
||||||
|
|
||||||
|
eos= index(&argp[2],'-');
|
||||||
|
eq= index(&argp[2],EQUAL) ;
|
||||||
|
if ( !eos ) {
|
||||||
|
eos= eq ;
|
||||||
|
} else {
|
||||||
|
if ( eq && eq<eos ) eos= eq ;
|
||||||
|
}
|
||||||
|
if ( !eos ) fuerror("Incorrect use of -R flag") ;
|
||||||
|
length= eos - &argp[2] ;
|
||||||
|
seen=NO ;
|
||||||
|
scanlist(l_first(tr_list), prog) {
|
||||||
|
if ( strncmp(t_cont(*prog)->t_name, &argp[2], length )==0 ) {
|
||||||
|
if ( *eos=='-' ) {
|
||||||
|
l_add(&(t_cont(*prog)->t_flags),eos) ;
|
||||||
|
} else {
|
||||||
|
t_cont(*prog)->t_prog= eos+1 ;
|
||||||
|
}
|
||||||
|
seen=YES ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( !seen ) error("Cannot find program for %s",argp) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* The creation of arguments for exec for a transformation */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
growstring scanb(line) char *line ; {
|
||||||
|
/* Scan a line for backslashes, setting the NO_SCAN bit in characters
|
||||||
|
preceded by a backslash.
|
||||||
|
*/
|
||||||
|
register char *in_c ;
|
||||||
|
register int token ;
|
||||||
|
growstring result ;
|
||||||
|
enum { TEXT, ESCAPED } state = TEXT ;
|
||||||
|
|
||||||
|
gr_init(&result) ;
|
||||||
|
for ( in_c= line ; *in_c ; in_c++ ) {
|
||||||
|
token= *in_c&0377 ;
|
||||||
|
switch( state ) {
|
||||||
|
case TEXT :
|
||||||
|
if ( token==BSLASH ) {
|
||||||
|
state= ESCAPED ;
|
||||||
|
} else {
|
||||||
|
gr_add(&result,token) ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
case ESCAPED :
|
||||||
|
gr_add(&result,token|NO_SCAN) ;
|
||||||
|
state=TEXT ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gr_add(&result,0) ;
|
||||||
|
if ( state!=TEXT ) werror("flag line ends with %c",BSLASH) ;
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
growstring scanvars(line) char *line ; {
|
||||||
|
/* Scan a line variable replacements started by S_VAR.
|
||||||
|
Two sequences exist: S_VAR name E_VAR, S_VAR name A_VAR text E_VAR.
|
||||||
|
neither name nor text may contain further replacements.
|
||||||
|
In the first form an error message is issued if the name is not
|
||||||
|
present in the variables, the second form produces text
|
||||||
|
in that case.
|
||||||
|
The sequence S_VAR S_VAR is transformed into S_VAR.
|
||||||
|
This to allow later recognition in mapflags, where B_SLASH
|
||||||
|
would be preventing any recognition.
|
||||||
|
*/
|
||||||
|
register char *in_c ;
|
||||||
|
register int token ;
|
||||||
|
growstring result ;
|
||||||
|
growstring name ;
|
||||||
|
register char *tr ;
|
||||||
|
enum { TEXT, FIRST, NAME, SKIP, COPY } state = TEXT ;
|
||||||
|
|
||||||
|
gr_init(&result) ; gr_init(&name) ;
|
||||||
|
for ( in_c= line ; *in_c ; in_c++ ) {
|
||||||
|
token= *in_c&0377 ;
|
||||||
|
switch( state ) {
|
||||||
|
case TEXT :
|
||||||
|
if ( token==S_VAR ) {
|
||||||
|
state= FIRST ;
|
||||||
|
} else {
|
||||||
|
gr_add(&result,token) ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
case FIRST :
|
||||||
|
switch ( token ) {
|
||||||
|
case S_VAR :
|
||||||
|
state= TEXT ;
|
||||||
|
gr_add(&result,token) ;
|
||||||
|
break ;
|
||||||
|
case A_VAR :
|
||||||
|
case C_VAR :
|
||||||
|
fatal("empty string variable name") ;
|
||||||
|
default :
|
||||||
|
state=NAME ;
|
||||||
|
gr_add(&name,token) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
case NAME:
|
||||||
|
switch ( token ) {
|
||||||
|
case A_VAR :
|
||||||
|
gr_add(&name,0) ;
|
||||||
|
if ( tr=getvar(gr_start(name)) ) {
|
||||||
|
while ( *tr ) {
|
||||||
|
gr_add(&result,*tr++) ;
|
||||||
|
}
|
||||||
|
state=SKIP ;
|
||||||
|
} else {
|
||||||
|
state=COPY ;
|
||||||
|
}
|
||||||
|
gr_throw(&name) ;
|
||||||
|
break ;
|
||||||
|
case C_VAR :
|
||||||
|
gr_add(&name,0) ;
|
||||||
|
if ( tr=getvar(gr_start(name)) ) {
|
||||||
|
while ( *tr ) {
|
||||||
|
gr_add(&result,*tr++);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
werror("No definition for %s",
|
||||||
|
gr_start(name)) ;
|
||||||
|
}
|
||||||
|
state=TEXT ;
|
||||||
|
gr_throw(&name) ;
|
||||||
|
break ;
|
||||||
|
default:
|
||||||
|
gr_add(&name,token) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
case SKIP :
|
||||||
|
if ( token==C_VAR ) state= TEXT ;
|
||||||
|
break ;
|
||||||
|
case COPY :
|
||||||
|
if ( token==C_VAR ) state= TEXT ; else {
|
||||||
|
gr_add(&result,token) ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gr_add(&result,0) ;
|
||||||
|
if ( state!=TEXT ) {
|
||||||
|
werror("flag line misses %c",C_VAR) ;
|
||||||
|
gr_throw(&name) ;
|
||||||
|
}
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
growstring scanexpr(line) char *line ; {
|
||||||
|
/* Scan a line for conditional or flag expressions,
|
||||||
|
dependent on the type. The format is
|
||||||
|
S_EXPR suflist M_EXPR suflist T_EXPR tail C_EXPR
|
||||||
|
the head and tail are passed to treat, together with the
|
||||||
|
growstring for futher treatment.
|
||||||
|
Nesting is not allowed.
|
||||||
|
*/
|
||||||
|
register char *in_c ;
|
||||||
|
char *heads ;
|
||||||
|
register int token ;
|
||||||
|
growstring sufs, tailval ;
|
||||||
|
growstring result ;
|
||||||
|
static list_head fsuff, lsuff ;
|
||||||
|
enum { TEXT, FDOT, FSUF, LDOT, LSUF, FTAIL } state = TEXT ;
|
||||||
|
|
||||||
|
gr_init(&result) ; gr_init(&sufs) ; gr_init(&tailval) ;
|
||||||
|
for ( in_c= line ; *in_c ; in_c++ ) {
|
||||||
|
token= *in_c&0377 ;
|
||||||
|
switch( state ) {
|
||||||
|
case TEXT :
|
||||||
|
if ( token==S_EXPR ) {
|
||||||
|
state= FDOT ;
|
||||||
|
heads=in_c ;
|
||||||
|
} else gr_add(&result,token) ;
|
||||||
|
break ;
|
||||||
|
case FDOT :
|
||||||
|
if ( token==M_EXPR ) {
|
||||||
|
state=LDOT ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
token &= ~NO_SCAN ;
|
||||||
|
if ( token!=SUFCHAR ) {
|
||||||
|
error("Missing %c in expression",SUFCHAR) ;
|
||||||
|
}
|
||||||
|
gr_add(&sufs,token) ; state=FSUF ;
|
||||||
|
break ;
|
||||||
|
case FSUF :
|
||||||
|
if ( token==M_EXPR || (token&~NO_SCAN)==SUFCHAR) {
|
||||||
|
gr_add(&sufs,0) ;
|
||||||
|
l_add(&fsuff,gr_final(&sufs)) ;
|
||||||
|
}
|
||||||
|
if ( token==M_EXPR ) {
|
||||||
|
state=LDOT ;
|
||||||
|
} else gr_add(&sufs,token&~NO_SCAN) ;
|
||||||
|
break ;
|
||||||
|
case LDOT :
|
||||||
|
if ( token==T_EXPR ) {
|
||||||
|
state=FTAIL ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
token &= ~NO_SCAN ;
|
||||||
|
if ( token!=SUFCHAR ) {
|
||||||
|
error("Missing %c in expression",SUFCHAR) ;
|
||||||
|
}
|
||||||
|
gr_add(&sufs,token) ; state=LSUF ;
|
||||||
|
break ;
|
||||||
|
case LSUF :
|
||||||
|
if ( token==T_EXPR || (token&~NO_SCAN)==SUFCHAR) {
|
||||||
|
gr_add(&sufs,0) ;
|
||||||
|
l_add(&lsuff,gr_final(&sufs)) ;
|
||||||
|
}
|
||||||
|
if ( token==T_EXPR ) {
|
||||||
|
state=FTAIL ;
|
||||||
|
} else gr_add(&sufs,token&~NO_SCAN) ;
|
||||||
|
break ;
|
||||||
|
case FTAIL :
|
||||||
|
if ( token==C_EXPR ) {
|
||||||
|
/* Found one !! */
|
||||||
|
gr_add(&tailval,0) ;
|
||||||
|
condit(&result,&fsuff,&lsuff,gr_start(tailval)) ;
|
||||||
|
l_throw(&fsuff) ; l_throw(&lsuff) ;
|
||||||
|
gr_throw(&tailval) ;
|
||||||
|
state=TEXT ;
|
||||||
|
} else gr_add(&tailval,token) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gr_add(&result,0) ;
|
||||||
|
if ( state!=TEXT ) {
|
||||||
|
l_throw(&fsuff) ; l_throw(&lsuff) ; gr_throw(&tailval) ;
|
||||||
|
werror("flag line has unclosed expression starting with %6s",
|
||||||
|
heads) ;
|
||||||
|
}
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
condit(line,fsuff,lsuff,tailval) growstring *line ;
|
||||||
|
list_head *fsuff, *lsuff;
|
||||||
|
char *tailval ;
|
||||||
|
{
|
||||||
|
register list_elem *first ;
|
||||||
|
register list_elem *last ;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=4 ) vprint("Conditional for %s, ",tailval) ;
|
||||||
|
#endif
|
||||||
|
scanlist( l_first(*fsuff), first ) {
|
||||||
|
scanlist( l_first(*lsuff), last ) {
|
||||||
|
if ( strcmp(l_content(*first),l_content(*last))==0 ) {
|
||||||
|
/* Found */
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=4 ) vprint(" matched\n") ;
|
||||||
|
#endif
|
||||||
|
while ( *tailval) gr_add(line,*tailval++ ) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=4) vprint(" non-matched\n") ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int mapflag(maplist,cflag) list_head *maplist ; char *cflag ; {
|
||||||
|
/* Expand a flag expression */
|
||||||
|
/* The flag "cflag" is checked for each of the mapflags.
|
||||||
|
A mapflag entry has the form
|
||||||
|
-text NAME=replacement or -text*text NAME=replacement
|
||||||
|
The star matches anything as in the shell.
|
||||||
|
If the entry matches the assignment will take place
|
||||||
|
This replacement is subjected to argument matching only.
|
||||||
|
When a match took place the replacement is returned
|
||||||
|
when not, (char *)0.
|
||||||
|
The replacement sits in stable storage.
|
||||||
|
*/
|
||||||
|
register list_elem *elem ;
|
||||||
|
|
||||||
|
scanlist(l_first(*maplist),elem) {
|
||||||
|
if ( mapexpand(l_content(*elem),cflag) ) {
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mapexpand(mapentry,cflag)
|
||||||
|
char *mapentry, *cflag ;
|
||||||
|
{
|
||||||
|
register char *star ;
|
||||||
|
register char *ptr ;
|
||||||
|
register char *space ;
|
||||||
|
int length ;
|
||||||
|
|
||||||
|
star=index(mapentry,STAR) ;
|
||||||
|
space=firstblank(mapentry) ;
|
||||||
|
if ( star >space ) star= (char *)0 ;
|
||||||
|
if ( star ) {
|
||||||
|
length= space-star-1 ;
|
||||||
|
if ( strncmp(mapentry,cflag,star-mapentry) ||
|
||||||
|
strncmp(star+1,cflag+strlen(cflag)-length,length) ) {
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
/* Match */
|
||||||
|
/* Now set star to the first char of the star
|
||||||
|
replacement and length to its length
|
||||||
|
*/
|
||||||
|
length=strlen(cflag)-(star-mapentry)-length ;
|
||||||
|
if ( length<0 ) return 0 ;
|
||||||
|
star=cflag+(star-mapentry) ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=6 ) {
|
||||||
|
vprint("Starmatch (%s,%s) %.*s\n",
|
||||||
|
mapentry,cflag,length,star) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
if ( strncmp(mapentry,cflag,space-mapentry)!=0 ||
|
||||||
|
cflag[space-mapentry] ) {
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptr= skipblank(space) ;
|
||||||
|
if ( *ptr==0 ) return 1 ;
|
||||||
|
doassign(ptr,star,length) ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
doassign(line,star,length) char *line, *star ; {
|
||||||
|
growstring varval, name, temp ;
|
||||||
|
register char *ptr ;
|
||||||
|
|
||||||
|
gr_init(&varval) ;
|
||||||
|
gr_init(&name) ;
|
||||||
|
ptr= line ;
|
||||||
|
for ( ; *ptr && *ptr!=SPACE && *ptr!=TAB && *ptr!=EQUAL ; ptr++ ) {
|
||||||
|
gr_add(&name,*ptr) ;
|
||||||
|
}
|
||||||
|
ptr= index(ptr,EQUAL) ;
|
||||||
|
if ( !ptr ) {
|
||||||
|
error("Missing %c in assignment %s",EQUAL,line);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
temp= scanvars(ptr+1) ;
|
||||||
|
for ( ptr=gr_start(temp); *ptr; ptr++ ) switch ( *ptr ) {
|
||||||
|
case STAR :
|
||||||
|
if ( star ) {
|
||||||
|
while ( length-- ) gr_add(&varval,*star++|NO_SCAN) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
default :
|
||||||
|
gr_add(&varval,*ptr) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
gr_throw(&temp) ;
|
||||||
|
setsvar(gr_final(&name),gr_final(&varval)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ISBLANK(c) ( (c)==SPACE || (c)==TAB )
|
||||||
|
|
||||||
|
unravel(line,action) char *line ; int (*action)() ; {
|
||||||
|
/* Unravel the line, get arguments a la shell */
|
||||||
|
/* each argument is handled to action */
|
||||||
|
/* The input string is left intact */
|
||||||
|
register char *in_c ;
|
||||||
|
register int token ;
|
||||||
|
enum { BLANK, ARG } state = BLANK ;
|
||||||
|
growstring argum ;
|
||||||
|
|
||||||
|
in_c=line ;
|
||||||
|
for (;;) {
|
||||||
|
token= *in_c&0377 ;
|
||||||
|
switch ( state ) {
|
||||||
|
case BLANK :
|
||||||
|
if ( token==0 ) break ;
|
||||||
|
if ( !ISBLANK(token) ) {
|
||||||
|
state= ARG ;
|
||||||
|
gr_init(&argum) ;
|
||||||
|
gr_add(&argum,token&~NO_SCAN) ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
case ARG :
|
||||||
|
if ( ISBLANK(token) || token==0 ) {
|
||||||
|
gr_add(&argum,0) ;
|
||||||
|
(*action)(gr_start(argum)) ;
|
||||||
|
gr_throw(&argum) ;
|
||||||
|
state=BLANK ;
|
||||||
|
} else {
|
||||||
|
gr_add(&argum,token&~NO_SCAN) ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
if ( token == 0 ) break ;
|
||||||
|
in_c++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *c_rep(string,place,rep) char *string, *place, *rep ; {
|
||||||
|
/* Produce a string in stable storage produced from 'string'
|
||||||
|
with the character at place replaced by rep
|
||||||
|
*/
|
||||||
|
growstring name ;
|
||||||
|
register char *nc ;
|
||||||
|
register char *xc ;
|
||||||
|
|
||||||
|
gr_init(&name) ;
|
||||||
|
for ( nc=string ; *nc && nc<place ; nc++ ) {
|
||||||
|
gr_add(&name,*nc) ;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( *nc==0 ) fatal("Place is not in string") ;
|
||||||
|
#endif
|
||||||
|
for ( xc=rep ; *xc ; xc++ ) gr_add(&name,*xc|NO_SCAN) ;
|
||||||
|
gr_add(&name,0) ;
|
||||||
|
gr_cat(&name,nc+1) ;
|
||||||
|
return gr_final(&name) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static list_head *curargs ;
|
||||||
|
|
||||||
|
addargs(string) char *string ; {
|
||||||
|
register char *temp, *repc ;
|
||||||
|
register list_elem *elem ;
|
||||||
|
|
||||||
|
repc=index(string,C_IN) ;
|
||||||
|
if ( repc ) {
|
||||||
|
/* INPUT FILE TOKEN seen, replace it and scan further */
|
||||||
|
if ( repc==string && string[1]==0 ) {
|
||||||
|
if ( in.p_path ) { /* All but combiner */
|
||||||
|
l_add(curargs,keeps(in.p_path)) ;
|
||||||
|
} else {
|
||||||
|
scanlist( l_first(c_arguments), elem ) {
|
||||||
|
l_add(curargs,l_content(*elem)) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if ( in.p_path ) { /* Not for the combiner */
|
||||||
|
temp=c_rep(string,repc,in.p_path) ;
|
||||||
|
addargs(temp) ;
|
||||||
|
throws(temp) ;
|
||||||
|
} else { /* For the combiner */
|
||||||
|
scanlist( l_first(c_arguments), elem ) {
|
||||||
|
temp=c_rep(string,repc,l_content(*elem)) ;
|
||||||
|
addargs(temp) ;
|
||||||
|
throws(temp) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
repc=index(string,C_OUT) ;
|
||||||
|
if ( repc ) {
|
||||||
|
/* replace the outfile token as with the infile token */
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( !out.p_path ) fatal("missing output filename") ;
|
||||||
|
#endif
|
||||||
|
temp=c_rep(string,repc,out.p_path) ;
|
||||||
|
addargs(temp) ;
|
||||||
|
throws(temp) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
temp= keeps(string) ;
|
||||||
|
clr_noscan(temp) ;
|
||||||
|
l_add(curargs,temp) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
getcallargs(phase) register trf *phase ; {
|
||||||
|
growstring arg1, arg2 ;
|
||||||
|
|
||||||
|
arg1= scanvars(phase->t_argd) ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=3 ) { vprint("\tvars: ") ; prns(gr_start(arg1)) ; }
|
||||||
|
#endif
|
||||||
|
arg2= scanexpr(gr_start(arg1)) ;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug>=3 ) { vprint("\texpr: ") ; prns(gr_start(arg2)) ; }
|
||||||
|
#endif
|
||||||
|
gr_throw(&arg1) ;
|
||||||
|
curargs= &phase->t_args ;
|
||||||
|
unravel( gr_start(arg2), addargs ) ;
|
||||||
|
gr_throw(&arg2) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
discardargs(phase) register trf *phase ; {
|
||||||
|
l_throw(&phase->t_args) ;
|
||||||
|
}
|
||||||
30
util/ack/trans.h
Normal file
30
util/ack/trans.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* This structure is the center of all actions */
|
||||||
|
/* It contains the description of all phases,
|
||||||
|
the suffices they consume and produce and various properties */
|
||||||
|
|
||||||
|
typedef struct transform trf;
|
||||||
|
|
||||||
|
struct transform {
|
||||||
|
char *t_in ; /* Suffices in '.o.k' */
|
||||||
|
char *t_out ; /* Result '.suffix' or 'name' */
|
||||||
|
char *t_name ; /* The name of this transformation */
|
||||||
|
list_head t_mapf ; /* Mapflags argument, uses varrep */
|
||||||
|
char *t_argd ; /* Argument descriptor, uses varrep */
|
||||||
|
char *t_needed ; /* Suffix indicating the libraries needed */
|
||||||
|
char *t_rts ; /* Suffix indicating the major language used*/
|
||||||
|
int t_stdin:1 ; /* The input is taken on stdin */
|
||||||
|
int t_stdout:1 ; /* The output comes on stdout */
|
||||||
|
int t_combine:1 ; /* Transform several files to one result */
|
||||||
|
int t_visited:1 ; /* NO before setup, YES after */
|
||||||
|
int t_prep:2 ; /* Needs preprocessor YES/NO/MAYBE */
|
||||||
|
int t_optim:1 ; /* Is optimizer */
|
||||||
|
int t_isprep:1 ; /* Is preprocessor */
|
||||||
|
int t_keep:1 ; /* Keep the output file */
|
||||||
|
char *t_prog ; /* Pathname for load file */
|
||||||
|
list_head t_flags ; /* List of flags */
|
||||||
|
list_head t_args ; /* List of arguments */
|
||||||
|
int t_scan:1 ; /* Used while finding path's */
|
||||||
|
int t_do:1 ; /* Is in path to execute */
|
||||||
|
} ;
|
||||||
|
|
||||||
|
#define t_cont(elem) ((trf *)l_content(elem))
|
||||||
190
util/ack/util.c
Normal file
190
util/ack/util.c
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Several utility routines used throughout ack */
|
||||||
|
/* error handling, string handling and such. */
|
||||||
|
/* */
|
||||||
|
/**********************************************************************/
|
||||||
|
|
||||||
|
#include "ack.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern char *progname ;
|
||||||
|
extern int w_flag ;
|
||||||
|
extern int n_error;
|
||||||
|
|
||||||
|
extern char *calloc();
|
||||||
|
extern char *realloc();
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
# define STDOUT stdout
|
||||||
|
#else
|
||||||
|
# define STDOUT stderr
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *basename(string) char *string ; {
|
||||||
|
static char retval[20] ;
|
||||||
|
char *last_dot, *last_start ;
|
||||||
|
register char *store;
|
||||||
|
register char *fetch ;
|
||||||
|
register int ctoken ;
|
||||||
|
|
||||||
|
last_dot= (char *)0 ;
|
||||||
|
last_start= string ;
|
||||||
|
for ( fetch=string ; ; fetch++ ) {
|
||||||
|
switch ( ctoken= *fetch&0377 ) {
|
||||||
|
case SUFCHAR : last_dot=fetch ; break ;
|
||||||
|
case '/' : last_start=fetch+1 ; break ;
|
||||||
|
case 0 : goto out ;
|
||||||
|
}
|
||||||
|
if ( !isascii(ctoken) || !isprint(ctoken) ) {
|
||||||
|
werror("non-ascii characters in argument %s",string) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
if ( ! *last_start ) fuerror("empty filename \"%s\"",string) ;
|
||||||
|
for ( fetch= last_start, store=retval ;
|
||||||
|
*fetch && fetch!=last_dot && store< &retval[sizeof retval-1] ;
|
||||||
|
fetch++, store++ ) {
|
||||||
|
*store= *fetch ;
|
||||||
|
}
|
||||||
|
*store= 0 ;
|
||||||
|
return retval ;
|
||||||
|
}
|
||||||
|
|
||||||
|
clr_noscan(str) char *str ; {
|
||||||
|
register char *ptr ;
|
||||||
|
for ( ptr=str ; *ptr ; ptr++ ) {
|
||||||
|
*ptr&= ~NO_SCAN ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *skipblank(str) char *str ; {
|
||||||
|
register char *ptr ;
|
||||||
|
|
||||||
|
for ( ptr=str ; *ptr==SPACE || *ptr==TAB ; ptr++ ) ;
|
||||||
|
return ptr ;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *firstblank(str) char *str ; {
|
||||||
|
register char *ptr ;
|
||||||
|
|
||||||
|
for ( ptr=str ; *ptr && *ptr!=SPACE && *ptr!=TAB ; ptr++ ) ;
|
||||||
|
return ptr ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* VARARGS1 */
|
||||||
|
fatal(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
|
||||||
|
/* Fatal internal error */
|
||||||
|
fprintf(STDOUT,"%s: fatal internal error, ",progname) ;
|
||||||
|
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
|
||||||
|
fprintf(STDOUT,"\n") ;
|
||||||
|
quit(-2) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* VARARGS1 */
|
||||||
|
vprint(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
|
||||||
|
/* Diagnostic print, no auto NL */
|
||||||
|
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
prns(s) register char *s ; {
|
||||||
|
for ( ; *s ; s++ ) {
|
||||||
|
putc((*s&0377)&~NO_SCAN,STDOUT) ;
|
||||||
|
}
|
||||||
|
putc('\n',STDOUT) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* VARARGS1 */
|
||||||
|
fuerror(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
|
||||||
|
/* Fatal user error */
|
||||||
|
fprintf(STDOUT,"%s: ",progname) ;
|
||||||
|
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
|
||||||
|
fprintf(STDOUT,"\n") ;
|
||||||
|
quit(-1) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* VARARGS1 */
|
||||||
|
werror(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
|
||||||
|
/* Warning user error, w_flag */
|
||||||
|
if ( w_flag ) return ;
|
||||||
|
fprintf(STDOUT,"%s: warning, ",progname) ;
|
||||||
|
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
|
||||||
|
fprintf(STDOUT,"\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* VARARGS1 */
|
||||||
|
error(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
|
||||||
|
/* User error, it is the callers responsibility to quit */
|
||||||
|
fprintf(STDOUT,"%s: ",progname) ;
|
||||||
|
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
|
||||||
|
fprintf(STDOUT,"\n") ;
|
||||||
|
n_error++ ;
|
||||||
|
}
|
||||||
|
|
||||||
|
do_flush() {
|
||||||
|
fflush(stdout) ;
|
||||||
|
fflush(stderr) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
noodstop() {
|
||||||
|
quit(-3) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
quit(code) {
|
||||||
|
rmtemps();
|
||||||
|
exit(code);
|
||||||
|
}
|
||||||
|
/******
|
||||||
|
char *keeps(string)
|
||||||
|
Keep the string in stable storage.
|
||||||
|
throws(string)
|
||||||
|
Remove the string stored by keep from stable storage.
|
||||||
|
***********/
|
||||||
|
|
||||||
|
char *keeps(str) char *str ; {
|
||||||
|
register char *result ;
|
||||||
|
result= getcore( (unsigned)(strlen(str)+1) ) ;
|
||||||
|
if ( !result ) fatal("Out of core") ;
|
||||||
|
return strcpy(result,str) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
throws(str) char *str ; {
|
||||||
|
freecore(str) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *getcore(size) unsigned size ; {
|
||||||
|
register char *retptr ;
|
||||||
|
|
||||||
|
retptr= calloc(1,size) ;
|
||||||
|
if ( !retptr ) fatal("Out of memory") ;
|
||||||
|
return retptr ;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *changecore(ptr,size) char *ptr ; unsigned size ; {
|
||||||
|
register char *retptr ;
|
||||||
|
|
||||||
|
retptr= realloc(ptr,size) ;
|
||||||
|
if ( !retptr ) fatal("Out of memory") ;
|
||||||
|
return retptr ;
|
||||||
|
}
|
||||||
30
util/cgg/Makefile
Normal file
30
util/cgg/Makefile
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# $Header$
|
||||||
|
|
||||||
|
PREFLAGS=-I../../h
|
||||||
|
CFLAGS=$(PREFLAGS)
|
||||||
|
LDFLAGS=-i
|
||||||
|
LINTOPTS=-hbxac $(PREFLAGS)
|
||||||
|
LIBS=../../lib/em_data.a
|
||||||
|
# LEXLIB is system dependent, try -ll or -lln first
|
||||||
|
LEXLIB=-lln
|
||||||
|
|
||||||
|
cgg: bootgram.o
|
||||||
|
cc $(LDFLAGS) bootgram.o $(LIBS) $(LEXLIB) -o cgg
|
||||||
|
|
||||||
|
bootgram.c: bootgram.y
|
||||||
|
@echo expect 1 shift/reduce conflict
|
||||||
|
yacc bootgram.y
|
||||||
|
mv y.tab.c bootgram.c
|
||||||
|
|
||||||
|
install: cgg
|
||||||
|
cp cgg ../../lib/cgg
|
||||||
|
|
||||||
|
cmp: cgg
|
||||||
|
cmp cgg ../../lib/cgg
|
||||||
|
|
||||||
|
lint: bootgram.c
|
||||||
|
lint $(LINTOPTS) bootgram.c
|
||||||
|
clean:
|
||||||
|
rm -f bootgram.o bootgram.c bootlex.c cgg
|
||||||
|
bootgram.o: bootlex.c
|
||||||
|
bootgram.o: ../../h/cg_pattern.h
|
||||||
2317
util/cgg/bootgram.y
Normal file
2317
util/cgg/bootgram.y
Normal file
File diff suppressed because it is too large
Load Diff
189
util/cgg/bootlex.l
Normal file
189
util/cgg/bootlex.l
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
%{
|
||||||
|
|
||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid2[]="$Header$";
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
#undef input
|
||||||
|
#undef output
|
||||||
|
#undef unput
|
||||||
|
|
||||||
|
#define MAXBACKUP 50
|
||||||
|
%}
|
||||||
|
%%
|
||||||
|
"/*" { char c;
|
||||||
|
c = input();
|
||||||
|
do {
|
||||||
|
while (c!='*')
|
||||||
|
c = input();
|
||||||
|
c = input();
|
||||||
|
} while (c!='/');
|
||||||
|
}
|
||||||
|
"REGISTERS:" return(REGISTERHEAD);
|
||||||
|
"TOKENS:" return(TOKENHEAD);
|
||||||
|
"TOKENEXPRESSIONS:" return(EXPRESSIONHEAD);
|
||||||
|
"CODE:" return(CODEHEAD);
|
||||||
|
"MOVES:" return(MOVEHEAD);
|
||||||
|
"TESTS:" return(TESTHEAD);
|
||||||
|
"STACKS:" return(STACKHEAD);
|
||||||
|
"SIZEFACTOR" return(SIZEFAC);
|
||||||
|
"TIMEFACTOR" return(TIMEFAC);
|
||||||
|
"FORMAT" return(FORMAT);
|
||||||
|
|
||||||
|
"cost" return(COST);
|
||||||
|
"remove" return(REMOVE);
|
||||||
|
"|" return(SEP);
|
||||||
|
"samesign" return(SAMESIGN);
|
||||||
|
"inreg" return(INREG);
|
||||||
|
"sfit" return(SFIT);
|
||||||
|
"ufit" return(UFIT);
|
||||||
|
"defined" return(DEFINED);
|
||||||
|
"rom" return(ROM);
|
||||||
|
"loww" return(LOWW);
|
||||||
|
"highw" return(HIGHW);
|
||||||
|
"move" return(MOVE);
|
||||||
|
"erase" return(ERASE);
|
||||||
|
"allocate" return(ALLOCATE);
|
||||||
|
"tostring" return(TOSTRING);
|
||||||
|
"nocc" return(NOCC);
|
||||||
|
"setcc" return(SETCC);
|
||||||
|
"samecc" return(SAMECC);
|
||||||
|
"test" return(TEST);
|
||||||
|
"STACK" return(STACK);
|
||||||
|
"nocoercions" return(NOCOERC);
|
||||||
|
|
||||||
|
"&&" return(AND2);
|
||||||
|
"||" return(OR2);
|
||||||
|
"==" return(CMPEQ);
|
||||||
|
"!=" return(CMPNE);
|
||||||
|
"<=" return(CMPLE);
|
||||||
|
"<" return(CMPLT);
|
||||||
|
">" return(CMPGT);
|
||||||
|
">=" return(CMPGE);
|
||||||
|
">>" return(RSHIFT);
|
||||||
|
"<<" return(LSHIFT);
|
||||||
|
"!" return(NOT);
|
||||||
|
"~" return(COMP);
|
||||||
|
"..." return(ELLIPS);
|
||||||
|
|
||||||
|
EM_WSIZE { yylval.yy_intp = &wsize; return(CIDENT); }
|
||||||
|
EM_PSIZE { yylval.yy_intp = &psize; return(CIDENT); }
|
||||||
|
EM_BSIZE { yylval.yy_intp = &bsize; return(CIDENT); }
|
||||||
|
REGISTER { yylval.yy_string = "REGISTER"; return(TYPENAME); }
|
||||||
|
INT { yylval.yy_string = "INT"; return(TYPENAME); }
|
||||||
|
STRING { yylval.yy_string = "STRING"; return(TYPENAME); }
|
||||||
|
|
||||||
|
regvar return(REGVAR);
|
||||||
|
loop return(LOOP);
|
||||||
|
pointer return(POINTER);
|
||||||
|
float return(FLOAT);
|
||||||
|
return return(RETURN);
|
||||||
|
|
||||||
|
[_A-Za-z][_A-Za-z0-9]+ {register ident_p ip;
|
||||||
|
if(!lookident || (ip=ilookup(yytext,JUSTLOOKING))==0) {
|
||||||
|
yylval.yy_string = scopy(yytext);return(IDENT);
|
||||||
|
} else {
|
||||||
|
yylval.yy_ident = ip;
|
||||||
|
switch(ip->i_type) {
|
||||||
|
default:assert(0);
|
||||||
|
case IREG:return(RIDENT);
|
||||||
|
case IPRP:return(PIDENT);
|
||||||
|
case ITOK:return(TIDENT);
|
||||||
|
case IEXP:return(EIDENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[a-z] {yylval.yy_char = yytext[0]; return(LCASELETTER);}
|
||||||
|
[0-9]* {yylval.yy_int = atoi(yytext);return(NUMBER);}
|
||||||
|
(\"|"%)") { char *p; int c,tipe;
|
||||||
|
p=yytext;
|
||||||
|
for (;;) {
|
||||||
|
c = input();
|
||||||
|
switch(c) {
|
||||||
|
default: *p++=c;break;
|
||||||
|
case '\\':
|
||||||
|
*p++=c; *p++=input(); break;
|
||||||
|
case '\n':
|
||||||
|
yyerror("Unterminated string");
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
tipe=STRING; goto endstr;
|
||||||
|
case '%':
|
||||||
|
c=input();
|
||||||
|
if (c == '(') {
|
||||||
|
tipe=LSTRING;goto endstr;
|
||||||
|
} else {
|
||||||
|
*p++ = '%'; unput(c); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endstr:
|
||||||
|
*p++ = 0;
|
||||||
|
yylval.yy_string = scopy(yytext);
|
||||||
|
return(tipe);
|
||||||
|
}
|
||||||
|
[ \t]* |
|
||||||
|
\n ;
|
||||||
|
. return(yytext[0]);
|
||||||
|
%%
|
||||||
|
|
||||||
|
char linebuf[256];
|
||||||
|
char prevbuf[256];
|
||||||
|
int linep;
|
||||||
|
int linepos; /* corrected for tabs */
|
||||||
|
char charstack[MAXBACKUP];
|
||||||
|
int nbackup=0;
|
||||||
|
|
||||||
|
output(c) {
|
||||||
|
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
input() {
|
||||||
|
|
||||||
|
if(nbackup)
|
||||||
|
return(charstack[--nbackup]);
|
||||||
|
if(linebuf[linep]==0) {
|
||||||
|
strcpy(prevbuf,linebuf);
|
||||||
|
if(fgets(linebuf,256,stdin)==NULL)
|
||||||
|
return(0);
|
||||||
|
lino++;
|
||||||
|
linepos=linep=0;
|
||||||
|
}
|
||||||
|
if (linebuf[linep] == '\t')
|
||||||
|
linepos = (linepos+8) & ~07;
|
||||||
|
else linepos++;
|
||||||
|
return(linebuf[linep++]);
|
||||||
|
}
|
||||||
|
|
||||||
|
unput(c) {
|
||||||
|
|
||||||
|
chktabsiz(nbackup,MAXBACKUP,"Lexical backup table");
|
||||||
|
charstack[nbackup++] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
yyerror(s,a1,a2,a3,a4) string s; {
|
||||||
|
|
||||||
|
fprintf(stderr,"%d\t%s%d\t%s\t%*c ",lino-1,prevbuf,lino,linebuf,
|
||||||
|
linepos-1,'^');
|
||||||
|
fprintf(stderr,s,a1,a2,a3,a4);
|
||||||
|
fprintf(stderr,"\n");
|
||||||
|
nerrors++;
|
||||||
|
}
|
||||||
202
util/opt/Makefile
Normal file
202
util/opt/Makefile
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
# $Header$
|
||||||
|
|
||||||
|
CFILES=main.c getline.c lookup.c var.c process.c backward.c util.c\
|
||||||
|
alloc.c putline.c cleanup.c peephole.c flow.c reg.c
|
||||||
|
OFILES=main.o getline.o lookup.o var.o process.o backward.o util.o\
|
||||||
|
alloc.o putline.o cleanup.o peephole.o flow.o reg.o
|
||||||
|
KFILES=main.k getline.k lookup.k var.k process.k backward.k util.k\
|
||||||
|
alloc.k putline.k cleanup.k peephole.k flow.k reg.k
|
||||||
|
LIBS=../../lib/em_data.a
|
||||||
|
CFLAGS=-O -DNDEBUG
|
||||||
|
LDFLAGS=-i
|
||||||
|
LINT=lint
|
||||||
|
OPR=wide|opr
|
||||||
|
XREF=xref -c -w80
|
||||||
|
PROPTS=
|
||||||
|
# LEXLIB is implementation dependent, try -ll or -lln first
|
||||||
|
LEXLIB=-ll
|
||||||
|
|
||||||
|
.DEFAULT:
|
||||||
|
co -q $<
|
||||||
|
|
||||||
|
opt: $(OFILES) pattern.o $(LIBS)
|
||||||
|
cc $(LDFLAGS) $(CFLAGS) $(OFILES) pattern.o $(LIBS) -o opt
|
||||||
|
|
||||||
|
test: opt testopt
|
||||||
|
testopt
|
||||||
|
|
||||||
|
cmp : opt
|
||||||
|
cmp opt ../../lib/em_opt
|
||||||
|
|
||||||
|
install:opt
|
||||||
|
size opt ../../lib/em_opt
|
||||||
|
cp opt ../../lib/em_opt
|
||||||
|
|
||||||
|
pattern.c: patterns mktab
|
||||||
|
/lib/cpp patterns | mktab > pattern.c
|
||||||
|
|
||||||
|
mktab: mktab.o $(LIBS)
|
||||||
|
cc $(CFLAGS) mktab.o $(LIBS) $(LEXLIB) -o mktab
|
||||||
|
|
||||||
|
depend: makedepend
|
||||||
|
makedepend
|
||||||
|
|
||||||
|
lint: $(CFILES) pattern.c
|
||||||
|
$(LINT) $(CFILES) pattern.c>lint 2>&1
|
||||||
|
|
||||||
|
printall:
|
||||||
|
-pr $(PROPTS) Makefile -n *.h `ls $(CFILES)` mktab.y scan.l patterns|$(OPR)
|
||||||
|
touch print
|
||||||
|
|
||||||
|
print: Makefile *.h $(CFILES) mktab.y scan.l patterns
|
||||||
|
-pr $(PROPTS) -n $? | $(OPR)
|
||||||
|
|
||||||
|
opr:
|
||||||
|
make pr ^ $(OPR)
|
||||||
|
|
||||||
|
pr:
|
||||||
|
@pr $(PROPTS) -n Makefile *.h $(CFILES) mktab.y scan.l patterns
|
||||||
|
|
||||||
|
xref:
|
||||||
|
$(XREF) *.h $(CFILES) | pr $(PROPTS) -h "XREF EMOPT"|$(OPR)&
|
||||||
|
|
||||||
|
sizes: opt
|
||||||
|
-nm opt | sort -n| /usr/plain/bin/map
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o opt mktab mktab.c scan.c pattern.c
|
||||||
|
|
||||||
|
kfiles: $(KFILES)
|
||||||
|
|
||||||
|
.SUFFIXES: .k
|
||||||
|
.c.k: ; cem -c $*.c
|
||||||
|
|
||||||
|
# the next lines are generated automatically
|
||||||
|
# AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO
|
||||||
|
alloc.o: alloc.h
|
||||||
|
alloc.o: assert.h
|
||||||
|
alloc.o: line.h
|
||||||
|
alloc.o: lookup.h
|
||||||
|
alloc.o: param.h
|
||||||
|
alloc.o: proinf.h
|
||||||
|
alloc.o: types.h
|
||||||
|
backward.o: ../../h/em_mnem.h
|
||||||
|
backward.o: ../../h/em_pseu.h
|
||||||
|
backward.o: ../../h/em_spec.h
|
||||||
|
backward.o: alloc.h
|
||||||
|
backward.o: assert.h
|
||||||
|
backward.o: ext.h
|
||||||
|
backward.o: line.h
|
||||||
|
backward.o: lookup.h
|
||||||
|
backward.o: param.h
|
||||||
|
backward.o: proinf.h
|
||||||
|
backward.o: types.h
|
||||||
|
cleanup.o: ../../h/em_mes.h
|
||||||
|
cleanup.o: ../../h/em_pseu.h
|
||||||
|
cleanup.o: ../../h/em_spec.h
|
||||||
|
cleanup.o: assert.h
|
||||||
|
cleanup.o: ext.h
|
||||||
|
cleanup.o: lookup.h
|
||||||
|
cleanup.o: param.h
|
||||||
|
cleanup.o: types.h
|
||||||
|
flow.o: ../../h/em_flag.h
|
||||||
|
flow.o: ../../h/em_mnem.h
|
||||||
|
flow.o: ../../h/em_spec.h
|
||||||
|
flow.o: alloc.h
|
||||||
|
flow.o: ext.h
|
||||||
|
flow.o: line.h
|
||||||
|
flow.o: optim.h
|
||||||
|
flow.o: param.h
|
||||||
|
flow.o: proinf.h
|
||||||
|
flow.o: types.h
|
||||||
|
getline.o: ../../h/em_flag.h
|
||||||
|
getline.o: ../../h/em_mes.h
|
||||||
|
getline.o: ../../h/em_pseu.h
|
||||||
|
getline.o: ../../h/em_spec.h
|
||||||
|
getline.o: alloc.h
|
||||||
|
getline.o: assert.h
|
||||||
|
getline.o: ext.h
|
||||||
|
getline.o: line.h
|
||||||
|
getline.o: lookup.h
|
||||||
|
getline.o: param.h
|
||||||
|
getline.o: proinf.h
|
||||||
|
getline.o: types.h
|
||||||
|
lookup.o: alloc.h
|
||||||
|
lookup.o: lookup.h
|
||||||
|
lookup.o: param.h
|
||||||
|
lookup.o: proinf.h
|
||||||
|
lookup.o: types.h
|
||||||
|
main.o: ../../h/em_spec.h
|
||||||
|
main.o: alloc.h
|
||||||
|
main.o: ext.h
|
||||||
|
main.o: param.h
|
||||||
|
main.o: types.h
|
||||||
|
mktab.o: ../../h/em_mnem.h
|
||||||
|
mktab.o: ../../h/em_spec.h
|
||||||
|
mktab.o: optim.h
|
||||||
|
mktab.o: param.h
|
||||||
|
mktab.o: pattern.h
|
||||||
|
mktab.o: scan.c
|
||||||
|
mktab.o: types.h
|
||||||
|
pattern.o: param.h
|
||||||
|
pattern.o: pattern.h
|
||||||
|
pattern.o: types.h
|
||||||
|
peephole.o: ../../h/em_mnem.h
|
||||||
|
peephole.o: ../../h/em_spec.h
|
||||||
|
peephole.o: alloc.h
|
||||||
|
peephole.o: assert.h
|
||||||
|
peephole.o: ext.h
|
||||||
|
peephole.o: line.h
|
||||||
|
peephole.o: lookup.h
|
||||||
|
peephole.o: optim.h
|
||||||
|
peephole.o: param.h
|
||||||
|
peephole.o: pattern.h
|
||||||
|
peephole.o: proinf.h
|
||||||
|
peephole.o: types.h
|
||||||
|
process.o: ../../h/em_pseu.h
|
||||||
|
process.o: ../../h/em_spec.h
|
||||||
|
process.o: alloc.h
|
||||||
|
process.o: assert.h
|
||||||
|
process.o: ext.h
|
||||||
|
process.o: line.h
|
||||||
|
process.o: lookup.h
|
||||||
|
process.o: param.h
|
||||||
|
process.o: proinf.h
|
||||||
|
process.o: types.h
|
||||||
|
putline.o: ../../h/em_flag.h
|
||||||
|
putline.o: ../../h/em_mnem.h
|
||||||
|
putline.o: ../../h/em_pseu.h
|
||||||
|
putline.o: ../../h/em_spec.h
|
||||||
|
putline.o: alloc.h
|
||||||
|
putline.o: assert.h
|
||||||
|
putline.o: ext.h
|
||||||
|
putline.o: line.h
|
||||||
|
putline.o: lookup.h
|
||||||
|
putline.o: optim.h
|
||||||
|
putline.o: param.h
|
||||||
|
putline.o: proinf.h
|
||||||
|
putline.o: types.h
|
||||||
|
reg.o: ../../h/em_mes.h
|
||||||
|
reg.o: ../../h/em_pseu.h
|
||||||
|
reg.o: ../../h/em_spec.h
|
||||||
|
reg.o: alloc.h
|
||||||
|
reg.o: assert.h
|
||||||
|
reg.o: ext.h
|
||||||
|
reg.o: line.h
|
||||||
|
reg.o: param.h
|
||||||
|
reg.o: proinf.h
|
||||||
|
reg.o: types.h
|
||||||
|
scan.o: stdio.h
|
||||||
|
special.o: param.h
|
||||||
|
special.o: types.h
|
||||||
|
util.o: assert.h
|
||||||
|
util.o: ext.h
|
||||||
|
util.o: lookup.h
|
||||||
|
util.o: optim.h
|
||||||
|
util.o: param.h
|
||||||
|
util.o: proinf.h
|
||||||
|
util.o: types.h
|
||||||
|
var.o: lookup.h
|
||||||
|
var.o: param.h
|
||||||
|
var.o: proinf.h
|
||||||
|
var.o: types.h
|
||||||
448
util/opt/alloc.c
Normal file
448
util/opt/alloc.c
Normal file
@ -0,0 +1,448 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "assert.h"
|
||||||
|
#include "alloc.h"
|
||||||
|
#include "line.h"
|
||||||
|
#include "lookup.h"
|
||||||
|
#include "proinf.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef USEMALLOC
|
||||||
|
|
||||||
|
short * myalloc();
|
||||||
|
|
||||||
|
#define newcore(size) myalloc(size)
|
||||||
|
#define oldcore(p,size) free(p)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* #define CORECHECK /* if defined tests are made to insure
|
||||||
|
each block occurs at most once */
|
||||||
|
|
||||||
|
#define CCHUNK 1024 /* number of shorts asked from system */
|
||||||
|
|
||||||
|
short *newcore(),*freshcore();
|
||||||
|
extern char *sbrk();
|
||||||
|
|
||||||
|
#ifdef COREDEBUG
|
||||||
|
int shortsasked=0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following two sizetables contain the sizes of the various kinds
|
||||||
|
* of line and argument structures.
|
||||||
|
* Care has been taken to make this table implementation independent,
|
||||||
|
* but if you think very hard you might find a compiler failing the
|
||||||
|
* assumptions made.
|
||||||
|
* A wasteful but safe approach is to replace every line of them by
|
||||||
|
* sizeof(line_t)
|
||||||
|
* and
|
||||||
|
* sizeof(arg_t)
|
||||||
|
* respectively.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LBASE (sizeof(line_t)-sizeof(un_l_a))
|
||||||
|
|
||||||
|
int lsizetab[] = {
|
||||||
|
LBASE,
|
||||||
|
LBASE+sizeof(short),
|
||||||
|
LBASE+sizeof(offset),
|
||||||
|
LBASE+sizeof(num_p),
|
||||||
|
LBASE+sizeof(sym_p),
|
||||||
|
LBASE+sizeof(s_la_sval),
|
||||||
|
LBASE+sizeof(s_la_lval),
|
||||||
|
LBASE+sizeof(arg_p),
|
||||||
|
LBASE
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ABASE (sizeof(arg_t)-sizeof(un_a_a))
|
||||||
|
|
||||||
|
int asizetab[] = {
|
||||||
|
ABASE+sizeof(offset),
|
||||||
|
ABASE+sizeof(num_p),
|
||||||
|
ABASE+sizeof(sym_p),
|
||||||
|
ABASE+sizeof(s_a_val),
|
||||||
|
ABASE+sizeof(argb_t),
|
||||||
|
ABASE+sizeof(s_a_con),
|
||||||
|
ABASE+sizeof(s_a_con),
|
||||||
|
ABASE+sizeof(s_a_con),
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* alloc routines:
|
||||||
|
* Two parts:
|
||||||
|
* 1) typed alloc and free routines
|
||||||
|
* 2) untyped raw core allocation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PART 1
|
||||||
|
*/
|
||||||
|
|
||||||
|
line_p newline(optyp) int optyp; {
|
||||||
|
register line_p lnp;
|
||||||
|
register kind=optyp;
|
||||||
|
|
||||||
|
if (kind>OPMINI)
|
||||||
|
kind = OPMINI;
|
||||||
|
lnp = (line_p) newcore(lsizetab[kind]);
|
||||||
|
lnp->l_optyp = optyp;
|
||||||
|
return(lnp);
|
||||||
|
}
|
||||||
|
|
||||||
|
oldline(lnp) register line_p lnp; {
|
||||||
|
register kind=lnp->l_optyp&BMASK;
|
||||||
|
|
||||||
|
if (kind>OPMINI)
|
||||||
|
kind = OPMINI;
|
||||||
|
if (kind == OPLIST)
|
||||||
|
oldargs(lnp->l_a.la_arg);
|
||||||
|
oldcore((short *) lnp,lsizetab[kind]);
|
||||||
|
}
|
||||||
|
|
||||||
|
arg_p newarg(kind) int kind; {
|
||||||
|
register arg_p ap;
|
||||||
|
|
||||||
|
ap = (arg_p) newcore(asizetab[kind]);
|
||||||
|
ap->a_typ = kind;
|
||||||
|
return(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
oldargs(ap) register arg_p ap; {
|
||||||
|
register arg_p next;
|
||||||
|
|
||||||
|
while (ap != (arg_p) 0) {
|
||||||
|
next = ap->a_next;
|
||||||
|
switch(ap->a_typ) {
|
||||||
|
case ARGSTR:
|
||||||
|
oldargb(ap->a_a.a_string.ab_next);
|
||||||
|
break;
|
||||||
|
case ARGICN:
|
||||||
|
case ARGUCN:
|
||||||
|
case ARGFCN:
|
||||||
|
oldargb(ap->a_a.a_con.ac_con.ab_next);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
oldcore((short *) ap,asizetab[ap->a_typ]);
|
||||||
|
ap = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oldargb(abp) register argb_p abp; {
|
||||||
|
register argb_p next;
|
||||||
|
|
||||||
|
while (abp != (argb_p) 0) {
|
||||||
|
next = abp->ab_next;
|
||||||
|
oldcore((short *) abp,sizeof (argb_t));
|
||||||
|
abp = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reg_p newreg() {
|
||||||
|
|
||||||
|
return((reg_p) newcore(sizeof(reg_t)));
|
||||||
|
}
|
||||||
|
|
||||||
|
oldreg(rp) reg_p rp; {
|
||||||
|
|
||||||
|
oldcore((short *) rp,sizeof(reg_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
num_p newnum() {
|
||||||
|
|
||||||
|
return((num_p) newcore(sizeof(num_t)));
|
||||||
|
}
|
||||||
|
|
||||||
|
oldnum(lp) num_p lp; {
|
||||||
|
|
||||||
|
oldcore((short *) lp,sizeof(num_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
offset *newrom() {
|
||||||
|
|
||||||
|
return((offset *) newcore(MAXROM*sizeof(offset)));
|
||||||
|
}
|
||||||
|
|
||||||
|
sym_p newsym(len) int len; {
|
||||||
|
/*
|
||||||
|
* sym_t includes a 2 character s_name at the end
|
||||||
|
* extend this structure with len-2 characters
|
||||||
|
*/
|
||||||
|
return((sym_p) newcore(sizeof(sym_t) - 2 + len));
|
||||||
|
}
|
||||||
|
|
||||||
|
argb_p newargb() {
|
||||||
|
|
||||||
|
return((argb_p) newcore(sizeof(argb_t)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef USEMALLOC
|
||||||
|
|
||||||
|
/******************************************************************/
|
||||||
|
/****** Start of raw core management package *****************/
|
||||||
|
/******************************************************************/
|
||||||
|
|
||||||
|
#define MAXSHORT 30 /* Maximum number of shorts one can ask for */
|
||||||
|
|
||||||
|
short *freelist[MAXSHORT];
|
||||||
|
|
||||||
|
typedef struct coreblock {
|
||||||
|
struct coreblock *co_next;
|
||||||
|
short co_size;
|
||||||
|
} core_t,*core_p;
|
||||||
|
|
||||||
|
#define SINC (sizeof(core_t)/sizeof(short))
|
||||||
|
#ifdef COREDEBUG
|
||||||
|
coreverbose() {
|
||||||
|
register size;
|
||||||
|
register short *p;
|
||||||
|
register sum;
|
||||||
|
|
||||||
|
sum = 0;
|
||||||
|
for(size=1;size<MAXSHORT;size++)
|
||||||
|
for (p=freelist[size];p!=0;p = *(short **) p)
|
||||||
|
sum += size;
|
||||||
|
fprintf(stderr,"Used core %u\n",(shortsasked-sum)*sizeof(short));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SEPID
|
||||||
|
|
||||||
|
compactcore() {
|
||||||
|
register core_p corelist=0,tp,cl;
|
||||||
|
int size;
|
||||||
|
|
||||||
|
#ifdef COREDEBUG
|
||||||
|
fprintf(stderr,"Almost out of core\n");
|
||||||
|
#endif
|
||||||
|
for(size=SINC;size<MAXSHORT;size++) {
|
||||||
|
while ((tp = (core_p) freelist[size]) != (core_p) 0) {
|
||||||
|
freelist[size] = (short *) tp->co_next;
|
||||||
|
tp->co_size = size;
|
||||||
|
if (corelist==0 || tp<corelist) {
|
||||||
|
tp->co_next = corelist;
|
||||||
|
corelist = tp;
|
||||||
|
} else {
|
||||||
|
for(cl=corelist;cl->co_next != 0 && tp>cl->co_next;
|
||||||
|
cl = cl->co_next)
|
||||||
|
;
|
||||||
|
tp->co_next = cl->co_next;
|
||||||
|
cl->co_next = tp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (corelist != 0) {
|
||||||
|
while ((short *) corelist->co_next ==
|
||||||
|
(short *) corelist + corelist->co_size) {
|
||||||
|
corelist->co_size += corelist->co_next->co_size;
|
||||||
|
corelist->co_next = corelist->co_next->co_next;
|
||||||
|
}
|
||||||
|
assert(corelist->co_next==0 ||
|
||||||
|
(short *) corelist->co_next >
|
||||||
|
(short *) corelist + corelist->co_size);
|
||||||
|
while (corelist->co_size >= MAXSHORT+SINC) {
|
||||||
|
oldcore((short *) corelist + corelist->co_size-(MAXSHORT-1),
|
||||||
|
sizeof(short)*(MAXSHORT-1));
|
||||||
|
corelist->co_size -= MAXSHORT;
|
||||||
|
}
|
||||||
|
if (corelist->co_size >= MAXSHORT) {
|
||||||
|
oldcore((short *) corelist + corelist->co_size-SINC,
|
||||||
|
sizeof(short)*SINC);
|
||||||
|
corelist->co_size -= SINC;
|
||||||
|
}
|
||||||
|
cl = corelist->co_next;
|
||||||
|
oldcore((short *) corelist, sizeof(short)*corelist->co_size);
|
||||||
|
corelist = cl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
short *grabcore(size) int size; {
|
||||||
|
register short *p;
|
||||||
|
register trysize;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Desperate situation, can't get more core from system.
|
||||||
|
* Postpone giving up just a little bit by splitting up
|
||||||
|
* larger free blocks if possible.
|
||||||
|
* Algorithm is worst fit.
|
||||||
|
*/
|
||||||
|
|
||||||
|
assert(size<2*MAXSHORT);
|
||||||
|
for(trysize=2*MAXSHORT-2; trysize>size; trysize -= 2) {
|
||||||
|
p = freelist[trysize/sizeof(short)];
|
||||||
|
if ( p != (short *) 0) {
|
||||||
|
freelist[trysize/sizeof(short)] = *(short **) p;
|
||||||
|
oldcore(p+size/sizeof(short),trysize-size);
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Can't get more core from the biggies, try to combine the
|
||||||
|
* little ones. This is expensive but probably better than
|
||||||
|
* giving up.
|
||||||
|
*/
|
||||||
|
|
||||||
|
compactcore();
|
||||||
|
if ((p=freelist[size/sizeof(short)]) != 0) {
|
||||||
|
freelist[size/sizeof(short)] = * (short **) p;
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
for(trysize=2*MAXSHORT-2; trysize>size; trysize -= 2) {
|
||||||
|
p = freelist[trysize/sizeof(short)];
|
||||||
|
if ( p != (short *) 0) {
|
||||||
|
freelist[trysize/sizeof(short)] = *(short **) p;
|
||||||
|
oldcore(p+size/sizeof(short),trysize-size);
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* That's it then. Finished.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
#endif /* SEPID */
|
||||||
|
|
||||||
|
short *newcore(size) int size; {
|
||||||
|
register short *p,*q;
|
||||||
|
|
||||||
|
if( size < 2*MAXSHORT ) {
|
||||||
|
if ((p=freelist[size/sizeof(short)]) != (short *) 0)
|
||||||
|
freelist[size/sizeof(short)] = *(short **) p;
|
||||||
|
else {
|
||||||
|
p = freshcore(size);
|
||||||
|
#ifdef SEPID
|
||||||
|
if (p == (short *) 0)
|
||||||
|
p = grabcore(size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
p = freshcore(size);
|
||||||
|
if (p == 0)
|
||||||
|
error("out of memory");
|
||||||
|
for (q=p; size > 0 ; size -= sizeof(short))
|
||||||
|
*q++ = 0;
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef NOMALLOC
|
||||||
|
|
||||||
|
/*
|
||||||
|
* stdio uses malloc and free.
|
||||||
|
* you can use these as substitutes
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *malloc(size) int size; {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* malloc(III) is called by stdio,
|
||||||
|
* this routine is a substitute.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return( (char *) newcore(size));
|
||||||
|
}
|
||||||
|
|
||||||
|
free() {
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
oldcore(p,size) short *p; int size; {
|
||||||
|
#ifdef CORECHECK
|
||||||
|
register short *cp;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
assert(size<2*MAXSHORT);
|
||||||
|
#ifdef CORECHECK
|
||||||
|
for (cp=freelist[size/sizeof(short)]; cp != (short *) 0;
|
||||||
|
cp = (short *) *cp)
|
||||||
|
assert(cp != p);
|
||||||
|
#endif
|
||||||
|
*(short **) p = freelist[size/sizeof(short)];
|
||||||
|
freelist[size/sizeof(short)] = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
short *ccur,*cend;
|
||||||
|
|
||||||
|
coreinit(p1,p2) short *p1,*p2; {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* coreinit is called with the boundaries of a piece of
|
||||||
|
* memory that can be used for starters.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ccur = p1;
|
||||||
|
cend = p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
short *freshcore(size) int size; {
|
||||||
|
register short *temp;
|
||||||
|
static int cchunk=CCHUNK;
|
||||||
|
|
||||||
|
while(&ccur[size/sizeof(short)] >= cend && cchunk>0) {
|
||||||
|
do {
|
||||||
|
temp = (short *) sbrk(cchunk*sizeof(short));
|
||||||
|
if (temp == (short *) -1)
|
||||||
|
cchunk >>= 1;
|
||||||
|
else if (temp != cend)
|
||||||
|
ccur = cend = temp;
|
||||||
|
} while (temp == (short *) -1 && cchunk>0);
|
||||||
|
cend += cchunk;
|
||||||
|
#ifdef COREDEBUG
|
||||||
|
shortsasked += cchunk;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (cchunk==0)
|
||||||
|
return(0);
|
||||||
|
temp = ccur;
|
||||||
|
ccur = &ccur[size/sizeof(short)];
|
||||||
|
return(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* USEMALLOC */
|
||||||
|
|
||||||
|
coreinit() {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Empty function, no initialization needed
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
short *myalloc(size) register size; {
|
||||||
|
register short *p,*q;
|
||||||
|
extern char *malloc();
|
||||||
|
|
||||||
|
p = (short *)malloc(size);
|
||||||
|
if (p == 0)
|
||||||
|
error("out of memory");
|
||||||
|
for(q=p;size>0;size -= sizeof(short))
|
||||||
|
*q++ = 0;
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
55
util/opt/alloc.h
Normal file
55
util/opt/alloc.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
extern line_p newline();
|
||||||
|
extern offset *newrom();
|
||||||
|
extern sym_p newsym();
|
||||||
|
extern num_p newnum();
|
||||||
|
extern arg_p newarg();
|
||||||
|
extern argb_p newargb();
|
||||||
|
extern reg_p newreg();
|
||||||
|
|
||||||
|
extern oldline();
|
||||||
|
extern oldloc();
|
||||||
|
extern oldreg();
|
||||||
|
|
||||||
|
/* #define USEMALLOC /* if defined malloc() and free() are used */
|
||||||
|
|
||||||
|
/* #define COREDEBUG /* keep records and print statistics */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The next define gives if defined the number of pseudo's outside
|
||||||
|
* procedures that are collected without processing.
|
||||||
|
* If undefined all pseudo's will be collected but that may
|
||||||
|
* give trouble on small machines, because of lack of room.
|
||||||
|
*/
|
||||||
|
#define PSEUBETWEEN 200
|
||||||
|
|
||||||
|
#ifndef USEMALLOC
|
||||||
|
/*
|
||||||
|
* Now the real bitsqueezing starts.
|
||||||
|
* When running on a machine where code and data live in
|
||||||
|
* separate address-spaces it is worth putting in some extra
|
||||||
|
* code to save on probably less data.
|
||||||
|
*/
|
||||||
|
#define SEPID /* code and data in separate spaces */
|
||||||
|
/*
|
||||||
|
* If the stack segment and the data are separate as on a PDP11 under UNIX
|
||||||
|
* it is worth squeezing some shorts out of the stack page.
|
||||||
|
*/
|
||||||
|
#ifndef EM_WSIZE
|
||||||
|
/*
|
||||||
|
* Compiled with 'standard' C compiler
|
||||||
|
*/
|
||||||
|
#define STACKROOM 3200 /* number of shorts space in stack */
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* Compiled with pcc, has trouble with lots of variables
|
||||||
|
*/
|
||||||
|
#define STACKROOM 2000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define STACKROOM 1 /* 0 gives problems */
|
||||||
|
|
||||||
|
#endif /* USEMALLOC */
|
||||||
7
util/opt/assert.h
Normal file
7
util/opt/assert.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define assert(x) if(!(x)) badassertion(__FILE__,__LINE__)
|
||||||
|
#else
|
||||||
|
#define assert(x) /* nothing */
|
||||||
|
#endif
|
||||||
187
util/opt/backward.c
Normal file
187
util/opt/backward.c
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "assert.h"
|
||||||
|
#include "line.h"
|
||||||
|
#include "lookup.h"
|
||||||
|
#include "alloc.h"
|
||||||
|
#include "proinf.h"
|
||||||
|
#include "../../h/em_spec.h"
|
||||||
|
#include "../../h/em_pseu.h"
|
||||||
|
#include "../../h/em_mnem.h"
|
||||||
|
#include "ext.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define local(x) if (((x)->s_flags&SYMKNOWN) == 0)\
|
||||||
|
x->s_flags &= ~ SYMGLOBAL
|
||||||
|
#define global(x) if(((x)->s_flags&SYMKNOWN) == 0)\
|
||||||
|
x->s_flags |= SYMGLOBAL
|
||||||
|
|
||||||
|
#define DTYPHOL 1
|
||||||
|
#define DTYPBSS 2
|
||||||
|
#define DTYPCON 3
|
||||||
|
#define DTYPROM 4
|
||||||
|
byte curdtyp;
|
||||||
|
bool goodrom;
|
||||||
|
short curfrag = 3; /* see also peephole.c */
|
||||||
|
offset rombuf[MAXROM];
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
backward() {
|
||||||
|
register line_p lnp;
|
||||||
|
line_p next;
|
||||||
|
register arg_p ap;
|
||||||
|
line_p i,p;
|
||||||
|
int n;
|
||||||
|
register sym_p sp;
|
||||||
|
|
||||||
|
i = p = (line_p) 0;
|
||||||
|
curdtyp=0;
|
||||||
|
for (lnp = curpro.lastline; lnp != (line_p) 0; lnp = next) {
|
||||||
|
next = lnp->l_next;
|
||||||
|
switch(lnp->l_optyp) {
|
||||||
|
case OPSYMBOL:
|
||||||
|
global(lnp->l_a.la_sp);
|
||||||
|
break;
|
||||||
|
case OPSVAL:
|
||||||
|
global(lnp->l_a.la_sval.lasv_sp);
|
||||||
|
break;
|
||||||
|
case OPLVAL:
|
||||||
|
global(lnp->l_a.la_lval.lalv_sp);
|
||||||
|
break;
|
||||||
|
case OPLIST:
|
||||||
|
ap = lnp->l_a.la_arg;
|
||||||
|
while (ap != (arg_p) 0 ) {
|
||||||
|
switch(ap->a_typ) {
|
||||||
|
case ARGSYM:
|
||||||
|
global(ap->a_a.a_sp);
|
||||||
|
break;
|
||||||
|
case ARGVAL:
|
||||||
|
global(ap->a_a.a_val.av_sp);
|
||||||
|
}
|
||||||
|
ap = ap->a_next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* references to symbols are processed now.
|
||||||
|
* for plain instructions nothing else is needed
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(lnp->l_instr&BMASK) {
|
||||||
|
/*
|
||||||
|
* count all local occurences for register counts;
|
||||||
|
* op_lal is omitted and not by accident.
|
||||||
|
*/
|
||||||
|
case op_del:
|
||||||
|
case op_inl:
|
||||||
|
case op_ldl:
|
||||||
|
case op_lil:
|
||||||
|
case op_lol:
|
||||||
|
case op_sdl:
|
||||||
|
case op_sil:
|
||||||
|
case op_stl:
|
||||||
|
case op_zrl:
|
||||||
|
switch(lnp->l_optyp) {
|
||||||
|
case OPNO:
|
||||||
|
case OPNUMLAB:
|
||||||
|
case OPSYMBOL:
|
||||||
|
case OPSVAL:
|
||||||
|
case OPLVAL:
|
||||||
|
case OPLIST:
|
||||||
|
break;
|
||||||
|
case OPOFFSET:
|
||||||
|
incregusage(lnp->l_a.la_offset);
|
||||||
|
break;
|
||||||
|
case OPSHORT:
|
||||||
|
incregusage((offset)lnp->l_a.la_short);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
incregusage((offset)(lnp->l_optyp&BMASK)-Z_OPMINI);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* fall through !! */
|
||||||
|
default:
|
||||||
|
assert((lnp->l_instr&BMASK)<=op_last);
|
||||||
|
lnp->l_next = i;
|
||||||
|
i = lnp;
|
||||||
|
continue;
|
||||||
|
case ps_sym:
|
||||||
|
sp = lnp->l_a.la_sp;
|
||||||
|
local(sp);
|
||||||
|
if (curdtyp == DTYPROM && goodrom) {
|
||||||
|
sp->s_rom = newrom();
|
||||||
|
for (n=0;n<rc;n++)
|
||||||
|
sp->s_rom[n] = rombuf[n];
|
||||||
|
}
|
||||||
|
sp->s_frag = curfrag;
|
||||||
|
break;
|
||||||
|
case ps_hol:
|
||||||
|
curdtyp = DTYPHOL;
|
||||||
|
curfrag++;
|
||||||
|
break;
|
||||||
|
case ps_bss:
|
||||||
|
curdtyp = DTYPBSS;
|
||||||
|
curfrag++;
|
||||||
|
break;
|
||||||
|
case ps_con:
|
||||||
|
if (curdtyp != DTYPCON) {
|
||||||
|
curdtyp = DTYPCON;
|
||||||
|
curfrag++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ps_rom:
|
||||||
|
if (curdtyp != DTYPROM) {
|
||||||
|
curdtyp = DTYPROM;
|
||||||
|
curfrag++;
|
||||||
|
}
|
||||||
|
ap = lnp->l_a.la_arg;
|
||||||
|
rc = 0;
|
||||||
|
while (ap != (arg_p) 0 && rc < MAXROM) {
|
||||||
|
if (ap->a_typ == ARGOFF) {
|
||||||
|
rombuf[rc++] = ap->a_a.a_offset;
|
||||||
|
ap = ap->a_next;
|
||||||
|
} else
|
||||||
|
ap = (arg_p) 0;
|
||||||
|
}
|
||||||
|
goodrom = (rc >= 2);
|
||||||
|
break;
|
||||||
|
case ps_mes:
|
||||||
|
break;
|
||||||
|
case ps_inp:
|
||||||
|
case ps_ina:
|
||||||
|
local(lnp->l_a.la_sp);
|
||||||
|
case ps_exp:
|
||||||
|
case ps_exa:
|
||||||
|
case ps_exc:
|
||||||
|
oldline(lnp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lnp->l_next = p;
|
||||||
|
p = lnp;
|
||||||
|
}
|
||||||
|
if (prodepth != 0)
|
||||||
|
local(curpro.symbol);
|
||||||
|
instrs = i; pseudos = p; curpro.lastline = (line_p) 0;
|
||||||
|
}
|
||||||
65
util/opt/cleanup.c
Normal file
65
util/opt/cleanup.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "assert.h"
|
||||||
|
#include "../../h/em_pseu.h"
|
||||||
|
#include "../../h/em_spec.h"
|
||||||
|
#include "../../h/em_mes.h"
|
||||||
|
#include "lookup.h"
|
||||||
|
#include "ext.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
FILE *infile;
|
||||||
|
register c;
|
||||||
|
register sym_p *spp,sp;
|
||||||
|
|
||||||
|
for (spp=symhash;spp< &symhash[NSYMHASH];spp++)
|
||||||
|
for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
|
||||||
|
if ((sp->s_flags & SYMOUT) == 0)
|
||||||
|
outdef(sp);
|
||||||
|
if(!Lflag)
|
||||||
|
return;
|
||||||
|
c=fclose(outfile);
|
||||||
|
assert(c != EOF);
|
||||||
|
outfile = stdout;
|
||||||
|
infile = fopen(template,"r");
|
||||||
|
if (infile == NULL)
|
||||||
|
error("temp file disappeared");
|
||||||
|
outshort(sp_magic);
|
||||||
|
outinst(ps_mes);
|
||||||
|
outint(ms_ext);
|
||||||
|
for (spp=symhash;spp< &symhash[NSYMHASH];spp++)
|
||||||
|
for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
|
||||||
|
if ((sp->s_flags&(SYMDEF|SYMGLOBAL)) == (SYMDEF|SYMGLOBAL))
|
||||||
|
outsym(sp);
|
||||||
|
putc(sp_cend,outfile);
|
||||||
|
while ( (c=getc(infile)) != EOF)
|
||||||
|
putc(c,outfile);
|
||||||
|
c=fclose(infile);
|
||||||
|
assert(c != EOF);
|
||||||
|
c=unlink(template);
|
||||||
|
assert(c == 0);
|
||||||
|
}
|
||||||
16
util/opt/ext.h
Normal file
16
util/opt/ext.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#ifndef FILE
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
extern unsigned linecount;
|
||||||
|
extern int prodepth;
|
||||||
|
extern bool Lflag;
|
||||||
|
extern bool nflag;
|
||||||
|
extern byte em_flag[];
|
||||||
|
extern line_p instrs,pseudos;
|
||||||
|
extern FILE *outfile;
|
||||||
|
extern char template[];
|
||||||
|
extern offset wordsize;
|
||||||
|
extern offset pointersize;
|
||||||
|
extern char *progname;
|
||||||
126
util/opt/flow.c
Normal file
126
util/opt/flow.c
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "../../h/em_flag.h"
|
||||||
|
#include "../../h/em_spec.h"
|
||||||
|
#include "../../h/em_mnem.h"
|
||||||
|
#include "alloc.h"
|
||||||
|
#include "line.h"
|
||||||
|
#include "proinf.h"
|
||||||
|
#include "optim.h"
|
||||||
|
#include "ext.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
flow() {
|
||||||
|
|
||||||
|
findreach(); /* determine reachable labels */
|
||||||
|
cleaninstrs(); /* throw away unreachable code */
|
||||||
|
}
|
||||||
|
|
||||||
|
findreach() {
|
||||||
|
register num_p *npp,np;
|
||||||
|
|
||||||
|
reach(instrs);
|
||||||
|
for(npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++)
|
||||||
|
for(np= *npp; np != (num_p) 0 ; np = np->n_next)
|
||||||
|
if (np->n_flags&NUMDATA) {
|
||||||
|
np->n_repl->n_flags |= NUMREACH;
|
||||||
|
np->n_repl->n_jumps++;
|
||||||
|
if (!(np->n_flags&NUMSCAN)) {
|
||||||
|
np->n_flags |= NUMSCAN;
|
||||||
|
reach(np->n_line->l_next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reach(lnp) register line_p lnp; {
|
||||||
|
register num_p np;
|
||||||
|
|
||||||
|
for (;lnp != (line_p) 0; lnp = lnp->l_next) {
|
||||||
|
if(lnp->l_optyp == OPNUMLAB) {
|
||||||
|
/*
|
||||||
|
* Branch instruction or label
|
||||||
|
*/
|
||||||
|
np = lnp->l_a.la_np;
|
||||||
|
if ((lnp->l_instr&BMASK) != op_lab)
|
||||||
|
np = np->n_repl;
|
||||||
|
np->n_flags |= NUMREACH;
|
||||||
|
if (!(np->n_flags&NUMSCAN)) {
|
||||||
|
np->n_flags |= NUMSCAN;
|
||||||
|
reach(np->n_line->l_next);
|
||||||
|
}
|
||||||
|
if ((lnp->l_instr&BMASK) == op_lab)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
np->n_jumps++;
|
||||||
|
}
|
||||||
|
if ((em_flag[(lnp->l_instr&BMASK)-sp_fmnem]&EM_FLO)==FLO_T)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleaninstrs() {
|
||||||
|
register line_p *lpp,lp,*lastbra;
|
||||||
|
bool reachable,superfluous;
|
||||||
|
int instr;
|
||||||
|
|
||||||
|
lpp = &instrs; lastbra = (line_p *) 0; reachable = TRUE;
|
||||||
|
while ((lp = *lpp) != (line_p) 0) {
|
||||||
|
instr = lp->l_instr&BMASK;
|
||||||
|
if (instr == op_lab) {
|
||||||
|
if ((lp->l_a.la_np->n_flags&NUMREACH) != 0) {
|
||||||
|
reachable = TRUE;
|
||||||
|
if (lastbra != (line_p *) 0
|
||||||
|
&& (*lastbra)->l_next == lp
|
||||||
|
&& (*lastbra)->l_a.la_np->n_repl==lp->l_a.la_np) {
|
||||||
|
oldline(*lastbra);
|
||||||
|
OPTIM(O_BRALAB);
|
||||||
|
lpp = lastbra;
|
||||||
|
*lpp = lp;
|
||||||
|
lp->l_a.la_np->n_jumps--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( lp->l_a.la_np->n_repl != lp->l_a.la_np ||
|
||||||
|
((lp->l_a.la_np->n_flags&NUMDATA)==0 &&
|
||||||
|
lp->l_a.la_np->n_jumps == 0))
|
||||||
|
superfluous = TRUE;
|
||||||
|
else
|
||||||
|
superfluous = FALSE;
|
||||||
|
} else
|
||||||
|
superfluous = FALSE;
|
||||||
|
if ( (!reachable) || superfluous) {
|
||||||
|
lp = lp->l_next;
|
||||||
|
oldline(*lpp);
|
||||||
|
OPTIM(O_UNREACH);
|
||||||
|
*lpp = lp;
|
||||||
|
} else {
|
||||||
|
if ( instr <= sp_lmnem &&
|
||||||
|
(em_flag[instr-sp_fmnem]&EM_FLO)==FLO_T) {
|
||||||
|
reachable = FALSE;
|
||||||
|
if ((lp->l_instr&BMASK) == op_bra)
|
||||||
|
lastbra = lpp;
|
||||||
|
}
|
||||||
|
lpp = &lp->l_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
556
util/opt/getline.c
Normal file
556
util/opt/getline.c
Normal file
@ -0,0 +1,556 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "assert.h"
|
||||||
|
#include "line.h"
|
||||||
|
#include "lookup.h"
|
||||||
|
#include "alloc.h"
|
||||||
|
#include "proinf.h"
|
||||||
|
#include "../../h/em_spec.h"
|
||||||
|
#include "../../h/em_pseu.h"
|
||||||
|
#include "../../h/em_flag.h"
|
||||||
|
#include "../../h/em_mes.h"
|
||||||
|
#include "ext.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
static short tabval; /* temp store for shorts */
|
||||||
|
static offset tabval2; /* temp store for offsets */
|
||||||
|
static char string[IDL+1]; /* temp store for names */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The next constants are close to sp_cend for fast switches
|
||||||
|
*/
|
||||||
|
#define INST 256 /* instruction: number in tabval */
|
||||||
|
#define PSEU 257 /* pseudo: number in tabval */
|
||||||
|
#define ILBX 258 /* label: number in tabval */
|
||||||
|
#define DLBX 259 /* symbol: name in string[] */
|
||||||
|
#define CSTX1 260 /* short constant: stored in tabval */
|
||||||
|
#define CSTX2 261 /* offset: value in tabval2 */
|
||||||
|
#define VALX1 262 /* symbol+short: in string[] and tabval */
|
||||||
|
#define VALX2 263 /* symbol+offset: in string[] and tabval2 */
|
||||||
|
#define ATEOF 264 /* bumped into end of file */
|
||||||
|
|
||||||
|
#define readbyte getchar
|
||||||
|
|
||||||
|
short readshort() {
|
||||||
|
register int l_byte, h_byte;
|
||||||
|
|
||||||
|
l_byte = readbyte();
|
||||||
|
h_byte = readbyte();
|
||||||
|
if ( h_byte>=128 ) h_byte -= 256 ;
|
||||||
|
return l_byte | (h_byte*256) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LONGOFF
|
||||||
|
offset readoffset() {
|
||||||
|
register long l;
|
||||||
|
register int h_byte;
|
||||||
|
|
||||||
|
l = readbyte();
|
||||||
|
l |= ((unsigned) readbyte())*256 ;
|
||||||
|
l |= readbyte()*256L*256L ;
|
||||||
|
h_byte = readbyte() ;
|
||||||
|
if ( h_byte>=128 ) h_byte -= 256 ;
|
||||||
|
return l | (h_byte*256L*256*256L) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
draininput() {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* called when MES ERR is encountered.
|
||||||
|
* Drain input in case it is a pipe.
|
||||||
|
*/
|
||||||
|
|
||||||
|
while (getchar() != EOF)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
short getint() {
|
||||||
|
|
||||||
|
switch(table2()) {
|
||||||
|
default: error("int expected");
|
||||||
|
case CSTX1:
|
||||||
|
return(tabval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sym_p getsym(status) int status; {
|
||||||
|
|
||||||
|
switch(table2()) {
|
||||||
|
default:
|
||||||
|
error("symbol expected");
|
||||||
|
case DLBX:
|
||||||
|
return(symlookup(string,status,0));
|
||||||
|
case sp_pnam:
|
||||||
|
return(symlookup(string,status,SYMPRO));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
offset getoff() {
|
||||||
|
|
||||||
|
switch (table2()) {
|
||||||
|
default: error("offset expected");
|
||||||
|
case CSTX1:
|
||||||
|
return((offset) tabval);
|
||||||
|
#ifdef LONGOFF
|
||||||
|
case CSTX2:
|
||||||
|
return(tabval2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
make_string(n) int n; {
|
||||||
|
register char *s;
|
||||||
|
extern char *sprintf();
|
||||||
|
|
||||||
|
s=sprintf(string,".%u",n);
|
||||||
|
assert(s == string);
|
||||||
|
}
|
||||||
|
|
||||||
|
inident() {
|
||||||
|
register n;
|
||||||
|
register char *p = string;
|
||||||
|
register c;
|
||||||
|
|
||||||
|
n = getint();
|
||||||
|
while (n--) {
|
||||||
|
c = readbyte();
|
||||||
|
if (p<&string[IDL])
|
||||||
|
*p++ = c;
|
||||||
|
}
|
||||||
|
*p++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int table3(n) int n; {
|
||||||
|
|
||||||
|
switch (n) {
|
||||||
|
case sp_ilb1: tabval = readbyte(); return(ILBX);
|
||||||
|
case sp_ilb2: tabval = readshort(); return(ILBX);
|
||||||
|
case sp_dlb1: make_string(readbyte()); return(DLBX);
|
||||||
|
case sp_dlb2: make_string(readshort()); return(DLBX);
|
||||||
|
case sp_dnam: inident(); return(DLBX);
|
||||||
|
case sp_pnam: inident(); return(n);
|
||||||
|
case sp_cst2: tabval = readshort(); return(CSTX1);
|
||||||
|
#ifdef LONGOFF
|
||||||
|
case sp_cst4: tabval2 = readoffset(); return(CSTX2);
|
||||||
|
#endif
|
||||||
|
case sp_doff: if (table2()!=DLBX) error("symbol expected");
|
||||||
|
switch(table2()) {
|
||||||
|
default: error("offset expected");
|
||||||
|
case CSTX1: return(VALX1);
|
||||||
|
#ifdef LONGOFF
|
||||||
|
case CSTX2: return(VALX2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
default: return(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int table1() {
|
||||||
|
register n;
|
||||||
|
|
||||||
|
n = readbyte();
|
||||||
|
if (n == EOF)
|
||||||
|
return(ATEOF);
|
||||||
|
if ((n <= sp_lmnem) && (n >= sp_fmnem)) {
|
||||||
|
tabval = n;
|
||||||
|
return(INST);
|
||||||
|
}
|
||||||
|
if ((n <= sp_lpseu) && (n >= sp_fpseu)) {
|
||||||
|
tabval = n;
|
||||||
|
return(PSEU);
|
||||||
|
}
|
||||||
|
if ((n < sp_filb0 + sp_nilb0) && (n >= sp_filb0)) {
|
||||||
|
tabval = n - sp_filb0;
|
||||||
|
return(ILBX);
|
||||||
|
}
|
||||||
|
return(table3(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
int table2() {
|
||||||
|
register n;
|
||||||
|
|
||||||
|
n = readbyte();
|
||||||
|
if ((n < sp_fcst0 + sp_ncst0) && (n >= sp_fcst0)) {
|
||||||
|
tabval = n - sp_zcst0;
|
||||||
|
return(CSTX1);
|
||||||
|
}
|
||||||
|
return(table3(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
getlines() {
|
||||||
|
register line_p lnp;
|
||||||
|
register instr;
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
linecount++;
|
||||||
|
switch(table1()) {
|
||||||
|
default:
|
||||||
|
error("unknown instruction byte");
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
|
case ATEOF:
|
||||||
|
if (prodepth!=0)
|
||||||
|
error("procedure unterminated at eof");
|
||||||
|
process();
|
||||||
|
return;
|
||||||
|
case INST:
|
||||||
|
tstinpro();
|
||||||
|
instr = tabval;
|
||||||
|
break;
|
||||||
|
case DLBX:
|
||||||
|
lnp = newline(OPSYMBOL);
|
||||||
|
lnp->l_instr = ps_sym;
|
||||||
|
lnp->l_a.la_sp= symlookup(string,DEFINING,0);
|
||||||
|
lnp->l_next = curpro.lastline;
|
||||||
|
curpro.lastline = lnp;
|
||||||
|
continue;
|
||||||
|
case ILBX:
|
||||||
|
tstinpro();
|
||||||
|
lnp = newline(OPNUMLAB);
|
||||||
|
lnp->l_instr = op_lab;
|
||||||
|
lnp->l_a.la_np = numlookup((unsigned) tabval);
|
||||||
|
if (lnp->l_a.la_np->n_line != (line_p) 0)
|
||||||
|
error("label %u multiple defined",(unsigned) tabval);
|
||||||
|
lnp->l_a.la_np->n_line = lnp;
|
||||||
|
lnp->l_next = curpro.lastline;
|
||||||
|
curpro.lastline = lnp;
|
||||||
|
continue;
|
||||||
|
case PSEU:
|
||||||
|
if(inpseudo(tabval))
|
||||||
|
return;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now we have an instruction number in instr
|
||||||
|
* There might be an operand, look for it
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ((em_flag[instr-sp_fmnem]&EM_PAR)==PAR_NO) {
|
||||||
|
lnp = newline(OPNO);
|
||||||
|
} else switch(table2()) {
|
||||||
|
default:
|
||||||
|
error("unknown offset byte");
|
||||||
|
case sp_cend:
|
||||||
|
lnp = newline(OPNO);
|
||||||
|
break;
|
||||||
|
case CSTX1:
|
||||||
|
if ((em_flag[instr-sp_fmnem]&EM_PAR)!= PAR_B) {
|
||||||
|
if (CANMINI(tabval))
|
||||||
|
lnp = newline(tabval+Z_OPMINI);
|
||||||
|
else {
|
||||||
|
lnp = newline(OPSHORT);
|
||||||
|
lnp->l_a.la_short = tabval;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lnp = newline(OPNUMLAB);
|
||||||
|
lnp->l_a.la_np = numlookup((unsigned) tabval);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#ifdef LONGOFF
|
||||||
|
case CSTX2:
|
||||||
|
lnp = newline(OPOFFSET);
|
||||||
|
lnp->l_a.la_offset = tabval2;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case ILBX:
|
||||||
|
tstinpro();
|
||||||
|
lnp = newline(OPNUMLAB);
|
||||||
|
lnp->l_a.la_np = numlookup((unsigned) tabval);
|
||||||
|
break;
|
||||||
|
case DLBX:
|
||||||
|
lnp = newline(OPSYMBOL);
|
||||||
|
lnp->l_a.la_sp = symlookup(string,OCCURRING,0);
|
||||||
|
break;
|
||||||
|
case sp_pnam:
|
||||||
|
lnp = newline(OPSYMBOL);
|
||||||
|
lnp->l_a.la_sp = symlookup(string,OCCURRING,SYMPRO);
|
||||||
|
break;
|
||||||
|
case VALX1:
|
||||||
|
lnp = newline(OPSVAL);
|
||||||
|
lnp->l_a.la_sval.lasv_sp = symlookup(string,OCCURRING,0);
|
||||||
|
lnp->l_a.la_sval.lasv_short = tabval;
|
||||||
|
break;
|
||||||
|
#ifdef LONGOFF
|
||||||
|
case VALX2:
|
||||||
|
lnp = newline(OPLVAL);
|
||||||
|
lnp->l_a.la_lval.lalv_sp = symlookup(string,OCCURRING,0);
|
||||||
|
lnp->l_a.la_lval.lalv_offset = tabval2;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
lnp->l_instr = instr;
|
||||||
|
lnp->l_next = curpro.lastline;
|
||||||
|
curpro.lastline = lnp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
argstring(length,abp) offset length; register argb_p abp; {
|
||||||
|
|
||||||
|
while (length--) {
|
||||||
|
if (abp->ab_index == NARGBYTES)
|
||||||
|
abp = abp->ab_next = newargb();
|
||||||
|
abp->ab_contents[abp->ab_index++] = readbyte();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line_p arglist(n) int n; {
|
||||||
|
line_p lnp;
|
||||||
|
register arg_p ap,*app;
|
||||||
|
bool moretocome;
|
||||||
|
offset length;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* creates an arglist with n elements
|
||||||
|
* if n == 0 the arglist is variable and terminated by sp_cend
|
||||||
|
*/
|
||||||
|
|
||||||
|
lnp = newline(OPLIST);
|
||||||
|
app = &lnp->l_a.la_arg;
|
||||||
|
moretocome = TRUE;
|
||||||
|
do {
|
||||||
|
switch(table2()) {
|
||||||
|
default:
|
||||||
|
error("unknown byte in arglist");
|
||||||
|
case CSTX1:
|
||||||
|
tabval2 = (offset) tabval;
|
||||||
|
case CSTX2:
|
||||||
|
*app = ap = newarg(ARGOFF);
|
||||||
|
ap->a_a.a_offset = tabval2;
|
||||||
|
app = &ap->a_next;
|
||||||
|
break;
|
||||||
|
case ILBX:
|
||||||
|
tstinpro();
|
||||||
|
*app = ap = newarg(ARGNUM);
|
||||||
|
ap->a_a.a_np = numlookup((unsigned) tabval);
|
||||||
|
ap->a_a.a_np->n_flags |= NUMDATA;
|
||||||
|
app = &ap->a_next;
|
||||||
|
break;
|
||||||
|
case DLBX:
|
||||||
|
*app = ap = newarg(ARGSYM);
|
||||||
|
ap->a_a.a_sp = symlookup(string,OCCURRING,0);
|
||||||
|
app = &ap->a_next;
|
||||||
|
break;
|
||||||
|
case sp_pnam:
|
||||||
|
*app = ap = newarg(ARGSYM);
|
||||||
|
ap->a_a.a_sp = symlookup(string,OCCURRING,SYMPRO);
|
||||||
|
app = &ap->a_next;
|
||||||
|
break;
|
||||||
|
case VALX1:
|
||||||
|
tabval2 = (offset) tabval;
|
||||||
|
case VALX2:
|
||||||
|
*app = ap = newarg(ARGVAL);
|
||||||
|
ap->a_a.a_val.av_sp = symlookup(string,OCCURRING,0);
|
||||||
|
ap->a_a.a_val.av_offset = tabval2;
|
||||||
|
app = &ap->a_next;
|
||||||
|
break;
|
||||||
|
case sp_scon:
|
||||||
|
*app = ap = newarg(ARGSTR);
|
||||||
|
length = getoff();
|
||||||
|
argstring(length,&ap->a_a.a_string);
|
||||||
|
app = &ap->a_next;
|
||||||
|
break;
|
||||||
|
case sp_icon:
|
||||||
|
*app = ap = newarg(ARGICN);
|
||||||
|
goto casecon;
|
||||||
|
case sp_ucon:
|
||||||
|
*app = ap = newarg(ARGUCN);
|
||||||
|
goto casecon;
|
||||||
|
case sp_fcon:
|
||||||
|
*app = ap = newarg(ARGFCN);
|
||||||
|
casecon:
|
||||||
|
length = getint();
|
||||||
|
ap->a_a.a_con.ac_length = (short) length;
|
||||||
|
argstring(getoff(),&ap->a_a.a_con.ac_con);
|
||||||
|
app = &ap->a_next;
|
||||||
|
break;
|
||||||
|
case sp_cend:
|
||||||
|
moretocome = FALSE;
|
||||||
|
}
|
||||||
|
if (n && (--n) == 0)
|
||||||
|
moretocome = FALSE;
|
||||||
|
} while (moretocome);
|
||||||
|
return(lnp);
|
||||||
|
}
|
||||||
|
|
||||||
|
offset aoff(ap,n) register arg_p ap; {
|
||||||
|
|
||||||
|
while (n>0) {
|
||||||
|
if (ap != (arg_p) 0)
|
||||||
|
ap = ap->a_next;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
if (ap == (arg_p) 0)
|
||||||
|
error("too few parameters");
|
||||||
|
if (ap->a_typ != ARGOFF)
|
||||||
|
error("offset expected");
|
||||||
|
return(ap->a_a.a_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
int inpseudo(n) short n; {
|
||||||
|
register line_p lnp,head,tail;
|
||||||
|
short n1,n2;
|
||||||
|
proinf savearea;
|
||||||
|
#ifdef PSEUBETWEEN
|
||||||
|
static int pcount=0;
|
||||||
|
|
||||||
|
if (pcount++ >= PSEUBETWEEN && prodepth==0) {
|
||||||
|
process();
|
||||||
|
pcount=0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch(n) {
|
||||||
|
default:
|
||||||
|
error("unknown pseudo");
|
||||||
|
case ps_bss:
|
||||||
|
case ps_hol:
|
||||||
|
lnp = arglist(3);
|
||||||
|
break;
|
||||||
|
case ps_rom:
|
||||||
|
case ps_con:
|
||||||
|
lnp = arglist(0);
|
||||||
|
break;
|
||||||
|
case ps_ina:
|
||||||
|
case ps_inp:
|
||||||
|
case ps_exa:
|
||||||
|
case ps_exp:
|
||||||
|
lnp = newline(OPSYMBOL);
|
||||||
|
lnp->l_a.la_sp = getsym(NOTHING);
|
||||||
|
break;
|
||||||
|
case ps_exc:
|
||||||
|
n1 = getint(); n2 = getint();
|
||||||
|
if (n1 != 0 && n2 != 0) {
|
||||||
|
tail = curpro.lastline;
|
||||||
|
while (--n2) tail = tail->l_next;
|
||||||
|
head = tail;
|
||||||
|
while (n1--) head = head->l_next;
|
||||||
|
lnp = tail->l_next;
|
||||||
|
tail->l_next = head->l_next;
|
||||||
|
head->l_next = curpro.lastline;
|
||||||
|
curpro.lastline = lnp;
|
||||||
|
}
|
||||||
|
lnp = newline(OPNO);
|
||||||
|
break;
|
||||||
|
case ps_mes:
|
||||||
|
lnp = arglist(0);
|
||||||
|
switch((int) aoff(lnp->l_a.la_arg,0)) {
|
||||||
|
case ms_err:
|
||||||
|
draininput(); exit(-1);
|
||||||
|
case ms_opt:
|
||||||
|
nflag = TRUE; break;
|
||||||
|
case ms_emx:
|
||||||
|
wordsize = aoff(lnp->l_a.la_arg,1);
|
||||||
|
pointersize = aoff(lnp->l_a.la_arg,2);
|
||||||
|
#ifndef LONGOFF
|
||||||
|
if (wordsize>2)
|
||||||
|
error("This optimizer cannot handle wordsize>2");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case ms_gto:
|
||||||
|
curpro.gtoproc=1;
|
||||||
|
/* Treat as empty mes ms_reg */
|
||||||
|
case ms_reg:
|
||||||
|
tstinpro();
|
||||||
|
regvar(lnp->l_a.la_arg->a_next);
|
||||||
|
oldline(lnp);
|
||||||
|
lnp=newline(OPNO);
|
||||||
|
n=ps_exc; /* kludge to force out this line */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ps_pro:
|
||||||
|
if (prodepth>0)
|
||||||
|
savearea = curpro;
|
||||||
|
else
|
||||||
|
process();
|
||||||
|
curpro.symbol = getsym(DEFINING);
|
||||||
|
switch(table2()) {
|
||||||
|
case sp_cend:
|
||||||
|
curpro.localbytes = (offset) -1;
|
||||||
|
break;
|
||||||
|
case CSTX1:
|
||||||
|
tabval2 = (offset) tabval;
|
||||||
|
case CSTX2:
|
||||||
|
curpro.localbytes = tabval2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error("bad second arg of PRO");
|
||||||
|
}
|
||||||
|
prodepth++;
|
||||||
|
curpro.gtoproc=0;
|
||||||
|
if (prodepth>1) {
|
||||||
|
register i;
|
||||||
|
|
||||||
|
curpro.lastline = (line_p) 0;
|
||||||
|
curpro.freg = (reg_p) 0;
|
||||||
|
for(i=0;i<NNUMHASH;i++)
|
||||||
|
curpro.numhash[i] = (num_p) 0;
|
||||||
|
getlines();
|
||||||
|
curpro = savearea;
|
||||||
|
prodepth--;
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
case ps_end:
|
||||||
|
if (prodepth==0)
|
||||||
|
error("END misplaced");
|
||||||
|
switch(table2()) {
|
||||||
|
case sp_cend:
|
||||||
|
if (curpro.localbytes == (offset) -1)
|
||||||
|
error("bytes for locals still unknown");
|
||||||
|
break;
|
||||||
|
case CSTX1:
|
||||||
|
tabval2 = (offset) tabval;
|
||||||
|
case CSTX2:
|
||||||
|
if (curpro.localbytes != (offset) -1 && curpro.localbytes != tabval2)
|
||||||
|
error("inconsistency in number of bytes for locals");
|
||||||
|
curpro.localbytes = tabval2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
process();
|
||||||
|
curpro.symbol = (sym_p) 0;
|
||||||
|
if (prodepth==1) {
|
||||||
|
prodepth=0;
|
||||||
|
#ifdef PSEUBETWEEN
|
||||||
|
pcount=0;
|
||||||
|
#endif
|
||||||
|
return(0);
|
||||||
|
} else
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
lnp->l_instr = n;
|
||||||
|
lnp->l_next = curpro.lastline;
|
||||||
|
curpro.lastline = lnp;
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
tstinpro() {
|
||||||
|
|
||||||
|
if (prodepth==0)
|
||||||
|
error("This is not allowed outside a procedure");
|
||||||
|
}
|
||||||
88
util/opt/line.h
Normal file
88
util/opt/line.h
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#define NARGBYTES 14
|
||||||
|
struct argbytes {
|
||||||
|
argb_p ab_next;
|
||||||
|
short ab_index;
|
||||||
|
char ab_contents[NARGBYTES];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
sym_p av_sp;
|
||||||
|
offset av_offset;
|
||||||
|
} s_a_val;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
short ac_length;
|
||||||
|
argb_t ac_con;
|
||||||
|
} s_a_con;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
offset a_offset;
|
||||||
|
num_p a_np;
|
||||||
|
sym_p a_sp;
|
||||||
|
s_a_val a_val;
|
||||||
|
argb_t a_string;
|
||||||
|
s_a_con a_con;
|
||||||
|
} un_a_a;
|
||||||
|
|
||||||
|
struct arg {
|
||||||
|
arg_p a_next;
|
||||||
|
short a_typ;
|
||||||
|
un_a_a a_a;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* possible values for .a_typ
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define ARGOFF 0
|
||||||
|
#define ARGNUM 1
|
||||||
|
#define ARGSYM 2
|
||||||
|
#define ARGVAL 3
|
||||||
|
#define ARGSTR 4
|
||||||
|
#define ARGICN 5
|
||||||
|
#define ARGUCN 6
|
||||||
|
#define ARGFCN 7
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
sym_p lasv_sp;
|
||||||
|
short lasv_short;
|
||||||
|
} s_la_sval;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
sym_p lalv_sp;
|
||||||
|
offset lalv_offset;
|
||||||
|
} s_la_lval;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
short la_short;
|
||||||
|
offset la_offset;
|
||||||
|
num_p la_np;
|
||||||
|
sym_p la_sp;
|
||||||
|
s_la_sval la_sval;
|
||||||
|
s_la_lval la_lval;
|
||||||
|
arg_p la_arg;
|
||||||
|
} un_l_a;
|
||||||
|
|
||||||
|
struct line {
|
||||||
|
line_p l_next; /* maintains linked list */
|
||||||
|
byte l_instr; /* instruction number */
|
||||||
|
byte l_optyp; /* specifies what follows */
|
||||||
|
un_l_a l_a;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Possible values for .l_optyp */
|
||||||
|
|
||||||
|
#define OPNO 0 /* no operand */
|
||||||
|
#define OPSHORT 1 /* 16 bit number */
|
||||||
|
#define OPOFFSET 2 /* 16 or 32 bit number */
|
||||||
|
#define OPNUMLAB 3 /* local label for branches */
|
||||||
|
#define OPSYMBOL 4 /* global label or procedurename */
|
||||||
|
#define OPSVAL 5 /* symbol + 16 bit constant */
|
||||||
|
#define OPLVAL 6 /* symbol + 16 or 32 bit constant */
|
||||||
|
#define OPLIST 7 /* operand list for some pseudos */
|
||||||
|
#define OPMINI 8 /* start of minis */
|
||||||
|
|
||||||
|
#define Z_OPMINI (OPMINI+100) /* tunable */
|
||||||
|
|
||||||
|
#define CANMINI(x) ((x)>=OPMINI-Z_OPMINI && (x)<256-Z_OPMINI)
|
||||||
94
util/opt/lookup.c
Normal file
94
util/opt/lookup.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "lookup.h"
|
||||||
|
#include "alloc.h"
|
||||||
|
#include "proinf.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned hash(string) char *string; {
|
||||||
|
register char *p;
|
||||||
|
register unsigned i,sum;
|
||||||
|
|
||||||
|
for (sum=i=0,p=string;*p;i += 3)
|
||||||
|
sum ^= (*p++)<<(i&07);
|
||||||
|
return(sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
sym_p symlookup(name,status,flags) char *name; int status,flags; {
|
||||||
|
register sym_p *spp,sp;
|
||||||
|
register i;
|
||||||
|
static short genfrag = 32767;
|
||||||
|
|
||||||
|
spp = &symhash[hash(name)%NSYMHASH];
|
||||||
|
while (*spp != (sym_p) 0)
|
||||||
|
if (strncmp((*spp)->s_name,name,IDL)==0) {
|
||||||
|
sp = *spp;
|
||||||
|
if ((sp->s_flags^flags)&SYMPRO)
|
||||||
|
error("%s is both proc and datalabel",name);
|
||||||
|
if (status == DEFINING) {
|
||||||
|
if (sp->s_flags&SYMDEF)
|
||||||
|
error("redefined symbol %s",name);
|
||||||
|
sp->s_flags |= SYMDEF;
|
||||||
|
}
|
||||||
|
return(sp);
|
||||||
|
} else
|
||||||
|
spp = &(*spp)->s_next;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* symbol not found, enter in table
|
||||||
|
*/
|
||||||
|
|
||||||
|
i = strlen(name) + 1;
|
||||||
|
if (i & 1)
|
||||||
|
i++;
|
||||||
|
if (i > IDL)
|
||||||
|
i = IDL;
|
||||||
|
*spp = sp = newsym(i);
|
||||||
|
strncpy(sp->s_name,name,i);
|
||||||
|
sp->s_flags = flags;
|
||||||
|
if (status == DEFINING)
|
||||||
|
sp->s_flags |= SYMDEF;
|
||||||
|
sp->s_frag = genfrag--;
|
||||||
|
return(sp);
|
||||||
|
}
|
||||||
|
|
||||||
|
num_p numlookup(number) unsigned number; {
|
||||||
|
register num_p *npp, np;
|
||||||
|
|
||||||
|
npp = &curpro.numhash[number%NNUMHASH];
|
||||||
|
while (*npp != (num_p) 0)
|
||||||
|
if ((*npp)->n_number == number)
|
||||||
|
return(*npp);
|
||||||
|
else
|
||||||
|
npp = &(*npp)->n_next;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* local label not found, enter in tabel
|
||||||
|
*/
|
||||||
|
|
||||||
|
*npp = np = newnum();
|
||||||
|
np->n_number = number;
|
||||||
|
np->n_repl = np;
|
||||||
|
return(np);
|
||||||
|
}
|
||||||
25
util/opt/lookup.h
Normal file
25
util/opt/lookup.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#define IDL 100
|
||||||
|
|
||||||
|
struct sym {
|
||||||
|
sym_p s_next;
|
||||||
|
offset *s_rom;
|
||||||
|
short s_flags;
|
||||||
|
short s_frag;
|
||||||
|
offset s_value;
|
||||||
|
char s_name[2]; /* to be extended up to IDL */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* contents of .s_flags */
|
||||||
|
#define SYMPRO 000001
|
||||||
|
#define SYMGLOBAL 000002
|
||||||
|
#define SYMKNOWN 000004
|
||||||
|
#define SYMOUT 000010
|
||||||
|
#define SYMDEF 000020
|
||||||
|
|
||||||
|
#define NSYMHASH 127
|
||||||
|
extern sym_p symhash[NSYMHASH],symlookup();
|
||||||
|
#define OCCURRING 0
|
||||||
|
#define DEFINING 1
|
||||||
|
#define NOTHING 2
|
||||||
77
util/opt/main.c
Normal file
77
util/opt/main.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "alloc.h"
|
||||||
|
#include "../../h/em_spec.h"
|
||||||
|
#include "ext.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Main program for EM optimizer
|
||||||
|
*/
|
||||||
|
|
||||||
|
main(argc,argv) int argc; char *argv[]; {
|
||||||
|
short somespace[STACKROOM];
|
||||||
|
|
||||||
|
progname = argv[0];
|
||||||
|
while (argc-->1 && **++argv == '-')
|
||||||
|
flags(*argv);
|
||||||
|
if (argc>1) {
|
||||||
|
fprintf(stderr,"Usage: %s [-Ln] [name]\n",progname);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
if (argc)
|
||||||
|
if (freopen(*argv,"r",stdin) == NULL)
|
||||||
|
error("Cannot open %s",*argv);
|
||||||
|
fileinit();
|
||||||
|
coreinit(somespace,somespace+STACKROOM);
|
||||||
|
getlines();
|
||||||
|
cleanup();
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
flags(s) register char *s; {
|
||||||
|
|
||||||
|
for (s++;*s;s++)
|
||||||
|
switch(*s) {
|
||||||
|
case 'L': Lflag = TRUE; break;
|
||||||
|
case 'n': nflag = TRUE; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileinit() {
|
||||||
|
char *mktemp();
|
||||||
|
short readshort();
|
||||||
|
|
||||||
|
if (readshort() != (short) sp_magic)
|
||||||
|
error("wrong input file");
|
||||||
|
if (Lflag) {
|
||||||
|
outfile = fopen(mktemp(template),"w");
|
||||||
|
if (outfile == NULL)
|
||||||
|
error("can't create %s",template);
|
||||||
|
} else {
|
||||||
|
outfile = stdout;
|
||||||
|
outshort(sp_magic);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
util/opt/makedepend
Executable file
15
util/opt/makedepend
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
: '$Header$'
|
||||||
|
for extension in c y
|
||||||
|
do
|
||||||
|
for file in *.$extension
|
||||||
|
do ofile=`basename $file .$extension`.o
|
||||||
|
grep '^# *include.*"' $file|sed "s/.*\"\(.*\)\".*/$ofile: \1/"
|
||||||
|
done
|
||||||
|
done | sort -u >depend
|
||||||
|
ed - Makefile <<'!'
|
||||||
|
/AUTOAUTOAUTO/+,$d
|
||||||
|
$r depend
|
||||||
|
w
|
||||||
|
q
|
||||||
|
!
|
||||||
|
rm -f depend
|
||||||
366
util/opt/mktab.y
Normal file
366
util/opt/mktab.y
Normal file
@ -0,0 +1,366 @@
|
|||||||
|
%{
|
||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "pattern.h"
|
||||||
|
#include "../../h/em_spec.h"
|
||||||
|
#include "../../h/em_mnem.h"
|
||||||
|
#include "optim.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAXNODES 1000
|
||||||
|
expr_t nodes[MAXNODES];
|
||||||
|
expr_p lastnode = nodes+1;
|
||||||
|
int curind,prevind;
|
||||||
|
int patlen,maxpatlen,rpllen;
|
||||||
|
int lino = 1;
|
||||||
|
int patno=1;
|
||||||
|
#define MAX 100
|
||||||
|
int patmnem[MAX],rplmnem[MAX],rplexpr[MAX];
|
||||||
|
byte nparam[N_EX_OPS];
|
||||||
|
bool nonumlab[N_EX_OPS];
|
||||||
|
bool onlyconst[N_EX_OPS];
|
||||||
|
int nerrors=0;
|
||||||
|
%}
|
||||||
|
|
||||||
|
%union {
|
||||||
|
int y_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
%left OR2
|
||||||
|
%left AND2
|
||||||
|
%left OR1
|
||||||
|
%left XOR1
|
||||||
|
%left AND1
|
||||||
|
%left CMPEQ,CMPNE
|
||||||
|
%left CMPLT,CMPLE,CMPGT,CMPGE
|
||||||
|
%left RSHIFT,LSHIFT
|
||||||
|
%left ARPLUS,ARMINUS
|
||||||
|
%left ARTIMES,ARDIVIDE,ARMOD
|
||||||
|
%nonassoc NOT,COMP,UMINUS
|
||||||
|
%nonassoc '$'
|
||||||
|
|
||||||
|
%token SFIT,UFIT,NOTREG,PSIZE,WSIZE,DEFINED,SAMESIGN,ROM,ROTATE
|
||||||
|
%token <y_int> MNEM
|
||||||
|
%token <y_int> NUMBER
|
||||||
|
%type <y_int> expr,argno,optexpr
|
||||||
|
|
||||||
|
%start patternlist
|
||||||
|
|
||||||
|
%%
|
||||||
|
patternlist
|
||||||
|
: /* empty */
|
||||||
|
| patternlist '\n'
|
||||||
|
| patternlist pattern
|
||||||
|
;
|
||||||
|
pattern :
|
||||||
|
mnemlist optexpr ':' replacement '\n'
|
||||||
|
{ register i;
|
||||||
|
outbyte(0); outshort(prevind); prevind=curind-3;
|
||||||
|
out(patlen);
|
||||||
|
for (i=0;i<patlen;i++) outbyte(patmnem[i]);
|
||||||
|
out($2);
|
||||||
|
out(rpllen);
|
||||||
|
for (i=0;i<rpllen;i++) {
|
||||||
|
outbyte(rplmnem[i]);
|
||||||
|
out(rplexpr[i]);
|
||||||
|
}
|
||||||
|
#ifdef DIAGOPT
|
||||||
|
outshort(patno);
|
||||||
|
#endif
|
||||||
|
patno++;
|
||||||
|
printf("\n");
|
||||||
|
if (patlen>maxpatlen) maxpatlen=patlen;
|
||||||
|
}
|
||||||
|
| error '\n'
|
||||||
|
{ yyerrok; }
|
||||||
|
;
|
||||||
|
replacement
|
||||||
|
: expr /* special optimization */
|
||||||
|
{
|
||||||
|
#ifdef ALLOWSPECIAL
|
||||||
|
rpllen=1; rplmnem[0]=0; rplexpr[0]=$1;
|
||||||
|
#else
|
||||||
|
yyerror("No specials allowed");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
| repllist
|
||||||
|
;
|
||||||
|
repllist: /* empty */
|
||||||
|
{ rpllen=0; }
|
||||||
|
| repllist repl
|
||||||
|
;
|
||||||
|
repl : MNEM optexpr
|
||||||
|
{ rplmnem[rpllen] = $1; rplexpr[rpllen++] = $2; }
|
||||||
|
;
|
||||||
|
mnemlist: MNEM
|
||||||
|
{ patlen=0; patmnem[patlen++] = $1; }
|
||||||
|
| mnemlist MNEM
|
||||||
|
{ patmnem[patlen++] = $2; }
|
||||||
|
;
|
||||||
|
optexpr : /* empty */
|
||||||
|
{ $$ = 0; }
|
||||||
|
| expr
|
||||||
|
;
|
||||||
|
expr
|
||||||
|
: '$' argno
|
||||||
|
{ $$ = lookup(0,EX_ARG,$2,0); }
|
||||||
|
| NUMBER
|
||||||
|
{ $$ = lookup(0,EX_CON,(int)(short)$1,0); }
|
||||||
|
| PSIZE
|
||||||
|
{ $$ = lookup(0,EX_POINTERSIZE,0,0); }
|
||||||
|
| WSIZE
|
||||||
|
{ $$ = lookup(0,EX_WORDSIZE,0,0); }
|
||||||
|
| DEFINED '(' expr ')'
|
||||||
|
{ $$ = lookup(0,EX_DEFINED,$3,0); }
|
||||||
|
| SAMESIGN '(' expr ',' expr ')'
|
||||||
|
{ $$ = lookup(1,EX_SAMESIGN,$3,$5); }
|
||||||
|
| SFIT '(' expr ',' expr ')'
|
||||||
|
{ $$ = lookup(0,EX_SFIT,$3,$5); }
|
||||||
|
| UFIT '(' expr ',' expr ')'
|
||||||
|
{ $$ = lookup(0,EX_UFIT,$3,$5); }
|
||||||
|
| ROTATE '(' expr ',' expr ')'
|
||||||
|
{ $$ = lookup(0,EX_ROTATE,$3,$5); }
|
||||||
|
| NOTREG '(' expr ')'
|
||||||
|
{ $$ = lookup(0,EX_NOTREG,$3,0); }
|
||||||
|
| ROM '(' argno ',' expr ')'
|
||||||
|
{ $$ = lookup(0,EX_ROM,$3,$5); }
|
||||||
|
| '(' expr ')'
|
||||||
|
{ $$ = $2; }
|
||||||
|
| expr CMPEQ expr
|
||||||
|
{ $$ = lookup(1,EX_CMPEQ,$1,$3); }
|
||||||
|
| expr CMPNE expr
|
||||||
|
{ $$ = lookup(1,EX_CMPNE,$1,$3); }
|
||||||
|
| expr CMPGT expr
|
||||||
|
{ $$ = lookup(0,EX_CMPGT,$1,$3); }
|
||||||
|
| expr CMPGE expr
|
||||||
|
{ $$ = lookup(0,EX_CMPGE,$1,$3); }
|
||||||
|
| expr CMPLT expr
|
||||||
|
{ $$ = lookup(0,EX_CMPLT,$1,$3); }
|
||||||
|
| expr CMPLE expr
|
||||||
|
{ $$ = lookup(0,EX_CMPLE,$1,$3); }
|
||||||
|
| expr OR2 expr
|
||||||
|
{ $$ = lookup(0,EX_OR2,$1,$3); }
|
||||||
|
| expr AND2 expr
|
||||||
|
{ $$ = lookup(0,EX_AND2,$1,$3); }
|
||||||
|
| expr OR1 expr
|
||||||
|
{ $$ = lookup(1,EX_OR1,$1,$3); }
|
||||||
|
| expr XOR1 expr
|
||||||
|
{ $$ = lookup(1,EX_XOR1,$1,$3); }
|
||||||
|
| expr AND1 expr
|
||||||
|
{ $$ = lookup(1,EX_AND1,$1,$3); }
|
||||||
|
| expr ARPLUS expr
|
||||||
|
{ $$ = lookup(1,EX_PLUS,$1,$3); }
|
||||||
|
| expr ARMINUS expr
|
||||||
|
{ $$ = lookup(0,EX_MINUS,$1,$3); }
|
||||||
|
| expr ARTIMES expr
|
||||||
|
{ $$ = lookup(1,EX_TIMES,$1,$3); }
|
||||||
|
| expr ARDIVIDE expr
|
||||||
|
{ $$ = lookup(0,EX_DIVIDE,$1,$3); }
|
||||||
|
| expr ARMOD expr
|
||||||
|
{ $$ = lookup(0,EX_MOD,$1,$3); }
|
||||||
|
| expr LSHIFT expr
|
||||||
|
{ $$ = lookup(0,EX_LSHIFT,$1,$3); }
|
||||||
|
| expr RSHIFT expr
|
||||||
|
{ $$ = lookup(0,EX_RSHIFT,$1,$3); }
|
||||||
|
| ARPLUS expr %prec UMINUS
|
||||||
|
{ $$ = $2; }
|
||||||
|
| ARMINUS expr %prec UMINUS
|
||||||
|
{ $$ = lookup(0,EX_UMINUS,$2,0); }
|
||||||
|
| NOT expr
|
||||||
|
{ $$ = lookup(0,EX_NOT,$2,0); }
|
||||||
|
| COMP expr
|
||||||
|
{ $$ = lookup(0,EX_COMP,$2,0); }
|
||||||
|
;
|
||||||
|
argno : NUMBER
|
||||||
|
{ if ($1<1 || $1>patlen) {
|
||||||
|
YYERROR;
|
||||||
|
}
|
||||||
|
$$ = (int) $1;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
extern char em_mnem[][4];
|
||||||
|
|
||||||
|
#define HASHSIZE (2*(sp_lmnem-sp_fmnem))
|
||||||
|
|
||||||
|
struct hashmnem {
|
||||||
|
char h_name[3];
|
||||||
|
byte h_value;
|
||||||
|
} hashmnem[HASHSIZE];
|
||||||
|
|
||||||
|
inithash() {
|
||||||
|
register i;
|
||||||
|
|
||||||
|
enter("lab",op_lab);
|
||||||
|
enter("LLP",op_LLP);
|
||||||
|
enter("LEP",op_LEP);
|
||||||
|
enter("SLP",op_SLP);
|
||||||
|
enter("SEP",op_SEP);
|
||||||
|
for(i=0;i<=sp_lmnem-sp_fmnem;i++)
|
||||||
|
enter(em_mnem[i],i+sp_fmnem);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned hashname(name) register char *name; {
|
||||||
|
register unsigned h;
|
||||||
|
|
||||||
|
h = (*name++)&BMASK;
|
||||||
|
h = (h<<4)^((*name++)&BMASK);
|
||||||
|
h = (h<<4)^((*name++)&BMASK);
|
||||||
|
return(h);
|
||||||
|
}
|
||||||
|
|
||||||
|
enter(name,value) char *name; {
|
||||||
|
register unsigned h;
|
||||||
|
|
||||||
|
h=hashname(name)%HASHSIZE;
|
||||||
|
while (hashmnem[h].h_name[0] != 0)
|
||||||
|
h = (h+1)%HASHSIZE;
|
||||||
|
strncpy(hashmnem[h].h_name,name,3);
|
||||||
|
hashmnem[h].h_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlookup(name) char *name; {
|
||||||
|
register unsigned h;
|
||||||
|
|
||||||
|
h = hashname(name)%HASHSIZE;
|
||||||
|
while (strncmp(hashmnem[h].h_name,name,3) != 0 &&
|
||||||
|
hashmnem[h].h_name[0] != 0)
|
||||||
|
h = (h+1)%HASHSIZE;
|
||||||
|
return(hashmnem[h].h_value&BMASK); /* 0 if not found */
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
|
||||||
|
inithash();
|
||||||
|
initio();
|
||||||
|
yyparse();
|
||||||
|
if (nerrors==0)
|
||||||
|
printnodes();
|
||||||
|
return nerrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
yyerror(s) char *s; {
|
||||||
|
|
||||||
|
fprintf(stderr,"line %d: %s\n",lino,s);
|
||||||
|
nerrors++;
|
||||||
|
}
|
||||||
|
|
||||||
|
lookup(comm,operator,lnode,rnode) {
|
||||||
|
register expr_p p;
|
||||||
|
|
||||||
|
for (p=nodes+1;p<lastnode;p++) {
|
||||||
|
if (p->ex_operator != operator)
|
||||||
|
continue;
|
||||||
|
if (!(p->ex_lnode == lnode && p->ex_rnode == rnode ||
|
||||||
|
comm && p->ex_lnode == rnode && p->ex_rnode == lnode))
|
||||||
|
continue;
|
||||||
|
return(p-nodes);
|
||||||
|
}
|
||||||
|
if (lastnode >= &nodes[MAXNODES])
|
||||||
|
yyerror("node table overflow");
|
||||||
|
lastnode++;
|
||||||
|
p->ex_operator = operator;
|
||||||
|
p->ex_lnode = lnode;
|
||||||
|
p->ex_rnode = rnode;
|
||||||
|
return(p-nodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
printnodes() {
|
||||||
|
register expr_p p;
|
||||||
|
|
||||||
|
printf("};\n\nshort lastind = %d;\n\nexpr_t enodes[] = {\n",prevind);
|
||||||
|
for (p=nodes;p<lastnode;p++)
|
||||||
|
printf("/* %3d */\t%3d,%6u,%6u,\n",
|
||||||
|
p-nodes,p->ex_operator,p->ex_lnode,p->ex_rnode);
|
||||||
|
printf("};\n\niarg_t iargs[%d];\n",maxpatlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
initio() {
|
||||||
|
register i;
|
||||||
|
|
||||||
|
printf("#include \"param.h\"\n#include \"types.h\"\n");
|
||||||
|
printf("#include \"pattern.h\"\n\n");
|
||||||
|
for(i=0;i<N_EX_OPS;i++) {
|
||||||
|
nparam[i]=2;
|
||||||
|
nonumlab[i]=TRUE;
|
||||||
|
onlyconst[i]=TRUE;
|
||||||
|
}
|
||||||
|
nparam[EX_POINTERSIZE] = 0;
|
||||||
|
nparam[EX_WORDSIZE] = 0;
|
||||||
|
nparam[EX_CON] = 0;
|
||||||
|
nparam[EX_ROM] = 0;
|
||||||
|
nparam[EX_ARG] = 0;
|
||||||
|
nparam[EX_DEFINED] = 0;
|
||||||
|
nparam[EX_OR2] = 1;
|
||||||
|
nparam[EX_AND2] = 1;
|
||||||
|
nparam[EX_UMINUS] = 1;
|
||||||
|
nparam[EX_NOT] = 1;
|
||||||
|
nparam[EX_COMP] = 1;
|
||||||
|
nparam[EX_NOTREG] = 1;
|
||||||
|
nonumlab[EX_CMPEQ] = FALSE;
|
||||||
|
nonumlab[EX_CMPNE] = FALSE;
|
||||||
|
onlyconst[EX_CMPEQ] = FALSE;
|
||||||
|
onlyconst[EX_CMPNE] = FALSE;
|
||||||
|
onlyconst[EX_CMPLE] = FALSE;
|
||||||
|
onlyconst[EX_CMPLT] = FALSE;
|
||||||
|
onlyconst[EX_CMPGE] = FALSE;
|
||||||
|
onlyconst[EX_CMPGT] = FALSE;
|
||||||
|
onlyconst[EX_PLUS] = FALSE;
|
||||||
|
onlyconst[EX_MINUS] = FALSE;
|
||||||
|
printf("byte nparam[] = {");
|
||||||
|
for (i=0;i<N_EX_OPS;i++) printf("%d,",nparam[i]);
|
||||||
|
printf("};\nbool nonumlab[] = {");
|
||||||
|
for (i=0;i<N_EX_OPS;i++) printf("%d,",nonumlab[i]);
|
||||||
|
printf("};\nbool onlyconst[] = {");
|
||||||
|
for (i=0;i<N_EX_OPS;i++) printf("%d,",onlyconst[i]);
|
||||||
|
printf("};\n\nbyte pattern[] = { 0\n");
|
||||||
|
curind = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
outbyte(b) {
|
||||||
|
|
||||||
|
printf(",%3d",b);
|
||||||
|
curind++;
|
||||||
|
}
|
||||||
|
|
||||||
|
outshort(s) {
|
||||||
|
|
||||||
|
outbyte(s&0377);
|
||||||
|
outbyte((s>>8)&0377);
|
||||||
|
}
|
||||||
|
|
||||||
|
out(w) {
|
||||||
|
|
||||||
|
if (w<255) {
|
||||||
|
outbyte(w);
|
||||||
|
} else {
|
||||||
|
outbyte(255);
|
||||||
|
outshort(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "scan.c"
|
||||||
12
util/opt/optim.h
Normal file
12
util/opt/optim.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
/* #define DIAGOPT /* if defined diagnostics are produced */
|
||||||
|
#ifdef DIAGOPT
|
||||||
|
#define OPTIM(x) optim(x)
|
||||||
|
#define O_UNREACH 1001
|
||||||
|
#define O_BRALAB 1002
|
||||||
|
#define O_LINLNI 1003
|
||||||
|
#define O_LINGONE 1004
|
||||||
|
#else
|
||||||
|
#define OPTIM(x) /* NOTHING */
|
||||||
|
#endif
|
||||||
15
util/opt/param.h
Normal file
15
util/opt/param.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
#define LONGOFF /* if defined long offsets are used */
|
||||||
|
|
||||||
|
#define TRUE 1
|
||||||
|
#define FALSE 0
|
||||||
|
|
||||||
|
#define MAXROM 3
|
||||||
|
|
||||||
|
#define op_lab (sp_lmnem+1)
|
||||||
|
#define op_last op_lab
|
||||||
|
#define ps_sym (sp_lpseu+1)
|
||||||
|
#define ps_last ps_sym
|
||||||
|
|
||||||
|
#define BMASK 0377
|
||||||
126
util/opt/pattern.h
Normal file
126
util/opt/pattern.h
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pattern contains the optimization patterns in an apparently
|
||||||
|
* unordered fashion. All patterns follow each other unaligned.
|
||||||
|
* Each pattern looks as follows:
|
||||||
|
* Byte 0: high byte of hash value associated with this pattern.
|
||||||
|
* Byte 1-2: index of next pattern with same low byte of hash value.
|
||||||
|
* Byte 3- : pattern and replacement.
|
||||||
|
* First comes the pattern length
|
||||||
|
* then the pattern opcodes,
|
||||||
|
* then a boolean expression,
|
||||||
|
* then the one-byte replacement length
|
||||||
|
* then the intermixed pattern opcodes and operands or
|
||||||
|
* 0 followed by the one-byte special optimization expression.
|
||||||
|
* If the DIAGOPT option is set, the optimization is followed
|
||||||
|
* by the line number in the tables.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* #define ALLOWSPECIAL /* Special optimizations allowed */
|
||||||
|
|
||||||
|
#define PO_HASH 0
|
||||||
|
#define PO_NEXT 1
|
||||||
|
#define PO_MATCH 3
|
||||||
|
|
||||||
|
struct exprnode {
|
||||||
|
short ex_operator;
|
||||||
|
short ex_lnode;
|
||||||
|
short ex_rnode;
|
||||||
|
};
|
||||||
|
typedef struct exprnode expr_t;
|
||||||
|
typedef struct exprnode *expr_p;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* contents of .ex_operator
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define EX_CON 0
|
||||||
|
#define EX_ARG 1
|
||||||
|
#define EX_CMPEQ 2
|
||||||
|
#define EX_CMPNE 3
|
||||||
|
#define EX_CMPGT 4
|
||||||
|
#define EX_CMPGE 5
|
||||||
|
#define EX_CMPLT 6
|
||||||
|
#define EX_CMPLE 7
|
||||||
|
#define EX_OR2 8
|
||||||
|
#define EX_AND2 9
|
||||||
|
#define EX_OR1 10
|
||||||
|
#define EX_XOR1 11
|
||||||
|
#define EX_AND1 12
|
||||||
|
#define EX_PLUS 13
|
||||||
|
#define EX_MINUS 14
|
||||||
|
#define EX_TIMES 15
|
||||||
|
#define EX_DIVIDE 16
|
||||||
|
#define EX_MOD 17
|
||||||
|
#define EX_LSHIFT 18
|
||||||
|
#define EX_RSHIFT 19
|
||||||
|
#define EX_UMINUS 20
|
||||||
|
#define EX_NOT 21
|
||||||
|
#define EX_COMP 22
|
||||||
|
#define EX_ROM 23
|
||||||
|
#define EX_NOTREG 24
|
||||||
|
#define EX_POINTERSIZE 25
|
||||||
|
#define EX_WORDSIZE 26
|
||||||
|
#define EX_DEFINED 27
|
||||||
|
#define EX_SAMESIGN 28
|
||||||
|
#define EX_SFIT 29
|
||||||
|
#define EX_UFIT 30
|
||||||
|
#define EX_ROTATE 31
|
||||||
|
#define N_EX_OPS 32 /* must be one higher then previous */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definition of special opcodes used in patterns
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define op_pfirst op_LLP
|
||||||
|
#define op_LLP (op_last+1)
|
||||||
|
#define op_LEP (op_last+2)
|
||||||
|
#define op_SLP (op_last+3)
|
||||||
|
#define op_SEP (op_last+4)
|
||||||
|
#define op_plast op_SEP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definition of the structure in which instruction operands
|
||||||
|
* are kept during pattern matching.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct eval eval_t;
|
||||||
|
typedef struct eval *eval_p;
|
||||||
|
|
||||||
|
struct eval {
|
||||||
|
short e_typ;
|
||||||
|
union {
|
||||||
|
offset e_con;
|
||||||
|
num_p e_np;
|
||||||
|
} e_v;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* contents of .e_typ
|
||||||
|
*/
|
||||||
|
#define EV_UNDEF 0
|
||||||
|
#define EV_CONST 1
|
||||||
|
#define EV_NUMLAB 2
|
||||||
|
#define EV_FRAG 3 /* and all higher numbers */
|
||||||
|
|
||||||
|
typedef struct iarg iarg_t;
|
||||||
|
typedef struct iarg *iarg_p;
|
||||||
|
|
||||||
|
struct iarg {
|
||||||
|
eval_t ia_ev;
|
||||||
|
sym_p ia_sp;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The next extern declarations refer to data generated by mktab
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern byte pattern[];
|
||||||
|
extern short lastind;
|
||||||
|
extern iarg_t iargs[];
|
||||||
|
extern byte nparam[];
|
||||||
|
extern bool nonumlab[];
|
||||||
|
extern bool onlyconst[];
|
||||||
|
extern expr_t enodes[];
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user