fixup commit for branch 'unlabeled-2.2.1'

This commit is contained in:
cvs2hg
1984-07-16 15:29:49 +00:00
parent 4410480e32
commit b5c00dbbf4
231 changed files with 0 additions and 64000 deletions

View File

@@ -1,178 +0,0 @@
# $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

View File

@@ -1,72 +0,0 @@
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,".short\t%d\n",(int) l);
fprintf(codefile,".short\t%d\n",(int) (l >> 16));
}
con_float() {
fatal("no reals");
}
prolog(nlocals) full nlocals; {
fprintf(codefile,"\tjsr Pro\n");
if (nlocals == 0)
return;
else
fprintf(codefile,
"\tldx #[%d].h\n\tlda #[%d].l\n\tjsr Lcs\n",
nlocals, nlocals);
}
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,".define %s\n",argstr) ;
break ;
}
}
default :
while ( getarg(any_ptyp) != sp_cend ) ;
break ;
}
}
char *segname[] = {
".text", /* SEGTXT */
".data", /* SEGCON */
".data", /* SEGROM */
".bss" /* SEGBSS */
};

View File

@@ -1,24 +0,0 @@
#define ex_ap(y) fprintf(codefile,".extern %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 dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y)
#define newlbss(l,x) fprintf(codefile,"%s: .space\t%d\n",l,x);
#define cst_fmt "%d"
#define off_fmt "%d"
#define ilb_fmt "I%02x%x"
#define dlb_fmt "_%d"
#define hol_fmt "hol%d"
#define hol_off "%d+hol%d"
#define con_cst(x) fprintf(codefile,".word\t%d\n",x)
#define con_ilb(x) fprintf(codefile,".word\t%s\n",x)
#define con_dlb(x) fprintf(codefile,".word\t%s\n",x)
#define modhead ""
#define id_first '_'
#define BSS_INIT 0

File diff suppressed because it is too large Load Diff

View File

@@ -1,178 +0,0 @@
# $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

View File

@@ -1,171 +0,0 @@
#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 /* save all registers in markblock */
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 */
};

View File

@@ -1,24 +0,0 @@
/* $Header$ */
#define ex_ap(y) fprintf(codefile,".globl %s\n",y)
#define in_ap(y) /* nothing */
#define newplb(x) fprintf(codefile,"%s:\n",x)
#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

View File

@@ -1,130 +0,0 @@
#include <stdio.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 buf[512];
main() {
register n,sa;
register char *p;
sa=0;
for (;;) {
getline(buf);
if (n=stackadjust()) {
sa += n;
continue;
}
if (nullinstruction())
continue;
if (sa) {
if (buf[0]=='t' && buf[1]=='s' && buf[2]=='t' && buf[3]==' ') {
sa -= 2;
buf[0]='m';
buf[1]='o';
buf[2]='v';
strcat(buf,",(sp)+");
} else if (buf[0]=='m' && buf[1]=='o' && buf[2]=='v' &&
buf[3]==' ' && (p=index(&buf[5],','))!=0 &&
p[1]=='-' && p[2]=='(' && p[3]=='s') {
sa -= 2;
p[1]=' ';
}
}
switch(sa) {
case 0:break;
case 2:puts("tst (sp)+");sa=0;break;
case 4:puts("cmp (sp)+,(sp)+");sa=0;break;
case 6:puts("add $6.,sp");sa=0;break;
}
puts(buf);
}
}
getline(buf) register char *buf; {
register c;
while ((c=getchar())==' ' || c=='\t')
;
if (c==EOF)
exit(0);
do *buf++=c;
while ((c=getchar())!='\n');
*buf=0;
}
stackadjust() {
if (buf[0]=='t' &&
buf[1]=='s' &&
buf[2]=='t' &&
buf[3]==' ' &&
buf[4]=='(' &&
buf[5]=='s' &&
buf[6]=='p' &&
buf[7]==')' &&
buf[8]=='+') return(2);
if (buf[0]=='c' &&
buf[1]=='m' &&
buf[2]=='p' &&
buf[3]==' ' &&
buf[4]=='(' &&
buf[5]=='s' &&
buf[6]=='p' &&
buf[7]==')' &&
buf[8]=='+' &&
buf[9]==',' &&
buf[10]=='(' &&
buf[11]=='s' &&
buf[12]=='p' &&
buf[13]==')' &&
buf[14]=='+') return(4);
if (buf[0]=='a' &&
buf[1]=='d' &&
buf[2]=='d' &&
buf[3]==' ' &&
buf[4]=='$' &&
buf[5]=='6' &&
buf[6]=='.' &&
buf[7]==',' &&
buf[8]=='s' &&
buf[9]=='p' &&
buf[10]==0) return(6);
return(0);
}
nullinstruction() {
register char *p;
if (buf[4]=='$' && buf[5]=='0' && buf[6]=='.' && buf[7]==',') {
p=index(buf,'-');
if (p!=0 && p[1]=='(')
return(0);
p=index(buf,'+');
if (p!=0 && p[-1]==')')
return(0);
if (buf[0]=='b' && buf[1]=='i' && (buf[2]=='s' || buf[2]=='c'))
return(1);
if (buf[0]=='a' && buf[1]=='d' && buf[2]=='d')
return(1);
if (buf[0]=='s' && buf[1]=='u' && buf[2]=='b')
return(1);
}
return(0);
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,178 +0,0 @@
# $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

View File

@@ -1,7 +0,0 @@
/* $Header$ */
#ifndef NDEBUG
#define assert(x) if(!(x)) badassertion("x",__FILE__,__LINE__)
#else
#define assert(x) /* nothing */
#endif

View File

@@ -1,672 +0,0 @@
#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);
}
}
}

