fixup commit for tag 'distr3'

This commit is contained in:
cvs2hg
1989-10-04 10:56:17 +00:00
parent 81b1d21c35
commit 42e84d8dd2
230 changed files with 71 additions and 31971 deletions

16
util/.distr Normal file
View File

@@ -0,0 +1,16 @@
LLgen
ack
amisc
arch
ass
cgg
cmisc
cpp
data
ego
led
misc
ncgg
opt
shf
topgen

View File

@@ -1,35 +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
*
*/
/*
* L L G E N
*
* An Extended LL(1) Parser Generator
*
* Author : Ceriel J.H. Jacobs
*/
/*
* tunable.h $Header$
* Tunable constants
*/
# define NNONTERMS 150 /* size of nonterminal array */
# define NTERMINALS 150 /* size of terminal array */
# define NAMESZ 3000 /* size of name table */
# define LTEXTSZ 51 /* size of token */
# define ENTSIZ 900 /* size of entry table, max 8191 */

View File

@@ -1,212 +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 "ack.h"
#ifdef DEBUG
#define ASSERT(p) if(!(p))botch("p");else
botch(s)
char *s;
{
printf("malloc/free botched: %s\n",s);
abort();
}
#else
#define ASSERT(p)
#endif
#ifndef NORCSID
static char rcs_id[] = "$Header$" ;
#endif
/* avoid break bug */
#ifdef pdp11
#define GRANULE 64
#else
#define GRANULE 0
#endif
/* C storage allocator
* circular first-fit strategy
* works with noncontiguous, but monotonically linked, arena
* each block is preceded by a ptr to the (pointer of)
* the next following block
* blocks are exact number of words long
* aligned to the data type requirements of ALIGN
* pointers to blocks must have BUSY bit 0
* bit in ptr is 1 for busy, 0 for idle
* gaps in arena are merely noted as busy blocks
* last block of arena (pointed to by alloct) is empty and
* has a pointer to first
* idle blocks are coalesced during space search
*
* a different implementation may need to redefine
* ALIGN, NALIGN, BLOCK, BUSY, INT
* where INT is integer type to which a pointer can be cast
*/
#define INT int
#define ALIGN int
#define NALIGN 1
#define WORD sizeof(union store)
#define BLOCK 1024 /* a multiple of WORD*/
#define BUSY 1
#define NULL 0
#define testbusy(p) ((INT)(p)&BUSY)
#define setbusy(p) (union store *)((INT)(p)|BUSY)
#define clearbusy(p) (union store *)((INT)(p)&~BUSY)
union store { union store *ptr;
ALIGN dummy[NALIGN];
int calloc; /*calloc clears an array of integers*/
};
static union store allocs[2]; /*initial arena*/
static union store *allocp; /*search ptr*/
static union store *alloct; /*arena top*/
static union store *allocx; /*for benefit of realloc*/
char *sbrk();
char *
malloc(nbytes)
unsigned nbytes;
{
register union store *p, *q;
register nw;
static temp; /*coroutines assume no auto*/
if(allocs[0].ptr==0) { /*first time*/
allocs[0].ptr = setbusy(&allocs[1]);
allocs[1].ptr = setbusy(&allocs[0]);
alloct = &allocs[1];
allocp = &allocs[0];
}
nw = (nbytes+WORD+WORD-1)/WORD;
ASSERT(allocp>=allocs && allocp<=alloct);
ASSERT(allock());
for(p=allocp; ; ) {
for(temp=0; ; ) {
if(!testbusy(p->ptr)) {
while(!testbusy((q=p->ptr)->ptr)) {
ASSERT(q>p&&q<alloct);
p->ptr = q->ptr;
}
if(q>=p+nw && p+nw>=p)
goto found;
}
q = p;
p = clearbusy(p->ptr);
if(p>q)
ASSERT(p<=alloct);
else if(q!=alloct || p!=allocs) {
ASSERT(q==alloct&&p==allocs);
return(NULL);
} else if(++temp>1)
break;
}
temp = ((nw+BLOCK/WORD)/(BLOCK/WORD))*(BLOCK/WORD);
q = (union store *)sbrk(0);
if(q+temp+GRANULE < q) {
return(NULL);
}
q = (union store *)sbrk(temp*WORD);
if((INT)q == -1) {
return(NULL);
}
ASSERT(q>alloct);
alloct->ptr = q;
if(q!=alloct+1)
alloct->ptr = setbusy(alloct->ptr);
alloct = q->ptr = q+temp-1;
alloct->ptr = setbusy(allocs);
}
found:
allocp = p + nw;
ASSERT(allocp<=alloct);
if(q>allocp) {
allocx = allocp->ptr;
allocp->ptr = p->ptr;
}
p->ptr = setbusy(allocp);
return((char *)(p+1));
}
/* freeing strategy tuned for LIFO allocation
*/
free(ap)
register char *ap;
{
register union store *p = (union store *)ap;
ASSERT(p>clearbusy(allocs[1].ptr)&&p<=alloct);
ASSERT(allock());
allocp = --p;
ASSERT(testbusy(p->ptr));
p->ptr = clearbusy(p->ptr);
ASSERT(p->ptr > allocp && p->ptr <= alloct);
}
/* realloc(p, nbytes) reallocates a block obtained from malloc()
* and freed since last call of malloc()
* to have new size nbytes, and old content
* returns new location, or 0 on failure
*/
char *
realloc(p, nbytes)
register union store *p;
unsigned nbytes;
{
register union store *q;
union store *s, *t;
register unsigned nw;
unsigned onw;
if(testbusy(p[-1].ptr))
free((char *)p);
onw = p[-1].ptr - p;
q = (union store *)malloc(nbytes);
if(q==NULL || q==p)
return((char *)q);
s = p;
t = q;
nw = (nbytes+WORD-1)/WORD;
if(nw<onw)
onw = nw;
while(onw--!=0)
*t++ = *s++;
if(q<p && q+nw>=p)
(q+(q+nw-p))->ptr = allocx;
return((char *)q);
}
#ifdef DEBUG
allock()
{
#ifdef DEBUG
register union store *p;
int x;
x = 0;
for(p= &allocs[0]; clearbusy(p->ptr) > p; p=clearbusy(p->ptr)) {
if(p==allocp)
x++;
}
ASSERT(p==alloct);
return(x==1|p==allocp);
#else
return(1);
#endif
}
#endif

View File

