Converting mach ncg...
This commit is contained in:
parent
ca57bb617b
commit
d853b7f2fb
16
h/con_float
16
h/con_float
@ -55,10 +55,7 @@
|
||||
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
|
||||
|
||||
#ifndef USE_FLT
|
||||
static int
|
||||
float_cst(str, sz, buf)
|
||||
char *str, *buf;
|
||||
int sz;
|
||||
static int float_cst(char *str, int sz, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
@ -87,10 +84,7 @@ float_cst(str, sz, buf)
|
||||
#include <ctype.h>
|
||||
#include <flt_arith.h>
|
||||
|
||||
int
|
||||
float_cst(str, sz, buf)
|
||||
char *str, *buf;
|
||||
int sz;
|
||||
int float_cst(char *str, int sz, char *buf)
|
||||
{
|
||||
int overflow = 0;
|
||||
flt_arith e;
|
||||
@ -237,7 +231,7 @@ float_cst(str, sz, buf)
|
||||
#endif /* USE_FLT */
|
||||
|
||||
#ifdef CODE_GENERATOR
|
||||
con_float()
|
||||
void con_float()
|
||||
{
|
||||
char buf[8];
|
||||
int rval = float_cst(str, (int)argval, buf);
|
||||
@ -260,9 +254,7 @@ con_float()
|
||||
#endif /* CODE_GENERATOR */
|
||||
|
||||
#ifdef CODE_EXPANDER
|
||||
con_float(str, argval)
|
||||
char *str;
|
||||
arith argval;
|
||||
void con_float(char *str, arith argval)
|
||||
{
|
||||
char buf[8];
|
||||
int rval = float_cst(str, (int)argval, buf);
|
||||
|
||||
@ -4,17 +4,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NORCSID
|
||||
static char rcs_m[]= "$Id$" ;
|
||||
static char rcs_mh[]= ID_MH ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* machine dependent back end routines for the Intel 8086
|
||||
*/
|
||||
|
||||
con_part(sz,w) register sz; word w; {
|
||||
|
||||
void con_part(int sz, word w)
|
||||
{
|
||||
while (part_size % sz)
|
||||
part_size++;
|
||||
if (part_size == TEM_WSIZE)
|
||||
@ -31,7 +26,8 @@ con_part(sz,w) register sz; word w; {
|
||||
part_size += sz;
|
||||
}
|
||||
|
||||
con_mult(sz) word sz; {
|
||||
void con_mult(word sz)
|
||||
{
|
||||
long l;
|
||||
|
||||
if (sz != 4)
|
||||
@ -61,8 +57,8 @@ string holstr(n) word n; {
|
||||
full lbytes;
|
||||
#endif
|
||||
|
||||
prolog(nlocals) full nlocals; {
|
||||
|
||||
void prolog(full nlocals)
|
||||
{
|
||||
fputs("\tpush\tbp\n\tmov\tbp,sp\n", codefile);
|
||||
#ifdef REGVARS
|
||||
lbytes = nlocals;
|
||||
@ -82,8 +78,7 @@ long si_off;
|
||||
long di_off;
|
||||
int firstreg;
|
||||
|
||||
regscore(off, size, typ, score, totyp)
|
||||
long off;
|
||||
int regscore(long off, int size, int typ, int score, int totyp)
|
||||
{
|
||||
if (size != 2) return -1;
|
||||
score -= 1;
|
||||
@ -94,14 +89,14 @@ regscore(off, size, typ, score, totyp)
|
||||
return score;
|
||||
}
|
||||
|
||||
i_regsave()
|
||||
void i_regsave()
|
||||
{
|
||||
si_off = -1;
|
||||
di_off = -1;
|
||||
firstreg = 0;
|
||||
}
|
||||
|
||||
f_regsave()
|
||||
void f_regsave()
|
||||
{
|
||||
if (si_off != di_off) {
|
||||
if (di_off == -lbytes) lbytes -= 2;
|
||||
@ -129,9 +124,7 @@ f_regsave()
|
||||
fprintf(codefile, "mov si,%ld(bp)\n", si_off);
|
||||
}
|
||||
|
||||
regsave(regstr, off, size)
|
||||
char *regstr;
|
||||
long off;
|
||||
void regsave(char *regstr, long off, int size)
|
||||
{
|
||||
if (strcmp(regstr, "si") == 0) {
|
||||
if (! firstreg) firstreg = -1;
|
||||
@ -143,7 +136,7 @@ regsave(regstr, off, size)
|
||||
}
|
||||
}
|
||||
|
||||
regreturn()
|
||||
void regreturn()
|
||||
{
|
||||
if (firstreg == 1) {
|
||||
if (si_off != -1) fputs("jmp .sdret\n", codefile);
|
||||
@ -157,7 +150,8 @@ regreturn()
|
||||
}
|
||||
#endif /* REGVARS */
|
||||
|
||||
mes(type) word type ; {
|
||||
void mes(word type)
|
||||
{
|
||||
int argt ;
|
||||
|
||||
switch ( (int)type ) {
|
||||
|
||||
@ -4,8 +4,13 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef MACH_PROTO_NCG_ASSERT_H
|
||||
#define MACH_PROTO_NCG_ASSERT_H
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define assert(x) if(!(x)) badassertion("x",__FILE__,__LINE__)
|
||||
#else
|
||||
#define assert(x) /* nothing */
|
||||
#endif
|
||||
|
||||
#endif /* MACH_PROTO_NCG_ASSERT_H */
|
||||
@ -1,7 +1,9 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 "param.h"
|
||||
#include "tables.h"
|
||||
@ -12,26 +14,24 @@ static char rcsid[] = "$Id$";
|
||||
#include "state.h"
|
||||
#include "equiv.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
|
||||
*/
|
||||
#include "codegen.h"
|
||||
#include "utils.h"
|
||||
#include "salloc.h"
|
||||
#include "subr.h"
|
||||
#include "nextem.h"
|
||||
#include "fillem.h"
|
||||
#include "reg.h"
|
||||
#include "move.h"
|
||||
#include "gencode.h"
|
||||
#include "compute.h"
|
||||
#include "codegen.h"
|
||||
#include "mach_dep.h"
|
||||
|
||||
#define ALLOW_NEXTEM /* code generator is allowed new try of NEXTEM
|
||||
in exceptional cases */
|
||||
|
||||
byte startupcode[] = { DO_NEXTEM };
|
||||
|
||||
byte *nextem();
|
||||
unsigned costcalc();
|
||||
unsigned docoerc();
|
||||
unsigned stackupto();
|
||||
string tostring();
|
||||
string ad2str();
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define DEBUG(string)
|
||||
#else
|
||||
@ -50,7 +50,8 @@ short *set_val;
|
||||
char *set_flag;
|
||||
#endif
|
||||
|
||||
unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned costlimit; {
|
||||
unsigned codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, int forced)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
byte *origcp=codep;
|
||||
static int level=0;
|
||||
@ -102,7 +103,7 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
|
||||
byte *bp;
|
||||
int n;
|
||||
unsigned mindistance,dist;
|
||||
register i;
|
||||
int i;
|
||||
int cindex;
|
||||
int npos,pos[MAXRULE];
|
||||
unsigned mincost,t;
|
||||
@ -243,7 +244,7 @@ if (Debug)
|
||||
case DO_XXMATCH:
|
||||
DEBUG("XXMATCH");
|
||||
case DO_XMATCH: {
|
||||
register i;
|
||||
int i;
|
||||
int temp;
|
||||
|
||||
DEBUG("XMATCH");
|
||||
@ -253,7 +254,7 @@ if (Debug)
|
||||
break; /* match already checked by distance() */
|
||||
}
|
||||
case DO_MATCH: {
|
||||
register i;
|
||||
int i;
|
||||
int j;
|
||||
unsigned mincost,t;
|
||||
token_p tp;
|
||||
@ -263,12 +264,12 @@ if (Debug)
|
||||
token_p regtp[MAXCREG];
|
||||
c3_p regcp[MAXCREG];
|
||||
rl_p regls[MAXCREG];
|
||||
c3_p cp,findcoerc();
|
||||
c3_p cp;
|
||||
#ifdef MAXSPLIT
|
||||
int sret;
|
||||
#endif
|
||||
int stackpad = 0;
|
||||
struct perm *tup,*ntup,*besttup,*tuples();
|
||||
struct perm *tup,*ntup,*besttup;
|
||||
|
||||
DEBUG("MATCH");
|
||||
tokpatlen=(codep[-1]>>5)&07;
|
||||
@ -500,7 +501,7 @@ normalfailed: if (stackpad!=tokpatlen) {
|
||||
}
|
||||
case DO_KILLREG:
|
||||
case DO_RREMOVE: { /* register remove */
|
||||
register i;
|
||||
int i;
|
||||
int nodeno;
|
||||
token_p tp;
|
||||
tkdef_p tdp;
|
||||
@ -542,7 +543,7 @@ normalfailed: if (stackpad!=tokpatlen) {
|
||||
break;
|
||||
}
|
||||
case DO_DEALLOCATE: {
|
||||
register i;
|
||||
int i;
|
||||
tkdef_p tdp;
|
||||
int tinstno;
|
||||
token_t token;
|
||||
@ -572,7 +573,7 @@ normalfailed: if (stackpad!=tokpatlen) {
|
||||
break;
|
||||
}
|
||||
case DO_ALLOCATE: {
|
||||
register i;
|
||||
int i;
|
||||
int j;
|
||||
int tinstno;
|
||||
int npos,npos2,pos[NREGS],pos2[NREGS];
|
||||
@ -596,7 +597,7 @@ normalfailed: if (stackpad!=tokpatlen) {
|
||||
if (!forced) {
|
||||
do {
|
||||
npos=exactmatch=0;
|
||||
for(rpp=reglist[propno];rp= *rpp; rpp++)
|
||||
for(rpp=reglist[propno] ; (rp= *rpp) ; rpp++)
|
||||
if (getrefcount((int)(rp-machregs), FALSE)==0) {
|
||||
pos[npos++] = rp-machregs;
|
||||
if (eqtoken(&rp->r_contents,&token))
|
||||
@ -705,7 +706,7 @@ normalfailed: if (stackpad!=tokpatlen) {
|
||||
break;
|
||||
}
|
||||
case DO_INSTR: {
|
||||
register i;
|
||||
int i;
|
||||
int n;
|
||||
int tinstno;
|
||||
token_t token;
|
||||
@ -782,7 +783,7 @@ normalfailed: if (stackpad!=tokpatlen) {
|
||||
break;
|
||||
}
|
||||
case DO_TOKREPLACE: {
|
||||
register i;
|
||||
int i;
|
||||
int tinstno;
|
||||
int repllen;
|
||||
token_t reptoken[MAXREPLLEN];
|
||||
@ -814,7 +815,7 @@ normalfailed: if (stackpad!=tokpatlen) {
|
||||
break;
|
||||
}
|
||||
case DO_EMREPLACE: {
|
||||
register i;
|
||||
int i;
|
||||
int j;
|
||||
int nodeno;
|
||||
result_t result[MAXEMREPLLEN];
|
||||
@ -927,9 +928,10 @@ normalfailed: if (stackpad!=tokpatlen) {
|
||||
return(totalcost);
|
||||
}
|
||||
|
||||
readcodebytes() {
|
||||
void readcodebytes()
|
||||
{
|
||||
#ifndef CODEINC
|
||||
register fd;
|
||||
int fd;
|
||||
extern int ncodebytes;
|
||||
|
||||
if ((fd=open("code",0))<0) {
|
||||
@ -943,9 +945,8 @@ readcodebytes() {
|
||||
}
|
||||
|
||||
#ifdef TABLEDEBUG
|
||||
initlset(f) char *f; {
|
||||
extern char *myalloc();
|
||||
|
||||
void initlset(char *f)
|
||||
{
|
||||
set_flag = f;
|
||||
if ((set_fd=open(f+1,2))<0)
|
||||
error("Can't open %s rw",f+1);
|
||||
@ -954,14 +955,14 @@ initlset(f) char *f; {
|
||||
read(set_fd,set_val,set_size);
|
||||
}
|
||||
|
||||
termlset() {
|
||||
|
||||
void termlset()
|
||||
{
|
||||
if (set_fd) {
|
||||
lseek(set_fd,(long) sizeof(int),0);
|
||||
write(set_fd,set_val,set_size);
|
||||
close(set_fd);
|
||||
if (set_flag[0]=='u') {
|
||||
register i;
|
||||
int i;
|
||||
|
||||
fprintf(stderr,"Unused code rules:\n\n");
|
||||
for(i=0;i<8*set_size;i++)
|
||||
|
||||
18
mach/proto/ncg/codegen.h
Normal file
18
mach/proto/ncg/codegen.h
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_CODEGEN_H
|
||||
#define MACH_PROTO_NCG_CODEGEN_H
|
||||
|
||||
/* mach/proto/ncg/codegen.c */
|
||||
unsigned codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, int forced);
|
||||
void readcodebytes(void);
|
||||
|
||||
#ifdef TABLEDEBUG
|
||||
void initlset(char *f);
|
||||
void termlset();
|
||||
#endif
|
||||
|
||||
#endif /* MACH_PROTO_NCG_CODEGEN_H */
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -14,16 +16,13 @@ static char rcsid[] = "$Id$";
|
||||
#include "result.h"
|
||||
#include "glosym.h"
|
||||
#include "extern.h"
|
||||
#include "salloc.h"
|
||||
#include "utils.h"
|
||||
#include "regvar.h"
|
||||
#ifdef USE_TES
|
||||
#include "label.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 "compute.h"
|
||||
|
||||
#define LLEAF 01
|
||||
#define LDEF 02
|
||||
@ -84,10 +83,9 @@ char opdesc[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
string salloc(),strcpy(),strcat();
|
||||
|
||||
string mycat(s1,s2) register string s1,s2; {
|
||||
register string s;
|
||||
string mycat(string s1, string s2)
|
||||
{
|
||||
string s;
|
||||
|
||||
if (s1==0 || *s1=='\0') return(s2);
|
||||
if (s2==0 || *s2=='\0') return(s1);
|
||||
@ -98,8 +96,9 @@ string mycat(s1,s2) register string s1,s2; {
|
||||
return(s);
|
||||
}
|
||||
|
||||
string mystrcpy(s) register string s; {
|
||||
register string r;
|
||||
string mystrcpy(string s)
|
||||
{
|
||||
string r;
|
||||
|
||||
r=salloc(strlen(s));
|
||||
strcpy(r,s);
|
||||
@ -108,7 +107,8 @@ string mystrcpy(s) register string s; {
|
||||
|
||||
char digstr[21][15];
|
||||
|
||||
string tostring(n) register word n; {
|
||||
string tostring(word n)
|
||||
{
|
||||
char buf[25];
|
||||
|
||||
if (n>=-20 && n<=20 && (n&1)==0) {
|
||||
@ -120,9 +120,10 @@ string tostring(n) register word n; {
|
||||
return(mystrcpy(buf));
|
||||
}
|
||||
|
||||
compute(node, presult) register node_p node; register result_t *presult; {
|
||||
void compute(node_p node, result_t *presult)
|
||||
{
|
||||
result_t leaf1,leaf2;
|
||||
register token_p tp;
|
||||
token_p tp;
|
||||
int desc;
|
||||
long mask,tmp;
|
||||
int i,tmpreg;
|
||||
|
||||
15
mach/proto/ncg/compute.h
Normal file
15
mach/proto/ncg/compute.h
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_COMPUTE_H
|
||||
#define MACH_PROTO_NCG_COMPUTE_H
|
||||
|
||||
/* mach/proto/ncg/compute.c */
|
||||
string mycat(string s1, string s2);
|
||||
string mystrcpy(string s);
|
||||
string tostring(long n);
|
||||
void compute(node_p node, result_t *presult);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_COMPUTE_H */
|
||||
|
||||
@ -4,6 +4,9 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef MACH_PROTO_NCG_DATA_H
|
||||
#define MACH_PROTO_NCG_DATA_H
|
||||
|
||||
typedef struct cost {
|
||||
short ct_space;
|
||||
short ct_time;
|
||||
@ -69,3 +72,5 @@ typedef struct {
|
||||
int rl_n; /* number in list */
|
||||
int rl_list[NREGS];
|
||||
} rl_t,*rl_p;
|
||||
|
||||
#endif /* MACH_PROTO_NCG_DATA_H */
|
||||
@ -1,9 +1,10 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 "equiv.h"
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "types.h"
|
||||
@ -11,15 +12,11 @@ static char rcsid[] = "$Id$";
|
||||
#include "data.h"
|
||||
#include "result.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
|
||||
*/
|
||||
|
||||
extern string myalloc();
|
||||
#include "salloc.h"
|
||||
#include "reg.h"
|
||||
#include "subr.h"
|
||||
#include "utils.h"
|
||||
#include "equiv.h"
|
||||
|
||||
int rar[MAXCREG];
|
||||
rl_p *lar;
|
||||
@ -27,11 +24,11 @@ int maxindex;
|
||||
int regclass[NREGS];
|
||||
struct perm *perms;
|
||||
|
||||
struct perm *
|
||||
tuples(regls,nregneeded) rl_p *regls; {
|
||||
struct perm *tuples(rl_p *regls, int nregneeded)
|
||||
{
|
||||
int class=0;
|
||||
register i,j;
|
||||
register struct reginfo *rp;
|
||||
int i,j;
|
||||
struct reginfo *rp;
|
||||
|
||||
/*
|
||||
* First compute equivalence classes of registers.
|
||||
@ -62,10 +59,11 @@ tuples(regls,nregneeded) rl_p *regls; {
|
||||
return(perms);
|
||||
}
|
||||
|
||||
permute(index) {
|
||||
register struct perm *pp;
|
||||
register rl_p rlp;
|
||||
register i,j;
|
||||
void permute(int index)
|
||||
{
|
||||
struct perm *pp;
|
||||
rl_p rlp;
|
||||
int i,j;
|
||||
|
||||
if (index == maxindex) {
|
||||
for (pp=perms; pp != 0; pp=pp->p_next) {
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Id$ */
|
||||
#ifndef MACH_PROTO_NCG_EQUIV_H
|
||||
#define MACH_PROTO_NCG_EQUIV_H
|
||||
|
||||
#define MAXCREG 4
|
||||
|
||||
@ -10,3 +12,8 @@ struct perm {
|
||||
struct perm *p_next;
|
||||
int p_rar[MAXCREG];
|
||||
};
|
||||
|
||||
struct perm *tuples(rl_p *regls, int nregneeded);
|
||||
void permute(int index);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_EQUIV_H */
|
||||
@ -4,6 +4,9 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef MACH_PROTO_NCG_EXTERN_H
|
||||
#define MACH_PROTO_NCG_EXTERN_H
|
||||
|
||||
extern int maxply; /* amount of lookahead allowed */
|
||||
extern int stackheight; /* # of tokens on fakestack */
|
||||
extern token_t fakestack[]; /* fakestack itself */
|
||||
@ -52,3 +55,5 @@ extern struct reginfo **reglist[]; /* lists of registers per property */
|
||||
extern int nregvar[]; /* # of register variables per type */
|
||||
extern int *rvnumbers[]; /* lists of numbers */
|
||||
#endif
|
||||
|
||||
#endif /* MACH_PROTO_NCG_EXTERN_H */
|
||||
@ -1,7 +1,9 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid2[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -18,34 +20,34 @@ static char rcsid2[] = "$Id$";
|
||||
#include <cgg_cg.h>
|
||||
#include "data.h"
|
||||
#include "result.h"
|
||||
#include "salloc.h"
|
||||
#include "utils.h"
|
||||
#ifdef REGVARS
|
||||
#include "regvar.h"
|
||||
#include <em_reg.h>
|
||||
#endif
|
||||
#include "fillem.h"
|
||||
#include "gencode.h"
|
||||
#include "glosym.h"
|
||||
#include "label.h"
|
||||
#include "reg.h"
|
||||
#include "mach_dep.h"
|
||||
#include "compute.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 */
|
||||
#define newplb newilb
|
||||
#endif
|
||||
|
||||
#ifdef fmt_id
|
||||
#ifdef id_first
|
||||
It is an error to define both fmt_id and id_first.
|
||||
Read the documentation.
|
||||
#error It is an error to define both fmt_id and id_first. Read the documentation.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef fmt_ilb
|
||||
#ifdef ilb_fmt
|
||||
It is an error to define both fmt_ilb and ilb_fmt.
|
||||
Read the documentation.
|
||||
#error It is an error to define both fmt_ilb and ilb_fmt. Read the documentation.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -55,13 +57,10 @@ Read the documentation.
|
||||
#define SEGROM 2
|
||||
#define SEGBSS 3
|
||||
|
||||
long con();
|
||||
|
||||
#define get8() getc(emfile)
|
||||
|
||||
FILE *emfile;
|
||||
extern FILE *codefile;
|
||||
extern FILE *freopen();
|
||||
|
||||
int nextispseu,savetab1;
|
||||
int opcode;
|
||||
@ -82,16 +81,14 @@ int regallowed=0;
|
||||
|
||||
extern char em_flag[];
|
||||
extern short em_ptyp[];
|
||||
extern double atof();
|
||||
|
||||
/* Own version of atol that continues computing on overflow.
|
||||
We don't know that about the ANSI C one.
|
||||
*/
|
||||
long our_atol(s)
|
||||
register char *s;
|
||||
long our_atol(char *s)
|
||||
{
|
||||
register long total = 0;
|
||||
register unsigned digit;
|
||||
long total = 0;
|
||||
unsigned digit;
|
||||
int minus = 0;
|
||||
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
@ -110,15 +107,8 @@ register char *s;
|
||||
|
||||
#define sp_cstx sp_cst2
|
||||
|
||||
string tostring();
|
||||
string holstr();
|
||||
string strarg();
|
||||
string mystrcpy();
|
||||
string myalloc();
|
||||
long get32();
|
||||
|
||||
in_init(filename) char *filename; {
|
||||
|
||||
void in_init(char *filename)
|
||||
{
|
||||
emfile = stdin;
|
||||
if (filename && (emfile=freopen(filename,"r",stdin))==NULL)
|
||||
error("Can't open %s",filename);
|
||||
@ -127,18 +117,21 @@ in_init(filename) char *filename; {
|
||||
str = myalloc(maxstrsiz=256);
|
||||
}
|
||||
|
||||
in_start() {
|
||||
void in_start()
|
||||
{
|
||||
#ifdef modhead
|
||||
fprintf(codefile,"%s",modhead) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
in_finish() {
|
||||
void in_finish()
|
||||
{
|
||||
}
|
||||
|
||||
fillemlines() {
|
||||
register int t,i;
|
||||
register struct emline *lp;
|
||||
void fillemlines()
|
||||
{
|
||||
int t,i;
|
||||
struct emline *lp;
|
||||
|
||||
while ((emlines+nemlines)-emp<MAXEMLINES-5) {
|
||||
assert(nemlines<MAXEMLINES);
|
||||
@ -226,14 +219,13 @@ fillemlines() {
|
||||
}
|
||||
}
|
||||
|
||||
dopseudo() {
|
||||
register b,t;
|
||||
register full n;
|
||||
register long save;
|
||||
void dopseudo() {
|
||||
int b,t;
|
||||
full n;
|
||||
long save;
|
||||
word romcont[MAXROM+1];
|
||||
int nromwords;
|
||||
int rombit,rommask;
|
||||
unsigned stackupto();
|
||||
|
||||
if (nextispseu==0 || nemlines>0)
|
||||
error("No table entry for %d",emlines[0].em_instr);
|
||||
@ -445,8 +437,9 @@ int getarg(int typset)
|
||||
return(argtyp);
|
||||
}
|
||||
|
||||
int table1() {
|
||||
register i;
|
||||
int table1()
|
||||
{
|
||||
int i;
|
||||
|
||||
i = get8();
|
||||
if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
|
||||
@ -464,8 +457,9 @@ int table1() {
|
||||
return(table3(i));
|
||||
}
|
||||
|
||||
int table2() {
|
||||
register i;
|
||||
int table2()
|
||||
{
|
||||
int i;
|
||||
|
||||
i = get8();
|
||||
if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
|
||||
@ -475,7 +469,8 @@ int table2() {
|
||||
return(table3(i));
|
||||
}
|
||||
|
||||
int table3(i) {
|
||||
int table3(int i)
|
||||
{
|
||||
word consiz;
|
||||
|
||||
switch(i) {
|
||||
@ -518,8 +513,9 @@ int table3(i) {
|
||||
return(i);
|
||||
}
|
||||
|
||||
int get16() {
|
||||
register int l_byte, h_byte;
|
||||
int get16()
|
||||
{
|
||||
int l_byte, h_byte;
|
||||
|
||||
l_byte = get8();
|
||||
h_byte = get8();
|
||||
@ -527,9 +523,10 @@ int get16() {
|
||||
return l_byte | (h_byte*256) ;
|
||||
}
|
||||
|
||||
long get32() {
|
||||
register long l;
|
||||
register int h_byte;
|
||||
long get32()
|
||||
{
|
||||
long l;
|
||||
int h_byte;
|
||||
|
||||
l = get8();
|
||||
l |= ((unsigned) get8())*256 ;
|
||||
@ -539,9 +536,10 @@ long get32() {
|
||||
return l | (h_byte*256L*256*256L) ;
|
||||
}
|
||||
|
||||
getstring() {
|
||||
register char *p;
|
||||
register n;
|
||||
void getstring()
|
||||
{
|
||||
char *p;
|
||||
int n;
|
||||
|
||||
getarg(cst_ptyp);
|
||||
if (argval < 0)
|
||||
@ -558,8 +556,9 @@ getstring() {
|
||||
*p++ = '\0';
|
||||
}
|
||||
|
||||
char *strarg(t) {
|
||||
register char *p;
|
||||
char *strarg(int t)
|
||||
{
|
||||
char *p;
|
||||
|
||||
switch (t) {
|
||||
case sp_ilb1:
|
||||
@ -606,8 +605,9 @@ char *strarg(t) {
|
||||
return(mystrcpy(argstr));
|
||||
}
|
||||
|
||||
bss(n,t,b) full n; {
|
||||
register long s = 0;
|
||||
void bss(full n, int t, int b)
|
||||
{
|
||||
long s = 0;
|
||||
|
||||
if (n % TEM_WSIZE)
|
||||
fatal("bad BSS size");
|
||||
@ -629,8 +629,9 @@ bss(n,t,b) full n; {
|
||||
fatal("bad BSS initializer");
|
||||
}
|
||||
|
||||
long con(t) {
|
||||
register i;
|
||||
long con(int t)
|
||||
{
|
||||
int i;
|
||||
|
||||
strarg(t);
|
||||
switch (t) {
|
||||
@ -670,16 +671,18 @@ long con(t) {
|
||||
}
|
||||
assert(FALSE);
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern char *segname[];
|
||||
|
||||
swtxt() {
|
||||
void swtxt()
|
||||
{
|
||||
switchseg(SEGTXT);
|
||||
}
|
||||
|
||||
switchseg(s) {
|
||||
|
||||
void switchseg(int s)
|
||||
{
|
||||
if (s == curseg)
|
||||
return;
|
||||
part_flush();
|
||||
@ -687,8 +690,9 @@ switchseg(s) {
|
||||
fprintf(codefile,"%s\n",segname[s]);
|
||||
}
|
||||
|
||||
savelab() {
|
||||
register char *p,*q;
|
||||
void savelab()
|
||||
{
|
||||
char *p,*q;
|
||||
|
||||
part_flush();
|
||||
if (labstr[0]) {
|
||||
@ -697,12 +701,12 @@ savelab() {
|
||||
}
|
||||
p = argstr;
|
||||
q = labstr;
|
||||
while (*q++ = *p++)
|
||||
while ( (*q++ = *p++) )
|
||||
;
|
||||
}
|
||||
|
||||
dumplab() {
|
||||
|
||||
void dumplab()
|
||||
{
|
||||
if (labstr[0] == 0)
|
||||
return;
|
||||
assert(part_size == 0);
|
||||
@ -710,16 +714,16 @@ dumplab() {
|
||||
labstr[0] = 0;
|
||||
}
|
||||
|
||||
xdumplab() {
|
||||
|
||||
void xdumplab()
|
||||
{
|
||||
if (labstr[0] == 0)
|
||||
return;
|
||||
assert(part_size == 0);
|
||||
newdlb(labstr);
|
||||
}
|
||||
|
||||
part_flush() {
|
||||
|
||||
void part_flush()
|
||||
{
|
||||
/*
|
||||
* Each new data fragment and each data label starts at
|
||||
* a new target machine word
|
||||
@ -731,8 +735,8 @@ part_flush() {
|
||||
part_word = 0;
|
||||
}
|
||||
|
||||
string holstr(n) word n; {
|
||||
|
||||
string holstr(word n)
|
||||
{
|
||||
sprintf(str,hol_off,n,holno);
|
||||
return(mystrcpy(str));
|
||||
}
|
||||
|
||||
34
mach/proto/ncg/fillem.h
Normal file
34
mach/proto/ncg/fillem.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_FILLEM_H
|
||||
#define MACH_PROTO_NCG_FILLEM_H
|
||||
|
||||
/* mach/proto/ncg/fillem.c */
|
||||
long our_atol(char *s);
|
||||
void in_init(char *filename);
|
||||
void in_start(void);
|
||||
void in_finish(void);
|
||||
void fillemlines(void);
|
||||
void dopseudo(void);
|
||||
int getarg(int typset);
|
||||
int table1(void);
|
||||
int table2(void);
|
||||
int table3(int i);
|
||||
int get16(void);
|
||||
long get32(void);
|
||||
void getstring(void);
|
||||
char *strarg(int t);
|
||||
void bss(int n, int t, int b);
|
||||
long con(int t);
|
||||
void swtxt(void);
|
||||
void switchseg(int s);
|
||||
void savelab(void);
|
||||
void dumplab(void);
|
||||
void xdumplab(void);
|
||||
void part_flush(void);
|
||||
string holstr(long n);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_FILLEM_H */
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
@ -11,24 +14,17 @@ static char rcsid[] = "$Id$";
|
||||
#include "data.h"
|
||||
#include "result.h"
|
||||
#include "extern.h"
|
||||
#include "compute.h"
|
||||
#include "utils.h"
|
||||
#include "gencode.h"
|
||||
#ifdef USE_TES
|
||||
#include "mach.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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
|
||||
*/
|
||||
|
||||
string mystrcpy();
|
||||
|
||||
FILE *codefile;
|
||||
extern FILE *freopen();
|
||||
|
||||
out_init(filename) char *filename; {
|
||||
|
||||
void out_init(char *filename)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
static char stderrbuff[BUFSIZ];
|
||||
|
||||
@ -48,8 +44,8 @@ out_init(filename) char *filename; {
|
||||
#endif
|
||||
}
|
||||
|
||||
out_finish() {
|
||||
|
||||
void out_finish()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (Debug)
|
||||
fflush(stderr);
|
||||
@ -61,18 +57,19 @@ out_finish() {
|
||||
#endif
|
||||
}
|
||||
|
||||
tstoutput() {
|
||||
|
||||
void tstoutput()
|
||||
{
|
||||
if (ferror(codefile))
|
||||
error("Write error on output");
|
||||
}
|
||||
|
||||
genstr(stringno) {
|
||||
|
||||
void genstr(int stringno)
|
||||
{
|
||||
fputs(codestrings[stringno],codefile);
|
||||
}
|
||||
|
||||
string ad2str(ad) addr_t ad; {
|
||||
string ad2str(addr_t ad)
|
||||
{
|
||||
static char buf[100];
|
||||
|
||||
if (ad.ea_str==0)
|
||||
@ -87,8 +84,8 @@ string ad2str(ad) addr_t ad; {
|
||||
return(mystrcpy(buf));
|
||||
}
|
||||
|
||||
praddr(ad) addr_t ad; {
|
||||
|
||||
void praddr(addr_t ad)
|
||||
{
|
||||
if (ad.ea_str==0 || *(ad.ea_str) == '\0')
|
||||
fprintf(codefile,WRD_FMT,ad.ea_off);
|
||||
else {
|
||||
@ -104,14 +101,16 @@ praddr(ad) addr_t ad; {
|
||||
}
|
||||
}
|
||||
|
||||
gennl() {
|
||||
void gennl()
|
||||
{
|
||||
putc('\n',codefile);
|
||||
}
|
||||
|
||||
prtoken(tp,leadingchar) token_p tp; {
|
||||
register c;
|
||||
register char *code;
|
||||
register tkdef_p tdp;
|
||||
void prtoken(token_p tp, int leadingchar)
|
||||
{
|
||||
int c;
|
||||
char *code;
|
||||
tkdef_p tdp;
|
||||
|
||||
putc(leadingchar,codefile);
|
||||
if (tp->t_token == -1) {
|
||||
@ -144,8 +143,7 @@ prtoken(tp,leadingchar) token_p tp; {
|
||||
}
|
||||
|
||||
#ifdef USE_TES
|
||||
printlabel(labnum)
|
||||
int labnum;
|
||||
void printlabel(int labnum)
|
||||
{
|
||||
newilb(dollar[labnum].e_v.e_addr.ea_str);
|
||||
}
|
||||
|
||||
20
mach/proto/ncg/gencode.h
Normal file
20
mach/proto/ncg/gencode.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_GENCODE_H
|
||||
#define MACH_PROTO_NCG_GENCODE_H
|
||||
|
||||
/* mach/proto/ncg/gencode.c */
|
||||
void out_init(char *filename);
|
||||
void out_finish(void);
|
||||
void tstoutput(void);
|
||||
void genstr(int stringno);
|
||||
string ad2str(addr_t ad);
|
||||
void praddr(addr_t ad);
|
||||
void gennl(void);
|
||||
void prtoken(token_p tp, int leadingchar);
|
||||
void printlabel(int labnum);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_GENCODE_H */
|
||||
|
||||
@ -1,28 +1,24 @@
|
||||
#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.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*
|
||||
* Author: Hans van Staveren
|
||||
*/
|
||||
|
||||
extern string myalloc();
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "types.h"
|
||||
#include "glosym.h"
|
||||
#include "salloc.h"
|
||||
#include "glosym.h"
|
||||
|
||||
glosym_p glolist= (glosym_p) 0;
|
||||
|
||||
enterglo(name,romp) string name; word *romp; {
|
||||
register glosym_p gp;
|
||||
register i;
|
||||
void enterglo(string name, word *romp)
|
||||
{
|
||||
glosym_p gp;
|
||||
int i;
|
||||
|
||||
gp = (glosym_p) myalloc(sizeof *gp);
|
||||
gp->gl_next = glolist;
|
||||
@ -33,8 +29,9 @@ enterglo(name,romp) string name; word *romp; {
|
||||
glolist = gp;
|
||||
}
|
||||
|
||||
glosym_p lookglo(name) string name; {
|
||||
register glosym_p gp;
|
||||
glosym_p lookglo(string name)
|
||||
{
|
||||
glosym_p gp;
|
||||
|
||||
for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next)
|
||||
if (strcmp(gp->gl_name,name)==0)
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Id$ */
|
||||
#ifndef MACH_PROTO_NCG_GLOSYM_H
|
||||
#define MACH_PROTO_NCG_GLOSYM_H
|
||||
|
||||
typedef struct glosym {
|
||||
struct glosym *gl_next;
|
||||
@ -10,4 +12,7 @@ typedef struct glosym {
|
||||
word gl_rom[MAXROM+1];
|
||||
} glosym_t,*glosym_p;
|
||||
|
||||
glosym_p lookglo();
|
||||
void enterglo(string name, word *romp);
|
||||
glosym_p lookglo(string name);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_GLOSYM_H */
|
||||
@ -3,13 +3,15 @@
|
||||
#include "types.h"
|
||||
#include "param.h"
|
||||
#include "label.h"
|
||||
#include "salloc.h"
|
||||
#include "utils.h"
|
||||
#include "label.h"
|
||||
|
||||
static label_p label_list = (label_p)0;
|
||||
extern char *myalloc();
|
||||
|
||||
add_label(num, height, flth)
|
||||
void add_label(int num, int height, int flth)
|
||||
{
|
||||
register label_p lbl = (label_p)0;
|
||||
label_p lbl = (label_p)0;
|
||||
|
||||
if (height <= 0) return;
|
||||
if (flth != TRUE && flth != FALSE)
|
||||
@ -23,10 +25,9 @@ add_label(num, height, flth)
|
||||
label_list = lbl;
|
||||
}
|
||||
|
||||
label_p get_label(num)
|
||||
register word num;
|
||||
label_p get_label(word num)
|
||||
{
|
||||
register label_p tmp = label_list;
|
||||
label_p tmp = label_list;
|
||||
|
||||
while (tmp != (label_p)0) {
|
||||
if (tmp->lb_number == num) return tmp;
|
||||
@ -35,7 +36,7 @@ register word num;
|
||||
return (label_p)0;
|
||||
}
|
||||
|
||||
kill_labels()
|
||||
void kill_labels()
|
||||
{
|
||||
label_p tmp;
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
*
|
||||
* Author: Hans van Eck.
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_LABEL_H
|
||||
#define MACH_PROTO_NCG_LABEL_H
|
||||
|
||||
typedef struct label *label_p;
|
||||
|
||||
@ -14,4 +16,8 @@ struct label {
|
||||
short lb_fallthrough;
|
||||
};
|
||||
|
||||
extern label_p get_label();
|
||||
void add_label(int num, int height, int flth);
|
||||
label_p get_label(word num);
|
||||
void kill_labels();
|
||||
|
||||
#endif /* MACH_PROTO_NCG_LABEL_H */
|
||||
21
mach/proto/ncg/mach_dep.h
Normal file
21
mach/proto/ncg/mach_dep.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_MACH_DEP_H
|
||||
#define MACH_PROTO_NCG_MACH_DEP_H
|
||||
|
||||
/* Function prototypes that must be exported by specific machines */
|
||||
void regreturn(void);
|
||||
void mes(word type);
|
||||
void prolog(full nlocals);
|
||||
void con_part(int sz, word w);
|
||||
void con_mult(word sz);
|
||||
void con_float(void);
|
||||
int regscore(long off, int size, int typ, int score, int totyp);
|
||||
void i_regsave();
|
||||
void f_regsave();
|
||||
void regsave(char *regstr, long off, int size);
|
||||
void regreturn();
|
||||
|
||||
#endif /* MACH_PROTO_NCG_MACH_DEP_H */
|
||||
@ -1,31 +1,47 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "mach.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
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include "mach.h"
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "types.h"
|
||||
#include "param.h"
|
||||
#include "data.h"
|
||||
#include <cgg_cg.h>
|
||||
#include "tables.h"
|
||||
#include "mach.h"
|
||||
#include "fillem.h"
|
||||
#include "gencode.h"
|
||||
#include "codegen.h"
|
||||
#include "subr.h"
|
||||
#include "utils.h"
|
||||
|
||||
char *progname;
|
||||
extern char startupcode[];
|
||||
extern unsigned codegen();
|
||||
int maxply=1;
|
||||
#ifndef NDEBUG
|
||||
int Debug=0;
|
||||
char *strtdebug="";
|
||||
#endif
|
||||
|
||||
main(argc,argv) char **argv; {
|
||||
register unsigned n;
|
||||
static unsigned int ggd(unsigned int a, unsigned int b)
|
||||
{
|
||||
unsigned int c;
|
||||
|
||||
do {
|
||||
c = a%b; a=b; b=c;
|
||||
} while (c!=0);
|
||||
return(a);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned n;
|
||||
extern unsigned cc1,cc2,cc3,cc4;
|
||||
unsigned ggd();
|
||||
|
||||
progname = argv[0];
|
||||
while (--argc && **++argv == '-') {
|
||||
@ -83,12 +99,3 @@ main(argc,argv) char **argv; {
|
||||
codegen(startupcode,maxply,TRUE,MAXINT,0);
|
||||
error("Bombed out of codegen");
|
||||
}
|
||||
|
||||
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$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 "param.h"
|
||||
#include "tables.h"
|
||||
@ -10,21 +12,20 @@ static char rcsid[] = "$Id$";
|
||||
#include "data.h"
|
||||
#include "result.h"
|
||||
#include "extern.h"
|
||||
#include "subr.h"
|
||||
#include "reg.h"
|
||||
#include "utils.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
|
||||
*/
|
||||
#include "move.h"
|
||||
|
||||
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
|
||||
register move_p mp;
|
||||
unsigned t;
|
||||
register struct reginfo *rp;
|
||||
register byte *tdpb;
|
||||
int move(token_p tp1, token_p tp2, int ply, int toplevel, unsigned int maxcost)
|
||||
{
|
||||
move_p mp;
|
||||
unsigned int t;
|
||||
struct reginfo *rp;
|
||||
byte *tdpb;
|
||||
int i;
|
||||
unsigned codegen();
|
||||
|
||||
if (eqtoken(tp1,tp2))
|
||||
return(0);
|
||||
@ -95,15 +96,15 @@ move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
|
||||
|
||||
#define cocoreg machregs[0].r_contents
|
||||
|
||||
setcc(tp) token_p tp; {
|
||||
|
||||
void setcc(token_p tp)
|
||||
{
|
||||
cocoreg = *tp;
|
||||
}
|
||||
|
||||
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
|
||||
register test_p mp;
|
||||
unsigned t;
|
||||
unsigned codegen();
|
||||
int test(token_p tp, int ply, int toplevel, unsigned int maxcost)
|
||||
{
|
||||
test_p mp;
|
||||
unsigned int t;
|
||||
|
||||
if (cocoreg.t_token!=0) {
|
||||
if (eqtoken(tp,&cocoreg))
|
||||
|
||||
14
mach/proto/ncg/move.h
Normal file
14
mach/proto/ncg/move.h
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_MOVE_H
|
||||
#define MACH_PROTO_NCG_MOVE_H
|
||||
|
||||
/* mach/proto/ncg/move.c */
|
||||
int move(token_p tp1, token_p tp2, int ply, int toplevel, unsigned int maxcost);
|
||||
void setcc(token_p tp);
|
||||
int test(token_p tp, int ply, int toplevel, unsigned int maxcost);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_MOVE_H */
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 <em_spec.h>
|
||||
#include <em_flag.h>
|
||||
#include "assert.h"
|
||||
@ -12,21 +14,18 @@ static char rcsid[] = "$Id$";
|
||||
#include "data.h"
|
||||
#include "result.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
|
||||
*/
|
||||
#include "compute.h"
|
||||
#include "fillem.h"
|
||||
#include "nextem.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#include <stdio.h>
|
||||
extern char em_mnem[][4];
|
||||
#endif
|
||||
|
||||
byte *trypat(bp,len) register byte *bp; {
|
||||
register patlen,i;
|
||||
byte *trypat(byte *bp, int len)
|
||||
{
|
||||
int patlen,i;
|
||||
result_t result;
|
||||
|
||||
getint(patlen,bp);
|
||||
@ -83,8 +82,8 @@ byte *trypat(bp,len) register byte *bp; {
|
||||
|
||||
extern char em_flag[];
|
||||
|
||||
argtyp(mn) {
|
||||
|
||||
int argtyp(int mn)
|
||||
{
|
||||
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
|
||||
case PAR_W:
|
||||
case PAR_S:
|
||||
@ -101,13 +100,14 @@ argtyp(mn) {
|
||||
}
|
||||
}
|
||||
|
||||
byte *nextem(toplevel) {
|
||||
register i;
|
||||
byte *nextem(int toplevel)
|
||||
{
|
||||
int i;
|
||||
short hash[3];
|
||||
register byte *bp;
|
||||
byte *bp;
|
||||
byte *cp;
|
||||
int index;
|
||||
register struct emline *ep;
|
||||
struct emline *ep;
|
||||
|
||||
if (toplevel) {
|
||||
if (nemlines && emp>emlines) {
|
||||
|
||||
14
mach/proto/ncg/nextem.h
Normal file
14
mach/proto/ncg/nextem.h
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_NEXTEM_H
|
||||
#define MACH_PROTO_NCG_NEXTEM_H
|
||||
|
||||
/* mach/proto/ncg/nextem.c */
|
||||
byte *trypat(byte *bp, int len);
|
||||
int argtyp(int mn);
|
||||
byte *nextem(int toplevel);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_NEXTEM_H */
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Id$ */
|
||||
#ifndef MACH_PROTO_NCG_PARAM_H
|
||||
#define MACH_PROTO_NCG_PARAM_H
|
||||
|
||||
#define BMASK 0377
|
||||
#define BSHIFT 8
|
||||
@ -24,3 +26,5 @@
|
||||
#define MAXEMLINES 20
|
||||
#define MAXFSTACK 20
|
||||
#define MAXTDBUG 32
|
||||
|
||||
#endif /* MACH_PROTO_NCG_PARAM_H */
|
||||
@ -41,6 +41,7 @@ proto_ncg = cprogram {
|
||||
cfile_with_tables (d.."state.c"),
|
||||
cfile_with_tables (d.."subr.c"),
|
||||
cfile_with_tables (d.."var.c"),
|
||||
cfile_with_tables (d.."utils.c"),
|
||||
|
||||
cfile {
|
||||
ith { make_tables, i = 1 },
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 "param.h"
|
||||
#include "tables.h"
|
||||
@ -10,18 +12,15 @@ static char rcsid[] = "$Id$";
|
||||
#include "data.h"
|
||||
#include "result.h"
|
||||
#include "extern.h"
|
||||
#include "utils.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
|
||||
*/
|
||||
#include "reg.h"
|
||||
|
||||
chrefcount(regno,amount,tflag) {
|
||||
register struct reginfo *rp;
|
||||
void chrefcount(int regno, int amount, int tflag)
|
||||
{
|
||||
struct reginfo *rp;
|
||||
#if MAXMEMBERS != 0
|
||||
register i, tmp;
|
||||
int i, tmp;
|
||||
#endif
|
||||
|
||||
rp= &machregs[regno];
|
||||
@ -40,10 +39,11 @@ chrefcount(regno,amount,tflag) {
|
||||
#endif
|
||||
}
|
||||
|
||||
getrefcount(regno, tflag) {
|
||||
register struct reginfo *rp;
|
||||
int getrefcount(int regno, int tflag)
|
||||
{
|
||||
struct reginfo *rp;
|
||||
#if MAXMEMBERS != 0
|
||||
register i,maxcount, tmp;
|
||||
int i,maxcount, tmp;
|
||||
#endif
|
||||
|
||||
rp= &machregs[regno];
|
||||
@ -61,13 +61,15 @@ getrefcount(regno, tflag) {
|
||||
}
|
||||
return(maxcount);
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
erasereg(regno) {
|
||||
register struct reginfo *rp = &machregs[regno];
|
||||
register int i;
|
||||
register byte *tdpb;
|
||||
void erasereg(int regno)
|
||||
{
|
||||
struct reginfo *rp = &machregs[regno];
|
||||
int i;
|
||||
byte *tdpb;
|
||||
|
||||
#if MAXMEMBERS==0
|
||||
rp->r_contents.t_token = 0;
|
||||
@ -106,7 +108,7 @@ erasereg(regno) {
|
||||
}
|
||||
#else
|
||||
extern short clashlist[];
|
||||
register short *sp = &clashlist[rp->r_iclash];
|
||||
short *sp = &clashlist[rp->r_iclash];
|
||||
|
||||
rp->r_contents.t_token = 0;
|
||||
while (*sp) {
|
||||
@ -149,9 +151,10 @@ erasereg(regno) {
|
||||
#endif
|
||||
}
|
||||
|
||||
cleanregs() {
|
||||
register struct reginfo *rp;
|
||||
register i;
|
||||
void cleanregs()
|
||||
{
|
||||
struct reginfo *rp;
|
||||
int i;
|
||||
|
||||
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||
rp->r_contents.t_token = 0;
|
||||
@ -161,9 +164,10 @@ cleanregs() {
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
inctcount(regno) {
|
||||
register struct reginfo *rp;
|
||||
register i;
|
||||
void inctcount(int regno)
|
||||
{
|
||||
struct reginfo *rp;
|
||||
int i;
|
||||
|
||||
rp = &machregs[regno];
|
||||
#if MAXMEMBERS!=0
|
||||
@ -179,10 +183,11 @@ inctcount(regno) {
|
||||
#endif
|
||||
}
|
||||
|
||||
chkregs() {
|
||||
register struct reginfo *rp;
|
||||
register token_p tp;
|
||||
register byte *tdpb;
|
||||
void chkregs()
|
||||
{
|
||||
struct reginfo *rp;
|
||||
token_p tp;
|
||||
byte *tdpb;
|
||||
int i;
|
||||
|
||||
for (rp=machregs+1;rp<machregs+NREGS;rp++) {
|
||||
|
||||
17
mach/proto/ncg/reg.h
Normal file
17
mach/proto/ncg/reg.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_REG_H
|
||||
#define MACH_PROTO_NCG_REG_H
|
||||
|
||||
/* mach/proto/ncg/reg.c */
|
||||
void chrefcount(int regno, int amount, int tflag);
|
||||
int getrefcount(int regno, int tflag);
|
||||
void erasereg(int regno);
|
||||
void cleanregs(void);
|
||||
void inctcount(int regno);
|
||||
void chkregs(void);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_REG_H */
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
/*
|
||||
* (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 "param.h"
|
||||
#include "tables.h"
|
||||
|
||||
#ifdef REGVARS
|
||||
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
#include <cgg_cg.h>
|
||||
#include "data.h"
|
||||
@ -15,19 +17,17 @@ static char rcsid[] = "$Id$";
|
||||
#include <em_reg.h>
|
||||
#include "result.h"
|
||||
#include "extern.h"
|
||||
#include "utils.h"
|
||||
#include "salloc.h"
|
||||
#include "reg.h"
|
||||
#include "fillem.h"
|
||||
#include "mach_dep.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 *
|
||||
linkreg(of,sz,tp,sc) long of; {
|
||||
register struct regvar *rvlp;
|
||||
struct regvar *linkreg(long of, int sz, int tp, int sc)
|
||||
{
|
||||
struct regvar *rvlp;
|
||||
|
||||
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
|
||||
rvlp->rv_next = rvlist;
|
||||
@ -40,10 +40,11 @@ linkreg(of,sz,tp,sc) long of; {
|
||||
return(rvlp);
|
||||
}
|
||||
|
||||
tryreg(rvlp,typ) register struct regvar *rvlp; {
|
||||
void tryreg(struct regvar *rvlp, int typ)
|
||||
{
|
||||
int score;
|
||||
register i;
|
||||
register struct regassigned *ra;
|
||||
int i;
|
||||
struct regassigned *ra;
|
||||
struct regvar *save;
|
||||
|
||||
if (typ != reg_any && nregvar[typ]!=0) {
|
||||
@ -85,9 +86,10 @@ tryreg(rvlp,typ) register struct regvar *rvlp; {
|
||||
}
|
||||
}
|
||||
|
||||
fixregvars(saveall) {
|
||||
register struct regvar *rv;
|
||||
register rvtyp,i;
|
||||
void fixregvars(int saveall)
|
||||
{
|
||||
struct regvar *rv;
|
||||
int rvtyp,i;
|
||||
|
||||
swtxt();
|
||||
i_regsave(); /* machine dependent initialization */
|
||||
@ -108,8 +110,9 @@ fixregvars(saveall) {
|
||||
f_regsave();
|
||||
}
|
||||
|
||||
isregvar(off) long off; {
|
||||
register struct regvar *rvlp;
|
||||
int isregvar(long off)
|
||||
{
|
||||
struct regvar *rvlp;
|
||||
|
||||
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
||||
if(rvlp->rv_off == off)
|
||||
@ -117,8 +120,9 @@ isregvar(off) long off; {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
isregtyp(off) long off; {
|
||||
register struct regvar *rvlp;
|
||||
int isregtyp(long off)
|
||||
{
|
||||
struct regvar *rvlp;
|
||||
|
||||
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
||||
if(rvlp->rv_off == off)
|
||||
@ -126,9 +130,10 @@ isregtyp(off) long off; {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
unlinkregs() {
|
||||
register struct regvar *rvlp,*t;
|
||||
register struct regassigned *ra;
|
||||
void unlinkregs()
|
||||
{
|
||||
struct regvar *rvlp,*t;
|
||||
struct regassigned *ra;
|
||||
int rvtyp,i;
|
||||
|
||||
for(rvlp=rvlist;rvlp!=0;rvlp=t) {
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Id$ */
|
||||
#ifndef MACH_PROTO_NCG_REGVAR_H
|
||||
#define MACH_PROTO_NCG_REGVAR_H
|
||||
|
||||
struct regvar {
|
||||
struct regvar *rv_next;
|
||||
@ -21,3 +23,12 @@ struct regassigned {
|
||||
extern struct regvar *rvlist;
|
||||
extern int nregvar[];
|
||||
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);
|
||||
int isregtyp(long off);
|
||||
void unlinkregs();
|
||||
|
||||
#endif /* MACH_PROTO_NCG_REGVAR_H */
|
||||
@ -4,6 +4,9 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef MACH_PROTO_NCG_RESULT_H
|
||||
#define MACH_PROTO_NCG_RESULT_H
|
||||
|
||||
struct result {
|
||||
int e_typ; /* EV_INT,EV_REG,EV_STR */
|
||||
union {
|
||||
@ -19,3 +22,5 @@ struct result {
|
||||
#define EV_ADDR 3
|
||||
|
||||
typedef struct result result_t;
|
||||
|
||||
#endif /* MACH_PROTO_NCG_RESULT_H */
|
||||
@ -1,17 +1,3 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "assert.h"
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "types.h"
|
||||
#include <cgg_cg.h>
|
||||
#include "data.h"
|
||||
#include "result.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".
|
||||
@ -24,6 +10,18 @@ static char rcsid[] = "$Id$";
|
||||
* Call salloc(size) to get room for string.
|
||||
* Every now and then call garbage_collect() from toplevel.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include "assert.h"
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "types.h"
|
||||
#include <cgg_cg.h>
|
||||
#include "data.h"
|
||||
#include "result.h"
|
||||
#include "extern.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "salloc.h"
|
||||
|
||||
#define MAXSTAB 1500
|
||||
#define THRESHOLD 200
|
||||
@ -31,8 +29,9 @@ static char rcsid[] = "$Id$";
|
||||
char *stab[MAXSTAB];
|
||||
int nstab=0;
|
||||
|
||||
string myalloc(size) {
|
||||
register string p;
|
||||
string myalloc(int size)
|
||||
{
|
||||
string p;
|
||||
|
||||
p = (string) malloc((unsigned)size);
|
||||
if (p==0)
|
||||
@ -40,21 +39,23 @@ string myalloc(size) {
|
||||
return(p);
|
||||
}
|
||||
|
||||
myfree(p) string p; {
|
||||
|
||||
void myfree(string p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
popstr(nnstab) {
|
||||
register i;
|
||||
void popstr(int nnstab)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=nnstab;i<nstab;i++)
|
||||
myfree(stab[i]);
|
||||
nstab = nnstab;
|
||||
}
|
||||
|
||||
char *salloc(size) {
|
||||
register char *p;
|
||||
char *salloc(int size)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (nstab==MAXSTAB)
|
||||
fatal("String table overflow");
|
||||
@ -63,21 +64,24 @@ char *salloc(size) {
|
||||
return(p);
|
||||
}
|
||||
|
||||
compar(p1,p2) char **p1,**p2; {
|
||||
|
||||
int compar(const void *vp1, const void *vp2)
|
||||
{
|
||||
char **p1 = (char **)vp1;
|
||||
char **p2 = (char **)vp2;
|
||||
assert(*p1 != *p2);
|
||||
if (*p1 < *p2)
|
||||
return(-1);
|
||||
return(1);
|
||||
}
|
||||
|
||||
garbage_collect() {
|
||||
register i;
|
||||
void garbage_collect()
|
||||
{
|
||||
int i;
|
||||
struct emline *emlp;
|
||||
token_p tp;
|
||||
tkdef_p tdp;
|
||||
struct reginfo *rp;
|
||||
register char **fillp,**scanp;
|
||||
char **fillp,**scanp;
|
||||
char used[MAXSTAB]; /* could be bitarray */
|
||||
|
||||
if (nstab<THRESHOLD)
|
||||
@ -115,8 +119,9 @@ garbage_collect() {
|
||||
nstab = fillp-stab;
|
||||
}
|
||||
|
||||
chkstr(str,used) string str; char used[]; {
|
||||
register low,middle,high;
|
||||
void chkstr(string str, char used[])
|
||||
{
|
||||
int low,middle,high;
|
||||
|
||||
low=0; high=nstab-1;
|
||||
while (high>low) {
|
||||
|
||||
18
mach/proto/ncg/salloc.h
Normal file
18
mach/proto/ncg/salloc.h
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_SALLOC_H
|
||||
#define MACH_PROTO_NCG_SALLOC_H
|
||||
|
||||
/* mach/proto/ncg/salloc.c */
|
||||
string myalloc(int size);
|
||||
void myfree(string p);
|
||||
void popstr(int nnstab);
|
||||
char *salloc(int size);
|
||||
int compar(const void *vp1, const void *vp2);
|
||||
void garbage_collect(void);
|
||||
void chkstr(string str, char used[]);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_SALLOC_H */
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 "param.h"
|
||||
#include "tables.h"
|
||||
@ -11,18 +13,15 @@ static char rcsid[] = "$Id$";
|
||||
#include "result.h"
|
||||
#include "state.h"
|
||||
#include "extern.h"
|
||||
#include "salloc.h"
|
||||
#include "utils.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
|
||||
*/
|
||||
#include "state.h"
|
||||
|
||||
extern int nstab; /* salloc.c */
|
||||
|
||||
savestatus(sp) register state_p sp; {
|
||||
|
||||
void savestatus(state_p sp)
|
||||
{
|
||||
sp->st_sh = stackheight;
|
||||
bmove((short *)fakestack,(short *)sp->st_fs,stackheight*sizeof(token_t));
|
||||
sp->st_na = nallreg;
|
||||
@ -38,8 +37,8 @@ savestatus(sp) register state_p sp; {
|
||||
sp->st_ns = nstab;
|
||||
}
|
||||
|
||||
restorestatus(sp) register state_p sp; {
|
||||
|
||||
void restorestatus(state_p sp)
|
||||
{
|
||||
stackheight = sp->st_sh;
|
||||
bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
|
||||
nallreg = sp->st_na;
|
||||
@ -55,8 +54,8 @@ restorestatus(sp) register state_p sp; {
|
||||
popstr(sp->st_ns);
|
||||
}
|
||||
|
||||
bmove(from,to,nbytes) register short *from,*to; register nbytes; {
|
||||
|
||||
void bmove(short *from, short *to, int nbytes)
|
||||
{
|
||||
if (nbytes<=0)
|
||||
return;
|
||||
assert(sizeof(short)==2 && (nbytes&1)==0);
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Id$ */
|
||||
#ifndef MACH_PROTO_NCG_STATE_H
|
||||
#define MACH_PROTO_NCG_STATE_H
|
||||
|
||||
typedef struct state {
|
||||
struct state *st_next; /* for linked list */
|
||||
@ -20,3 +22,9 @@ typedef struct state {
|
||||
int st_tl; /* tokpatlen */
|
||||
int st_ns; /* nstab */
|
||||
} state_t,*state_p;
|
||||
|
||||
void savestatus(state_p sp);
|
||||
void restorestatus(state_p sp);
|
||||
void bmove(short *from, short *to, int nbytes);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_STATE_H */
|
||||
@ -1,9 +1,12 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "assert.h"
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
@ -12,19 +15,17 @@ static char rcsid[] = "$Id$";
|
||||
#include "data.h"
|
||||
#include "result.h"
|
||||
#include "extern.h"
|
||||
#include "utils.h"
|
||||
#include "compute.h"
|
||||
#include "reg.h"
|
||||
#include "regvar.h"
|
||||
#include "codegen.h"
|
||||
#include "salloc.h"
|
||||
#include "subr.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
|
||||
*/
|
||||
|
||||
string myalloc();
|
||||
unsigned codegen();
|
||||
|
||||
match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
||||
register bitno;
|
||||
int match(token_p tp, set_p tep, int optexp)
|
||||
{
|
||||
int bitno;
|
||||
token_p ct;
|
||||
result_t result;
|
||||
|
||||
@ -49,10 +50,11 @@ match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
||||
return(result.e_v.e_con);
|
||||
}
|
||||
|
||||
instance(instno,token) register token_p token; {
|
||||
register inst_p inp;
|
||||
void instance(int instno, token_p token)
|
||||
{
|
||||
inst_p inp;
|
||||
int i;
|
||||
register token_p tp;
|
||||
token_p tp;
|
||||
#if MAXMEMBERS != 0
|
||||
struct reginfo *rp;
|
||||
#endif
|
||||
@ -145,8 +147,9 @@ instance(instno,token) register token_p token; {
|
||||
}
|
||||
}
|
||||
|
||||
cinstance(instno,token,tp,regno) register token_p token,tp; {
|
||||
register inst_p inp;
|
||||
void cinstance(int instno,token_p token, token_p tp, int regno)
|
||||
{
|
||||
inst_p inp;
|
||||
int i;
|
||||
#if MAXMEMBERS != 0
|
||||
struct reginfo *rp;
|
||||
@ -240,9 +243,10 @@ cinstance(instno,token,tp,regno) register token_p token,tp; {
|
||||
}
|
||||
}
|
||||
|
||||
eqtoken(tp1,tp2) token_p tp1,tp2; {
|
||||
register i;
|
||||
register tkdef_p tdp;
|
||||
int eqtoken(token_p tp1, token_p tp2)
|
||||
{
|
||||
int i;
|
||||
tkdef_p tdp;
|
||||
|
||||
if (tp1->t_token!=tp2->t_token)
|
||||
return(0);
|
||||
@ -276,10 +280,11 @@ eqtoken(tp1,tp2) token_p tp1,tp2; {
|
||||
return(1);
|
||||
}
|
||||
|
||||
distance(cindex) {
|
||||
register char *bp;
|
||||
register i;
|
||||
register token_p tp;
|
||||
int distance(int cindex)
|
||||
{
|
||||
char *bp;
|
||||
int i;
|
||||
token_p tp;
|
||||
int tokexp,tpl;
|
||||
int expsize,toksize,exact;
|
||||
int xsekt=0;
|
||||
@ -355,37 +360,38 @@ distance(cindex) {
|
||||
|
||||
extern set_t unstackset;
|
||||
|
||||
int from_stack(s1)
|
||||
register set_p s1;
|
||||
int from_stack(set_p s1)
|
||||
{
|
||||
register set_p s2 = &unstackset;
|
||||
register int i;
|
||||
set_p s2 = &unstackset;
|
||||
int i;
|
||||
for (i = 0; i < SETSIZE; i++) {
|
||||
if ((s1->set_val[i] & s2->set_val[i]) != 0) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned costcalc(cost) cost_t cost; {
|
||||
unsigned int costcalc(cost_t cost)
|
||||
{
|
||||
extern unsigned cc1,cc2,cc3,cc4;
|
||||
|
||||
return(cost.ct_space*cc1/cc2 + cost.ct_time*cc3/cc4);
|
||||
}
|
||||
|
||||
ssize(tokexpno) {
|
||||
|
||||
int ssize(int tokexpno)
|
||||
{
|
||||
return(machsets[tokexpno].set_size);
|
||||
}
|
||||
|
||||
tsize(tp) register token_p tp; {
|
||||
|
||||
int tsize(token_p tp)
|
||||
{
|
||||
if (tp->t_token==-1)
|
||||
return(machregs[tp->t_att[0].ar].r_size);
|
||||
return(tokens[tp->t_token].t_size);
|
||||
}
|
||||
|
||||
#ifdef MAXSPLIT
|
||||
instsize(tinstno,tp) token_p tp; {
|
||||
int instsize(int tinstno, token_p tp)
|
||||
{
|
||||
inst_p inp;
|
||||
struct reginfo *rp;
|
||||
|
||||
@ -418,9 +424,10 @@ instsize(tinstno,tp) token_p tp; {
|
||||
}
|
||||
#endif /* MAXSPLIT */
|
||||
|
||||
tref(tp,amount) register token_p tp; {
|
||||
register i;
|
||||
register byte *tdpb;
|
||||
void tref(token_p tp, int amount)
|
||||
{
|
||||
int i;
|
||||
byte *tdpb;
|
||||
|
||||
if (tp->t_token==-1)
|
||||
chrefcount(tp->t_att[0].ar,amount,FALSE);
|
||||
@ -440,7 +447,8 @@ tref(tp,amount) register token_p tp; {
|
||||
token_t aside[MAXSAVE] ;
|
||||
int aside_length = -1 ;
|
||||
|
||||
save_stack(tp) register token_p tp ; {
|
||||
void save_stack(token_p tp)
|
||||
{
|
||||
int i ;
|
||||
token_p tmp = &fakestack[stackheight - 1];
|
||||
|
||||
@ -458,10 +466,11 @@ save_stack(tp) register token_p tp ; {
|
||||
stackheight -= aside_length;
|
||||
}
|
||||
|
||||
in_stack(reg) {
|
||||
register token_p tp ;
|
||||
register i ;
|
||||
register tkdef_p tdp ;
|
||||
int in_stack(int reg)
|
||||
{
|
||||
token_p tp ;
|
||||
int i ;
|
||||
tkdef_p tdp ;
|
||||
|
||||
for ( i=0, tp=aside ; i<aside_length ; i++, tp++ )
|
||||
if (tp->t_token==-1) {
|
||||
@ -484,8 +493,9 @@ gotone:
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
rest_stack() {
|
||||
register int i ;
|
||||
void rest_stack()
|
||||
{
|
||||
int i ;
|
||||
|
||||
assert(aside_length!= -1);
|
||||
#ifndef NDEBUG
|
||||
@ -499,11 +509,12 @@ rest_stack() {
|
||||
}
|
||||
|
||||
#ifdef MAXSPLIT
|
||||
split(tp,ip,ply,toplevel) token_p tp; register int *ip; {
|
||||
register c2_p cp;
|
||||
voir split(token_p tp, int *ip, int ply, int toplevel)
|
||||
{
|
||||
c2_p cp;
|
||||
token_t savestack[MAXSAVE];
|
||||
int ok;
|
||||
register i;
|
||||
int i;
|
||||
int diff;
|
||||
token_p stp;
|
||||
int tpl;
|
||||
@ -533,8 +544,9 @@ found:
|
||||
}
|
||||
#endif /* MAXSPLIT */
|
||||
|
||||
unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; register c3_p cp; {
|
||||
unsigned cost;
|
||||
unsigned int docoerc(token_p tp, c3_p cp, int ply, int toplevel, int forced)
|
||||
{
|
||||
unsigned int cost;
|
||||
int tpl; /* saved tokpatlen */
|
||||
|
||||
save_stack(tp) ;
|
||||
@ -547,16 +559,17 @@ unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; register c3_p cp; {
|
||||
return(cost);
|
||||
}
|
||||
|
||||
unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
||||
unsigned int stackupto(token_p limit, int ply, int toplevel)
|
||||
{
|
||||
token_t savestack[MAXFSTACK];
|
||||
token_p stp;
|
||||
int i,diff;
|
||||
int tpl; /* saved tokpatlen */
|
||||
int nareg; /* saved nareg */
|
||||
int areg[MAXALLREG];
|
||||
register c1_p cp;
|
||||
register token_p tp;
|
||||
unsigned totalcost=0;
|
||||
c1_p cp;
|
||||
token_p tp;
|
||||
int totalcost=0;
|
||||
struct reginfo *rp,**rpp;
|
||||
|
||||
for (tp=fakestack;tp<=limit;limit--) {
|
||||
@ -611,11 +624,12 @@ unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
||||
return(totalcost);
|
||||
}
|
||||
|
||||
c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
||||
register c3_p cp;
|
||||
c3_p findcoerc(token_p tp, set_p tep)
|
||||
{
|
||||
c3_p cp;
|
||||
token_t rtoken;
|
||||
register i;
|
||||
register struct reginfo **rpp;
|
||||
int i;
|
||||
struct reginfo **rpp;
|
||||
|
||||
for (cp=c3coercs;cp->c3_texpno>=0; cp++) {
|
||||
if (tp!=(token_p) 0) {
|
||||
@ -648,63 +662,10 @@ c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
||||
return(0); /* nothing found */
|
||||
}
|
||||
|
||||
itokcost() {
|
||||
register tkdef_p tdp;
|
||||
void itokcost()
|
||||
{
|
||||
tkdef_p tdp;
|
||||
|
||||
for(tdp=tokens+1;tdp->t_size!=0;tdp++)
|
||||
tdp->t_cost.ct_space = costcalc(tdp->t_cost);
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
error(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; {
|
||||
|
||||
fprintf(stderr,"Error: ");
|
||||
fprintf(stderr,s,a1,a2,a3,a4,a5,a6,a7,a8);
|
||||
fprintf(stderr,"\n");
|
||||
#ifdef TABLEDEBUG
|
||||
ruletrace();
|
||||
#endif
|
||||
out_finish();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
fatal(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; {
|
||||
|
||||
fprintf(stderr,"Fatal: ");
|
||||
fprintf(stderr,s,a1,a2,a3,a4,a5,a6,a7,a8);
|
||||
fprintf(stderr,"\n");
|
||||
#ifdef TABLEDEBUG
|
||||
ruletrace();
|
||||
#endif
|
||||
out_finish();
|
||||
abort();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef TABLEDEBUG
|
||||
|
||||
ruletrace() {
|
||||
register i;
|
||||
extern int tablelines[MAXTDBUG];
|
||||
extern int ntableline;
|
||||
extern char *tablename;
|
||||
|
||||
fprintf(stderr,"Last code rules used\n");
|
||||
i=ntableline-1;
|
||||
while(i!=ntableline) {
|
||||
if (i<0)
|
||||
i += MAXTDBUG;
|
||||
if (tablelines[i]!=0)
|
||||
fprintf(stderr,"\%d: \"%s\", line %d\n",i,tablename,tablelines[i]);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
badassertion(asstr,file,line) char *asstr, *file; {
|
||||
|
||||
fatal("\"%s\", line %d:Assertion \"%s\" failed",file,line,asstr);
|
||||
}
|
||||
#endif
|
||||
|
||||
28
mach/proto/ncg/subr.h
Normal file
28
mach/proto/ncg/subr.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_SUBR_H
|
||||
#define MACH_PROTO_NCG_SUBR_H
|
||||
|
||||
/* mach/proto/ncg/subr.c */
|
||||
int match(token_p tp, set_p tep, int optexp);
|
||||
void instance(int instno, token_p token);
|
||||
void cinstance(int instno, token_p token, token_p tp, int regno);
|
||||
int eqtoken(token_p tp1, token_p tp2);
|
||||
int distance(int cindex);
|
||||
int from_stack(set_p s1);
|
||||
unsigned int costcalc(cost_t cost);
|
||||
int ssize(int tokexpno);
|
||||
int tsize(token_p p);
|
||||
void tref(token_p tp, int amount);
|
||||
void save_stack(token_p tp);
|
||||
int in_stack(int reg);
|
||||
void rest_stack(void);
|
||||
unsigned int docoerc(token_p tp, c3_p cp, int ply, int toplevel, int forced);
|
||||
unsigned int stackupto(token_p limit, int ply, int toplevel);
|
||||
c3_p findcoerc(token_p tp, set_p tep);
|
||||
void itokcost(void);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_SUBR_H */
|
||||
|
||||
@ -4,15 +4,17 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef MACH_PROTO_NCG_TYPES_H
|
||||
#define MACH_PROTO_NCG_TYPES_H
|
||||
|
||||
#ifndef TEM_WSIZE
|
||||
TEM_WSIZE should be defined at this point
|
||||
#warning TEM_WSIZE should be defined at this point
|
||||
#endif
|
||||
#ifndef TEM_PSIZE
|
||||
TEM_PSIZE should be defined at this point
|
||||
#warning TEM_PSIZE should be defined at this point
|
||||
#endif
|
||||
#if TEM_WSIZE>4 || TEM_PSIZE>4
|
||||
Implementation will not be correct unless a long integer
|
||||
has more then 4 bytes of precision.
|
||||
#error Implementation will not be correct unless a long integer has more then 4 bytes of precision.
|
||||
#endif
|
||||
|
||||
typedef char byte;
|
||||
@ -28,3 +30,5 @@ typedef char * string;
|
||||
#ifndef WRD_FMT
|
||||
#define WRD_FMT "%ld"
|
||||
#endif /* WRD_FMT */
|
||||
|
||||
#endif /* MACH_PROTO_NCG_TYPES_H */
|
||||
81
mach/proto/ncg/utils.c
Normal file
81
mach/proto/ncg/utils.c
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*
|
||||
* Author: Manoel Trapier
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "types.h"
|
||||
#include "data.h"
|
||||
|
||||
#include "gencode.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef TABLEDEBUG
|
||||
static void ruletrace();
|
||||
#endif
|
||||
|
||||
/*VARARGS1*/
|
||||
void error(char *s, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr,"Error: ");
|
||||
va_start(ap, s);
|
||||
vfprintf(stderr, s, ap);
|
||||
va_end(ap);
|
||||
fprintf(stderr,"\n");
|
||||
#ifdef TABLEDEBUG
|
||||
ruletrace();
|
||||
#endif
|
||||
out_finish();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
void fatal(char *s, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr,"Fatal: ");
|
||||
va_start(ap, s);
|
||||
vfprintf(stderr, s, ap);
|
||||
va_end(ap);
|
||||
fprintf(stderr,"\n");
|
||||
#ifdef TABLEDEBUG
|
||||
ruletrace();
|
||||
#endif
|
||||
out_finish();
|
||||
abort();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef TABLEDEBUG
|
||||
static void ruletrace()
|
||||
{
|
||||
int i;
|
||||
extern int tablelines[MAXTDBUG];
|
||||
extern int ntableline;
|
||||
extern char *tablename;
|
||||
|
||||
fprintf(stderr,"Last code rules used\n");
|
||||
i=ntableline-1;
|
||||
while(i!=ntableline) {
|
||||
if (i<0)
|
||||
i += MAXTDBUG;
|
||||
if (tablelines[i]!=0)
|
||||
fprintf(stderr,"\"%d: \"%s\", line %d\n",i,tablename,tablelines[i]);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
void badassertion(char *asstr, char *file, int line)
|
||||
{
|
||||
fatal("\"%s\", line %d:Assertion \"%s\" failed", file, line, asstr);
|
||||
}
|
||||
#endif
|
||||
14
mach/proto/ncg/utils.h
Normal file
14
mach/proto/ncg/utils.h
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef MACH_PROTO_NCG_UTILS_H
|
||||
#define MACH_PROTO_NCG_UTILS_H
|
||||
|
||||
/* mach/proto/ncg/utils.c */
|
||||
void error(char *s, ...);
|
||||
void fatal(char *s, ...);
|
||||
void badassertion(char *asstr, char *file, int line);
|
||||
|
||||
#endif /* MACH_PROTO_NCG_UTILS_H */
|
||||
|
||||
@ -1,20 +1,15 @@
|
||||
#ifndef NORCSID
|
||||
static char rcsid[] = "$Id$";
|
||||
#endif
|
||||
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "types.h"
|
||||
#include <cgg_cg.h>
|
||||
#include "data.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
|
||||
*/
|
||||
#include "param.h"
|
||||
#include "tables.h"
|
||||
#include "types.h"
|
||||
#include <cgg_cg.h>
|
||||
#include "data.h"
|
||||
#include "result.h"
|
||||
|
||||
int stackheight = 0;
|
||||
token_t fakestack[MAXFSTACK];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user