View File

@@ -1,364 +0,0 @@
#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);
}
}

View File

@@ -1,54 +0,0 @@
/* $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;

View File

@@ -1,105 +0,0 @@
#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);
}
}
}

View File

@@ -1,8 +0,0 @@
/* $Header$ */
#define MAXCREG 4
struct perm {
struct perm *p_next;
int p_rar[MAXCREG];
};

View File

@@ -1,49 +0,0 @@
/* $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

View File

@@ -1,648 +0,0 @@
#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
*/
#ifndef newplb /* retrofit for older mach.h */
#define newplb newilb
#endif
/* 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)));
newplb(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"

View File

@@ -1,194 +0,0 @@
#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;
}
}
}
}

View File

@@ -1,52 +0,0 @@
#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);
}

View File

@@ -1,9 +0,0 @@
/* $Header$ */
typedef struct glosym {
struct glosym *gl_next;
string gl_name;
word gl_rom[MAXROM+1];
} glosym_t,*glosym_p;
glosym_p lookglo();

View File

@@ -1,84 +0,0 @@
#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);
}

View File

@@ -1,110 +0,0 @@
#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);
}

View File

@@ -1,131 +0,0 @@
#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);
}

View File

@@ -1,19 +0,0 @@
/* $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

View File

@@ -1,175 +0,0 @@
#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

View File

@@ -1,151 +0,0 @@
#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= &regassigned[rvtyp][i];
ra->ra_rv = 0;
ra->ra_score = 0;
}
}
}
#endif REGVARS
/* nothing after this */

View File

