ANSI C conversion
This commit is contained in:
parent
708c1ba1b0
commit
de45c1036d
27 changed files with 1370 additions and 960 deletions
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
@ -12,13 +14,11 @@ static char rcsid[] = "$Id$";
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "equiv.h"
|
#include "equiv.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
/*
|
#include "gencode.h"
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
#include "reg.h"
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
#include "salloc.h"
|
||||||
*
|
#include "fillem.h"
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define SHORTCUT /* Stop searching at distance 0 */
|
#define SHORTCUT /* Stop searching at distance 0 */
|
||||||
|
|
||||||
|
@ -31,14 +31,16 @@ static char rcsid[] = "$Id$";
|
||||||
#define MAXPATTERN 5
|
#define MAXPATTERN 5
|
||||||
#define MAXREPLLEN 5 /* Max length of EM-replacement, should come from boot */
|
#define MAXREPLLEN 5 /* Max length of EM-replacement, should come from boot */
|
||||||
|
|
||||||
byte startupcode[] = { DO_NEXTEM };
|
byte startupcode[] =
|
||||||
|
{ DO_NEXTEM };
|
||||||
|
|
||||||
byte *nextem();
|
extern byte *nextem(int);
|
||||||
unsigned costcalc();
|
|
||||||
unsigned docoerc();
|
|
||||||
unsigned stackupto();
|
|
||||||
string tostring();
|
string tostring();
|
||||||
|
|
||||||
|
extern int move(token_p,token_p,int,int,unsigned int);
|
||||||
|
extern struct perm* tuples(rl_p*, int);
|
||||||
|
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#define DEBUG(xxxxx)
|
#define DEBUG(xxxxx)
|
||||||
#else
|
#else
|
||||||
|
@ -49,7 +51,11 @@ string tostring();
|
||||||
#define BROKE() {assert(origcp!=startupcode);DEBUG("BROKE");goto doreturn;}
|
#define BROKE() {assert(origcp!=startupcode);DEBUG("BROKE");goto doreturn;}
|
||||||
#define CHKCOST() {if (totalcost>=costlimit) BROKE();}
|
#define CHKCOST() {if (totalcost>=costlimit) BROKE();}
|
||||||
|
|
||||||
unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned costlimit; {
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, int forced)
|
||||||
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
byte *origcp = codep;
|
byte *origcp = codep;
|
||||||
static int level = 0;
|
static int level = 0;
|
||||||
|
@ -93,69 +99,89 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
|
||||||
token_p regtp[MAXCREG];
|
token_p regtp[MAXCREG];
|
||||||
c3_p regcp[MAXCREG];
|
c3_p regcp[MAXCREG];
|
||||||
rl_p regls[MAXCREG];
|
rl_p regls[MAXCREG];
|
||||||
c3_p findcoerc();
|
#ifdef MAXSPLIT
|
||||||
int sret;
|
int sret;
|
||||||
|
#endif /* MAXSPLIT */
|
||||||
token_t reptoken[MAXREPLLEN];
|
token_t reptoken[MAXREPLLEN];
|
||||||
int emrepllen, eminstr;
|
int emrepllen, eminstr;
|
||||||
int inscoerc = 0;
|
int inscoerc = 0;
|
||||||
int stackpad;
|
int stackpad;
|
||||||
struct perm *tup,*ntup,*besttup,*tuples();
|
struct perm *tup, *ntup, *besttup;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
level++;
|
level++;
|
||||||
DEBUG("Entering codegen");
|
DEBUG("Entering codegen");
|
||||||
#endif
|
#endif
|
||||||
for (;;) {
|
for (;;)
|
||||||
switch( (*codep++)&037 ) {
|
{
|
||||||
|
switch ((*codep++) & 037)
|
||||||
|
{
|
||||||
default:
|
default:
|
||||||
assert(FALSE);
|
assert(FALSE);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case DO_NEXTEM:
|
case DO_NEXTEM:
|
||||||
DEBUG("NEXTEM");
|
DEBUG("NEXTEM")
|
||||||
|
;
|
||||||
tokpatlen = 0;
|
tokpatlen = 0;
|
||||||
nallreg = 0;
|
nallreg = 0;
|
||||||
if (toplevel) {
|
if (toplevel)
|
||||||
|
{
|
||||||
garbage_collect();
|
garbage_collect();
|
||||||
totalcost = 0;
|
totalcost = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (--ply <= 0)
|
if (--ply <= 0)
|
||||||
goto doreturn;
|
goto doreturn;
|
||||||
}
|
}
|
||||||
if (stackheight > MAXFSTACK - 7)
|
if (stackheight > MAXFSTACK - 7)
|
||||||
totalcost += stackupto(&fakestack[6], ply, toplevel);
|
totalcost += stackupto(&fakestack[6], ply, toplevel);
|
||||||
bp = nextem(toplevel);
|
bp = nextem(toplevel);
|
||||||
if (bp == 0) {
|
if (bp == 0)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* No pattern found, can be pseudo or error
|
* No pattern found, can be pseudo or error
|
||||||
* in table.
|
* in table.
|
||||||
*/
|
*/
|
||||||
if (toplevel) {
|
if (toplevel)
|
||||||
|
{
|
||||||
codep--;
|
codep--;
|
||||||
DEBUG("pseudo");
|
DEBUG("pseudo");
|
||||||
dopseudo();
|
dopseudo();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
goto doreturn;
|
goto doreturn;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
chkregs();
|
chkregs();
|
||||||
#endif
|
#endif
|
||||||
if (! toplevel) {
|
if (!toplevel)
|
||||||
|
{
|
||||||
ply -= emp - saveemp + 1;
|
ply -= emp - saveemp + 1;
|
||||||
if (ply <= 0) ply = 1;
|
if (ply <= 0)
|
||||||
|
ply = 1;
|
||||||
}
|
}
|
||||||
n = *bp++;
|
n = *bp++;
|
||||||
assert(n>0 && n<=MAXRULE);
|
assert(n>0 && n<=MAXRULE);
|
||||||
if (n>1) {
|
if (n > 1)
|
||||||
mindistance = MAXINT; npos=0;
|
{
|
||||||
for(i=0;i<n;i++) {
|
mindistance = MAXINT;
|
||||||
|
npos = 0;
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
getint(cindex, bp);
|
getint(cindex, bp);
|
||||||
dist = distance(cindex);
|
dist = distance(cindex);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (Debug)
|
if (Debug)
|
||||||
fprintf(stderr,"distance of pos %d is %u\n",i,dist);
|
fprintf(stderr, "distance of pos %d is %u\n", i,
|
||||||
|
dist);
|
||||||
#endif
|
#endif
|
||||||
if (dist<=mindistance) {
|
if (dist <= mindistance)
|
||||||
if (dist<mindistance) {
|
{
|
||||||
|
if (dist < mindistance)
|
||||||
|
{
|
||||||
#ifdef SHORTCUT
|
#ifdef SHORTCUT
|
||||||
if (dist == 0)
|
if (dist == 0)
|
||||||
goto gotit;
|
goto gotit;
|
||||||
|
@ -167,35 +193,45 @@ if (Debug)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(mindistance<MAXINT);
|
assert(mindistance<MAXINT);
|
||||||
if (npos>1) {
|
if (npos > 1)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* More than 1 tokenpattern is a candidate.
|
* More than 1 tokenpattern is a candidate.
|
||||||
* Decision has to be made by lookahead.
|
* Decision has to be made by lookahead.
|
||||||
*/
|
*/
|
||||||
SAVEST;
|
SAVEST;
|
||||||
mincost = costlimit - totalcost + 1;
|
mincost = costlimit - totalcost + 1;
|
||||||
for(i=0;i<npos;i++) {
|
for (i = 0; i < npos; i++)
|
||||||
|
{
|
||||||
t = codegen(&coderules[pos[i]], ply, FALSE,
|
t = codegen(&coderules[pos[i]], ply, FALSE,
|
||||||
costlimit<MAXINT?mincost:MAXINT,0);
|
costlimit < MAXINT ? mincost : MAXINT,
|
||||||
|
0);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (Debug)
|
if (Debug)
|
||||||
fprintf(stderr,"mincost %u,cost %u,pos %d\n",mincost,t,i);
|
fprintf(stderr,
|
||||||
|
"mincost %u,cost %u,pos %d\n",
|
||||||
|
mincost, t, i);
|
||||||
#endif
|
#endif
|
||||||
if (t<mincost) {
|
if (t < mincost)
|
||||||
|
{
|
||||||
mincost = t;
|
mincost = t;
|
||||||
cindex = pos[i];
|
cindex = pos[i];
|
||||||
}
|
}
|
||||||
RESTST;
|
RESTST;
|
||||||
}
|
} FREEST;
|
||||||
FREEST;
|
if (totalcost + mincost > costlimit)
|
||||||
if (totalcost+mincost>costlimit) {
|
{
|
||||||
totalcost += mincost;
|
totalcost += mincost;
|
||||||
BROKE();
|
BROKE();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
cindex = pos[0];
|
cindex = pos[0];
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
getint(cindex, bp);
|
getint(cindex, bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,34 +244,43 @@ if (Debug)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DO_COERC:
|
case DO_COERC:
|
||||||
DEBUG("COERC");
|
DEBUG("COERC")
|
||||||
|
;
|
||||||
tokpatlen = 1;
|
tokpatlen = 1;
|
||||||
inscoerc = 1;
|
inscoerc = 1;
|
||||||
break;
|
break;
|
||||||
case DO_XXMATCH:
|
case DO_XXMATCH:
|
||||||
DEBUG("XXMATCH");
|
DEBUG("XXMATCH")
|
||||||
|
;
|
||||||
case DO_XMATCH:
|
case DO_XMATCH:
|
||||||
DEBUG("XMATCH");
|
DEBUG("XMATCH")
|
||||||
|
;
|
||||||
tokpatlen = (codep[-1] >> 5) & 07;
|
tokpatlen = (codep[-1] >> 5) & 07;
|
||||||
for (i = 0; i < tokpatlen; i++)
|
for (i = 0; i < tokpatlen; i++)
|
||||||
getint(tokexp[i],codep);
|
getint(tokexp[i], codep)
|
||||||
|
;
|
||||||
tokexp[i] = 0;
|
tokexp[i] = 0;
|
||||||
break; /* match already checked by distance() */
|
break; /* match already checked by distance() */
|
||||||
case DO_MATCH:
|
case DO_MATCH:
|
||||||
DEBUG("MATCH");
|
DEBUG("MATCH")
|
||||||
|
;
|
||||||
tokpatlen = (codep[-1] >> 5) & 07;
|
tokpatlen = (codep[-1] >> 5) & 07;
|
||||||
for (i = 0; i < tokpatlen; i++)
|
for (i = 0; i < tokpatlen; i++)
|
||||||
getint(tokexp[i],codep);
|
getint(tokexp[i], codep)
|
||||||
|
;
|
||||||
tokexp[i] = 0;
|
tokexp[i] = 0;
|
||||||
tp = &fakestack[stackheight - 1];
|
tp = &fakestack[stackheight - 1];
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i<tokpatlen && tp>=fakestack) {
|
while (i < tokpatlen && tp >= fakestack)
|
||||||
|
{
|
||||||
size = tsize(tp);
|
size = tsize(tp);
|
||||||
while (i<tokpatlen && (lsize=ssize(tokexp[i]))<=size) {
|
while (i < tokpatlen && (lsize = ssize(tokexp[i])) <= size)
|
||||||
|
{
|
||||||
size -= lsize;
|
size -= lsize;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (i<tokpatlen && size!=0) {
|
if (i < tokpatlen && size != 0)
|
||||||
|
{
|
||||||
totalcost += stackupto(tp, ply, toplevel);
|
totalcost += stackupto(tp, ply, toplevel);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
break;
|
break;
|
||||||
|
@ -244,13 +289,16 @@ if (Debug)
|
||||||
}
|
}
|
||||||
tp = &fakestack[stackheight - 1];
|
tp = &fakestack[stackheight - 1];
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i<tokpatlen && tp >= fakestack) {
|
while (i < tokpatlen && tp >= fakestack)
|
||||||
|
{
|
||||||
size = tsize(tp);
|
size = tsize(tp);
|
||||||
lsize = ssize(tokexp[i]);
|
lsize = ssize(tokexp[i]);
|
||||||
if (size != lsize) { /* find coercion */
|
if (size != lsize)
|
||||||
|
{ /* find coercion */
|
||||||
#ifdef MAXSPLIT
|
#ifdef MAXSPLIT
|
||||||
sret = split(tp,&tokexp[i],ply,toplevel);
|
sret = split(tp,&tokexp[i],ply,toplevel);
|
||||||
if (sret==0) {
|
if (sret==0)
|
||||||
|
{
|
||||||
#endif /* MAXSPLIT */
|
#endif /* MAXSPLIT */
|
||||||
totalcost += stackupto(tp, ply, toplevel);
|
totalcost += stackupto(tp, ply, toplevel);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
|
@ -259,27 +307,36 @@ if (Debug)
|
||||||
}
|
}
|
||||||
i += sret;
|
i += sret;
|
||||||
#endif /* MAXSPLIT */
|
#endif /* MAXSPLIT */
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
i += 1;
|
i += 1;
|
||||||
tp--;
|
tp--;
|
||||||
}
|
}
|
||||||
nextmatch:
|
nextmatch: tp = &fakestack[stackheight - 1];
|
||||||
tp = &fakestack[stackheight-1];
|
i = 0;
|
||||||
i=0; nregneeded = 0;
|
nregneeded = 0;
|
||||||
while (i<tokpatlen && tp>=fakestack) {
|
while (i < tokpatlen && tp >= fakestack)
|
||||||
if (!match(tp,&machsets[tokexp[i]],0)) {
|
{
|
||||||
|
if (!match(tp, &machsets[tokexp[i]], 0))
|
||||||
|
{
|
||||||
register c3_p cp = findcoerc(tp, &machsets[tokexp[i]]);
|
register c3_p cp = findcoerc(tp, &machsets[tokexp[i]]);
|
||||||
if (cp==0) {
|
if (cp == 0)
|
||||||
|
{
|
||||||
for (j = 0; j < nregneeded; j++)
|
for (j = 0; j < nregneeded; j++)
|
||||||
regtp[j] -= (tp - fakestack + 1);
|
regtp[j] -= (tp - fakestack + 1);
|
||||||
totalcost += stackupto(tp, ply, toplevel);
|
totalcost += stackupto(tp, ply, toplevel);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
if (cp->c3_prop==0) {
|
else
|
||||||
|
{
|
||||||
|
if (cp->c3_prop == 0)
|
||||||
|
{
|
||||||
totalcost += docoerc(tp, cp, ply, toplevel, 0);
|
totalcost += docoerc(tp, cp, ply, toplevel, 0);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
assert(nregneeded<MAXCREG);
|
assert(nregneeded<MAXCREG);
|
||||||
regtp[nregneeded] = tp;
|
regtp[nregneeded] = tp;
|
||||||
regcp[nregneeded] = cp;
|
regcp[nregneeded] = cp;
|
||||||
|
@ -288,12 +345,16 @@ if (Debug)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++; tp--;
|
i++;
|
||||||
|
tp--;
|
||||||
}
|
}
|
||||||
if (tokpatlen>stackheight) {
|
if (tokpatlen > stackheight)
|
||||||
|
{
|
||||||
int k;
|
int k;
|
||||||
stackpad = tokpatlen - stackheight;
|
stackpad = tokpatlen - stackheight;
|
||||||
for (j=stackheight-1, k = j + stackpad;j>=0;j--, k--) {
|
for (j = stackheight - 1, k = j + stackpad; j >= 0;
|
||||||
|
j--, k--)
|
||||||
|
{
|
||||||
fakestack[k] = fakestack[j];
|
fakestack[k] = fakestack[j];
|
||||||
/* fakestack[j+stackpad] = fakestack[j]; does not
|
/* fakestack[j+stackpad] = fakestack[j]; does not
|
||||||
compile under Xenix
|
compile under Xenix
|
||||||
|
@ -305,28 +366,36 @@ if (Debug)
|
||||||
for (j = 0; j < nregneeded; j++)
|
for (j = 0; j < nregneeded; j++)
|
||||||
regtp[j] += stackpad;
|
regtp[j] += stackpad;
|
||||||
tp = &fakestack[stackpad - 1];
|
tp = &fakestack[stackpad - 1];
|
||||||
while (i<tokpatlen && tp>=fakestack) {
|
while (i < tokpatlen && tp >= fakestack)
|
||||||
register c3_p cp = findcoerc((token_p) 0, &machsets[tokexp[i]]);
|
{
|
||||||
if (cp==0) {
|
register c3_p cp = findcoerc((token_p) 0,
|
||||||
|
&machsets[tokexp[i]]);
|
||||||
|
if (cp == 0)
|
||||||
|
{
|
||||||
assert(!toplevel);
|
assert(!toplevel);
|
||||||
for (j = 0; j < nregneeded; j++)
|
for (j = 0; j < nregneeded; j++)
|
||||||
myfree(regls[j]);
|
myfree(regls[j]);
|
||||||
totalcost = INFINITY;
|
totalcost = INFINITY;
|
||||||
BROKE();
|
BROKE();
|
||||||
}
|
}
|
||||||
if (cp->c3_prop==0) {
|
if (cp->c3_prop == 0)
|
||||||
|
{
|
||||||
totalcost += docoerc(tp, cp, ply, toplevel, 0);
|
totalcost += docoerc(tp, cp, ply, toplevel, 0);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
assert(nregneeded<MAXCREG);
|
assert(nregneeded<MAXCREG);
|
||||||
regtp[nregneeded] = tp;
|
regtp[nregneeded] = tp;
|
||||||
regcp[nregneeded] = cp;
|
regcp[nregneeded] = cp;
|
||||||
regls[nregneeded] = curreglist;
|
regls[nregneeded] = curreglist;
|
||||||
nregneeded++;
|
nregneeded++;
|
||||||
}
|
}
|
||||||
i++; tp--;
|
i++;
|
||||||
|
tp--;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
stackpad = 0;
|
stackpad = 0;
|
||||||
assert(i == tokpatlen);
|
assert(i == tokpatlen);
|
||||||
if (nregneeded == 0)
|
if (nregneeded == 0)
|
||||||
|
@ -335,49 +404,62 @@ if (Debug)
|
||||||
mincost = costlimit - totalcost + 1;
|
mincost = costlimit - totalcost + 1;
|
||||||
tup = tuples(regls, nregneeded);
|
tup = tuples(regls, nregneeded);
|
||||||
besttup = 0;
|
besttup = 0;
|
||||||
for (; tup != 0; tup = ntup) {
|
for (; tup != 0; tup = ntup)
|
||||||
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if(Debug>1) { fprintf(stderr,"Next tuple %d,%d,%d,%d\n",
|
if (Debug > 1)
|
||||||
tup->p_rar[0],
|
{
|
||||||
tup->p_rar[1],
|
fprintf(stderr, "Next tuple %d,%d,%d,%d\n",
|
||||||
tup->p_rar[2],
|
tup->p_rar[0], tup->p_rar[1], tup->p_rar[2],
|
||||||
tup->p_rar[3]);
|
tup->p_rar[3]);
|
||||||
fprintf(stderr, "totalcost = %u, costlimit = %u, mincost = %u\n",
|
fprintf(stderr,
|
||||||
|
"totalcost = %u, costlimit = %u, mincost = %u\n",
|
||||||
totalcost, costlimit, mincost);
|
totalcost, costlimit, mincost);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
ntup = tup->p_next;
|
ntup = tup->p_next;
|
||||||
for (i = 0, t = 0; i < nregneeded && t < mincost; i++)
|
for (i = 0, t = 0; i < nregneeded && t < mincost; i++)
|
||||||
t += docoerc(regtp[i],regcp[i],ply,FALSE,tup->p_rar[i]);
|
t += docoerc(regtp[i], regcp[i], ply, FALSE,
|
||||||
|
tup->p_rar[i]);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
if (Debug > 1)
|
||||||
|
fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
#endif
|
#endif
|
||||||
if (t < mincost)
|
if (t < mincost)
|
||||||
t += codegen(codep,ply,FALSE,mincost<MAXINT?mincost-t:MAXINT,0);
|
t += codegen(codep, ply, FALSE,
|
||||||
if (t<mincost) {
|
mincost < MAXINT ? mincost - t : MAXINT, 0);
|
||||||
|
if (t < mincost)
|
||||||
|
{
|
||||||
mincost = t;
|
mincost = t;
|
||||||
besttup = tup;
|
besttup = tup;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
myfree(tup);
|
myfree(tup);
|
||||||
RESTST;
|
RESTST;
|
||||||
}
|
}
|
||||||
FREEST;
|
FREEST;
|
||||||
for (i = 0; i < nregneeded; i++)
|
for (i = 0; i < nregneeded; i++)
|
||||||
myfree(regls[i]);
|
myfree(regls[i]);
|
||||||
if (totalcost+mincost>costlimit) {
|
if (totalcost + mincost > costlimit)
|
||||||
|
{
|
||||||
if (besttup)
|
if (besttup)
|
||||||
myfree(besttup);
|
myfree(besttup);
|
||||||
if (stackpad!=tokpatlen) {
|
if (stackpad != tokpatlen)
|
||||||
if (stackpad) {
|
{
|
||||||
if (costlimit<MAXINT) {
|
if (stackpad)
|
||||||
|
{
|
||||||
|
if (costlimit < MAXINT)
|
||||||
|
{
|
||||||
totalcost = costlimit + 1;
|
totalcost = costlimit + 1;
|
||||||
BROKE();
|
BROKE();
|
||||||
}
|
}
|
||||||
for (i = 0; i < stackheight - stackpad; i++)
|
for (i = 0; i < stackheight - stackpad; i++)
|
||||||
fakestack[i] = fakestack[i + stackpad];
|
fakestack[i] = fakestack[i + stackpad];
|
||||||
stackheight -= stackpad;
|
stackheight -= stackpad;
|
||||||
totalcost += stackupto(&fakestack[stackheight-1],ply,toplevel);
|
totalcost += stackupto(&fakestack[stackheight - 1],
|
||||||
} else
|
ply, toplevel);
|
||||||
|
}
|
||||||
|
else
|
||||||
totalcost += stackupto(fakestack, ply, toplevel);
|
totalcost += stackupto(fakestack, ply, toplevel);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
goto nextmatch;
|
goto nextmatch;
|
||||||
|
@ -386,20 +468,27 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
BROKE();
|
BROKE();
|
||||||
}
|
}
|
||||||
for (i = 0; i < nregneeded; i++)
|
for (i = 0; i < nregneeded; i++)
|
||||||
totalcost += docoerc(regtp[i],regcp[i],ply,toplevel,besttup->p_rar[i]);
|
totalcost += docoerc(regtp[i], regcp[i], ply, toplevel,
|
||||||
|
besttup->p_rar[i]);
|
||||||
myfree(besttup);
|
myfree(besttup);
|
||||||
break;
|
break;
|
||||||
case DO_REMOVE:
|
case DO_REMOVE:
|
||||||
DEBUG("REMOVE");
|
DEBUG("REMOVE")
|
||||||
if (codep[-1]&32) {
|
;
|
||||||
|
if (codep[-1] & 32)
|
||||||
|
{
|
||||||
getint(texpno, codep);
|
getint(texpno, codep);
|
||||||
getint(nodeno, codep);
|
getint(nodeno, codep);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
getint(texpno, codep);
|
getint(texpno, codep);
|
||||||
nodeno = 0;
|
nodeno = 0;
|
||||||
}
|
}
|
||||||
for (tp= &fakestack[stackheight-tokpatlen-1];tp>=&fakestack[0];tp--)
|
for (tp = &fakestack[stackheight - tokpatlen - 1];
|
||||||
if (match(tp,&machsets[texpno],nodeno)) {
|
tp >= &fakestack[0]; tp--)
|
||||||
|
if (match(tp, &machsets[texpno], nodeno))
|
||||||
|
{
|
||||||
/* investigate possible coercion to register */
|
/* investigate possible coercion to register */
|
||||||
totalcost += stackupto(tp, ply, toplevel);
|
totalcost += stackupto(tp, ply, toplevel);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
|
@ -410,34 +499,44 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
rp->r_contents.t_token = 0;
|
rp->r_contents.t_token = 0;
|
||||||
break;
|
break;
|
||||||
case DO_RREMOVE: /* register remove */
|
case DO_RREMOVE: /* register remove */
|
||||||
DEBUG("RREMOVE");
|
DEBUG("RREMOVE")
|
||||||
getint(nodeno,codep);
|
;
|
||||||
|
getint(nodeno, codep)
|
||||||
|
;
|
||||||
result = compute(&enodes[nodeno]);
|
result = compute(&enodes[nodeno]);
|
||||||
assert(result.e_typ==EV_REG);
|
assert(result.e_typ==EV_REG);
|
||||||
for (tp= &fakestack[stackheight-tokpatlen-1];tp>=&fakestack[0];tp--)
|
for (tp = &fakestack[stackheight - tokpatlen - 1];
|
||||||
if (tp->t_token==-1) {
|
tp >= &fakestack[0]; tp--)
|
||||||
|
if (tp->t_token == -1)
|
||||||
|
{
|
||||||
if (tp->t_att[0].ar == result.e_v.e_reg)
|
if (tp->t_att[0].ar == result.e_v.e_reg)
|
||||||
goto gotone;
|
goto gotone;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
tdp = &tokens[tp->t_token];
|
tdp = &tokens[tp->t_token];
|
||||||
for (i = 0; i < TOKENSIZE; i++)
|
for (i = 0; i < TOKENSIZE; i++)
|
||||||
if (tdp->t_type[i]==EV_REG &&
|
if (tdp->t_type[i] == EV_REG
|
||||||
tp->t_att[i].ar==result.e_v.e_reg)
|
&& tp->t_att[i].ar == result.e_v.e_reg)
|
||||||
goto gotone;
|
goto gotone;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
gotone:
|
gotone:
|
||||||
/* investigate possible coercion to register */
|
/* investigate possible coercion to register */
|
||||||
totalcost += stackupto(tp, ply, toplevel);
|
totalcost += stackupto(tp, ply, toplevel);
|
||||||
CHKCOST();
|
CHKCOST()
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
case DO_DEALLOCATE:
|
case DO_DEALLOCATE:
|
||||||
DEBUG("DEALLOCATE");
|
DEBUG("DEALLOCATE")
|
||||||
getint(tinstno,codep);
|
;
|
||||||
|
getint(tinstno, codep)
|
||||||
|
;
|
||||||
instance(tinstno, &token);
|
instance(tinstno, &token);
|
||||||
if (token.t_token == -1)
|
if (token.t_token == -1)
|
||||||
chrefcount(token.t_att[0].ar, -1, TRUE);
|
chrefcount(token.t_att[0].ar, -1, TRUE);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
tdp = &tokens[token.t_token];
|
tdp = &tokens[token.t_token];
|
||||||
for (i = 0; i < TOKENSIZE; i++)
|
for (i = 0; i < TOKENSIZE; i++)
|
||||||
if (tdp->t_type[i] == EV_REG)
|
if (tdp->t_type[i] == EV_REG)
|
||||||
|
@ -445,28 +544,37 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DO_REALLOCATE:
|
case DO_REALLOCATE:
|
||||||
DEBUG("REALLOCATE");
|
DEBUG("REALLOCATE")
|
||||||
|
;
|
||||||
for (rp = machregs; rp < machregs + NREGS; rp++)
|
for (rp = machregs; rp < machregs + NREGS; rp++)
|
||||||
if(rp->r_tcount) {
|
if (rp->r_tcount)
|
||||||
|
{
|
||||||
rp->r_refcount -= rp->r_tcount;
|
rp->r_refcount -= rp->r_tcount;
|
||||||
rp->r_tcount = 0;
|
rp->r_tcount = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DO_ALLOCATE:
|
case DO_ALLOCATE:
|
||||||
DEBUG("ALLOCATE");
|
DEBUG("ALLOCATE")
|
||||||
if (codep[-1]&32) {
|
;
|
||||||
|
if (codep[-1] & 32)
|
||||||
|
{
|
||||||
getint(propno, codep);
|
getint(propno, codep);
|
||||||
getint(tinstno, codep);
|
getint(tinstno, codep);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
getint(propno, codep);
|
getint(propno, codep);
|
||||||
tinstno = 0;
|
tinstno = 0;
|
||||||
}
|
}
|
||||||
instance(tinstno, &token);
|
instance(tinstno, &token);
|
||||||
if (!forced) {
|
if (!forced)
|
||||||
do {
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
npos = exactmatch = 0;
|
npos = exactmatch = 0;
|
||||||
for(rpp=reglist[propno];rp= *rpp; rpp++)
|
for (rpp = reglist[propno]; (rp = *rpp); rpp++)
|
||||||
if (getrefcount((int)(rp-machregs), FALSE)==0) {
|
if (getrefcount((int) (rp - machregs), FALSE) == 0)
|
||||||
|
{
|
||||||
pos[npos++] = rp - machregs;
|
pos[npos++] = rp - machregs;
|
||||||
if (eqtoken(&rp->r_contents, &token))
|
if (eqtoken(&rp->r_contents, &token))
|
||||||
exactmatch++;
|
exactmatch++;
|
||||||
|
@ -475,24 +583,33 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
* Now pos[] contains all free registers with desired
|
* Now pos[] contains all free registers with desired
|
||||||
* property. If none then some stacking has to take place.
|
* property. If none then some stacking has to take place.
|
||||||
*/
|
*/
|
||||||
if (npos==0) {
|
if (npos == 0)
|
||||||
if (stackheight<=tokpatlen) {
|
{
|
||||||
if (!toplevel) {
|
if (stackheight <= tokpatlen)
|
||||||
|
{
|
||||||
|
if (!toplevel)
|
||||||
|
{
|
||||||
totalcost = INFINITY;
|
totalcost = INFINITY;
|
||||||
BROKE();
|
BROKE();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fatal("No regs available");
|
fatal("No regs available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
totalcost += stackupto( &fakestack[0],ply,toplevel);
|
totalcost += stackupto(&fakestack[0], ply,
|
||||||
|
toplevel);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
}
|
}
|
||||||
} while (npos == 0);
|
} while (npos == 0);
|
||||||
if (!exactmatch) {
|
if (!exactmatch)
|
||||||
|
{
|
||||||
npos2 = npos;
|
npos2 = npos;
|
||||||
for (i = 0; i < npos; i++)
|
for (i = 0; i < npos; i++)
|
||||||
pos2[i] = pos[i];
|
pos2[i] = pos[i];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Now we are reducing the number of possible registers.
|
* Now we are reducing the number of possible registers.
|
||||||
* We take only one equally likely register out of every
|
* We take only one equally likely register out of every
|
||||||
|
@ -501,10 +618,12 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
mtoken = token;
|
mtoken = token;
|
||||||
npos2 = 0;
|
npos2 = 0;
|
||||||
for (i = 0; i < npos; i++)
|
for (i = 0; i < npos; i++)
|
||||||
if (eqtoken(&machregs[pos[i]].r_contents,&mtoken)) {
|
if (eqtoken(&machregs[pos[i]].r_contents, &mtoken))
|
||||||
|
{
|
||||||
pos2[npos2++] = pos[i];
|
pos2[npos2++] = pos[i];
|
||||||
for (j = 0; j < npos2 - 1; j++)
|
for (j = 0; j < npos2 - 1; j++)
|
||||||
if (eqregclass(pos2[j],pos[i])) {
|
if (eqregclass(pos2[j], pos[i]))
|
||||||
|
{
|
||||||
npos2--;
|
npos2--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -519,36 +638,45 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
token2.t_att[i].aw = 0;
|
token2.t_att[i].aw = 0;
|
||||||
if (npos2 == 1)
|
if (npos2 == 1)
|
||||||
decision = pos2[0];
|
decision = pos2[0];
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
SAVEST;
|
SAVEST;
|
||||||
mincost = costlimit - totalcost + 1;
|
mincost = costlimit - totalcost + 1;
|
||||||
for(j=0;j<npos2;j++) {
|
for (j = 0; j < npos2; j++)
|
||||||
|
{
|
||||||
chrefcount(pos2[j], 1, FALSE);
|
chrefcount(pos2[j], 1, FALSE);
|
||||||
token2.t_att[0].ar = pos2[j];
|
token2.t_att[0].ar = pos2[j];
|
||||||
allreg[nallreg++] = pos2[j];
|
allreg[nallreg++] = pos2[j];
|
||||||
if (token.t_token != 0)
|
if (token.t_token != 0)
|
||||||
t = move(&token, &token2, ply, FALSE, mincost);
|
t = move(&token, &token2, ply, FALSE, mincost);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
t = 0;
|
t = 0;
|
||||||
erasereg(pos2[j]);
|
erasereg(pos2[j]);
|
||||||
}
|
}
|
||||||
if (t < mincost)
|
if (t < mincost)
|
||||||
t += codegen(codep,ply,FALSE,mincost<MAXINT?mincost-t:MAXINT,0);
|
t += codegen(codep, ply, FALSE,
|
||||||
if (t<mincost) {
|
mincost < MAXINT ? mincost - t : MAXINT,
|
||||||
|
0);
|
||||||
|
if (t < mincost)
|
||||||
|
{
|
||||||
mincost = t;
|
mincost = t;
|
||||||
decision = pos2[j];
|
decision = pos2[j];
|
||||||
}
|
}
|
||||||
RESTST;
|
RESTST;
|
||||||
}
|
} FREEST;
|
||||||
FREEST;
|
if (totalcost + mincost > costlimit)
|
||||||
if (totalcost+mincost>costlimit) {
|
{
|
||||||
totalcost = INFINITY;
|
totalcost = INFINITY;
|
||||||
BROKE();
|
BROKE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
decision = forced;
|
decision = forced;
|
||||||
if (getrefcount(decision, FALSE)!=0) {
|
if (getrefcount(decision, FALSE) != 0)
|
||||||
|
{
|
||||||
totalcost = INFINITY;
|
totalcost = INFINITY;
|
||||||
BROKE();
|
BROKE();
|
||||||
}
|
}
|
||||||
|
@ -556,64 +684,84 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
}
|
}
|
||||||
chrefcount(decision, 1, FALSE);
|
chrefcount(decision, 1, FALSE);
|
||||||
token2.t_att[0].ar = decision;
|
token2.t_att[0].ar = decision;
|
||||||
if (token.t_token != 0) {
|
if (token.t_token != 0)
|
||||||
|
{
|
||||||
totalcost += move(&token, &token2, ply, toplevel, MAXINT);
|
totalcost += move(&token, &token2, ply, toplevel, MAXINT);
|
||||||
CHKCOST();
|
CHKCOST();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
erasereg(decision);
|
erasereg(decision);
|
||||||
allreg[nallreg++] = decision;
|
allreg[nallreg++] = decision;
|
||||||
break;
|
break;
|
||||||
case DO_LOUTPUT:
|
case DO_LOUTPUT:
|
||||||
DEBUG("LOUTPUT");
|
DEBUG("LOUTPUT")
|
||||||
getint(stringno,codep);
|
;
|
||||||
getint(nodeno,codep);
|
getint(stringno, codep)
|
||||||
if (toplevel) {
|
;
|
||||||
|
getint(nodeno, codep)
|
||||||
|
;
|
||||||
|
if (toplevel)
|
||||||
|
{
|
||||||
gencode(codestrings[stringno]);
|
gencode(codestrings[stringno]);
|
||||||
genexpr(nodeno);
|
genexpr(nodeno);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DO_ROUTPUT:
|
case DO_ROUTPUT:
|
||||||
DEBUG("ROUTPUT");
|
DEBUG("ROUTPUT")
|
||||||
|
;
|
||||||
i = ((codep[-1] >> 5) & 07);
|
i = ((codep[-1] >> 5) & 07);
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
getint(stringno, codep);
|
getint(stringno, codep);
|
||||||
if (toplevel) {
|
if (toplevel)
|
||||||
|
{
|
||||||
gencode(codestrings[stringno]);
|
gencode(codestrings[stringno]);
|
||||||
gennl();
|
gennl();
|
||||||
}
|
}
|
||||||
} while (i--);
|
} while (i--);
|
||||||
break;
|
break;
|
||||||
case DO_MOVE:
|
case DO_MOVE:
|
||||||
DEBUG("MOVE");
|
DEBUG("MOVE")
|
||||||
getint(tinstno,codep);
|
;
|
||||||
|
getint(tinstno, codep)
|
||||||
|
;
|
||||||
instance(tinstno, &token);
|
instance(tinstno, &token);
|
||||||
getint(tinstno,codep);
|
getint(tinstno, codep)
|
||||||
|
;
|
||||||
instance(tinstno, &token2);
|
instance(tinstno, &token2);
|
||||||
totalcost += move(&token,&token2,ply,toplevel,costlimit-totalcost+1);
|
totalcost += move(&token, &token2, ply, toplevel,
|
||||||
CHKCOST();
|
costlimit - totalcost + 1);
|
||||||
|
CHKCOST()
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
case DO_ERASE:
|
case DO_ERASE:
|
||||||
DEBUG("ERASE");
|
DEBUG("ERASE")
|
||||||
getint(nodeno,codep);
|
;
|
||||||
|
getint(nodeno, codep)
|
||||||
|
;
|
||||||
result = compute(&enodes[nodeno]);
|
result = compute(&enodes[nodeno]);
|
||||||
assert(result.e_typ==EV_REG);
|
assert(result.e_typ==EV_REG);
|
||||||
erasereg(result.e_v.e_reg);
|
erasereg(result.e_v.e_reg);
|
||||||
break;
|
break;
|
||||||
case DO_TOKREPLACE:
|
case DO_TOKREPLACE:
|
||||||
DEBUG("TOKREPLACE");
|
DEBUG("TOKREPLACE")
|
||||||
|
;
|
||||||
assert(stackheight >= tokpatlen);
|
assert(stackheight >= tokpatlen);
|
||||||
repllen = (codep[-1] >> 5) & 07;
|
repllen = (codep[-1] >> 5) & 07;
|
||||||
for(i=0;i<repllen;i++) {
|
for (i = 0; i < repllen; i++)
|
||||||
|
{
|
||||||
getint(tinstno, codep);
|
getint(tinstno, codep);
|
||||||
instance(tinstno, &reptoken[i]);
|
instance(tinstno, &reptoken[i]);
|
||||||
tref(&reptoken[i], 1);
|
tref(&reptoken[i], 1);
|
||||||
}
|
}
|
||||||
for(i=0;i<tokpatlen;i++) {
|
for (i = 0; i < tokpatlen; i++)
|
||||||
|
{
|
||||||
if (!inscoerc)
|
if (!inscoerc)
|
||||||
tref(&fakestack[stackheight - 1], -1);
|
tref(&fakestack[stackheight - 1], -1);
|
||||||
stackheight--;
|
stackheight--;
|
||||||
}
|
}
|
||||||
for (i=0;i<repllen;i++) {
|
for (i = 0; i < repllen; i++)
|
||||||
|
{
|
||||||
assert(stackheight<MAXFSTACK);
|
assert(stackheight<MAXFSTACK);
|
||||||
fakestack[stackheight] = reptoken[i];
|
fakestack[stackheight] = reptoken[i];
|
||||||
stackheight++;
|
stackheight++;
|
||||||
|
@ -625,10 +773,12 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
chrefcount(allreg[i], -1, FALSE);
|
chrefcount(allreg[i], -1, FALSE);
|
||||||
break;
|
break;
|
||||||
case DO_EMREPLACE:
|
case DO_EMREPLACE:
|
||||||
DEBUG("EMREPLACE");
|
DEBUG("EMREPLACE")
|
||||||
|
;
|
||||||
emrepllen = (codep[-1] >> 5) & 07;
|
emrepllen = (codep[-1] >> 5) & 07;
|
||||||
j = emp - emlines;
|
j = emp - emlines;
|
||||||
if (emrepllen>j) {
|
if (emrepllen > j)
|
||||||
|
{
|
||||||
int k = nemlines + emrepllen - j;
|
int k = nemlines + emrepllen - j;
|
||||||
assert(k<MAXEMLINES);
|
assert(k<MAXEMLINES);
|
||||||
for (i = nemlines; i >= 0; i--, k--)
|
for (i = nemlines; i >= 0; i--, k--)
|
||||||
|
@ -637,12 +787,14 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
emp += emrepllen - j;
|
emp += emrepllen - j;
|
||||||
}
|
}
|
||||||
emp -= emrepllen;
|
emp -= emrepllen;
|
||||||
for (i=0;i<emrepllen;i++) {
|
for (i = 0; i < emrepllen; i++)
|
||||||
|
{
|
||||||
getint(eminstr, codep);
|
getint(eminstr, codep);
|
||||||
getint(nodeno, codep);
|
getint(nodeno, codep);
|
||||||
emp[i].em_instr = eminstr;
|
emp[i].em_instr = eminstr;
|
||||||
result = compute(&enodes[nodeno]);
|
result = compute(&enodes[nodeno]);
|
||||||
switch(result.e_typ) {
|
switch (result.e_typ)
|
||||||
|
{
|
||||||
default:
|
default:
|
||||||
assert(FALSE);
|
assert(FALSE);
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -660,27 +812,34 @@ if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!toplevel) {
|
if (!toplevel)
|
||||||
|
{
|
||||||
ply += emrepllen;
|
ply += emrepllen;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DO_COST:
|
case DO_COST:
|
||||||
DEBUG("COST");
|
DEBUG("COST")
|
||||||
getint(cost.c_size,codep);
|
;
|
||||||
getint(cost.c_time,codep);
|
getint(cost.c_size, codep)
|
||||||
|
;
|
||||||
|
getint(cost.c_time, codep)
|
||||||
|
;
|
||||||
totalcost += costcalc(cost);
|
totalcost += costcalc(cost);
|
||||||
CHKCOST();
|
CHKCOST()
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
#ifdef REGVARS
|
#ifdef REGVARS
|
||||||
case DO_PRETURN:
|
case DO_PRETURN:
|
||||||
if (toplevel) {
|
if (toplevel)
|
||||||
|
{
|
||||||
swtxt();
|
swtxt();
|
||||||
regreturn(); /* in mach.c */
|
regreturn(); /* in mach.c */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case DO_RETURN:
|
case DO_RETURN:
|
||||||
DEBUG("RETURN");
|
DEBUG("RETURN")
|
||||||
|
;
|
||||||
assert(origcp != startupcode);
|
assert(origcp != startupcode);
|
||||||
doreturn:
|
doreturn:
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
13
mach/proto/cg/codegen.h
Normal file
13
mach/proto/cg/codegen.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-14
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef CODEGEN_H_
|
||||||
|
#define CODEGEN_H_
|
||||||
|
|
||||||
|
unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, int forced);
|
||||||
|
|
||||||
|
#endif /* CODEGEN_H_ */
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -14,13 +16,9 @@ static char rcsid[] = "$Id$";
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "glosym.h"
|
#include "glosym.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define LLEAF 01
|
#define LLEAF 01
|
||||||
#define LDEF 02
|
#define LDEF 02
|
||||||
|
@ -73,9 +71,10 @@ char opdesc[] = {
|
||||||
LLDEF, /* EX_REGVAR */
|
LLDEF, /* EX_REGVAR */
|
||||||
};
|
};
|
||||||
|
|
||||||
string salloc();
|
|
||||||
|
|
||||||
string mycat(s1,s2) string s1,s2; {
|
|
||||||
|
string mycat(string s1,string s2)
|
||||||
|
{
|
||||||
register string s;
|
register string s;
|
||||||
|
|
||||||
s=salloc(strlen(s1)+strlen(s2));
|
s=salloc(strlen(s1)+strlen(s2));
|
||||||
|
@ -84,7 +83,8 @@ string mycat(s1,s2) string s1,s2; {
|
||||||
return(s);
|
return(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
string mystrcpy(s) string s; {
|
string mystrcpy(string s)
|
||||||
|
{
|
||||||
register string r;
|
register string r;
|
||||||
|
|
||||||
r=salloc(strlen(s));
|
r=salloc(strlen(s));
|
||||||
|
@ -94,7 +94,8 @@ string mystrcpy(s) string s; {
|
||||||
|
|
||||||
char digstr[21][15];
|
char digstr[21][15];
|
||||||
|
|
||||||
string tostring(n) word n; {
|
string tostring(word n)
|
||||||
|
{
|
||||||
char buf[25];
|
char buf[25];
|
||||||
|
|
||||||
if (n>=-20 && n<=20 && (n&1)==0) {
|
if (n>=-20 && n<=20 && (n&1)==0) {
|
||||||
|
@ -108,7 +109,8 @@ string tostring(n) word n; {
|
||||||
|
|
||||||
result_t undefres= {EV_UNDEF};
|
result_t undefres= {EV_UNDEF};
|
||||||
|
|
||||||
result_t compute(node) register node_p node; {
|
result_t compute(register node_p node)
|
||||||
|
{
|
||||||
result_t leaf1,leaf2,result;
|
result_t leaf1,leaf2,result;
|
||||||
token_p tp;
|
token_p tp;
|
||||||
int desc;
|
int desc;
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
* (c) copyright 1987 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".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef DATA_H_
|
||||||
|
#define DATA_H_
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int t_token; /* kind of token, -1 for register */
|
int t_token; /* kind of token, -1 for register */
|
||||||
|
@ -56,3 +59,5 @@ typedef struct {
|
||||||
int rl_n; /* number in list */
|
int rl_n; /* number in list */
|
||||||
int rl_list[NREGS];
|
int rl_list[NREGS];
|
||||||
} rl_t,*rl_p;
|
} rl_t,*rl_p;
|
||||||
|
|
||||||
|
#endif /* DATA_H_ */
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "equiv.h"
|
#include "equiv.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
@ -11,15 +13,12 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
#include "reg.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern string myalloc();
|
|
||||||
|
|
||||||
int rar[MAXCREG];
|
int rar[MAXCREG];
|
||||||
rl_p* lar;
|
rl_p* lar;
|
||||||
|
@ -27,12 +26,12 @@ int maxindex;
|
||||||
int regclass[NREGS];
|
int regclass[NREGS];
|
||||||
struct perm* perms;
|
struct perm* perms;
|
||||||
|
|
||||||
void permute(int index);
|
static void permute(int index);
|
||||||
|
|
||||||
struct perm* tuples(rl_p* regls, int nregneeded)
|
struct perm* tuples(rl_p* regls, int nregneeded)
|
||||||
{
|
{
|
||||||
int class = 0;
|
int class = 0;
|
||||||
register i, j;
|
register int i, j;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First compute equivalence classes of registers.
|
* First compute equivalence classes of registers.
|
||||||
|
@ -66,11 +65,11 @@ struct perm* tuples(rl_p* regls, int nregneeded)
|
||||||
return (perms);
|
return (perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void permute(int index)
|
static void permute(int index)
|
||||||
{
|
{
|
||||||
register struct perm* pp;
|
register struct perm* pp;
|
||||||
register rl_p rlp;
|
register rl_p rlp;
|
||||||
register i, j;
|
register int i, j;
|
||||||
|
|
||||||
if (index == maxindex)
|
if (index == maxindex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
* (c) copyright 1987 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".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef EQUIV_H_
|
||||||
|
#define EQUIV_H_
|
||||||
|
|
||||||
|
|
||||||
#define MAXCREG 4
|
#define MAXCREG 4
|
||||||
|
|
||||||
|
@ -10,3 +12,6 @@ struct perm {
|
||||||
struct perm *p_next;
|
struct perm *p_next;
|
||||||
int p_rar[MAXCREG];
|
int p_rar[MAXCREG];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* EQUIV_H_ */
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid2[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -18,23 +20,48 @@ static char rcsid2[] = "$Id$";
|
||||||
#include <cg_pattern.h>
|
#include <cg_pattern.h>
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "reg.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
#include "gencode.h"
|
||||||
|
#include "glosym.h"
|
||||||
#ifdef REGVARS
|
#ifdef REGVARS
|
||||||
#include "regvar.h"
|
#include "regvar.h"
|
||||||
#include <em_reg.h>
|
#include <em_reg.h>
|
||||||
#endif
|
#endif
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef newplb /* retrofit for older mach.h */
|
#ifndef newplb /* retrofit for older mach.h */
|
||||||
#define newplb newilb
|
#define newplb newilb
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
string tostring();
|
||||||
|
static string holstr(word n);
|
||||||
|
static char *strarg(int t);
|
||||||
|
string mystrcpy();
|
||||||
|
static int get16(void);
|
||||||
|
static long get32(void);
|
||||||
|
static int getarg(int typset);
|
||||||
|
static void getstring(void);
|
||||||
|
static void switchseg(int s);
|
||||||
|
static int table1(void);
|
||||||
|
static int table2(void);
|
||||||
|
static int table3(int i);
|
||||||
|
static void bss(full n, int t, int b);
|
||||||
|
void swtxt(void);
|
||||||
|
static void savelab(void);
|
||||||
|
static void dumplab(void);
|
||||||
|
static void xdumplab(void);
|
||||||
|
static void part_flush(void);
|
||||||
|
static long con(int t);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef fmt_id
|
#ifdef fmt_id
|
||||||
#ifdef id_first
|
#ifdef id_first
|
||||||
It is an error to define both fmt_id and id_first.
|
It is an error to define both fmt_id and id_first.
|
||||||
|
@ -55,7 +82,7 @@ Read the documentation.
|
||||||
#define SEGROM 2
|
#define SEGROM 2
|
||||||
#define SEGBSS 3
|
#define SEGBSS 3
|
||||||
|
|
||||||
long con();
|
|
||||||
|
|
||||||
#define get8() getc(emfile)
|
#define get8() getc(emfile)
|
||||||
|
|
||||||
|
@ -63,7 +90,6 @@ long con();
|
||||||
|
|
||||||
FILE *emfile;
|
FILE *emfile;
|
||||||
extern FILE *codefile;
|
extern FILE *codefile;
|
||||||
extern FILE *freopen();
|
|
||||||
|
|
||||||
int nextispseu,savetab1;
|
int nextispseu,savetab1;
|
||||||
int opcode;
|
int opcode;
|
||||||
|
@ -84,14 +110,14 @@ int regallowed=0;
|
||||||
|
|
||||||
extern char em_flag[];
|
extern char em_flag[];
|
||||||
extern short em_ptyp[];
|
extern short em_ptyp[];
|
||||||
extern double atof();
|
|
||||||
extern void con_float(void);
|
|
||||||
|
|
||||||
|
|
||||||
/* Own version of atol that continues computing on overflow.
|
/* Own version of atol that continues computing on overflow.
|
||||||
We don't know that about the ANSI C one.
|
We don't know that about the ANSI C one.
|
||||||
*/
|
*/
|
||||||
long our_atol(s)
|
static long our_atol(register char *s)
|
||||||
register char *s;
|
|
||||||
{
|
{
|
||||||
register long total = 0;
|
register long total = 0;
|
||||||
register unsigned digit;
|
register unsigned digit;
|
||||||
|
@ -112,13 +138,8 @@ register char *s;
|
||||||
|
|
||||||
#define sp_cstx sp_cst2
|
#define sp_cstx sp_cst2
|
||||||
|
|
||||||
string tostring();
|
|
||||||
string holstr();
|
|
||||||
string strarg();
|
|
||||||
string mystrcpy();
|
|
||||||
long get32();
|
|
||||||
|
|
||||||
in_init(filename) char *filename; {
|
void in_init(char *filename) {
|
||||||
|
|
||||||
if ((emfile=freopen(filename,"r",stdin))==NULL)
|
if ((emfile=freopen(filename,"r",stdin))==NULL)
|
||||||
error("Can't open %s",filename);
|
error("Can't open %s",filename);
|
||||||
|
@ -126,16 +147,16 @@ in_init(filename) char *filename; {
|
||||||
error("Bad format %s",filename);
|
error("Bad format %s",filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
in_start() {
|
void in_start(void) {
|
||||||
#ifdef modhead
|
#ifdef modhead
|
||||||
fprintf(codefile,"%s",modhead) ;
|
fprintf(codefile,"%s",modhead) ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
in_finish() {
|
void in_finish(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fillemlines() {
|
void fillemlines(void) {
|
||||||
int t,i;
|
int t,i;
|
||||||
register struct emline *lp;
|
register struct emline *lp;
|
||||||
|
|
||||||
|
@ -214,14 +235,14 @@ fillemlines() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dopseudo() {
|
void dopseudo(void) {
|
||||||
register b,t;
|
register int b,t;
|
||||||
register full n;
|
register full n;
|
||||||
register long save;
|
register long save;
|
||||||
word romcont[MAXROM+1];
|
word romcont[MAXROM+1];
|
||||||
int nromwords;
|
int nromwords;
|
||||||
int rombit,rommask;
|
int rombit,rommask;
|
||||||
unsigned dummy,stackupto();
|
int dummy;
|
||||||
|
|
||||||
if (nextispseu==0 || nemlines>0)
|
if (nextispseu==0 || nemlines>0)
|
||||||
error("No table entry for %d",emlines[0].em_instr);
|
error("No table entry for %d",emlines[0].em_instr);
|
||||||
|
@ -396,8 +417,8 @@ dopseudo() {
|
||||||
|
|
||||||
/* ----- input ----- */
|
/* ----- input ----- */
|
||||||
|
|
||||||
int getarg(typset) {
|
static int getarg(int typset) {
|
||||||
register t,argtyp;
|
register int t,argtyp;
|
||||||
|
|
||||||
argtyp = t = table2();
|
argtyp = t = table2();
|
||||||
if (t == EOF)
|
if (t == EOF)
|
||||||
|
@ -409,8 +430,8 @@ int getarg(typset) {
|
||||||
return(argtyp);
|
return(argtyp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int table1() {
|
static int table1(void) {
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
i = get8();
|
i = get8();
|
||||||
if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
|
if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
|
||||||
|
@ -428,8 +449,8 @@ int table1() {
|
||||||
return(table3(i));
|
return(table3(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
int table2() {
|
static int table2(void) {
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
i = get8();
|
i = get8();
|
||||||
if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
|
if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
|
||||||
|
@ -439,7 +460,7 @@ int table2() {
|
||||||
return(table3(i));
|
return(table3(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
int table3(i) {
|
static int table3(int i) {
|
||||||
word consiz;
|
word consiz;
|
||||||
|
|
||||||
switch(i) {
|
switch(i) {
|
||||||
|
@ -482,7 +503,7 @@ int table3(i) {
|
||||||
return(i);
|
return(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get16() {
|
static int get16(void) {
|
||||||
register int l_byte, h_byte;
|
register int l_byte, h_byte;
|
||||||
|
|
||||||
l_byte = get8();
|
l_byte = get8();
|
||||||
|
@ -491,7 +512,7 @@ int get16() {
|
||||||
return l_byte | (h_byte*256) ;
|
return l_byte | (h_byte*256) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
long get32() {
|
static long get32(void) {
|
||||||
register long l;
|
register long l;
|
||||||
register int h_byte;
|
register int h_byte;
|
||||||
|
|
||||||
|
@ -503,9 +524,9 @@ long get32() {
|
||||||
return l | (h_byte*256L*256*256L) ;
|
return l | (h_byte*256L*256*256L) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
getstring() {
|
static void getstring(void) {
|
||||||
register char *p;
|
register char *p;
|
||||||
register n;
|
register int n;
|
||||||
|
|
||||||
getarg(cst_ptyp);
|
getarg(cst_ptyp);
|
||||||
if (argval < 0 || argval > MAXSTR-1)
|
if (argval < 0 || argval > MAXSTR-1)
|
||||||
|
@ -517,7 +538,7 @@ getstring() {
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strarg(t) {
|
static char *strarg(int t) {
|
||||||
register char *p;
|
register char *p;
|
||||||
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
|
@ -565,7 +586,8 @@ char *strarg(t) {
|
||||||
return(mystrcpy(argstr));
|
return(mystrcpy(argstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
bss(n,t,b) full n; {
|
static void bss(full n, int t, int b)
|
||||||
|
{
|
||||||
register long s;
|
register long s;
|
||||||
|
|
||||||
if (n % TEM_WSIZE)
|
if (n % TEM_WSIZE)
|
||||||
|
@ -588,8 +610,8 @@ bss(n,t,b) full n; {
|
||||||
fatal("bad BSS initializer");
|
fatal("bad BSS initializer");
|
||||||
}
|
}
|
||||||
|
|
||||||
long con(t) {
|
static long con(int t) {
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
strarg(t);
|
strarg(t);
|
||||||
switch (t) {
|
switch (t) {
|
||||||
|
@ -633,11 +655,11 @@ long con(t) {
|
||||||
|
|
||||||
extern char *segname[];
|
extern char *segname[];
|
||||||
|
|
||||||
swtxt() {
|
void swtxt(void) {
|
||||||
switchseg(SEGTXT);
|
switchseg(SEGTXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
switchseg(s) {
|
static void switchseg(int s) {
|
||||||
|
|
||||||
if (s == curseg)
|
if (s == curseg)
|
||||||
return;
|
return;
|
||||||
|
@ -646,9 +668,9 @@ switchseg(s) {
|
||||||
fprintf(codefile,"%s\n",segname[s]);
|
fprintf(codefile,"%s\n",segname[s]);
|
||||||
}
|
}
|
||||||
|
|
||||||
savelab() {
|
static void savelab(void)
|
||||||
|
{
|
||||||
register char *p,*q;
|
register char *p,*q;
|
||||||
|
|
||||||
part_flush();
|
part_flush();
|
||||||
if (labstr[0]) {
|
if (labstr[0]) {
|
||||||
dlbdlb(argstr,labstr);
|
dlbdlb(argstr,labstr);
|
||||||
|
@ -656,11 +678,11 @@ savelab() {
|
||||||
}
|
}
|
||||||
p = argstr;
|
p = argstr;
|
||||||
q = labstr;
|
q = labstr;
|
||||||
while (*q++ = *p++)
|
while ((*q++ = *p++))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
dumplab() {
|
static void dumplab(void) {
|
||||||
|
|
||||||
if (labstr[0] == 0)
|
if (labstr[0] == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -669,7 +691,7 @@ dumplab() {
|
||||||
labstr[0] = 0;
|
labstr[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
xdumplab() {
|
static void xdumplab(void) {
|
||||||
|
|
||||||
if (labstr[0] == 0)
|
if (labstr[0] == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -677,7 +699,7 @@ xdumplab() {
|
||||||
newdlb(labstr);
|
newdlb(labstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
part_flush() {
|
static void part_flush(void) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each new data fragment and each data label starts at
|
* Each new data fragment and each data label starts at
|
||||||
|
@ -690,7 +712,7 @@ part_flush() {
|
||||||
part_word = 0;
|
part_word = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
string holstr(n) word n; {
|
static string holstr(word n) {
|
||||||
|
|
||||||
sprintf(str,hol_off,n,holno);
|
sprintf(str,hol_off,n,holno);
|
||||||
return(mystrcpy(str));
|
return(mystrcpy(str));
|
||||||
|
|
22
mach/proto/cg/fillem.h
Normal file
22
mach/proto/cg/fillem.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-14
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef FILLEM_H_
|
||||||
|
#define FILLEM_H_
|
||||||
|
|
||||||
|
/** Switch to text segment. */
|
||||||
|
void swtxt(void);
|
||||||
|
|
||||||
|
|
||||||
|
void in_init(char *filename);
|
||||||
|
void in_start(void);
|
||||||
|
void in_finish(void);
|
||||||
|
void fillemlines(void);
|
||||||
|
|
||||||
|
void dopseudo(void);
|
||||||
|
|
||||||
|
#endif /* FILLEM_H_ */
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
@ -11,39 +13,35 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
/*
|
#include "gencode.h"
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
#include "fillem.h"
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
FILE *codefile;
|
FILE *codefile;
|
||||||
extern FILE *freopen();
|
|
||||||
|
|
||||||
out_init(filename) char *filename; {
|
|
||||||
|
void out_init(char *filename)
|
||||||
|
{
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
static char stderrbuff[BUFSIZ];
|
|
||||||
|
|
||||||
if (Debug) {
|
if (Debug)
|
||||||
|
{
|
||||||
codefile = stderr;
|
codefile = stderr;
|
||||||
if (!isatty(2))
|
}
|
||||||
setbuf(stderr,stderrbuff);
|
else
|
||||||
} else {
|
{
|
||||||
#endif
|
#endif
|
||||||
if (filename == (char *) 0)
|
if (filename == (char *) 0)
|
||||||
codefile = stdout;
|
codefile = stdout;
|
||||||
else
|
else if ((codefile = freopen(filename, "w", stdout)) == NULL)
|
||||||
if ((codefile=freopen(filename,"w",stdout))==NULL)
|
|
||||||
error("Can't create %s", filename);
|
error("Can't create %s", filename);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
out_finish() {
|
void out_finish(void) {
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (Debug)
|
if (Debug)
|
||||||
|
@ -53,14 +51,15 @@ out_finish() {
|
||||||
fclose(codefile);
|
fclose(codefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
tstoutput() {
|
void tstoutput(void) {
|
||||||
|
|
||||||
if (ferror(codefile))
|
if (ferror(codefile))
|
||||||
error("Write error on output");
|
error("Write error on output");
|
||||||
}
|
}
|
||||||
|
|
||||||
gencode(code) register char *code; {
|
void gencode(register char *code)
|
||||||
register c;
|
{
|
||||||
|
register int c;
|
||||||
int tokno,fldno,insno,regno,subno;
|
int tokno,fldno,insno,regno,subno;
|
||||||
register token_p tp;
|
register token_p tp;
|
||||||
|
|
||||||
|
@ -131,7 +130,8 @@ gencode(code) register char *code; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
genexpr(nodeno) {
|
void genexpr(int nodeno)
|
||||||
|
{
|
||||||
result_t result;
|
result_t result;
|
||||||
|
|
||||||
result= compute(&enodes[nodeno]);
|
result= compute(&enodes[nodeno]);
|
||||||
|
@ -149,12 +149,14 @@ genexpr(nodeno) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gennl() {
|
void gennl(void)
|
||||||
|
{
|
||||||
fputc('\n',codefile);
|
fputc('\n',codefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
prtoken(tp) token_p tp; {
|
void prtoken(token_p tp)
|
||||||
register c;
|
{
|
||||||
|
register int c;
|
||||||
register char *code;
|
register char *code;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
|
|
||||||
|
|
22
mach/proto/cg/gencode.h
Normal file
22
mach/proto/cg/gencode.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-12
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef GENCODE_H_
|
||||||
|
#define GENCODE_H_
|
||||||
|
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
void out_init(char *filename);
|
||||||
|
void out_finish(void);
|
||||||
|
void tstoutput(void);
|
||||||
|
void gencode(register char *code);
|
||||||
|
void genexpr(int nodeno);
|
||||||
|
void gennl(void);
|
||||||
|
void prtoken(token_p tp);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* GENCODE_H_ */
|
|
@ -1,28 +1,26 @@
|
||||||
#ifndef NORCSID
|
|
||||||
static char rcsid[] = "$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "param.h"
|
|
||||||
#include "tables.h"
|
|
||||||
#include "types.h"
|
|
||||||
#include "glosym.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 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".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*
|
*
|
||||||
* Author: Hans van Staveren
|
* Author: Hans van Staveren
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "glosym.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern string myalloc();
|
|
||||||
|
|
||||||
glosym_p glolist= (glosym_p) 0;
|
glosym_p glolist= (glosym_p) 0;
|
||||||
|
|
||||||
enterglo(name,romp) string name; word *romp; {
|
void enterglo(string name,word *romp)
|
||||||
|
{
|
||||||
register glosym_p gp;
|
register glosym_p gp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
gp = (glosym_p) myalloc(sizeof *gp);
|
gp = (glosym_p) myalloc(sizeof *gp);
|
||||||
gp->gl_next = glolist;
|
gp->gl_next = glolist;
|
||||||
|
@ -33,7 +31,8 @@ enterglo(name,romp) string name; word *romp; {
|
||||||
glolist = gp;
|
glolist = gp;
|
||||||
}
|
}
|
||||||
|
|
||||||
glosym_p lookglo(name) string name; {
|
glosym_p lookglo(string name)
|
||||||
|
{
|
||||||
register glosym_p gp;
|
register glosym_p gp;
|
||||||
|
|
||||||
for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next)
|
for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next)
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
* (c) copyright 1987 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".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef GLOSYM_H_
|
||||||
|
#define GLOSYM_H_
|
||||||
|
|
||||||
|
|
||||||
typedef struct glosym {
|
typedef struct glosym {
|
||||||
struct glosym *gl_next;
|
struct glosym *gl_next;
|
||||||
|
@ -10,4 +12,7 @@ typedef struct glosym {
|
||||||
word gl_rom[MAXROM+1];
|
word gl_rom[MAXROM+1];
|
||||||
} glosym_t,*glosym_p;
|
} glosym_t,*glosym_p;
|
||||||
|
|
||||||
|
void enterglo(string name, word *romp);
|
||||||
glosym_p lookglo();
|
glosym_p lookglo();
|
||||||
|
|
||||||
|
#endif /* GLOSYM_H_ */
|
||||||
|
|
|
@ -1,19 +1,24 @@
|
||||||
#ifndef NORCSID
|
|
||||||
static char rcsid[] = "$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "param.h"
|
|
||||||
#include "mach.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 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".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*
|
*
|
||||||
* Author: Hans van Staveren
|
* Author: Hans van Staveren
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "mach.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "fillem.h"
|
||||||
|
#include "gencode.h"
|
||||||
|
#include "codegen.h"
|
||||||
|
|
||||||
char *progname;
|
char *progname;
|
||||||
extern char startupcode[];
|
extern byte startupcode[];
|
||||||
int maxply=1;
|
int maxply=1;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
int Debug=0;
|
int Debug=0;
|
||||||
|
@ -21,10 +26,23 @@ int Debug=0;
|
||||||
|
|
||||||
extern int endofprog;
|
extern int endofprog;
|
||||||
|
|
||||||
main(argc,argv) char **argv; {
|
|
||||||
|
unsigned ggd(unsigned int a,unsigned int b)
|
||||||
|
{
|
||||||
|
register unsigned c;
|
||||||
|
|
||||||
|
do {
|
||||||
|
c = a%b; a=b; b=c;
|
||||||
|
} while (c!=0);
|
||||||
|
return(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
register unsigned n;
|
register unsigned n;
|
||||||
extern unsigned cc1,cc2,cc3,cc4;
|
extern unsigned cc1,cc2,cc3,cc4;
|
||||||
unsigned ggd();
|
|
||||||
|
|
||||||
progname = argv[0];
|
progname = argv[0];
|
||||||
while (--argc && **++argv == '-') {
|
while (--argc && **++argv == '-') {
|
||||||
|
@ -70,11 +88,3 @@ main(argc,argv) char **argv; {
|
||||||
out_finish();
|
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);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
@ -10,23 +12,18 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "reg.h"
|
||||||
|
#include "codegen.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned costcalc();
|
int move(token_p tp1,token_p tp2,int ply,int toplevel,unsigned int maxcost)
|
||||||
|
{
|
||||||
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
|
|
||||||
register move_p mp;
|
register move_p mp;
|
||||||
register unsigned t;
|
register unsigned t;
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
tkdef_p tdp;
|
tkdef_p tdp;
|
||||||
int i;
|
int i;
|
||||||
unsigned codegen();
|
|
||||||
|
|
||||||
if (eqtoken(tp1,tp2))
|
if (eqtoken(tp1,tp2))
|
||||||
return(0);
|
return(0);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <em_spec.h>
|
#include <em_spec.h>
|
||||||
#include <em_flag.h>
|
#include <em_flag.h>
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
@ -12,21 +14,36 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "fillem.h"
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
extern char em_mnem[][4];
|
extern char em_mnem[][4];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
byte *trypat(bp,len) register byte *bp; {
|
extern char em_flag[];
|
||||||
register patlen,i;
|
|
||||||
|
static int argtyp(int 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 *trypat(register byte *bp, int len)
|
||||||
|
{
|
||||||
|
register int patlen,i;
|
||||||
result_t result;
|
result_t result;
|
||||||
|
|
||||||
getint(patlen,bp);
|
getint(patlen,bp);
|
||||||
|
@ -71,28 +88,10 @@ byte *trypat(bp,len) register byte *bp; {
|
||||||
return(bp);
|
return(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char em_flag[];
|
|
||||||
|
|
||||||
argtyp(mn) {
|
|
||||||
|
|
||||||
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
|
byte *nextem(int toplevel) {
|
||||||
case PAR_W:
|
register int i;
|
||||||
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];
|
short hash[3];
|
||||||
register byte *bp;
|
register byte *bp;
|
||||||
byte *cp;
|
byte *cp;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
@ -10,17 +12,16 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "reg.h"
|
||||||
|
|
||||||
/*
|
/* Froward local declarations */
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
static void awayreg(int);
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
chrefcount(regno,amount,tflag) {
|
void chrefcount(int regno, int amount, int tflag)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
rp= &machregs[regno];
|
rp= &machregs[regno];
|
||||||
#if MAXMEMBERS!=0
|
#if MAXMEMBERS!=0
|
||||||
|
@ -38,9 +39,10 @@ chrefcount(regno,amount,tflag) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
getrefcount(regno, tflag) {
|
int getrefcount(int regno, int tflag)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register i,maxcount;
|
register int i,maxcount;
|
||||||
|
|
||||||
rp= &machregs[regno];
|
rp= &machregs[regno];
|
||||||
#if MAXMEMBERS!=0
|
#if MAXMEMBERS!=0
|
||||||
|
@ -58,7 +60,8 @@ getrefcount(regno, tflag) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
erasereg(regno) {
|
void erasereg(int regno)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
|
@ -83,10 +86,11 @@ erasereg(regno) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
awayreg(regno) {
|
static void awayreg(int regno)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
/* Now erase recursively all registers containing
|
/* Now erase recursively all registers containing
|
||||||
* something using this one
|
* something using this one
|
||||||
|
@ -107,9 +111,10 @@ awayreg(regno) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanregs() {
|
void cleanregs(void)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||||
rp->r_contents.t_token = 0;
|
rp->r_contents.t_token = 0;
|
||||||
|
@ -119,9 +124,10 @@ cleanregs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
inctcount(regno) {
|
void inctcount(int regno)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
rp = &machregs[regno];
|
rp = &machregs[regno];
|
||||||
#if MAXMEMBERS!=0
|
#if MAXMEMBERS!=0
|
||||||
|
@ -137,7 +143,8 @@ inctcount(regno) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
chkregs() {
|
void chkregs(void)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register token_p tp;
|
register token_p tp;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
|
|
17
mach/proto/cg/reg.h
Normal file
17
mach/proto/cg/reg.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-14
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef REG_H_
|
||||||
|
#define REG_H_
|
||||||
|
|
||||||
|
void chrefcount(int regno, int amount, int tflag);
|
||||||
|
int getrefcount(int regno, int tflag);
|
||||||
|
void erasereg(int regno);
|
||||||
|
void cleanregs(void);
|
||||||
|
void chkregs(void);
|
||||||
|
|
||||||
|
#endif /* REG_H_ */
|
|
@ -1,12 +1,16 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
|
||||||
#ifdef REGVARS
|
#ifdef REGVARS
|
||||||
|
|
||||||
#ifndef NORCSID
|
|
||||||
static char rcsid[] = "$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <cg_pattern.h>
|
#include <cg_pattern.h>
|
||||||
|
@ -15,18 +19,20 @@ static char rcsid[] = "$Id$";
|
||||||
#include <em_reg.h>
|
#include <em_reg.h>
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
#include "fillem.h"
|
||||||
|
#include "regvar.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
extern string myalloc();
|
|
||||||
struct regvar *rvlist;
|
struct regvar *rvlist;
|
||||||
|
|
||||||
struct regvar *
|
/* Defined in mach.c of the specific machine. */
|
||||||
linkreg(of,sz,tp,sc) long of; {
|
extern int regscore(long off,int size,int typ,int score,int totyp);
|
||||||
|
extern void i_regsave(void);
|
||||||
|
extern void f_regsave(void);
|
||||||
|
void regsave(char *regstr,long off,int size);
|
||||||
|
|
||||||
|
struct regvar *linkreg(long of,int sz,int tp,int sc)
|
||||||
|
{
|
||||||
struct regvar *rvlp;
|
struct regvar *rvlp;
|
||||||
|
|
||||||
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
|
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
|
||||||
|
@ -40,9 +46,10 @@ linkreg(of,sz,tp,sc) long of; {
|
||||||
return(rvlp);
|
return(rvlp);
|
||||||
}
|
}
|
||||||
|
|
||||||
tryreg(rvlp,typ) struct regvar *rvlp; {
|
void tryreg(struct regvar *rvlp, int typ)
|
||||||
|
{
|
||||||
int score;
|
int score;
|
||||||
register i;
|
register int i;
|
||||||
struct regassigned *ra;
|
struct regassigned *ra;
|
||||||
struct regvar *save;
|
struct regvar *save;
|
||||||
|
|
||||||
|
@ -85,9 +92,10 @@ tryreg(rvlp,typ) struct regvar *rvlp; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fixregvars(saveall) {
|
void fixregvars(int saveall)
|
||||||
|
{
|
||||||
register struct regvar *rv;
|
register struct regvar *rv;
|
||||||
register rvtyp,i;
|
register int rvtyp,i;
|
||||||
|
|
||||||
swtxt();
|
swtxt();
|
||||||
i_regsave(); /* machine dependent initialization */
|
i_regsave(); /* machine dependent initialization */
|
||||||
|
@ -107,7 +115,8 @@ fixregvars(saveall) {
|
||||||
f_regsave();
|
f_regsave();
|
||||||
}
|
}
|
||||||
|
|
||||||
isregvar(off) long off; {
|
int isregvar(long off)
|
||||||
|
{
|
||||||
register struct regvar *rvlp;
|
register struct regvar *rvlp;
|
||||||
|
|
||||||
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
||||||
|
@ -116,7 +125,7 @@ isregvar(off) long off; {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
unlinkregs() {
|
void unlinkregs(void) {
|
||||||
register struct regvar *rvlp,*t;
|
register struct regvar *rvlp,*t;
|
||||||
register struct regassigned *ra;
|
register struct regassigned *ra;
|
||||||
int rvtyp,i;
|
int rvtyp,i;
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
* (c) copyright 1987 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".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef REGVAR_H_
|
||||||
|
#define REGVAR_H_
|
||||||
|
|
||||||
struct regvar {
|
struct regvar {
|
||||||
struct regvar *rv_next;
|
struct regvar *rv_next;
|
||||||
|
@ -21,3 +22,12 @@ struct regassigned {
|
||||||
extern struct regvar *rvlist;
|
extern struct regvar *rvlist;
|
||||||
extern int nregvar[];
|
extern int nregvar[];
|
||||||
extern struct regassigned *regassigned[];
|
extern struct regassigned *regassigned[];
|
||||||
|
|
||||||
|
|
||||||
|
struct regvar *linkreg(long of,int sz,int tp,int sc);
|
||||||
|
void tryreg(struct regvar *rvlp, int typ);
|
||||||
|
void fixregvars(int saveall);
|
||||||
|
int isregvar(long off);
|
||||||
|
void unlinkregs(void);
|
||||||
|
|
||||||
|
#endif /* REGVAR_H_ */
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
@ -11,13 +13,10 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Package for string allocation and garbage collection.
|
* Package for string allocation and garbage collection.
|
||||||
|
@ -31,7 +30,33 @@ static char rcsid[] = "$Id$";
|
||||||
char *stab[MAXSTAB];
|
char *stab[MAXSTAB];
|
||||||
int nstab=0;
|
int nstab=0;
|
||||||
|
|
||||||
string myalloc(size) {
|
static void chkstr(string str,char used[])
|
||||||
|
{
|
||||||
|
register int 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string myalloc(int size)
|
||||||
|
{
|
||||||
register string p;
|
register string p;
|
||||||
|
|
||||||
p = (string) malloc(size);
|
p = (string) malloc(size);
|
||||||
|
@ -40,22 +65,22 @@ string myalloc(size) {
|
||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
myfree(p) string p; {
|
void myfree(void* p)
|
||||||
|
{
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
popstr(nnstab) {
|
void popstr(int nnstab)
|
||||||
register i;
|
{
|
||||||
|
register int i;
|
||||||
for (i=nnstab;i<nstab;i++)
|
for (i=nnstab;i<nstab;i++)
|
||||||
myfree(stab[i]);
|
myfree(stab[i]);
|
||||||
nstab = nnstab;
|
nstab = nnstab;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *salloc(size) {
|
char *salloc(int size)
|
||||||
|
{
|
||||||
register char *p;
|
register char *p;
|
||||||
|
|
||||||
if (nstab==MAXSTAB)
|
if (nstab==MAXSTAB)
|
||||||
fatal("String table overflow");
|
fatal("String table overflow");
|
||||||
p = myalloc(size+1); /* extra room for terminating zero */
|
p = myalloc(size+1); /* extra room for terminating zero */
|
||||||
|
@ -63,16 +88,16 @@ char *salloc(size) {
|
||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
compar(p1,p2) char **p1,**p2; {
|
int compar(char **p1, char **p2)
|
||||||
|
{
|
||||||
assert(*p1 != *p2);
|
assert(*p1 != *p2);
|
||||||
if (*p1 < *p2)
|
if (*p1 < *p2)
|
||||||
return(-1);
|
return(-1);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
garbage_collect() {
|
void garbage_collect(void) {
|
||||||
register i;
|
register int i;
|
||||||
struct emline *emlp;
|
struct emline *emlp;
|
||||||
token_p tp;
|
token_p tp;
|
||||||
tkdef_p tdp;
|
tkdef_p tdp;
|
||||||
|
@ -115,25 +140,3 @@ garbage_collect() {
|
||||||
nstab = fillp-stab;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
20
mach/proto/cg/salloc.h
Normal file
20
mach/proto/cg/salloc.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-14
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef SALLOC_H_
|
||||||
|
#define SALLOC_H_
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
string myalloc(int size);
|
||||||
|
void myfree(void* p);
|
||||||
|
void popstr(int nnstab);
|
||||||
|
char *salloc(int size);
|
||||||
|
int compar(char **p1, char **p2);
|
||||||
|
void garbage_collect(void);
|
||||||
|
|
||||||
|
#endif /* SALLOC_H_ */
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
@ -11,13 +13,10 @@ static char rcsid[] = "$Id$";
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern int nstab; /* salloc.c */
|
extern int nstab; /* salloc.c */
|
||||||
|
|
||||||
|
@ -27,10 +26,24 @@ extern string myalloc();
|
||||||
state_p stlist=0;
|
state_p stlist=0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static void bmove(register short *from, register short *to, register int nbytes)
|
||||||
|
{
|
||||||
|
if (nbytes<=0)
|
||||||
|
return;
|
||||||
|
assert(sizeof(short)==2 && (nbytes&1)==0);
|
||||||
|
nbytes>>=1;
|
||||||
|
do
|
||||||
|
*to++ = *from++;
|
||||||
|
while (--nbytes);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef STONSTACK
|
#ifdef STONSTACK
|
||||||
savestatus(sp) register state_p sp; {
|
state_p savestatus(register state_p sp)
|
||||||
|
{
|
||||||
#else
|
#else
|
||||||
state_p savestatus() {
|
state_p state_p savestatus(void)
|
||||||
|
{
|
||||||
register state_p sp;
|
register state_p sp;
|
||||||
|
|
||||||
if ((sp=stlist)==0)
|
if ((sp=stlist)==0)
|
||||||
|
@ -56,8 +69,8 @@ state_p savestatus() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
restorestatus(sp) register state_p sp; {
|
void restorestatus(register state_p sp)
|
||||||
|
{
|
||||||
stackheight = sp->st_sh;
|
stackheight = sp->st_sh;
|
||||||
bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
|
bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
|
||||||
nallreg = sp->st_na;
|
nallreg = sp->st_na;
|
||||||
|
@ -74,20 +87,11 @@ restorestatus(sp) register state_p sp; {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef STONSTACK
|
#ifndef STONSTACK
|
||||||
freestatus(sp) state_p sp; {
|
void freestatus(state_p sp)
|
||||||
|
{
|
||||||
sp->st_next = stlist;
|
sp->st_next = stlist;
|
||||||
stlist = sp;
|
stlist = sp;
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
* (c) copyright 1987 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".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef STATE_H_
|
||||||
|
#define STATE_H_
|
||||||
|
|
||||||
|
|
||||||
#define STONSTACK /* if defined state is saved in stackframe */
|
#define STONSTACK /* if defined state is saved in stackframe */
|
||||||
|
|
||||||
|
@ -24,5 +26,10 @@ typedef struct state {
|
||||||
} state_t,*state_p;
|
} state_t,*state_p;
|
||||||
|
|
||||||
#ifndef STONSTACK
|
#ifndef STONSTACK
|
||||||
state_p savestatus();
|
state_p state_p savestatus(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void restorestatus(register state_p sp);
|
||||||
|
state_p savestatus(register state_p sp);
|
||||||
|
|
||||||
|
#endif /* STATE_H_ */
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
@ -12,19 +16,20 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "reg.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
#include "gencode.h"
|
||||||
|
#include "regvar.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern string myalloc();
|
|
||||||
unsigned codegen();
|
unsigned codegen();
|
||||||
|
extern unsigned cc1,cc2,cc3,cc4;
|
||||||
|
|
||||||
match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
|
||||||
register bitno;
|
int match(register token_p tp, register set_p tep, int optexp)
|
||||||
|
{
|
||||||
|
register int bitno;
|
||||||
token_p ct;
|
token_p ct;
|
||||||
result_t result;
|
result_t result;
|
||||||
|
|
||||||
|
@ -49,7 +54,8 @@ match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
||||||
return(result.e_v.e_con);
|
return(result.e_v.e_con);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance(instno,token) register token_p token; {
|
void instance(int instno,register token_p token)
|
||||||
|
{
|
||||||
register inst_p inp;
|
register inst_p inp;
|
||||||
int i;
|
int i;
|
||||||
token_p tp;
|
token_p tp;
|
||||||
|
@ -128,7 +134,9 @@ instance(instno,token) register token_p token; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cinstance(instno,token,tp,regno) register token_p token,tp; {
|
void cinstance(int instno,register token_p token,
|
||||||
|
register token_p tp,int regno)
|
||||||
|
{
|
||||||
register inst_p inp;
|
register inst_p inp;
|
||||||
int i;
|
int i;
|
||||||
struct reginfo *rp;
|
struct reginfo *rp;
|
||||||
|
@ -195,8 +203,9 @@ cinstance(instno,token,tp,regno) register token_p token,tp; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eqtoken(tp1,tp2) token_p tp1,tp2; {
|
int eqtoken(token_p tp1,token_p tp2)
|
||||||
register i;
|
{
|
||||||
|
register int i;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
|
|
||||||
if (tp1->t_token!=tp2->t_token)
|
if (tp1->t_token!=tp2->t_token)
|
||||||
|
@ -229,9 +238,9 @@ eqtoken(tp1,tp2) token_p tp1,tp2; {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
distance(cindex) {
|
int distance(int cindex) {
|
||||||
register char *bp;
|
register byte *bp;
|
||||||
register i;
|
register int i;
|
||||||
register token_p tp;
|
register token_p tp;
|
||||||
int tokexp,tpl;
|
int tokexp,tpl;
|
||||||
int expsize,toksize,exact;
|
int expsize,toksize,exact;
|
||||||
|
@ -281,9 +290,9 @@ distance(cindex) {
|
||||||
return(20-exact);
|
return(20-exact);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned costcalc(cost) cost_t cost; {
|
unsigned costcalc(cost_t cost)
|
||||||
|
{
|
||||||
result_t result1,result2;
|
result_t result1,result2;
|
||||||
extern unsigned cc1,cc2,cc3,cc4;
|
|
||||||
|
|
||||||
result1=compute(&enodes[cost.c_size]);
|
result1=compute(&enodes[cost.c_size]);
|
||||||
result2=compute(&enodes[cost.c_time]);
|
result2=compute(&enodes[cost.c_time]);
|
||||||
|
@ -291,20 +300,20 @@ unsigned costcalc(cost) cost_t cost; {
|
||||||
return(result1.e_v.e_con*cc1/cc2 + result2.e_v.e_con*cc3/cc4);
|
return(result1.e_v.e_con*cc1/cc2 + result2.e_v.e_con*cc3/cc4);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize(tokexpno) {
|
int ssize(int tokexpno) {
|
||||||
|
|
||||||
return(machsets[tokexpno].set_size);
|
return(machsets[tokexpno].set_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsize(tp) register token_p tp; {
|
int tsize(register token_p tp)
|
||||||
|
{
|
||||||
if (tp->t_token==-1)
|
if (tp->t_token==-1)
|
||||||
return(machregs[tp->t_att[0].ar].r_size);
|
return(machregs[tp->t_att[0].ar].r_size);
|
||||||
return(tokens[tp->t_token].t_size);
|
return(tokens[tp->t_token].t_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MAXSPLIT
|
#ifdef MAXSPLIT
|
||||||
instsize(tinstno,tp) token_p tp; {
|
int instsize(int tinstno,token_p tp) {
|
||||||
inst_p inp;
|
inst_p inp;
|
||||||
struct reginfo *rp;
|
struct reginfo *rp;
|
||||||
|
|
||||||
|
@ -335,8 +344,8 @@ instsize(tinstno,tp) token_p tp; {
|
||||||
}
|
}
|
||||||
#endif /* MAXSPLIT */
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
tref(tp,amount) register token_p tp; {
|
void tref(register token_p tp,int amount) {
|
||||||
register i;
|
register int i;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
|
|
||||||
if (tp->t_token==-1)
|
if (tp->t_token==-1)
|
||||||
|
@ -352,11 +361,12 @@ tref(tp,amount) register token_p tp; {
|
||||||
#define MAXSAVE 10
|
#define MAXSAVE 10
|
||||||
|
|
||||||
#ifdef MAXSPLIT
|
#ifdef MAXSPLIT
|
||||||
split(tp,ip,ply,toplevel) token_p tp; int *ip; {
|
int split(token_p tp,int *ip,int ply,int toplevel)
|
||||||
|
{
|
||||||
c2_p cp;
|
c2_p cp;
|
||||||
token_t savestack[MAXSAVE];
|
token_t savestack[MAXSAVE];
|
||||||
int ok;
|
int ok;
|
||||||
register i;
|
register int i;
|
||||||
int diff;
|
int diff;
|
||||||
token_p stp;
|
token_p stp;
|
||||||
int tpl;
|
int tpl;
|
||||||
|
@ -392,11 +402,12 @@ found:
|
||||||
}
|
}
|
||||||
#endif /* MAXSPLIT */
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; c3_p cp; {
|
unsigned docoerc(token_p tp,c3_p cp,int ply,int toplevel,int forced)
|
||||||
|
{
|
||||||
token_t savestack[MAXSAVE];
|
token_t savestack[MAXSAVE];
|
||||||
token_p stp;
|
token_p stp;
|
||||||
int i,diff;
|
int i,diff;
|
||||||
unsigned cost;
|
unsigned int cost;
|
||||||
int tpl; /* saved tokpatlen */
|
int tpl; /* saved tokpatlen */
|
||||||
|
|
||||||
stp = &fakestack[stackheight-1];
|
stp = &fakestack[stackheight-1];
|
||||||
|
@ -415,7 +426,8 @@ unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; c3_p cp; {
|
||||||
return(cost);
|
return(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
unsigned stackupto(token_p limit,int ply,int toplevel)
|
||||||
|
{
|
||||||
token_t savestack[MAXFSTACK];
|
token_t savestack[MAXFSTACK];
|
||||||
token_p stp;
|
token_p stp;
|
||||||
int i,diff;
|
int i,diff;
|
||||||
|
@ -473,10 +485,11 @@ unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
||||||
return(totalcost);
|
return(totalcost);
|
||||||
}
|
}
|
||||||
|
|
||||||
c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
c3_p findcoerc(token_p tp,set_p tep)
|
||||||
|
{
|
||||||
register c3_p cp;
|
register c3_p cp;
|
||||||
token_t rtoken;
|
token_t rtoken;
|
||||||
register i;
|
register int i;
|
||||||
register struct reginfo **rpp;
|
register struct reginfo **rpp;
|
||||||
|
|
||||||
for (cp=c3coercs;cp< &c3coercs[NC3]; cp++) {
|
for (cp=c3coercs;cp< &c3coercs[NC3]; cp++) {
|
||||||
|
@ -508,30 +521,42 @@ c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
||||||
return(0); /* nothing found */
|
return(0); /* nothing found */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void error_str(char *s, va_list argptr)
|
||||||
error(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; {
|
{
|
||||||
|
|
||||||
fatal(s,a1,a2,a3,a4,a5,a6,a7,a8);
|
|
||||||
}
|
|
||||||
|
|
||||||
fatal(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; {
|
|
||||||
|
|
||||||
fprintf(stderr,"Error: ");
|
fprintf(stderr,"Error: ");
|
||||||
fprintf(stderr,s,a1,a2,a3,a4,a5,a6,a7,a8);
|
vfprintf(stderr, s, argptr);
|
||||||
fprintf(stderr,"\n");
|
fprintf(stderr,"\n");
|
||||||
out_finish();
|
out_finish();
|
||||||
abort();
|
abort();
|
||||||
exit(-1);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
void error(char *s, ...)
|
||||||
badassertion(asstr,file,line) char *asstr, *file; {
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, s);
|
||||||
|
error_str(s, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fatal(char *s, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, s);
|
||||||
|
error_str(s, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
void badassertion(char* asstr,char *file,int line)
|
||||||
|
{
|
||||||
fatal("Assertion \"%s\" failed %s(%d)",asstr,file,line);
|
fatal("Assertion \"%s\" failed %s(%d)",asstr,file,line);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
max(a,b) {
|
int max(int a,int b)
|
||||||
|
{
|
||||||
return(a>b ? a : b);
|
return(a>b ? a : b);
|
||||||
}
|
}
|
||||||
|
|
47
mach/proto/cg/subr.h
Normal file
47
mach/proto/cg/subr.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-12
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef SUBR_H_
|
||||||
|
#define SUBR_H_
|
||||||
|
|
||||||
|
#include "data.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
int match(register token_p tp, register set_p tep, int optexp);
|
||||||
|
void instance(int instno,register token_p token);
|
||||||
|
void cinstance(int instno,register token_p token,
|
||||||
|
register token_p tp,int regno);
|
||||||
|
int eqtoken(token_p tp1,token_p tp2);
|
||||||
|
int distance(int cindex);
|
||||||
|
unsigned costcalc(cost_t cost);
|
||||||
|
int ssize(int tokexpno);
|
||||||
|
int tsize(register token_p tp);
|
||||||
|
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
int instsize(int tinstno,token_p tp);
|
||||||
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
|
void tref(register token_p tp,int amount);
|
||||||
|
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
int split(token_p tp,int *ip,int ply,int toplevel);
|
||||||
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
|
unsigned docoerc(token_p tp,c3_p cp,int ply,int toplevel,int forced);
|
||||||
|
unsigned stackupto(token_p limit,int ply,int toplevel);
|
||||||
|
c3_p findcoerc(token_p tp,set_p tep);
|
||||||
|
void error(char *s, ...);
|
||||||
|
void fatal(char *s, ...);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
void badassertion(char* asstr,char *file,int line);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int max(int a,int b);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* SUBR_H_ */
|
|
@ -2,7 +2,9 @@
|
||||||
* (c) copyright 1987 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".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef TYPES_H_
|
||||||
|
#define TYPES_H_
|
||||||
|
|
||||||
|
|
||||||
#ifndef TEM_WSIZE
|
#ifndef TEM_WSIZE
|
||||||
TEM_WSIZE should be defined at this point
|
TEM_WSIZE should be defined at this point
|
||||||
|
@ -15,7 +17,7 @@ Implementation will not be correct unless a long integer
|
||||||
has more then 4 bytes of precision.
|
has more then 4 bytes of precision.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef char byte;
|
typedef unsigned char byte;
|
||||||
typedef char * string;
|
typedef char * string;
|
||||||
|
|
||||||
#if TEM_WSIZE>2 || TEM_PSIZE>2
|
#if TEM_WSIZE>2 || TEM_PSIZE>2
|
||||||
|
@ -28,3 +30,5 @@ typedef char * string;
|
||||||
#ifndef WRD_FMT
|
#ifndef WRD_FMT
|
||||||
#define WRD_FMT "%ld"
|
#define WRD_FMT "%ld"
|
||||||
#endif /* WRD_FMT */
|
#endif /* WRD_FMT */
|
||||||
|
|
||||||
|
#endif /* TYPES_H_ */
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
@ -9,12 +11,6 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
int stackheight = 0;
|
int stackheight = 0;
|
||||||
token_t fakestack[MAXFSTACK];
|
token_t fakestack[MAXFSTACK];
|
||||||
|
|
Loading…
Reference in a new issue