minor fix; generate code for ACK assembler
This commit is contained in:
parent
731edd0940
commit
235871bf4b
3 changed files with 126 additions and 33 deletions
|
@ -3,19 +3,8 @@ static char rcsid[] = "$Header$";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
*
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
* 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
|
* Author: Hans van Staveren
|
||||||
*/
|
*/
|
||||||
|
@ -24,11 +13,13 @@ static char rcsid[] = "$Header$";
|
||||||
* machine dependent back end routines for the PDP-11
|
* machine dependent back end routines for the PDP-11
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* #define REGPATCH /* save all registers in markblock */
|
||||||
|
|
||||||
con_part(sz,w) register sz; word w; {
|
con_part(sz,w) register sz; word w; {
|
||||||
|
|
||||||
while (part_size % sz)
|
while (part_size % sz)
|
||||||
part_size++;
|
part_size++;
|
||||||
if (part_size == 2)
|
if (part_size == TEM_WSIZE)
|
||||||
part_flush();
|
part_flush();
|
||||||
if (sz == 1) {
|
if (sz == 1) {
|
||||||
w &= 0xFF;
|
w &= 0xFF;
|
||||||
|
@ -43,24 +34,67 @@ con_part(sz,w) register sz; word w; {
|
||||||
}
|
}
|
||||||
|
|
||||||
con_mult(sz) word sz; {
|
con_mult(sz) word sz; {
|
||||||
long l;
|
long l, atol();
|
||||||
|
|
||||||
if (sz != 4)
|
if (sz != 4)
|
||||||
fatal("bad icon/ucon size");
|
fatal("bad icon/ucon size");
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
fprintf(codefile,".data4 %s\n",str);
|
||||||
|
#else
|
||||||
l = atol(str);
|
l = atol(str);
|
||||||
fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
|
fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
con_float() {
|
|
||||||
double f;
|
|
||||||
register short *p,i;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This code is correct only when the code generator is
|
* The next function is difficult to do when not running on a PDP 11 or VAX
|
||||||
* run on a PDP-11 or VAX-11 since it assumes native
|
* The strategy followed is to assume the code generator is running on a PDP 11
|
||||||
* floating point format is PDP-11 format.
|
* unless the ACK_ASS define is on.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
con_float() {
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
double f, f1;
|
||||||
|
double atof(), frexp(), modf();
|
||||||
|
int i, j;
|
||||||
|
int sign = 0;
|
||||||
|
int fraction ;
|
||||||
|
|
||||||
|
if (argval != 4 && argval != 8)
|
||||||
|
fatal("bad fcon size");
|
||||||
|
f = atof(str);
|
||||||
|
f = frexp(f, &i);
|
||||||
|
if (f < 0) {
|
||||||
|
f = -f;
|
||||||
|
sign = 1;
|
||||||
|
}
|
||||||
|
while (f < 0.5) {
|
||||||
|
f += f;
|
||||||
|
i --;
|
||||||
|
}
|
||||||
|
f = modf(2 * f, &f1); /* hidden bit */
|
||||||
|
i = (i + 128) & 0377;
|
||||||
|
fraction = (sign << 15) | (i << 7);
|
||||||
|
for (j = 6; j>= 0; j--) {
|
||||||
|
if (f >= 0.5) fraction |= (1 << j);
|
||||||
|
f = modf(2*f, &f1);
|
||||||
|
}
|
||||||
|
fprintf(codefile, ".data2 0%o", fraction);
|
||||||
|
for (i = argval / 2 - 1; i; i--) {
|
||||||
|
fraction = 0;
|
||||||
|
for (j = 15; j>= 0; j--) {
|
||||||
|
if (f >= 0.5) fraction |= (1 << j);
|
||||||
|
f = modf(2*f, &f1);
|
||||||
|
}
|
||||||
|
fprintf(codefile, ", 0%o", fraction);
|
||||||
|
}
|
||||||
|
putc('\n', codefile);
|
||||||
|
#else
|
||||||
|
double f;
|
||||||
|
double atof();
|
||||||
|
int i;
|
||||||
|
short *p;
|
||||||
|
|
||||||
if (argval != 4 && argval != 8)
|
if (argval != 4 && argval != 8)
|
||||||
fatal("bad fcon size");
|
fatal("bad fcon size");
|
||||||
f = atof(str);
|
f = atof(str);
|
||||||
|
@ -71,6 +105,7 @@ con_float() {
|
||||||
i = *p++;
|
i = *p++;
|
||||||
}
|
}
|
||||||
fprintf(codefile,"\t%o;%o\n",i,*p++);
|
fprintf(codefile,"\t%o;%o\n",i,*p++);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef REGVARS
|
#ifdef REGVARS
|
||||||
|
@ -85,11 +120,6 @@ int n_regvars;
|
||||||
|
|
||||||
regscore(off,size,typ,score,totyp) long off; {
|
regscore(off,size,typ,score,totyp) long off; {
|
||||||
|
|
||||||
/*
|
|
||||||
* This function is full of magic constants.
|
|
||||||
* They are a result of experimentation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (size != 2)
|
if (size != 2)
|
||||||
return(-1);
|
return(-1);
|
||||||
score -= 1; /* allow for save/restore */
|
score -= 1; /* allow for save/restore */
|
||||||
|
@ -101,7 +131,7 @@ regscore(off,size,typ,score,totyp) long off; {
|
||||||
score = 10*score+50; /* Guestimate */
|
score = 10*score+50; /* Guestimate */
|
||||||
else
|
else
|
||||||
score *= 10;
|
score *= 10;
|
||||||
return(score); /* 10 * estimated # of words of profit */
|
return(score); /* estimated # of words of profit */
|
||||||
}
|
}
|
||||||
|
|
||||||
i_regsave() {
|
i_regsave() {
|
||||||
|
@ -114,6 +144,9 @@ f_regsave() {
|
||||||
register i;
|
register i;
|
||||||
|
|
||||||
if (n_regvars==0 || lbytes==0) {
|
if (n_regvars==0 || lbytes==0) {
|
||||||
|
#ifdef REGPATCH
|
||||||
|
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
|
||||||
|
#endif
|
||||||
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
||||||
if (lbytes == 2)
|
if (lbytes == 2)
|
||||||
fprintf(codefile,"tst -(sp)\n");
|
fprintf(codefile,"tst -(sp)\n");
|
||||||
|
@ -137,7 +170,16 @@ f_regsave() {
|
||||||
|
|
||||||
regsave(regstr,off,size) char *regstr; long off; {
|
regsave(regstr,off,size) char *regstr; long off; {
|
||||||
|
|
||||||
fprintf(codefile,"/ Local %ld into %s\n",off,regstr);
|
fprintf(codefile,"%c Local %ld into %s\n",COMMENTCHAR,off,regstr);
|
||||||
|
/* commented away
|
||||||
|
#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);
|
||||||
|
end of commented away */
|
||||||
|
|
||||||
strcat(Rstring,regstr);
|
strcat(Rstring,regstr);
|
||||||
regadm[n_regvars].ra_str = regstr;
|
regadm[n_regvars].ra_str = regstr;
|
||||||
regadm[n_regvars].ra_off = off;
|
regadm[n_regvars].ra_off = off;
|
||||||
|
@ -146,7 +188,11 @@ regsave(regstr,off,size) char *regstr; long off; {
|
||||||
|
|
||||||
regreturn() {
|
regreturn() {
|
||||||
|
|
||||||
|
#ifdef REGPATCH
|
||||||
|
fprintf(codefile,"jmp eret\n");
|
||||||
|
#else
|
||||||
fprintf(codefile,"jmp RT%s\n",Rstring);
|
fprintf(codefile,"jmp RT%s\n",Rstring);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -154,6 +200,9 @@ regreturn() {
|
||||||
prolog(nlocals) full nlocals; {
|
prolog(nlocals) full nlocals; {
|
||||||
|
|
||||||
#ifndef REGVARS
|
#ifndef REGVARS
|
||||||
|
#ifdef REGPATCH
|
||||||
|
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
|
||||||
|
#endif
|
||||||
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
||||||
if (nlocals == 0)
|
if (nlocals == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -187,7 +236,11 @@ mes(type) word type; {
|
||||||
return ;
|
return ;
|
||||||
default:
|
default:
|
||||||
strarg(argt) ;
|
strarg(argt) ;
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
fprintf(codefile,".define %s\n",argstr) ;
|
||||||
|
#else
|
||||||
fprintf(codefile,".globl %s\n",argstr) ;
|
fprintf(codefile,".globl %s\n",argstr) ;
|
||||||
|
#endif
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,8 +251,15 @@ mes(type) word type; {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *segname[] = {
|
char *segname[] = {
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
".sect .text", /* SEGTXT */
|
||||||
|
".sect .data", /* SEGCON */
|
||||||
|
".sect .rom", /* SEGROM */
|
||||||
|
".sect .bss" /* SEGBSS */
|
||||||
|
#else
|
||||||
".text", /* SEGTXT */
|
".text", /* SEGTXT */
|
||||||
".data", /* SEGCON */
|
".data", /* SEGCON */
|
||||||
".data", /* SEGROM */
|
".data", /* SEGROM */
|
||||||
".bss" /* SEGBSS */
|
".bss" /* SEGBSS */
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,32 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
|
|
||||||
|
/* The next define switches between codegeneration for an ACK assembler
|
||||||
|
* or for the standard UNIX V7 assembler.
|
||||||
|
* If on code is generated for the ACK assembler.
|
||||||
|
*/
|
||||||
|
#define ACK_ASS /* code for ACK assembler */
|
||||||
|
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
#define COMMENTCHAR '!'
|
||||||
|
#define ex_ap(y) fprintf(codefile,".extern %s\n",y)
|
||||||
|
#else
|
||||||
|
#define COMMENTCHAR '/'
|
||||||
#define ex_ap(y) fprintf(codefile,".globl %s\n",y)
|
#define ex_ap(y) fprintf(codefile,".globl %s\n",y)
|
||||||
|
#endif
|
||||||
#define in_ap(y) /* nothing */
|
#define in_ap(y) /* nothing */
|
||||||
|
|
||||||
#define newplb(x) fprintf(codefile,"%s:\n",x)
|
#define newplb(x) fprintf(codefile,"%s:\n",x)
|
||||||
#define newilb(x) fprintf(codefile,"%s:\n",x)
|
#define newilb(x) fprintf(codefile,"%s:\n",x)
|
||||||
#define newdlb(x) fprintf(codefile,"%s:\n",x)
|
#define newdlb(x) fprintf(codefile,"%s:\n",x)
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
#define newlbss(l,x) fprintf(codefile,"%s:.space 0%o\n",l,x);
|
||||||
|
#else
|
||||||
#define newlbss(l,x) fprintf(codefile,"%s:.=.+0%o\n",l,x);
|
#define newlbss(l,x) fprintf(codefile,"%s:.=.+0%o\n",l,x);
|
||||||
|
#endif
|
||||||
|
|
||||||
#define cst_fmt "$0%o"
|
#define cst_fmt "$0%o"
|
||||||
#define off_fmt "0%o"
|
#define off_fmt "0%o"
|
||||||
|
@ -14,11 +34,23 @@
|
||||||
#define dlb_fmt "_%d"
|
#define dlb_fmt "_%d"
|
||||||
#define hol_fmt "hol%d"
|
#define hol_fmt "hol%d"
|
||||||
|
|
||||||
#define hol_off "0%o+hol%d"
|
#define hol_off "0%lo+hol%d"
|
||||||
|
|
||||||
#define con_cst(x) fprintf(codefile,"0%o\n",x)
|
#ifdef ACK_ASS
|
||||||
|
#define con_cst(x) fprintf(codefile,".data2 0%lo\n",x)
|
||||||
|
#define con_ilb(x) fprintf(codefile,".data2 %s\n",x)
|
||||||
|
#define con_dlb(x) fprintf(codefile,".data2 %s\n",x)
|
||||||
|
#else
|
||||||
|
#define con_cst(x) fprintf(codefile,"0%lo\n",x)
|
||||||
#define con_ilb(x) fprintf(codefile,"%s\n",x)
|
#define con_ilb(x) fprintf(codefile,"%s\n",x)
|
||||||
#define con_dlb(x) fprintf(codefile,"%s\n",x)
|
#define con_dlb(x) fprintf(codefile,"%s\n",x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
#define modhead ".sect .text; .sect .rom; .sect .data; .sect .bss\n"
|
||||||
|
#define fmt_id(f,t) sprintf(t,"_%s",f)
|
||||||
|
#else
|
||||||
#define id_first '_'
|
#define id_first '_'
|
||||||
|
#endif
|
||||||
|
|
||||||
#define BSS_INIT 0
|
#define BSS_INIT 0
|
||||||
|
|
|
@ -30,7 +30,8 @@ PROGRAMCOUNTER
|
||||||
REGISTERS
|
REGISTERS
|
||||||
|
|
||||||
r0 : GENREG,REG.
|
r0 : GENREG,REG.
|
||||||
r2,r4 : GENREG,REG regvar.
|
r2 : GENREG,REG regvar.
|
||||||
|
r4 : GENREG,REG regvar.
|
||||||
r1,r3 : GENREG,REG,ODDREG.
|
r1,r3 : GENREG,REG,ODDREG.
|
||||||
r01("r0")=r0+r1 : REGPAIR.
|
r01("r0")=r0+r1 : REGPAIR.
|
||||||
fr0("r0"),fr1("r1"),fr2("r2"),fr3("r3") : GENFREG,FLTREG.
|
fr0("r0"),fr1("r1"),fr2("r2"),fr3("r3") : GENFREG,FLTREG.
|
||||||
|
|
Loading…
Add table
Reference in a new issue