@@ -1,19 +0,0 @@
/* $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[];

View File

@@ -1,19 +0,0 @@
/* $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();

View File

@@ -1,150 +0,0 @@
#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;
}
}

View File

@@ -1,104 +0,0 @@
#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);
}

View File

@@ -1,24 +0,0 @@
/* $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

View File

@@ -1,547 +0,0 @@
#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);
}

View File

@@ -1,33 +0,0 @@
/* $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

View File

@@ -1,41 +0,0 @@
#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;

View File

@@ -1,178 +0,0 @@
# $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

View File

@@ -1,178 +0,0 @@
# $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

View File

@@ -1,4 +0,0 @@
CFLAGS=-O
dl: dl.o
cc -n -o dl dl.o

View File

@@ -1,23 +0,0 @@
The interpreter contained here is tested under CP/M on a RC702 Z80
microcomputer. Make it by typing `doas'.
E.out files to interpret must be made with a special Pascal library
using whatever means available, because the UNIX and CP/M conventions
about end of file and end of line differ.
Then the following sequence can be used to transmit it to CP/M.
cv <e.out >file.cv
dl file.cv file.hex
< Transmission to file.hex under CP/M using pip >
LOAD FILE
The resulting file.com can be used as an argument to the interpreter.
This implementation has been tested but is not guaranteed to be complete.
Simple UNIX-system calls have been implemented but anything except
terminal I/O has not been thoroughly tested.
Please send any errors in the implementation to
Hans van Staveren
Vrije Universiteit
Wiskundig Seminarium
De Boelelaan 1081
1081 HV Amsterdam
Holland
..!decvax!mcvax!vu44!sater

View File

@@ -1,280 +0,0 @@
.data
! Set of variables
big: .byte 0
.byte 0
.byte 0x40
.byte 24 ! 2^23
negfrac:.space 1
negexp: .space 1
begzero:
nd: .space 2
fl: .space 6
exp=fl+4
eexp: .space 2
flexp: .space 4
exp5: .space 4
endzero:
ten: .byte 0
.byte 0
.byte 0x50
.byte 4 ! 10
dig: .byte 0
.byte 0
fildig: .byte 0 ! here a number from 0 to 31 will be converted flt.
.byte 7
bexp: .space 2
.text
atof: ! entry with stringpointer in hl
! exit with pointer to float in hl
push ix
push iy
push bc
push de
push af
ld b,1
1:
ld a,(hl)
inc hl
cp ' '
jr z,1b
cp '-'
jr nz,1f
ld b,-1
jr 2f
1: cp '+'
jr z,2f
dec hl
2: ld a,b
ld (negfrac),a
xor a
ld de,begzero
ld b,endzero-begzero
1: ld (de),a
inc de
djnz 1b
1: ld a,(hl)
inc hl
sub '0'
jr c,1f
cp 10
jr nc,1f
ld (fildig),a
call cmpbigfl
jr z,2f
call mulandadd
jr 3f
2: ld de,(exp)
inc de
ld (exp),de
3: ld de,(nd)
inc de
ld (nd),de
jr 1b
1: cp '.'-'0'
jr nz,4f
1: ld a,(hl)
inc hl
sub '0'
jr c,4f
cp 10
jr nc,4f
ld (fildig),a
call cmpbigfl
jr z,2f
call mulandadd
ld de,(exp)
dec de
ld (exp),de
2: ld de,(nd)
inc de
ld (nd),de
jr 1b
4:
ld b,1
cp 'E'-'0'
jr z,1f
cp 'e'-'0'
jr nz,5f
1: ld a,(hl)
inc hl
cp '+'
jr z,1f
cp '-'
jr nz,2f
ld b,-1
jr 1f
2: dec hl
1: ld a,b
ld (negexp),a
exx
xor a
ld h,a
ld l,a
ld b,a
ld d,a
ld e,a
exx
1: ld a,(hl)
inc hl
sub '0'
jr c,1f
cp 10
jr nc,1f
exx
ld c,a
add hl,hl
add hl,hl
add hl,de
add hl,hl
add hl,bc
ld d,h
ld e,l
exx
jr 1b
1: exx
ld hl,negexp
or a
bit 7,(hl)
ld hl,(exp)
jr z,1f
sbc hl,de
jr 2f
1: add hl,de
2: ld (exp),hl
exx
5: ld a,1
ld de,(exp)
push de
bit 7,d
jr z,1f
neg
ld hl,0
or a
sbc hl,de
ex de,hl
1: ld (negexp),a
ld (exp),de
pop de
ld hl,(nd)
add hl,de
ld de,-33 ! -LOGHUGE ?
xor a
sbc hl,de
jp p,1f
ld hl,fl
ld b,6
2: ld (hl),a
inc hl
djnz 2b
1: ld hl,0x0140 ! 1.0
ld (flexp+2),hl
ld hl,0x0350 ! 5.0
ld (exp5+2),hl
ld hl,(exp)
ld (bexp),hl
1: bit 0,l
jr z,2f
call xflt
.word flexp,exp5,fpmult,4,flexp
2: sra h
rr l
ld a,h
or l
jr z,3f
call xflt
.word exp5,exp5,fpmult,4,exp5
jr 1b
3: ld hl,negexp
ld a,(bexp)
bit 7,(hl)
jr z,1f
call xflt
.word flexp,fl,fpdiv,4,fl
neg
jr 2f
1: call xflt
.word flexp,fl,fpmult,4,fl
2: ld b,a
ld a,(fl+3)
add a,b
ld (fl+3),a
ld a,(negfrac)
bit 7,a
jr z,1f
call xflt
.word fl,fl,fpcomp,4,fl
1: call xflt
.word fl,fl,fpnorm,4,fl
ld hl,fl
pop af
pop de
pop bc
pop iy
pop ix
ret
cmpbigfl:
call xflt
.word big,fl,fpcmf,0
ld a,(fpac+1)
bit 7,a
ret
mulandadd:
call xflt
.word fl,ten,fpmult,4,fl
ld a,7
ld (fildig+1),a
call xflt
.word dig,dig,fpnorm,4,dig
call xflt
.word fl,dig,fpadd,4,fl
ret
xflt:
ex (sp),iy
push af
push bc
push de
push hl
ld h,(iy+1)
ld l,(iy+0)
ld de,fpac
ld bc,4
ldir
ld h,(iy+3)
ld l,(iy+2)
ld de,fpop
ld bc,4
ldir
push iy
ld hl,1f
push hl
ld h,(iy+5)
ld l,(iy+4)
jp (hl)
1: pop iy
ld b,(iy+7)
ld c,(iy+6)
ld a,b
or c
jr z,1f
inc iy
inc iy
ld hl,fpac
ld d,(iy+7)
ld e,(iy+6)
ldir
1: push iy
pop hl
ld de,8
add hl,de
push hl
pop iy
pop hl
pop de
pop bc
pop af
ex (sp),iy
ret

View File

@@ -1,34 +0,0 @@
/*
* (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>
unsigned memaddr = 0x100;
main() {
char buf[256];
register i,len;
while((len=read(0,buf,sizeof(buf))) > 0) {
putw(memaddr,stdout);
putw(0,stdout);
putw(len,stdout);
memaddr += len;
for(i=0;i<len;i++)
putc(buf[i],stdout);
}
}

View File

@@ -1,200 +0,0 @@
/*
* (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 <sgtty.h>
#include <stdio.h>
#include <assert.h>
struct sgttyb tty;
#define DATTYPE 0
#define EOFTYPE 1
#define SEGTYPE 2
#define PCTYPE 3
#define MAXBYTE 32
int check;
int echo;
int istty;
int bytecount;
int ttyfd;
char *progname;
char hex[] = "0123456789ABCDEF";
main(argc,argv) char **argv; {
register nd,pc,sg,osg,first;
register char *s;
int uid;
progname = argv[0];
if (argc > 3)
fatal("usage: %s [object [tty]]\n",argv[0]);
s = "a.out";
if (argc >= 2)
s = argv[1];
if (freopen(s,"r",stdin) == NULL)
fatal("can't open %s",s);
s = "/dev/tty05";
if (argc >= 3)
s = argv[2];
if ((ttyfd = open(s,2)) < 0)
if ((ttyfd = creat(s,0666)) < 0)
fatal("can't open %s",s);
if (gtty(ttyfd,&tty) == 0) {
echo++;
istty++;
tty.sg_ispeed = tty.sg_ospeed = B2400;
tty.sg_flags = RAW;
stty(ttyfd,&tty);
} else {
freopen(s,"w",stdout);
}
first = 1; osg = 0;
uid = getuid();
lock(1);
for (;;) {
pc = get2c(stdin);
if (feof(stdin))
break;
sg = get2c(stdin);
nd = get2c(stdin);
if (first) {
put('L'); reply();
put('S'); reply();
first = 0;
}
if (sg != osg) {
segment(sg);
osg = sg;
}
while (nd > MAXBYTE) {
data(MAXBYTE,pc);
nd -= MAXBYTE;
pc += MAXBYTE;
}
if (nd > 0)
data(nd,pc);
assert(feof(stdin) == 0);
}
if (first == 0)
eof();
/* lock(0); */
/* setuid(uid); */
/* if (echo) */
/* for (;;) */
/* reply(); */
}
segment(sg) {
newline(2,0,SEGTYPE);
word(sg);
endline();
}
startad(pc) {
newline(4,0,PCTYPE);
word(0);
word(pc);
endline();
}
data(nd,pc) {
newline(nd,pc,DATTYPE);
do
byte(getc(stdin));
while (--nd);
endline();
}
eof() {
newline(0,0,EOFTYPE);
byte(0xFF);
put('\n');
}
newline(n,pc,typ) {
check = 0;
bytecount = n+5;
put('\n'); /* added instruction */
put(':');
byte(n);
word(pc);
byte(typ);
}
endline() {
byte(-check);
assert(bytecount == 0);
assert(check == 0);
}
word(w) {
byte(w>>8);
byte(w);
}
byte(b) {
check += b;
--bytecount;
put(hex[(b>>4) & 017]);
put(hex[b & 017]);
}
put(c) {
if (istty)
write(ttyfd,&c,1);
else
putchar(c);
}
reply() {
register i;
int c;
if (echo == 0)
return;
i = read(ttyfd,&c,1);
assert(i > 0);
write(1,&c,1);
}
get2c(f) FILE *f; {
register c;
c = getc(f);
return((getc(f) << 8) | c);
}
fatal(s,a) {
fprintf(stderr,"%s: ",progname);
fprintf(stderr,s,a);
fprintf(stderr,"\n");
exit(-1);
}