@@ -31,6 +31,7 @@ int toterr;
int parent;
char *eeflag;
char *vvflag = "-V";
int no_pemflag = 0 ;
char *pemflag[MAX_FLAG];
char *eflag;
@@ -145,7 +146,7 @@ char *flag(f) char *f; {
wflag = f;
break;
case 'V':
initsizes(f+2);
vvflag = f;
return(0);
case '{':
if ( no_pemflag>=MAX_FLAG ) {
@@ -168,10 +169,11 @@ char *flag(f) char *f; {
return(0);
}
initsizes(vvflag) char *vvflag; {
initsizes(f) FILE *f; {
register c, i;
register char *p = vvflag;
register char *p;
p = vvflag + 2;
while (c = *p++) {
i = atoi(p);
while (*p >= '0' && *p <= '9')
@@ -194,6 +196,10 @@ initsizes(vvflag) char *vvflag; {
(sz_long != 4)) {
fatal("bad V-flag %s",vvflag);
}
if (sz_head == 0)
sz_head = 6*sz_word + 2*sz_addr;
for (i = 0; i <= sz_last; i++)
fprintf(f, "%d\n",sizes[i]);
}
/* ------------------ calling sequences -------------------- */
@@ -208,10 +214,7 @@ pem(p,q) char *p,*q; {
d = tempfile('d');
if ((erfil = fopen(d,"w")) == NULL)
syserr(d);
if (sz_head == 0)
sz_head = 6*sz_word + 2*sz_addr;
for (i = 0; i <= sz_last; i++)
fprintf(erfil, "%d\n",sizes[i]);
initsizes(erfil);
fprintf(erfil,"%s\n",basename(source));
for ( i=0 ; i<no_pemflag ; i++ ) fprintf(erfil,"%s\n",pemflag[i]);
fclose(erfil);

View File

@@ -1,5 +0,0 @@
for i in *.descr
do
m=`basename $i .descr`
../../../lib/cpp -P -I../../../h $i | sed -f descr.sed > ../../../lib/ego/${m}descr
done

View File

@@ -1,117 +0,0 @@
wordsize: 2
pointersize: 4
%%RA
general registers: 3
address registers: 4
floating point registers: 0
register score parameters:
local variable:
(2 cases)
pointer,pointer
(2 sizes)
fitbyte -> (5,2)
default -> (4,3)
general,general
(2 sizes)
fitbyte -> (3,1)
default -> (2,2)
address of local variable:
(2 cases)
pointer,pointer
(2 sizes)
fitbyte -> (0,1)
default -> (0,2)
general,pointer
(2 sizes)
fitbyte -> (0,1)
default -> (0,2)
constant:
(3 sizes)
in_0_63 -> (0,0)
fitbyte -> (0,1)
default -> (1,2)
double constant:
(1 size)
default -> (-1,-1)
address of global variable:
(1 size)
default -> (2,4)
address of procedure:
(1 size)
default -> (2,4)
opening cost parameters:
local variable:
(2 cases)
pointer
(2 sizes)
fitbyte -> (10,4)
default -> (9,5)
general
(2 sizes)
fitbyte -> (8,4)
default -> (7,5)
address of local variable:
(2 cases)
pointer
(2 sizes)
fitbyte -> (0,4)
default -> (0,5)
general
(2 sizes)
fitbyte -> (0,4)
general -> (0,5)
constant:
(3 sizes)
in_0_63 -> (4,2)
fitbyte -> (5,3)
default -> (6,4)
double constant:
(1 size)
default -> (1000,1000)
address of global variable:
(1 size)
default -> (6,7)
address of procedure:
(1 size)
default -> (6,7)
register save costs:
(9 cases)
0 -> (0,0)
1 -> (1,0)
2 -> (2,0)
3 -> (3,0)
4 -> (4,0)
5 -> (5,0)
6 -> (6,0)
7 -> (7,0)
0 -> (0,0)
%%UD
access costs of global variables:
(1 size)
default -> (7,4)
access costs of local variables:
(2 sizes)
fitbyte -> (3,1)
default -> (2,2)
%%SR
overflow harmful?: no
array bound harmful?: no
%%CS
#include "../../../h/em_mnem.h"
first time then space:
addressing modes: op_adp op_lof op_ldf op_loi op_dch op_lpb -1
op_adp op_lof op_ldf op_loi op_dch op_lpb -1
cheap operations: op_cii op_cui op_cfi op_ciu op_cff op_cuu op_cif
op_cmi op_cmf op_cmu op_cms op_cmp -1
op_cii op_cui op_cfi op_ciu op_cff op_cuu op_cif
op_cmi op_cmf op_cmu op_cms op_cmp -1
lexical tresholds: 1 1
indirection limit: 8
do sli if index?: no no
forbidden operators: -1 -1
%%SP
global stack pollution allowed?: yes

View File

@@ -1,600 +0,0 @@
You may want to change mach.c in this directory.
Archives MUST have a table of contents. Arch in subdirectory arch
automatically makes one when you change an archive.
Several changes in the assembler were needed to have it generate the
necessary output.
A contextual diff follows. You can apply them as follows:
patch -d /usr/em/philips/mach/68000/as < READ_ME
*** comm0.h.old Thu Dec 6 16:18:39 1984
--- comm0.h Thu Dec 6 17:49:51 1984
***************
*** 213,218
/*
* extra type bits out of S_ETC, internal use only
* S_COM:
* - symbols declared by .comm
* S_VAR:
--- 213,219 -----
/*
* extra type bits out of S_ETC, internal use only
+ #ifndef DUK
* S_COM:
* - symbols declared by .comm
#endif DUK
***************
*** 215,220
* extra type bits out of S_ETC, internal use only
* S_COM:
* - symbols declared by .comm
* S_VAR:
* - type not known at end of PASS_1 (S_VAR|S_UND)
* - value not known at end of PASS_2 (S_VAR|S_ABS)
--- 216,222 -----
#ifndef DUK
* S_COM:
* - symbols declared by .comm
+ #endif DUK
* S_VAR:
* - type not known at end of PASS_1 (S_VAR|S_UND)
* - value not known at end of PASS_2 (S_VAR|S_ABS)
***************
*** 221,226
* S_DOT:
* - dot expression
*/
#define S_COM 0x0100
#define S_VAR 0x0200
#define S_DOT 0x0400
--- 223,229 -----
* S_DOT:
* - dot expression
*/
+ #ifndef DUK
#define S_COM 0x0100
#endif DUK
#define S_VAR 0x0200
***************
*** 222,227
* - dot expression
*/
#define S_COM 0x0100
#define S_VAR 0x0200
#define S_DOT 0x0400
/* should be tested by preprocessor
--- 225,231 -----
*/
#ifndef DUK
#define S_COM 0x0100
+ #endif DUK
#define S_VAR 0x0200
#define S_DOT 0x0400
/* should be tested by preprocessor
*** comm2.y.old Thu Dec 6 16:19:07 1984
--- comm2.y Thu Dec 6 16:02:19 1984
***************
*** 229,234
{
#ifdef RELOCATION
if (rflag != 0 && PASS_RELO)
newrelo($1.typ, (int)$<y_word>0);
#endif
emitx($1.val, (int)$<y_word>0);
--- 229,239 -----
{
#ifdef RELOCATION
if (rflag != 0 && PASS_RELO)
+ #ifdef DUK
+ newrelo($1.typ,
+ (int)$<y_word>0 | RELBR | RELWR
+ );
+ #else DUK
newrelo($1.typ, (int)$<y_word>0);
#endif DUK
#endif
***************
*** 230,235
#ifdef RELOCATION
if (rflag != 0 && PASS_RELO)
newrelo($1.typ, (int)$<y_word>0);
#endif
emitx($1.val, (int)$<y_word>0);
}
--- 235,241 -----
);
#else DUK
newrelo($1.typ, (int)$<y_word>0);
+ #endif DUK
#endif
emitx($1.val, (int)$<y_word>0);
}
***************
*** 237,242
{
#ifdef RELOCATION
if (rflag != 0 && PASS_RELO)
newrelo($3.typ, (int)$<y_word>0);
#endif
emitx($3.val, (int)$<y_word>0);
--- 243,253 -----
{
#ifdef RELOCATION
if (rflag != 0 && PASS_RELO)
+ #ifdef DUK
+ newrelo($3.typ,
+ (int)$<y_word>0 | RELBR | RELWR
+ );
+ #else DUK
newrelo($3.typ, (int)$<y_word>0);
#endif DUK
#endif
***************
*** 238,243
#ifdef RELOCATION
if (rflag != 0 && PASS_RELO)
newrelo($3.typ, (int)$<y_word>0);
#endif
emitx($3.val, (int)$<y_word>0);
}
--- 249,255 -----
);
#else DUK
newrelo($3.typ, (int)$<y_word>0);
+ #endif DUK
#endif
emitx($3.val, (int)$<y_word>0);
}
*** comm3.c.old Wed Jul 11 09:22:24 1984
--- comm3.c Fri Dec 7 13:06:26 1984
***************
*** 11,16
struct outhead outhead = {
O_MAGIC, O_STAMP, 0
#ifdef BYTES_REVERSED
| HF_BREV
#endif
--- 11,17 -----
struct outhead outhead = {
O_MAGIC, O_STAMP, 0
+ #ifndef DUK
#ifdef BYTES_REVERSED
| HF_BREV
#endif
***************
*** 17,22
#ifdef WORDS_REVERSED
| HF_WREV
#endif
};
#include "y.tab.h"
--- 18,24 -----
#ifdef WORDS_REVERSED
| HF_WREV
#endif
+ #endif DUK
};
#include "y.tab.h"
*** comm5.c.old Thu Dec 6 16:19:40 1984
--- comm5.c Thu Oct 11 14:03:27 1984
***************
*** 162,167
#endif
case STRING:
p = stringbuf;
*p++ = n = getc(tempfile); break;
case OP_EQ:
case OP_NE:
--- 162,172 -----
#endif
case STRING:
p = stringbuf;
+ #ifdef DUK
+ *p++ = n = getc(tempfile);
+ p[n] = '\0';
+ break;
+ #else DUK
*p++ = n = getc(tempfile); break;
#endif DUK
case OP_EQ:
***************
*** 163,168
case STRING:
p = stringbuf;
*p++ = n = getc(tempfile); break;
case OP_EQ:
case OP_NE:
case OP_LE:
--- 168,174 -----
break;
#else DUK
*p++ = n = getc(tempfile); break;
+ #endif DUK
case OP_EQ:
case OP_NE:
case OP_LE:
***************
*** 354,359
break;
if (c == '\\')
c = inescape();
if (p >= &stringbuf[STRINGMAX])
fatal("string buffer overflow");
*p++ = c;
--- 360,368 -----
break;
if (c == '\\')
c = inescape();
+ #ifdef DUK
+ if (p >= &stringbuf[STRINGMAX - 1])
+ #else DUK
if (p >= &stringbuf[STRINGMAX])
#endif DUK
fatal("string buffer overflow");
***************
*** 355,360
if (c == '\\')
c = inescape();
if (p >= &stringbuf[STRINGMAX])
fatal("string buffer overflow");
*p++ = c;
}
--- 364,370 -----
if (p >= &stringbuf[STRINGMAX - 1])
#else DUK
if (p >= &stringbuf[STRINGMAX])
+ #endif DUK
fatal("string buffer overflow");
*p++ = c;
}
***************
*** 359,364
*p++ = c;
}
stringbuf[0] = p - stringbuf - 1;
return(STRING);
}
--- 369,377 -----
*p++ = c;
}
stringbuf[0] = p - stringbuf - 1;
+ #ifdef DUK
+ *p = '\0';
+ #endif DUK
return(STRING);
}
*** comm6.c.old Thu Dec 6 16:20:22 1984
--- comm6.c Wed Oct 3 15:59:31 1984
***************
*** 106,111
sp = &sect[typ - S_MIN];
sp->s_item = ip;
sp->s_lign = ALIGNSECT;
ip->i_type = typ | S_EXT;
ip->i_valu = 0;
} else if (typ >= S_MIN) {
--- 106,114 -----
sp = &sect[typ - S_MIN];
sp->s_item = ip;
sp->s_lign = ALIGNSECT;
+ #ifdef DUK
+ ip->i_type = typ;
+ #else DUK
ip->i_type = typ | S_EXT;
#endif DUK
ip->i_valu = 0;
***************
*** 107,112
sp->s_item = ip;
sp->s_lign = ALIGNSECT;
ip->i_type = typ | S_EXT;
ip->i_valu = 0;
} else if (typ >= S_MIN) {
sp = &sect[typ - S_MIN];
--- 110,116 -----
ip->i_type = typ;
#else DUK
ip->i_type = typ | S_EXT;
+ #endif DUK
ip->i_valu = 0;
} else if (typ >= S_MIN) {
sp = &sect[typ - S_MIN];
***************
*** 180,185
* for possible relocation
*/
ip->i_valu = outhead.oh_nname;
newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val);
#endif
}
--- 184,192 -----
* for possible relocation
*/
ip->i_valu = outhead.oh_nname;
+ #ifdef DUK
+ newsymb(ip->i_name, S_COM|S_EXT|DOTTYP, (short)0, val);
+ #else DUK
newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val);
#endif DUK
#endif
***************
*** 181,186
*/
ip->i_valu = outhead.oh_nname;
newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val);
#endif
}
--- 188,194 -----
newsymb(ip->i_name, S_COM|S_EXT|DOTTYP, (short)0, val);
#else DUK
newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val);
+ #endif DUK
#endif
}
***************
*** 255,260
short s;
{
struct outrelo outrelo;
if (rflag == 0)
return;
--- 263,271 -----
short s;
{
struct outrelo outrelo;
+ #ifdef DUK
+ int iscomm;
+ #endif DUK
if (rflag == 0)
return;
***************
*** 272,277
* b=a
* a: .data2 0
*/
s &= ~S_COM;
if ((n & RELPC) == 0 && s == S_ABS)
return;
--- 283,291 -----
* b=a
* a: .data2 0
*/
+ #ifdef DUK
+ iscomm = s & S_COM;
+ #endif DUK
s &= ~S_COM;
if ((n & RELPC) == 0 && s == S_ABS)
return;
***************
*** 285,290
outrelo.or_type = (char)n;
outrelo.or_sect = (char)DOTTYP;
#ifndef ASLD
if (s == S_UND) {
assert(relonami != 0);
outrelo.or_nami = relonami-1;
--- 299,307 -----
outrelo.or_type = (char)n;
outrelo.or_sect = (char)DOTTYP;
#ifndef ASLD
+ #ifdef DUK
+ if (s == S_UND || iscomm) {
+ #else DUK
if (s == S_UND) {
#endif DUK
assert(relonami != 0);
***************
*** 286,291
outrelo.or_sect = (char)DOTTYP;
#ifndef ASLD
if (s == S_UND) {
assert(relonami != 0);
outrelo.or_nami = relonami-1;
relonami = 0;
--- 303,309 -----
if (s == S_UND || iscomm) {
#else DUK
if (s == S_UND) {
+ #endif DUK
assert(relonami != 0);
outrelo.or_nami = relonami-1;
relonami = 0;
*** comm7.c.old Thu Dec 6 16:20:50 1984
--- comm7.c Wed Oct 3 16:35:31 1984
***************
*** 19,24
return(ip->i_valu);
return(ip->i_valu + sect[typ].s_base);
#else
if ((ip->i_type & S_TYP) == S_UND) {
if (pass == PASS_3) {
if (relonami != 0)
--- 19,27 -----
return(ip->i_valu);
return(ip->i_valu + sect[typ].s_base);
#else
+ #ifdef DUK
+ if ((ip->i_type & S_TYP) == S_UND || (ip->i_type & S_COM)) {
+ #else DUK
if ((ip->i_type & S_TYP) == S_UND) {
#endif DUK
if (pass == PASS_3) {
***************
*** 20,25
return(ip->i_valu + sect[typ].s_base);
#else
if ((ip->i_type & S_TYP) == S_UND) {
if (pass == PASS_3) {
if (relonami != 0)
serror("relocation error");
--- 23,29 -----
if ((ip->i_type & S_TYP) == S_UND || (ip->i_type & S_COM)) {
#else DUK
if ((ip->i_type & S_TYP) == S_UND) {
+ #endif DUK
if (pass == PASS_3) {
if (relonami != 0)
serror("relocation error");
*** mach0.c.old Thu Dec 6 16:21:11 1984
--- mach0.c Fri Sep 14 14:15:54 1984
***************
*** 1,3
/* @(#)mach0.c 1.5 */
/*
* Motorola 68000/68010 options
--- 1,4 -----
+ #define DUK
/* @(#)mach0.c 1.5 */
/*
* Motorola 68000/68010 options
*** mach4.c.old Thu Dec 6 16:21:30 1984
--- mach4.c Thu Dec 6 16:05:00 1984
***************
*** 21,26
fit(fitw($4.val));
emit2($1 | $2);
#ifdef RELOCATION
newrelo($4.typ, RELPC|RELO2);
#endif
emit2(loww($4.val));
--- 21,29 -----
fit(fitw($4.val));
emit2($1 | $2);
#ifdef RELOCATION
+ #ifdef DUK
+ newrelo($4.typ, RELPC|RELO2|RELBR|RELWR);
+ #else DUK
newrelo($4.typ, RELPC|RELO2);
#endif DUK
#endif
***************
*** 22,27
emit2($1 | $2);
#ifdef RELOCATION
newrelo($4.typ, RELPC|RELO2);
#endif
emit2(loww($4.val));
}
--- 25,31 -----
newrelo($4.typ, RELPC|RELO2|RELBR|RELWR);
#else DUK
newrelo($4.typ, RELPC|RELO2);
+ #endif DUK
#endif
emit2(loww($4.val));
}
*** mach5.c.old Thu Dec 6 16:21:54 1984
--- mach5.c Thu Dec 6 16:07:05 1984
***************
*** 37,42
#ifdef RELOCATION
RELOMOVE(relonami, rel_1);
if (flag & ~0xFF)
newrelo(exp_1.typ, flag>>8);
#endif
if (flag & PUTL)
--- 37,45 -----
#ifdef RELOCATION
RELOMOVE(relonami, rel_1);
if (flag & ~0xFF)
+ #ifdef DUK
+ newrelo(exp_1.typ, (flag>>8) | RELBR | RELWR);
+ #else DUK
newrelo(exp_1.typ, flag>>8);
#endif DUK
#endif
***************
*** 38,43
RELOMOVE(relonami, rel_1);
if (flag & ~0xFF)
newrelo(exp_1.typ, flag>>8);
#endif
if (flag & PUTL)
emit4(exp_1.val);
--- 41,47 -----
newrelo(exp_1.typ, (flag>>8) | RELBR | RELWR);
#else DUK
newrelo(exp_1.typ, flag>>8);
+ #endif DUK
#endif
if (flag & PUTL)
emit4(exp_1.val);
***************
*** 357,362
fit(fitw(exp.val));
emit2(opc);
#ifdef RELOCATION
newrelo(exp.typ, RELPC|RELO2);
#endif
emit2(loww(exp.val));
--- 361,369 -----
fit(fitw(exp.val));
emit2(opc);
#ifdef RELOCATION
+ #ifdef DUK
+ newrelo(exp.typ, RELPC|RELO2|RELBR|RELWR);
+ #else DUK
newrelo(exp.typ, RELPC|RELO2);
#endif DUK
#endif
***************
*** 358,363
emit2(opc);
#ifdef RELOCATION
newrelo(exp.typ, RELPC|RELO2);
#endif
emit2(loww(exp.val));
}
--- 365,371 -----
newrelo(exp.typ, RELPC|RELO2|RELBR|RELWR);
#else DUK
newrelo(exp.typ, RELPC|RELO2);
+ #endif DUK
#endif
emit2(loww(exp.val));
}

View File

@@ -1,90 +0,0 @@
#ifndef lint
static char rcsid[] = "$Header$";
#endif lint
#include "const.h"
#include "assert.h"
bool bytes_reversed = FALSE;
bool words_reversed = FALSE;
/*
* Determine the byte/word order in shorts/longs, assuming the size of a short
* is 2 chars, and the size of a long is 4 chars. Not all theoretical
* possibilities are tested; only bytes reversed and/or words reversed.
*/
determine_ordering()
{
short s;
long l;
register char *cp;
register short *sp;
cp = (char *)&s;
cp[0] = 0x01; cp[1] = 0x02;
if (s != 0x01 + (0x02 << 8))
bytes_reversed = TRUE;
sp = (short *)&l;
sp[0] = 0x0001; sp[1] = 0x0002;
if (l != 0x0001 + (0x0002L << 16))
words_reversed = TRUE;
}
/*
* `Format' is a string of digits indicating how many bytes must be taken
* from `buf' to form an integer of some type. E.g. if the digit is '2', two
* bytes are taken to form a short.
*/
swap(buf, format)
register char *buf;
register char *format;
{
register char savebyte;
while (*format) {
switch (*format++) {
case '1':
buf += 1;
break;
case '2':
if (bytes_reversed) {
savebyte = buf[0];
buf[0] = buf[1];
buf[1] = savebyte;
}
buf += 2;
break;
case '4':
/*
* Written out to save recursive calls.
*/
if (bytes_reversed && words_reversed) {
savebyte = buf[0];
buf[0] = buf[3];
buf[3] = savebyte;
savebyte = buf[1];
buf[1] = buf[2];
buf[2] = savebyte;
} else if (bytes_reversed) {
savebyte = buf[0];
buf[0] = buf[1];
buf[1] = savebyte;
savebyte = buf[2];
buf[2] = buf[3];
buf[3] = savebyte;
} else if (words_reversed) {
savebyte = buf[0];
buf[0] = buf[2];
buf[2] = savebyte;
savebyte = buf[1];
buf[1] = buf[3];
buf[3] = savebyte;
}
buf += 4;
break;
default:
assert(FALSE);
break;
}
}
}

View File

@@ -1,499 +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
*
*/
#ifndef NORCSID
static char rcsid[] = "$Header$";
#endif
/*
* Decode compact EM assembly language
*
* Author: Johan Stevenson, Vrije Universiteit, Amsterdam
*/
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <em_spec.h>
#include <em_pseu.h>
#include <em_flag.h>
#include <em_ptyp.h>
#include <em_mes.h>
#define get8() ((unsigned)getchar())
#define check(x) if (!(x)) fail_check()
#define MAXSTR 256
/*
* global variables
*/
int opcode;
int offtyp;
long argval;
int dlbval;
char string[MAXSTR];
int strsiz;
int wsize;
int psize;
int lineno;
int argnum;
int errors;
char *progname;
char *filename;
long wordmask[] = { /* allowed bits in a word */
0x00000000,
0x000000FF,
0x0000FFFF,
0x00000000,
0xFFFFFFFF
};
long sizemask[] = { /* allowed bits in multiples of 'wsize' */
0x00000000,
0x7FFFFFFF,
0x7FFFFFFE,
0x00000000,
0x7FFFFFFC
};
/*
* external tables
*/
extern char em_flag[];
extern short em_ptyp[];
extern char em_mnem[][4];
extern char em_pseu[][4];
/*
* routines
*/
int get16();
long get32();
main(argc,argv) char **argv; {
progname = argv[0];
if (argc >= 2) {
filename = argv[1];
if (freopen(argv[1],"r",stdin) == NULL)
fatal("can't open %s",argv[1]);
}
if (argc >= 3)
if (freopen(argv[2],"w",stdout) == NULL)
fatal("can't create %s",argv[2]);
if (get16() != sp_magic)
fatal("bad magic word");
/* In System III the array is called _ctype[] without the trailing '_' */
(_ctype_+1)['_'] = (_ctype_+1)['a'];
while (nextline())
;
return(errors ? -1 : 0);
}
/* ----- copy ----- */
int nextline() {
register t;
lineno++;
argnum = 1;
switch (t = table1()) {
case EOF:
return(0);
case sp_fmnem:
instr();
break;
case sp_fpseu:
pseudo();
break;
case sp_ilb1:
case sp_ilb2:
argnum = 0;
putarg(sp_cst2);
break;
case sp_dlb1:
case sp_dlb2:
case sp_dnam:
argnum = 0;
putarg(t);
break;
default:
error("unknown opcode %d",t);
}
putchar('\n');
return(1);
}
instr() {
register i,j,t;
register long l;
i = opcode - sp_fmnem;
printf(" %s",em_mnem[i]);
j = em_flag[i] & EM_PAR;
if (j == PAR_NO)
return;
t = em_ptyp[j];
t = getarg(t);
/*
* range checking
*/
switch (j) {
case PAR_N:
check(argval >= 0);
break;
case PAR_G:
if (t != sp_cst2 && t != sp_cst4)
break;
check(argval >= 0);
/* fall through */
case PAR_L:
l = argval >= 0 ? argval : -argval;
check((l & ~wordmask[psize]) == 0);
break;
case PAR_W:
if (t == sp_cend)
break;
check((argval & ~wordmask[wsize]) == 0);
/* fall through */
case PAR_S:
check(argval != 0);
/* fall through */
case PAR_Z:
check((argval & ~sizemask[wsize]) == 0);
break;
case PAR_O:
check(argval != 0);
check((argval & ~sizemask[wsize])==0 || (wsize % argval)==0);
break;
case PAR_B:
t = sp_ilb2;
break;
case PAR_R:
check(argval >= 0 && argval <= 2);
break;
}
putarg(t);
}
pseudo() {
register i,t;
i = opcode;
printf(" %s",em_pseu[i - sp_fpseu]);
switch (i) {
case ps_bss:
case ps_hol:
putarg(getarg(cst_ptyp));
putarg(getarg(val_ptyp));
putarg(getarg(ptyp(sp_cst2)));
check(argval==0 || argval==1);
break;
case ps_rom:
case ps_con:
putarg(getarg(val_ptyp));
while ((t = getarg(any_ptyp)) != sp_cend)
putarg(t);
break;
case ps_mes:
putarg(getarg(ptyp(sp_cst2)));
if (argval == ms_emx) {
putarg(getarg(ptyp(sp_cst2)));
check(argval > 0 && argval <= 4);
wsize = (int) argval;
putarg(getarg(ptyp(sp_cst2)));
check(argval > 0 && argval <= 4);
psize = (int) argval;
}
while ((t = getarg(any_ptyp)) != sp_cend)
putarg(t);
break;
case ps_exa:
case ps_ina:
putarg(getarg(sym_ptyp));
break;
case ps_exp:
case ps_inp:
putarg(getarg(ptyp(sp_pnam)));
break;
case ps_exc:
putarg(getarg(ptyp(sp_cst2)));
putarg(getarg(ptyp(sp_cst2)));
break;
case ps_pro:
putarg(getarg(ptyp(sp_pnam)));
putarg(getarg(cst_ptyp|ptyp(sp_cend)));
break;
case ps_end:
putarg(getarg(cst_ptyp|ptyp(sp_cend)));
break;
default:
error("bad pseudo %d",i);
}
}
/* ----- input ----- */
int getarg(typset) {
register t,argtyp;
argtyp = t = table2();
if (t == EOF)
fatal("unexpected EOF");
t -= sp_fspec;
assert(t >= 0 && t < 16);
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_cst2);
}
return(table3(i));
}
int table3(i) {
long consiz;
switch(i) {
case sp_ilb1:
argval = get8();
break;
case sp_dlb1:
dlbval = get8();
break;
case sp_dlb2:
dlbval = get16();
if ( dlbval<0 ) {
error("illegal data label .%d",dlbval);
dlbval=0 ;
}
break;
case sp_cst2:
argval = get16();
break;
case sp_ilb2:
argval = get16();
if ( argval<0 ) {
error("illegal instruction label %ld",argval);
argval=0 ;
}
break;
case sp_cst4:
argval = get32();
break;
case sp_dnam:
case sp_pnam:
getstring(1);
break;
case sp_scon:
getstring(0);
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 = (long) argval;
getstring(0);
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(ident) {
register char *p;
register n;
getarg(cst_ptyp);
if (argval < 0 || argval > MAXSTR)
fatal("string/identifier too long");
strsiz = n = argval;
p = string;
while (--n >= 0)
*p++ = get8();
if (ident) {
if (!isascii(string[0]) || !isalpha(string[0])) {
identerror();
return;
}
for (n=strsiz,p=string+1;--n>0;p++)
if (!isascii(*p) || !isalnum(*p)) {
identerror();
return;
}
}
}
/* ----- output ----- */
putarg(t) {
if (argnum != 0)
putchar(argnum == 1 ? ' ' : ',');
argnum++;
puttyp(t);
}
puttyp(t) {
switch (t) {
case sp_ilb1:
case sp_ilb2:
printf("*%d",(int) argval);
break;
case sp_dlb1:
case sp_dlb2:
printf(".%d",dlbval);
break;
case sp_dnam:
putstr(0,0);
break;
case sp_cst2:
case sp_cst4:
printf("%ld",argval);
break;
case sp_doff:
puttyp(offtyp);
if (argval >= 0) putchar('+');
printf("%ld",argval);
break;
case sp_pnam:
putstr('$',0);
break;
case sp_scon:
putstr('\'','\'');
break;
case sp_icon:
putstr(0,'I');
printf("%ld",argval);
break;
case sp_ucon:
putstr(0,'U');
printf("%ld",argval);
break;
case sp_fcon:
putstr(0,'F');
printf("%ld",argval);
break;
case sp_cend:
putchar('?');
break;
}
}
putstr(c,c2) register c; {
register char *p;
if (c)
putchar(c);
p = string;
while (--strsiz >= 0) {
c = *p++ & 0377;
if (c >= 040 && c < 0177) {
if (c == '\'' || c == '\\')
putchar('\\');
putchar(c);
} else
printf("\\%03o",c);
}
if (c2)
putchar(c2);
}
/* ----- error handling ----- */
fail_check() {
error("argument range error");
}
identerror() {
error("'%s' is not a correct identifier",string);
}
/* VARARGS */
error(s,a1,a2,a3,a4) char *s; {
fprintf(stderr,
"%s: line %d: ",
filename ? filename : progname,
lineno);
fprintf(stderr,s,a1,a2,a3,a4);
fprintf(stderr,"\n");
errors++;
}
/* VARARGS */
fatal(s,a1,a2,a3,a4) char *s; {
error(s,a1,a2,a3,a4);
exit(-1);
}

View File

@@ -1,761 +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
*
*/
#ifndef NORCSID
static char rcsid[] = "$Header$";
#endif
/*
* Encode to compact EM assembly language
*
* Author: Johan Stevenson, Vrije Universiteit, Amsterdam
*/
#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include <setjmp.h>
#include <em_spec.h>
#include <em_pseu.h>
#include <em_flag.h>
#include <em_ptyp.h>
#include <em_mes.h>
#define put8(x) putchar(x)
#define check(x) if (!(x)) fail_check()
#define fit16i(x) ((x) >= 0xFFFF8000 && (x) <= 0x00007FFF)
#define fit8u(x) ((x) >= 0 && (x) <= 0xFF)
#define MAXSTR 256
#define HSIZE 256
#define EMPTY (EOF-1)
/*
* global variables
*/
int opcode;
int offtyp;
long argval;
int dlbval;
char string[MAXSTR];
int strsiz;
int wsize;
int psize;
int lineno;
int argnum;
int errors;
char *progname;
char *filename = "INPUT";
long wordmask[] = { /* allowed bits in a word */
0x00000000,
0x000000FF,
0x0000FFFF,
0x00000000,
0xFFFFFFFF
};
long sizemask[] = { /* allowed bits in multiples of 'wsize' */
0x00000000,
0x7FFFFFFF,
0x7FFFFFFE,
0x00000000,
0x7FFFFFFC
};
int peekc = EMPTY;
int hashtab[HSIZE];
jmp_buf recover;
/*
* external tables
*/
extern char em_flag[];
extern short em_ptyp[];
extern char em_mnem[][4];
extern char em_pseu[][4];
int main(argc,argv) char **argv; {
progname = argv[0];
if (argc >= 2) {
filename = argv[1];
if (freopen(filename,"r",stdin) == NULL)
fatal("can't open %s",filename);
}
if (argc >= 3)
if (freopen(argv[2],"w",stdout) == NULL)
fatal("can't create %s",argv[2]);
init();
put16(sp_magic);
setjmp(recover);
while (nextline())
;
return(errors ? -1 : 0);
}
/* ----- copy ----- */
int nextline() {
register c,i;
lineno++;
argnum = 1;
c = nextchar();
if (c == EOF)
return(0);
if (isspace(c) && c != '\n') {
c = nospace();
if (isalpha(c)) {
inmnem(c);
if (opcode <= sp_lmnem)
instr();
else
pseudo();
} else
peekc = c;
} else if (c == '#') {
line_line();
} else {
peekc = c;
i = gettyp(sym_ptyp | ptyp(sp_cst2) | ptyp(sp_cend));
switch (i) {
case sp_cst2:
i = (int) argval;
if (i >= 0 && i < sp_nilb0)
put8(i + sp_filb0);
else
putarg(sp_ilb2);
break;
case sp_dlb2:
case sp_dnam:
putarg(i);
break;
case sp_cend:
break;
}
}
if (nospace() != '\n')
syntax("end of line expected");
return(1);
}
instr() {
register i,j,t;
register long l;
i = opcode;
put8(i);
i -= sp_fmnem;
j = em_flag[i] & EM_PAR;
if (j == PAR_NO)
return;
t = em_ptyp[j];
if (j == PAR_B)
t = ptyp(sp_ilb2);
t = getarg(t);
/*
* range checking
*/
switch (j) {
case PAR_N:
check(argval >= 0);
break;
case PAR_G:
if (t != sp_cst2 && t != sp_cst4)
break;
check(argval >= 0);
/* fall through */
case PAR_L:
l = argval >= 0 ? argval : -argval;
check((l & ~wordmask[psize]) == 0);
break;
case PAR_W:
if (t == sp_cend)
break;
check((argval & ~wordmask[wsize]) == 0);
/* fall through */
case PAR_S:
check(argval != 0);
/* fall through */
case PAR_Z:
check((argval & ~sizemask[wsize]) == 0);
break;
case PAR_O:
check(argval != 0);
check((argval & ~sizemask[wsize])==0 || (wsize % argval)==0);
break;
case PAR_B:
t = sp_cst2;
break;
case PAR_R:
check(argval >= 0 && argval <= 2);
break;
}
putarg(t);
}
pseudo() {
register i,t;
i = opcode;
put8(i);
switch (i) {
case ps_bss:
case ps_hol:
putarg(getarg(cst_ptyp));
putarg(getarg(val_ptyp));
putarg(getarg(ptyp(sp_cst2)));
check(argval==0 || argval==1);
break;
case ps_rom:
case ps_con:
putarg(getarg(val_ptyp));
do
putarg(t = getarg(any_ptyp));
while (t != sp_cend);
break;
case ps_mes:
putarg(getarg(ptyp(sp_cst2)));
if (argval == ms_emx) {
putarg(getarg(ptyp(sp_cst2)));
check(argval > 0 && argval <= 4);
wsize = (int) argval;
putarg(getarg(ptyp(sp_cst2)));
check(argval > 0 && argval <= 4);
psize = (int) argval;
}
do
putarg(t = getarg(any_ptyp));
while (t != sp_cend);
break;
case ps_exa:
case ps_ina:
putarg(getarg(sym_ptyp));
break;
case ps_exp:
case ps_inp:
putarg(getarg(ptyp(sp_pnam)));
break;
case ps_exc:
putarg(getarg(ptyp(sp_cst2)));
putarg(getarg(ptyp(sp_cst2)));
break;
case ps_pro:
putarg(getarg(ptyp(sp_pnam)));
putarg(getarg(cst_ptyp|ptyp(sp_cend)));
break;
case ps_end:
putarg(getarg(cst_ptyp|ptyp(sp_cend)));
break;
default:
syntax("bad pseudo %d",i);
}
}
/* ----- input ----- */
int getarg(typset) {
register c;
if (argnum != 1) {
c = nospace();
if (c != ',') {
if (c != '\n')
syntax("comma expected");
peekc = c;
}
}
argnum++;
return(gettyp(typset));
}
int gettyp(typset) {
register c,t,sp;
c = nospace();
if (c == '\n') {
peekc = c;
sp = sp_cend;
} else if (isdigit(c) || c == '+' || c == '-' || c == '(') {
sp = inexpr1(c);
if (sp == sp_cst4 && fit16i(argval))
sp = sp_cst2;
} else if (isalpha(c)) {
inname(c);
sp = offsetted(sp_dnam);
} else if (c == '.') {
in15u();
dlbval = (int) argval;
sp = offsetted(sp_dlb2);
} else if (c == '*') {
in15u();
sp = sp_ilb2;
} else if (c == '$') {
inname(nextchar());
sp = sp_pnam;
} else if (c == '"' || c == '\'') {
sp = instring(c);
} else if (c == '?') {
sp = sp_cend;
} else
syntax("operand expected");
t = sp - sp_fspec;
assert(t >= 0 && t < 16);
t = 1 << t;
if ((typset & t) == 0)
error("bad argument type %d",sp);
return(sp);
}
int offsetted(sp) {
register c;
c = nospace();
if (c == '+' || c == '-') {
gettyp(cst_ptyp);
if (c == '-')
argval = -argval;
offtyp = sp;
return(sp_doff);
}
peekc = c;
return(sp);
}
inname(c) register c; {
register char *p;
if (isalpha(c) == 0)
syntax("letter expected");
p = string;
do {
if (p < &string[MAXSTR-1])
*p++ = c;
c = nextchar();
} while (isalnum(c));
peekc = c;
*p = '\0';
strsiz = p - string;
}
int inmnem(c) register c; {
register unsigned h;
register i;
inname(c);
h = hash(string);
for (;;) {
h++;
h %= HSIZE;
i = hashtab[h];
if (i == 0)
syntax("bad mnemonic");
if (i <= sp_lmnem) {
assert(i >= sp_fmnem);
if (strcmp(string,em_mnem[i - sp_fmnem]) != 0)
continue;
return(opcode = i);
}
assert(i <= sp_lpseu && i >= sp_fpseu);
if (strcmp(string,em_pseu[i - sp_fpseu]) != 0)
continue;
return(opcode = i);
}
}
int inexpr1(c) register c; {
long left;
if ((c = inexpr2(c)) != sp_cst4)
return(c);
for (;;) {
c = nospace();
if (c != '+' && c != '-') {
peekc = c;
break;
}
left = argval;
if (inexpr2(nospace()) != sp_cst4)
syntax("term expected");
if (c == '+')
argval += left;
else
argval = left - argval;
}
return(sp_cst4);
}
int inexpr2(c) register c; {
long left;
if ((c = inexpr3(c)) != sp_cst4)
return(c);
for (;;) {
c = nospace();
if (c != '*' && c != '/' && c != '%') {
peekc = c;
break;
}
left = argval;
if (inexpr3(nospace()) != sp_cst4)
syntax("factor expected");
if (c == '*')
argval *= left;
else if (c == '/')
argval = left / argval;
else
argval = left % argval;
}
return(sp_cst4);
}
inexpr3(c) register c; {
if (c == '(') {
if (inexpr1(nospace()) != sp_cst4)
syntax("expression expected");
if (nospace() != ')')
syntax("')' expected");
return(sp_cst4);
}
return(innumber(c));
}
int innumber(c) register c; {
register char *p;
register n;
int expsign;
static char numstr[MAXSTR];
long atol();
p = numstr;
expsign = 0;
if (c == '+' || c == '-') {
if (c == '-')
*p++ = c;
c = nextchar();
}
if (isdigit(c) == 0)
syntax("digit expected");
n = sp_cst4;
for (;;) {
if (p >= &numstr[MAXSTR-1])
fatal("number too long");
*p++ = c;
c = nextchar();
if (c == '.' || c == 'e' || c == 'E') {
expsign = c != '.';
n = sp_fcon;
continue;
}
if (expsign) {
expsign = 0;
if (c == '+' || c == '-')
continue;
}
if (isdigit(c) == 0)
break;
}
peekc = c;
*p = '\0';
c = nospace();
if (n == sp_fcon && c != 'F')
syntax("'F' expected");
if (c == 'I' || c == 'U' || c == 'F')
return(incon(numstr,c));
peekc = c;
argval = atol(numstr);
return(sp_cst4);
}
in15u() {
if (innumber(nextchar()) != sp_cst4)
syntax("integer expected");
check((argval & ~077777) == 0);
}
int incon(p,c) register char *p; {
register char *q;
q = string;
while (*q++ = *p++)
;
strsiz = q - string - 1;
gettyp(cst_ptyp);
return(c == 'I' ? sp_icon : (c == 'U' ? sp_ucon : sp_fcon));
}
int instring(termc) {
register char *p;
register c;
p = string;
for (;;) {
c = nextchar();
if (c == '\n' || c == EOF) {
peekc = c;
syntax("non-terminated string");
}
if (c == termc) {
if (termc == '"')
*p++ = '\0';
break;
}
if (c == '\\')
c = inescape();
if (p >= &string[MAXSTR-1])
fatal("string too long");
*p++ = c;
}
strsiz = p - string;
return(sp_scon);
}
int inescape() {
register c,j,r;
c = nextchar();
if (c >= '0' && c <= '7') {
r = c - '0';
for (j = 0; j < 2; j++) {
c = nextchar();
if (c < '0' || c > '7') {
peekc = c;
return(r);
}
r <<= 3;
r += (c - '0');
}
return(r);
}
switch (c) {
case 'b': return('\b');
case 'f': return('\f');
case 'n': return('\n');
case 'r': return('\r');
case 't': return('\t');
}
return(c);
}
int nospace() {
register c;
do
c = nextchar();
while (isspace(c) && c != '\n');
if (c == ';')
do
c = nextchar();
while (c != '\n' && c != EOF);
return(c);
}
int nextchar() {
register c;
if (peekc != EMPTY) {
c = peekc;
peekc = EMPTY;
return(c);
}
c = getchar();
if (isascii(c) == 0 && c != EOF)
fatal("non-ascii char");
return(c);
}
line_line() {
register char *p,*q;
static char filebuff[MAXSTR+1];
gettyp(ptyp(sp_cst2));
lineno = (int) (argval-1);
gettyp(ptyp(sp_scon));
p = string;
q = filebuff;
while (--strsiz >= 0)
*q++ = *p++;
*q = '\0';
filename = filebuff;
}
init() {
register i;
for (i = sp_fmnem; i <= sp_lmnem; i++)
pre_hash(i,em_mnem[i - sp_fmnem]);
for (i = sp_fpseu; i <= sp_lpseu; i++)
pre_hash(i,em_pseu[i - sp_fpseu]);
/* treat '_' as letter */
/* In System III the array is called _ctype[] without the trailing '_' */
(_ctype_+1)['_'] = (_ctype_+1)['a'];
}
pre_hash(i,s) char *s; {
register unsigned h;
assert(i != 0);
h = hash(s);
for (;;) {
h++;
h %= HSIZE;
if (hashtab[h] == 0) {
hashtab[h] = i;
return;
}
}
}
int hash(s) register char *s; {
register h;
h = 0;
while (*s) {
h <<= 1;
h += *s++;
}
return(h);
}
/* ----- output ----- */
putarg(sp) register sp; {
register i;
switch (sp) {
case sp_ilb2:
i = (int) argval;
if (fit8u(i)) {
put8(sp_ilb1);
put8(i);
break;
}
put8(sp);
put16(i);
break;
case sp_dlb2:
i = dlbval;
if (fit8u(i)) {
put8(sp_dlb1);
put8(i);
break;
}
put8(sp);
put16(i);
break;
case sp_cst2:
case sp_cst4:
if (fit16i(argval) == 0) {
put8(sp_cst4);
put32(argval);
break;
}
i = (int) argval;
if (i >= -sp_zcst0 && i < sp_ncst0 - sp_zcst0) {
put8(i + sp_zcst0 + sp_fcst0);
break;
}
put8(sp_cst2);
put16(i);
break;
case sp_doff:
put8(sp);
putarg(offtyp);
putarg(sp_cst4);
break;
case sp_dnam:
case sp_pnam:
case sp_scon:
put8(sp);
putstr();
break;
case sp_icon:
case sp_ucon:
case sp_fcon:
put8(sp);
putarg(sp_cst4);
putstr();
break;
case sp_cend:
put8(sp);
break;
}
}
putstr() {
register char *p;
long consiz;
consiz = argval;
argval = strsiz;
putarg(sp_cst4);
argval = consiz;
p = string;
while (--strsiz >= 0)
put8(*p++);
}
put16(w) int w; {
put8(w);
put8(w >> 8);
}
put32(f) long f; {
put16((int) f);
put16((int)(f >> 16));
}
/* ----- error handling ----- */
fail_check() {
error("argument range error");
}
/* VARARGS */
error(s,a1,a2,a3,a4) char *s; {
fprintf(stderr,"%s: line %d: ", filename, lineno);
fprintf(stderr,s,a1,a2,a3,a4);
fprintf(stderr,"\n");
errors++;
}
/* VARARGS */
fatal(s,a1,a2,a3,a4) char *s; {
error(s,a1,a2,a3,a4);
exit(-1);
}
/* VARARGS */
syntax(s,a1,a2,a3,a4) char *s; {
register c;
error(s,a1,a2,a3,a4);
do
c = nextchar();
while (c != '\n' && c != EOF);
longjmp(recover);
}