View File

@@ -1,3 +0,0 @@
/usr/em/mach/z80/as/as -d em.s atof.s fpp.s mli4.s dvu4.s dvi4.s eb.s >em.list
dl a.out int.hex
dosort int.hex

View File

@@ -1,9 +0,0 @@
case $# in
1) ;;
*) echo "usage $0 file";exit ;;
esac
head -1 $1>$$.head
tail -1 $1>$$.tail
tail +2 $1|sort +0.3|tail +2>$$.middle
cat $$.head $$.middle $$.tail >$1
rm $$.head $$.middle $$.tail

View File

@@ -1,74 +0,0 @@
.dvi4:
pop hl
ld (retaddr),hl
xor a
ld (.flag1),a
ld (.flag2),a
ld ix,0
add ix,sp
ld b,(ix+7) ! dividend
bit 7,b
jr z,1f
ld c,(ix+6)
ld d,(ix+5)
ld e,(ix+4)
call .negbd
ld (ix+7),b
ld (ix+6),c
ld (ix+5),d
ld (ix+4),e
ld a,1
ld (.flag1),a
1:
ld b,(ix+3)
bit 7,b
jr z,2f
call .negst
ld a,1
ld (.flag2),a
2:
call .dvu4
ld a,(.flag1)
or a
jr z,3f
call .negbd
3:
ld (.savebc),bc
ld (.savede),de
ld a,(.flag2)
ld b,a
ld a,(.flag1)
xor b
jr z,4f
call .negst
4:
ld bc,(.savebc)
ld de,(.savede)
ld hl,(retaddr)
jp (hl)
.negbd:
xor a
ld h,a
ld l,a
sbc hl,de
ex de,hl
ld h,a
ld l,a
sbc hl,bc
ld b,h
ld c,l
ret
.negst:
pop iy
pop de
pop bc
call .negbd
push bc
push de
jp (iy)
.data
.flag1: .byte 0
.flag2: .byte 0
retaddr:.word 0
.savebc: .word 0
.savede: .word 0

View File

@@ -1,137 +0,0 @@
.define .dvu4
! 4-byte divide routine for z80
! parameters:
! stack: divisor
! dividend
! stack: quotient (out)
! bc de: remainder (out) (high part in bc)
! a n-byte divide may be implemented
! using 2 (virtual) registers:
! - a n-byte register containing
! the divisor
! - a 2n-byte shiftregister (VSR)
!
! Initially, the VSR contains the dividend
! in its low (right) n bytes and zeroes in its
! high n bytes. The dividend is shifted
! left into a "window" bit by bit. After
! each shift, the contents of the window
! is compared with the divisor. If it is
! higher or equal, the divisor is subtracted from
! it and a "1" bit is inserted in the
! VSR from the right side; else a "0" bit
! is inserted. These bits are shifted left
! too during subsequent iterations.
! At the end, the rightmost part of VSR
! contains the quotient.
! For n=4, we need 2*4+4 = 12 bytes of
! registers. Unfortunately we only have
! 5 2-byte registers on the z80
! (bc,de,hl,ix and iy). Therefore we use
! an overlay technique for the rightmost
! 4 bytes of the VSR. The 32 iterations
! are split up into two groups: during
! the first 16 iterations we use the high
! order 16 bits of the dividend; during
! the last 16 iterations we use the
! low order 16 bits.
! register allocation:
! VSR iy hl ix
! divisor -de bc
.dvu4:
! initialization
pop hl ! save return address
ld (.retaddr),hl
pop bc ! low part (2 bytes)
! of divisor in bc
xor a ! clear carry, a := 0
ld h,a ! hl := 0
ld l,a
ld (.flag),a ! first pass main loop
pop de ! high part divisor
sbc hl,de ! inverse of high part
ex de,hl ! of divisor in de
pop hl ! save low part of
! dividend in memory
ld (.low),hl ! used during second
! iteration over main loop
pop ix ! high part of dividend
push iy ! save LB
ld h,a ! hl := 0
ld l,a
ld iy,0 ! now the VSR is initialized
! main loop, done twice
1:
ld a,16
! sub-loop, done 16 times
2:
add iy,iy ! shift VSR left
add ix,ix
adc hl,hl
jp nc,3f
inc iy
3:
or a ! subtract divisor from
! window (iy hl)
ld (.iysave),iy
sbc hl,bc
jr nc,4f ! decrement iy if there
! was no borrow
dec iy
4:
add iy,de ! there is no "sbc iy,ss"
! on the z80, so de was
! inverted during init.
inc ix
! see if the result is non-negative,
! otherwise undo the subtract.
! note that this uncooperating machine
! does not set its S -or Z flag after
! a 16-bit add.
ex (sp),iy ! does anyone see a better
ex (sp),hl ! solution ???
bit 7,h
ex (sp),hl
ex (sp),iy
jp z,5f
! undo the subtract
add hl,bc
ld iy,(.iysave)
dec ix
5:
dec a
jr nz,2b
ld a,(.flag) ! see if this was first or
! second iteration of main loop
or a ! 0=first, 1=second
jr nz,6f
inc a ! a := 1
ld (.flag),a ! flag := 1
ld (.result),ix ! save high part of result
ld ix,(.low) ! initialize second
! iteration, ix := low
! part of dividend
jr 1b
6:
! clean up
push iy ! transfer remainder
pop bc ! from iy-hl to bc-de
ex de,hl
pop iy ! restore LB
ld hl,(.result) ! high part of result
push hl
push ix ! low part of result
ld hl,(.retaddr)
jp (hl) ! return
.data
.flag: .byte 0
.low: .word 0
.iysave: .word 0
.retaddr: .word 0
.result: .word 0

View File

@@ -1,2 +0,0 @@
.bss
eb:

File diff suppressed because it is too large Load Diff

View File

@@ -1,474 +0,0 @@
! floating point pakket voor Z80
! geimplementeerd zoals beschreven in
! Electronica top internationaal.
! September 1979
! Auteur: Hr. R. Beverdam, Zuidbroekweg 9,7642 NW Wierden
xa: .space 1
fpac:
fal: .space 1
fan: .space 1
fam: .space 1
fax: .space 1
xo: .space 1
fpop:
fol: .space 1
fon: .space 1
fom: .space 1
fox: .space 1
.errnz xa/256-fox/256
fpsub:
call fpcomp ! inverteer fpacc
fpadd:
ld de,(fam) ! d fax,e fam
ld bc,(fom) ! b fox,c fom
ld a,e ! test fpacc
or a ! 0?
jr z,movop ! ja: som=fpop dus verplaats
xor a
add a,c
ret z ! som is dus fpacc, klaar
ld a,b
sub d ! a:=fox-fax
ld l,a ! bewaar verschil exponenten
jp p,skpneg ! maak positief
neg
skpneg:
cp 0x18 ! verschil meer dan 23?
ld a,l
jp m,lineup ! spring indien binnen bereik
and a ! getallen te groot tov elkaar
ret m ! klaar als fpacc het grootst
movop:
ld hl,fol ! verplaats fpop naar fpacc
ld de,fal ! want fpop is het antwoord
ld bc,4
ldir
ret
lineup:
and a ! kijk welke groter is
jp m,shifto ! spring als fpop>fpac
inc a ! bereken sa
ld b,a ! save sa in b register
ld a,1 ! so 1
push af ! bewaar so op stapel
jr shacop ! gr schuiven
shifto:
neg ! bereken fox-fax
eqexp:
inc a ! so 1+(fox-fax)
push af ! bewaar so op stapel
ld b,1 ! sa 1
shacop:
ld hl,(fal) ! l fal,h fan
xor a ! xa 0
moracc:
sra e ! schuif fam
rr h ! fan
rr l ! fal
rra ! xa
inc d ! update voor fax
djnz moracc ! herhaal sa keer
ld (xa),a ! berg alles
ld (fal),hl ! weg in
ld (fam),de ! fpacc en xa
pop af ! haal so terug van stapel
ld b,a ! en zet in b register
xor a ! xo 0
ld hl,(fol) ! l fol,h fon
morop:
sra c ! schuif: fom
rr h ! fon
rr l !
rra ! xo
djnz morop ! herhaal so keer
ld (xo),a
ld (fol),hl
ld (fom),bc ! berg alles weg in fpop en xo
ld de,xa
ld hl,xo
ld b,4
or a ! reset carry
addmor:
ld a,(de) ! haal een byte
adc a,(hl) ! tel er een bij op
ld (de),a ! en berg de som weer op
inc e
inc l
djnz addmor ! herhaal dit 4 keer
jr fpnorm
fpmult:
call setsgn
add a,(hl) ! bereken exponent produkt
ld (hl),a ! fax exponent produkt
ld l,fom%256
ex de,hl ! gebruik de als wijzer
xor a
ld h,a
ld l,a ! hoogste 16 bits van pp worden nul
exx
ld bc,(fal)
ld de,(fam) ! haal mc in registers
ld d,a ! d:=0 tbv 16-bit add
ld h,a
ld l,a ! middelste 16 bits van pp worden nul
ld ix,0 ! laagste 16 bits ook
exx
ld c,3
mult:
ld a,(de) ! haal een byte van mr
dec e
ld b,8 ! bits in a byte
shift:
rla ! schuif vooste bit in carry
exx
jr nc,noadd ! vooste bit is 0, dan niet optellen
add ix,bc ! pp:=pp+mc
adc hl,de ! continued
noadd:
add ix,ix
adc hl,hl
exx
adc hl,hl ! dit schoof het hele partiele produkt <
djnz shift ! herhaal voor alle 8 bits
dec c
jr nz,mult ! herhaal voor 3 bytes
exx
rl l
rla
add a,h
ld (fal),a
ld a,d
exx
adc a,l
ld (fan),a ! rond getal in pp af en berg resultaat op
ld a,c
adc a,h
ld (fam),a
call fpnorm
exmldv:
ld hl,xa
ld c,(hl)
jp resign ! fix sign
fpdiv:
call setsgn
sub (hl)
ld (hl),a ! berg exponent quotient op
ld hl,(fol)
push hl
pop ix
ld de,(fal)
ld a,(fam)
or a ! fpacc = 0 ?
jr z,fperr ! fout, deling door nul
ld b,a ! b:=fam
ld a,(fom)
ld c,a
exx
ld hl,fam
ld e,3
divide:
ld b,8
mordiv:
exx
and a
sbc hl,de
sbc a,b ! probeer de aftrekking
jp m,nogo ! gaat niet
push hl
pop ix
ld c,a
ex af,af2 ! quotient in tweede accumulator
scf
jr quorot
nogo:
ex af,af2
or a
quorot:
rla ! volgende bit in quotient
ex af,af2
add ix,ix ! schuif eventueel vernieuwde
rl c ! dd naar links
push ix
pop hl
ld a,c ! zet nieuwe dd in rekenregisters
exx
djnz mordiv ! herhaal 8 keer
ex af,af2
ld (hl),a ! zet een byte van het quotient in het geheugen
dec l
ex af,af2
dec e
jr nz,divide ! herhaal 3 keer
ld bc,(fal)
ld hl,(fam) ! haal quotient terug in cpu
bit 7,l
jp z,exmldv ! als niet te groot tekenherstellen
ld a,1 ! wel te groot
add a,c ! eerst getal afronden
ld c,a
ld a,e
adc a,b
ld b,a
ld a,e
adc a,l
ld l,a
shft:
inc h ! nu getal naar rechts schuiven
rr l
rr b
rr c
or a
bit 7,l
jr nz,shft ! door afronding weer te groot
ld (fal),bc
ld (fam),hl
jr exmldv ! inspecteer teken
setsgn:
ld a,(fom) ! ******** setsgn ************
ld c,1 ! teken -1
rlca ! fpop 0 ?
jr nc,tstacc ! nee
rrc c ! ja, dus teken:=teken*(-1)
ld hl,fol ! en inverteer fpop
call complm
tstacc:
ld a,(fam)
rlca ! fpacc 0?
jr nc,init ! nee
rrc c ! ja dus teken:=teken*(-1)
call fpcomp
init:
ld hl,xa ! initialiseer nog een paar registers
ld (hl),c
ld a,(fox)
ld l,fax%256
ret
fpcif:
ld de,(fpac) ! integer to convert
xor a
sra d
rr e
rr a
ld (fan),de
ld (fal),a
ld a,16
ld (fax),a
jr fpnorm
fpcfi:
ld a,(fax)
dec a
jp m,fpzero ! really integer zero here
sub 15
jp p,fperr ! overflow
ld de,(fan)
inc a
neg
jr z,2f
ld b,a
ld a,(fal)
1:
sra d
rr e
rr a
djnz 1b
2:
bit 7,d
jr z,0f
inc de
0:
ld (fpac),de
ret
fpcdf:
ld de,(fpac)
ld bc,(fpac+2)
ld h,31
3:
ld a,b
and 0300
jr z,1f
cp 0300
jr z,1f
or a
jp p,2f
sra b
rr c
rr d
inc h
2:
ld a,h
ld (fax),a
ld (fan),bc
ld a,d
ld (fal),a
ret
1:
sla e
rl d
rl c
rl b
dec h
jr 3b
fpcfd:
ld a,(fax)
dec a
jp m,fpzero
cp 32
jp p,fperr
sub 31
cpl
ld bc,(fan)
ld de,(fal)
ld d,e
ld e,0
1:
dec a
jp m,2f
sra b
rr c
rr d
rr e
jr 1b
2:
bit 7,b
jr z,3f
sla e
rl d
rl c
rl b
3:
ld (fpac+2),bc
ld (fpac),de
ret
fpfef:
ld a,(fox)
ld (fpac),a
9:
bit 7,a
jr z,1f
ld a,0xFF
jr 2f
1:
xor a
2:
ld (fpac+1),a
xor a
ld (fox),a
ret
fpcmf:
call fpsub
ld a,(fam)
ld (fpac),a
jr 9b
fpfif:
call fpmult
ld a,(fax)
dec a
jp m,intzero
inc a
ld b,a
xor a
ld c,0200
ld d,a
ld e,a
1:
sra c
rr d
rr e
djnz 1b
ld hl,fam
ld b,(hl)
ld a,c
and b
ld (fom),a
ld a,c
xor 0177
and b
ld (hl),a
dec l
ld b,(hl)
ld a,d
and b
ld (fon),a
ld a,d
cpl
and b
ld (hl),a
dec l
ld b,(hl)
ld a,e
and b
ld (fol),a
ld a,e
cpl
and b
ld (hl),a
ld a,(fax)
ld (fox),a
jr fpnorm
intzero:
xor a
ld hl,fol
ld b,4
1: ld (hl),a
inc hl
djnz 1b
ret
fpzero:
xor a
ld h,a
ld l,a
ld (fal),hl
ld (fam),hl
ret
fpnorm:
ld a,(fam)
ld c,a
or a ! fpacc < 0 ?
call m,fpcomp ! ja -- inverteer
ld hl,(fal)
ld de,(fam)
ld a,l
or h
or e
jr z,fpzero ! als hele facc 0 is
ld a,e
mortst:
bit 6,a ! test meest significante bit
jr nz,catch ! stop als bit is 1
add hl,hl ! schuif links zolang bit = 0
adc a,a
dec d ! pas fax ook aan
jr mortst
catch:
ld e,a ! herstel nu fpacc in geheugen
ld (fal),hl
ld (fam),de
resign:
bit 7,c ! test op teken
ret z ! positief, geen actie
fpcomp:
ld hl,fal
complm:
ld b,3 ! inverteer alleen mantisse
xor a
morcom:
sbc a,(hl)
ld (hl),a
inc hl
ld a,0
djnz morcom
or a
ret
fperr:
scf
ret

View File

@@ -1,75 +0,0 @@
.define .mli4
! 32-bit multiply routine for z80
! parameters:
! on stack
! register utilization:
! ix: least significant 2 bytes of result
! hl: most significant 2 bytes of result
! bc: least significant 2 bytes of multiplicand
! de: most significant 2 bytes of multiplicand
! iy: 2 bytes of multiplier (first most significant,
! later least significant)
! a: bit count
.mli4:
!initialization
pop hl ! return address
pop de
ld (.mplier+2),de! least significant bytes of
! multiplier
pop de
ld (.mplier),de ! most sign. bytes
pop de ! least significant bytes of
! multiplicand
pop bc ! most sign. bytes
push hl ! return address
push iy ! LB
ld ix,0
xor a
ld h,a ! clear result
ld l,a
ld (.flag),a ! indicate that this is
! first pass of main loop
ld iy,(.mplier)
! main loop, done twice, once for each part (2 bytes)
! of multiplier
1:
ld a,16
! sub-loop, done 16 times
2:
add iy,iy ! shift left multiplier
jr nc,3f ! skip if most sign. bit is 0
add ix,de ! 32-bit add
adc hl,bc
3:
dec a
jr z,4f ! done with this part of multiplier
add ix,ix ! 32-bit shift left
adc hl,hl
jr 2b
4:
! see if we have just processed the first part
! of the multiplier (flag = 0) or the second
! part (flag = 1)
ld a,(.flag)
or a
jr nz,5f
inc a ! a := 1
ld (.flag),a ! set flag
ld iy,(.mplier+2)! least significant 2 bytes now in iy
add ix,ix ! 32-bit shift left
adc hl,hl
jr 1b
5:
! clean up
pop iy ! restore LB
ex (sp),hl ! put most sign. 2 bytes of result
! on stack; put return address in hl
push ix ! least sign. 2 bytes of result
jp (hl) ! return
.data
.flag: .byte 0
.mplier: .space 4

View File

@@ -1,178 +0,0 @@
# $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

View File

@@ -1,107 +0,0 @@
/*
* (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
*
*/
/*
* machine dependent back end routines for the z8000
*/
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 == 0)
w <<= 8;
part_word |= w;
} else {
assert(sz == 2);
part_word = w;
}
part_size += sz;
}
con_mult(sz) word sz; {
if (sz != 4)
fatal("bad icon/ucon size");
fprintf(codefile,"\t.long %s\n", str);
}
con_float() {
static int been_here;
if (argval != 4 && argval != 8)
fatal("bad fcon size");
fprintf(codefile,"\t.long ");
if (argval == 8)
fprintf(codefile,"F_DUM, ");
fprintf(codefile,"F_DUM\n");
if ( !been_here++)
{
fprintf(stderr,"Warning : dummy float-constant(s)\n");
}
}
/*
string holstr(n) word n; {
sprintf(str,hol_off,n,holno);
return(mystrcpy(str));
}
*/
prolog(nlocals) full nlocals; {
fprintf(codefile,"\tpush\t*RR14, R13\n\tld\tR13, R15\n");
if (nlocals == 0)
return;
else
fprintf(codefile,"\tsub\tR15, $%d\n",nlocals);
}
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) ;
printf(".define %s\n",argstr) ;
break ;
}
}
default :
while ( getarg(any_ptyp) != sp_cend ) ;
break ;
}
}
char *segname[] = {
".text", /* SEGTXT */
".data", /* SEGCON */
".data", /* SEGROM */
".bss" /* SEGBSS */
};

View File

@@ -1,24 +0,0 @@
#define ex_ap(y) fprintf(codefile,".extern %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 dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y)
#define newlbss(l,x) fprintf(codefile,"%s:\t.space %d\n",l,x);
#define cst_fmt "%d"
#define off_fmt "%d"
#define ilb_fmt "I%03x%x"
#define dlb_fmt "_%d"
#define hol_fmt "hol%d"
#define hol_off "%d+hol%d"
#define con_cst(x) fprintf(codefile,"\t.word %d\n",x)
#define con_ilb(x) fprintf(codefile,"\t.word %s\n",x)
#define con_dlb(x) fprintf(codefile,"\t.word %s\n",x)
#define modhead ""
#define id_first '_'
#define BSS_INIT 0

File diff suppressed because it is too large Load Diff