Converting mach ncg...

This commit is contained in:
Manoel Trapier 2013-03-21 16:08:18 +01:00 committed by Manoël Trapier
parent ca57bb617b
commit d853b7f2fb
42 changed files with 879 additions and 555 deletions

View File

@ -55,10 +55,7 @@
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0)) + (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
#ifndef USE_FLT #ifndef USE_FLT
static int static int float_cst(char *str, int sz, char *buf)
float_cst(str, sz, buf)
char *str, *buf;
int sz;
{ {
int i; int i;
char *p; char *p;
@ -87,10 +84,7 @@ float_cst(str, sz, buf)
#include <ctype.h> #include <ctype.h>
#include <flt_arith.h> #include <flt_arith.h>
int int float_cst(char *str, int sz, char *buf)
float_cst(str, sz, buf)
char *str, *buf;
int sz;
{ {
int overflow = 0; int overflow = 0;
flt_arith e; flt_arith e;
@ -237,7 +231,7 @@ float_cst(str, sz, buf)
#endif /* USE_FLT */ #endif /* USE_FLT */
#ifdef CODE_GENERATOR #ifdef CODE_GENERATOR
con_float() void con_float()
{ {
char buf[8]; char buf[8];
int rval = float_cst(str, (int)argval, buf); int rval = float_cst(str, (int)argval, buf);
@ -260,9 +254,7 @@ con_float()
#endif /* CODE_GENERATOR */ #endif /* CODE_GENERATOR */
#ifdef CODE_EXPANDER #ifdef CODE_EXPANDER
con_float(str, argval) void con_float(char *str, arith argval)
char *str;
arith argval;
{ {
char buf[8]; char buf[8];
int rval = float_cst(str, (int)argval, buf); int rval = float_cst(str, (int)argval, buf);

View File

@ -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 * 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) while (part_size % sz)
part_size++; part_size++;
if (part_size == TEM_WSIZE) if (part_size == TEM_WSIZE)
@ -31,7 +26,8 @@ con_part(sz,w) register sz; word w; {
part_size += sz; part_size += sz;
} }
con_mult(sz) word sz; { void con_mult(word sz)
{
long l; long l;
if (sz != 4) if (sz != 4)
@ -61,8 +57,8 @@ string holstr(n) word n; {
full lbytes; full lbytes;
#endif #endif
prolog(nlocals) full nlocals; { void prolog(full nlocals)
{
fputs("\tpush\tbp\n\tmov\tbp,sp\n", codefile); fputs("\tpush\tbp\n\tmov\tbp,sp\n", codefile);
#ifdef REGVARS #ifdef REGVARS
lbytes = nlocals; lbytes = nlocals;
@ -82,8 +78,7 @@ long si_off;
long di_off; long di_off;
int firstreg; int firstreg;
regscore(off, size, typ, score, totyp) int regscore(long off, int size, int typ, int score, int totyp)
long off;
{ {
if (size != 2) return -1; if (size != 2) return -1;
score -= 1; score -= 1;
@ -94,14 +89,14 @@ regscore(off, size, typ, score, totyp)
return score; return score;
} }
i_regsave() void i_regsave()
{ {
si_off = -1; si_off = -1;
di_off = -1; di_off = -1;
firstreg = 0; firstreg = 0;
} }
f_regsave() void f_regsave()
{ {
if (si_off != di_off) { if (si_off != di_off) {
if (di_off == -lbytes) lbytes -= 2; if (di_off == -lbytes) lbytes -= 2;
@ -129,9 +124,7 @@ f_regsave()
fprintf(codefile, "mov si,%ld(bp)\n", si_off); fprintf(codefile, "mov si,%ld(bp)\n", si_off);
} }
regsave(regstr, off, size) void regsave(char *regstr, long off, int size)
char *regstr;
long off;
{ {
if (strcmp(regstr, "si") == 0) { if (strcmp(regstr, "si") == 0) {
if (! firstreg) firstreg = -1; if (! firstreg) firstreg = -1;
@ -143,7 +136,7 @@ regsave(regstr, off, size)
} }
} }
regreturn() void regreturn()
{ {
if (firstreg == 1) { if (firstreg == 1) {
if (si_off != -1) fputs("jmp .sdret\n", codefile); if (si_off != -1) fputs("jmp .sdret\n", codefile);
@ -157,7 +150,8 @@ regreturn()
} }
#endif /* REGVARS */ #endif /* REGVARS */
mes(type) word type ; { void mes(word type)
{
int argt ; int argt ;
switch ( (int)type ) { switch ( (int)type ) {

View File

@ -4,8 +4,13 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_ASSERT_H
#define MACH_PROTO_NCG_ASSERT_H
#ifndef NDEBUG #ifndef NDEBUG
#define assert(x) if(!(x)) badassertion("x",__FILE__,__LINE__) #define assert(x) if(!(x)) badassertion("x",__FILE__,__LINE__)
#else #else
#define assert(x) /* nothing */ #define assert(x) /* nothing */
#endif #endif
#endif /* MACH_PROTO_NCG_ASSERT_H */

View File

@ -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,26 +14,24 @@ static char rcsid[] = "$Id$";
#include "state.h" #include "state.h"
#include "equiv.h" #include "equiv.h"
#include "extern.h" #include "extern.h"
#include "codegen.h"
/* #include "utils.h"
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. #include "salloc.h"
* See the copyright notice in the ACK home directory, in the file "Copyright". #include "subr.h"
* #include "nextem.h"
* Author: Hans van Staveren #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 #define ALLOW_NEXTEM /* code generator is allowed new try of NEXTEM
in exceptional cases */ in exceptional cases */
byte startupcode[] = { DO_NEXTEM }; byte startupcode[] = { DO_NEXTEM };
byte *nextem();
unsigned costcalc();
unsigned docoerc();
unsigned stackupto();
string tostring();
string ad2str();
#ifdef NDEBUG #ifdef NDEBUG
#define DEBUG(string) #define DEBUG(string)
#else #else
@ -50,7 +50,8 @@ short *set_val;
char *set_flag; char *set_flag;
#endif #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 #ifndef NDEBUG
byte *origcp=codep; byte *origcp=codep;
static int level=0; static int level=0;
@ -102,7 +103,7 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
byte *bp; byte *bp;
int n; int n;
unsigned mindistance,dist; unsigned mindistance,dist;
register i; int i;
int cindex; int cindex;
int npos,pos[MAXRULE]; int npos,pos[MAXRULE];
unsigned mincost,t; unsigned mincost,t;
@ -243,7 +244,7 @@ if (Debug)
case DO_XXMATCH: case DO_XXMATCH:
DEBUG("XXMATCH"); DEBUG("XXMATCH");
case DO_XMATCH: { case DO_XMATCH: {
register i; int i;
int temp; int temp;
DEBUG("XMATCH"); DEBUG("XMATCH");
@ -253,7 +254,7 @@ if (Debug)
break; /* match already checked by distance() */ break; /* match already checked by distance() */
} }
case DO_MATCH: { case DO_MATCH: {
register i; int i;
int j; int j;
unsigned mincost,t; unsigned mincost,t;
token_p tp; token_p tp;
@ -263,12 +264,12 @@ if (Debug)
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 cp,findcoerc(); c3_p cp;
#ifdef MAXSPLIT #ifdef MAXSPLIT
int sret; int sret;
#endif #endif
int stackpad = 0; int stackpad = 0;
struct perm *tup,*ntup,*besttup,*tuples(); struct perm *tup,*ntup,*besttup;
DEBUG("MATCH"); DEBUG("MATCH");
tokpatlen=(codep[-1]>>5)&07; tokpatlen=(codep[-1]>>5)&07;
@ -500,7 +501,7 @@ normalfailed: if (stackpad!=tokpatlen) {
} }
case DO_KILLREG: case DO_KILLREG:
case DO_RREMOVE: { /* register remove */ case DO_RREMOVE: { /* register remove */
register i; int i;
int nodeno; int nodeno;
token_p tp; token_p tp;
tkdef_p tdp; tkdef_p tdp;
@ -542,7 +543,7 @@ normalfailed: if (stackpad!=tokpatlen) {
break; break;
} }
case DO_DEALLOCATE: { case DO_DEALLOCATE: {
register i; int i;
tkdef_p tdp; tkdef_p tdp;
int tinstno; int tinstno;
token_t token; token_t token;
@ -572,7 +573,7 @@ normalfailed: if (stackpad!=tokpatlen) {
break; break;
} }
case DO_ALLOCATE: { case DO_ALLOCATE: {
register i; int i;
int j; int j;
int tinstno; int tinstno;
int npos,npos2,pos[NREGS],pos2[NREGS]; int npos,npos2,pos[NREGS],pos2[NREGS];
@ -596,7 +597,7 @@ normalfailed: if (stackpad!=tokpatlen) {
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))
@ -705,7 +706,7 @@ normalfailed: if (stackpad!=tokpatlen) {
break; break;
} }
case DO_INSTR: { case DO_INSTR: {
register i; int i;
int n; int n;
int tinstno; int tinstno;
token_t token; token_t token;
@ -782,7 +783,7 @@ normalfailed: if (stackpad!=tokpatlen) {
break; break;
} }
case DO_TOKREPLACE: { case DO_TOKREPLACE: {
register i; int i;
int tinstno; int tinstno;
int repllen; int repllen;
token_t reptoken[MAXREPLLEN]; token_t reptoken[MAXREPLLEN];
@ -814,7 +815,7 @@ normalfailed: if (stackpad!=tokpatlen) {
break; break;
} }
case DO_EMREPLACE: { case DO_EMREPLACE: {
register i; int i;
int j; int j;
int nodeno; int nodeno;
result_t result[MAXEMREPLLEN]; result_t result[MAXEMREPLLEN];
@ -927,9 +928,10 @@ normalfailed: if (stackpad!=tokpatlen) {
return(totalcost); return(totalcost);
} }
readcodebytes() { void readcodebytes()
{
#ifndef CODEINC #ifndef CODEINC
register fd; int fd;
extern int ncodebytes; extern int ncodebytes;
if ((fd=open("code",0))<0) { if ((fd=open("code",0))<0) {
@ -943,9 +945,8 @@ readcodebytes() {
} }
#ifdef TABLEDEBUG #ifdef TABLEDEBUG
initlset(f) char *f; { void initlset(char *f)
extern char *myalloc(); {
set_flag = f; set_flag = f;
if ((set_fd=open(f+1,2))<0) if ((set_fd=open(f+1,2))<0)
error("Can't open %s rw",f+1); error("Can't open %s rw",f+1);
@ -954,14 +955,14 @@ initlset(f) char *f; {
read(set_fd,set_val,set_size); read(set_fd,set_val,set_size);
} }
termlset() { void termlset()
{
if (set_fd) { if (set_fd) {
lseek(set_fd,(long) sizeof(int),0); lseek(set_fd,(long) sizeof(int),0);
write(set_fd,set_val,set_size); write(set_fd,set_val,set_size);
close(set_fd); close(set_fd);
if (set_flag[0]=='u') { if (set_flag[0]=='u') {
register i; int i;
fprintf(stderr,"Unused code rules:\n\n"); fprintf(stderr,"Unused code rules:\n\n");
for(i=0;i<8*set_size;i++) for(i=0;i<8*set_size;i++)

18
mach/proto/ncg/codegen.h Normal file
View 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 */

View File

@ -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,16 +16,13 @@ static char rcsid[] = "$Id$";
#include "result.h" #include "result.h"
#include "glosym.h" #include "glosym.h"
#include "extern.h" #include "extern.h"
#include "salloc.h"
#include "utils.h"
#include "regvar.h"
#ifdef USE_TES #ifdef USE_TES
#include "label.h" #include "label.h"
#endif #endif
#include "compute.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
@ -70,24 +69,23 @@ char opdesc[] = {
LLDEF, /* EX_TOSTRING */ LLDEF, /* EX_TOSTRING */
LLDEF, /* EX_UMINUS */ LLDEF, /* EX_UMINUS */
0, /* EX_REG */ 0, /* EX_REG */
0, /* EX_LOWW */ 0, /* EX_LOWW */
0, /* EX_HIGHW */ 0, /* EX_HIGHW */
LLDEF, /* EX_INREG */ LLDEF, /* EX_INREG */
LLDEF, /* EX_REGVAR */ LLDEF, /* EX_REGVAR */
LLDEF|RLDEF, /* EX_OR */ LLDEF|RLDEF, /* EX_OR */
LLDEF|RLDEF, /* EX_XOR */ LLDEF|RLDEF, /* EX_XOR */
LLDEF|RLDEF, /* EX_AND */ LLDEF|RLDEF, /* EX_AND */
0, /* EX_ISROM */ 0, /* EX_ISROM */
#ifdef USE_TES #ifdef USE_TES
0, /* EX_TOPELTSIZE */ 0, /* EX_TOPELTSIZE */
0, /* EX_FALLTHROUGH */ 0, /* EX_FALLTHROUGH */
#endif #endif
}; };
string salloc(),strcpy(),strcat(); string mycat(string s1, string s2)
{
string mycat(s1,s2) register string s1,s2; { string s;
register string s;
if (s1==0 || *s1=='\0') return(s2); if (s1==0 || *s1=='\0') return(s2);
if (s2==0 || *s2=='\0') return(s1); if (s2==0 || *s2=='\0') return(s1);
@ -98,8 +96,9 @@ string mycat(s1,s2) register string s1,s2; {
return(s); return(s);
} }
string mystrcpy(s) register string s; { string mystrcpy(string s)
register string r; {
string r;
r=salloc(strlen(s)); r=salloc(strlen(s));
strcpy(r,s); strcpy(r,s);
@ -108,7 +107,8 @@ string mystrcpy(s) register string s; {
char digstr[21][15]; char digstr[21][15];
string tostring(n) register 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) {
@ -120,9 +120,10 @@ string tostring(n) register word n; {
return(mystrcpy(buf)); 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; result_t leaf1,leaf2;
register token_p tp; token_p tp;
int desc; int desc;
long mask,tmp; long mask,tmp;
int i,tmpreg; int i,tmpreg;

15
mach/proto/ncg/compute.h Normal file
View 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 */

View File

@ -4,6 +4,9 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_DATA_H
#define MACH_PROTO_NCG_DATA_H
typedef struct cost { typedef struct cost {
short ct_space; short ct_space;
short ct_time; short ct_time;
@ -69,3 +72,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 /* MACH_PROTO_NCG_DATA_H */

View File

@ -1,9 +1,10 @@
#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 "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -11,15 +12,11 @@ static char rcsid[] = "$Id$";
#include "data.h" #include "data.h"
#include "result.h" #include "result.h"
#include "extern.h" #include "extern.h"
#include "salloc.h"
/* #include "reg.h"
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. #include "subr.h"
* See the copyright notice in the ACK home directory, in the file "Copyright". #include "utils.h"
* #include "equiv.h"
* Author: Hans van Staveren
*/
extern string myalloc();
int rar[MAXCREG]; int rar[MAXCREG];
rl_p *lar; rl_p *lar;
@ -27,11 +24,11 @@ int maxindex;
int regclass[NREGS]; int regclass[NREGS];
struct perm *perms; struct perm *perms;
struct perm * struct perm *tuples(rl_p *regls, int nregneeded)
tuples(regls,nregneeded) rl_p *regls; { {
int class=0; int class=0;
register i,j; int i,j;
register struct reginfo *rp; struct reginfo *rp;
/* /*
* First compute equivalence classes of registers. * First compute equivalence classes of registers.
@ -62,10 +59,11 @@ tuples(regls,nregneeded) rl_p *regls; {
return(perms); return(perms);
} }
permute(index) { void permute(int index)
register struct perm *pp; {
register rl_p rlp; struct perm *pp;
register i,j; rl_p rlp;
int i,j;
if (index == maxindex) { if (index == maxindex) {
for (pp=perms; pp != 0; pp=pp->p_next) { for (pp=perms; pp != 0; pp=pp->p_next) {

View File

@ -3,6 +3,8 @@
* 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$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_EQUIV_H
#define MACH_PROTO_NCG_EQUIV_H
#define MAXCREG 4 #define MAXCREG 4
@ -10,3 +12,8 @@ struct perm {
struct perm *p_next; struct perm *p_next;
int p_rar[MAXCREG]; int p_rar[MAXCREG];
}; };
struct perm *tuples(rl_p *regls, int nregneeded);
void permute(int index);
#endif /* MACH_PROTO_NCG_EQUIV_H */

View File

@ -4,6 +4,9 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_EXTERN_H
#define MACH_PROTO_NCG_EXTERN_H
extern int maxply; /* amount of lookahead allowed */ extern int maxply; /* amount of lookahead allowed */
extern int stackheight; /* # of tokens on fakestack */ extern int stackheight; /* # of tokens on fakestack */
extern token_t fakestack[]; /* fakestack itself */ 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 nregvar[]; /* # of register variables per type */
extern int *rvnumbers[]; /* lists of numbers */ extern int *rvnumbers[]; /* lists of numbers */
#endif #endif
#endif /* MACH_PROTO_NCG_EXTERN_H */

View File

@ -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,34 +20,34 @@ static char rcsid2[] = "$Id$";
#include <cgg_cg.h> #include <cgg_cg.h>
#include "data.h" #include "data.h"
#include "result.h" #include "result.h"
#include "salloc.h"
#include "utils.h"
#ifdef REGVARS #ifdef REGVARS
#include "regvar.h" #include "regvar.h"
#include <em_reg.h> #include <em_reg.h>
#endif #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" #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
#ifdef fmt_id #ifdef fmt_id
#ifdef id_first #ifdef id_first
It is an error to define both fmt_id and id_first. #error It is an error to define both fmt_id and id_first. Read the documentation.
Read the documentation.
#endif #endif
#endif #endif
#ifdef fmt_ilb #ifdef fmt_ilb
#ifdef ilb_fmt #ifdef ilb_fmt
It is an error to define both fmt_ilb and ilb_fmt. #error It is an error to define both fmt_ilb and ilb_fmt. Read the documentation.
Read the documentation.
#endif #endif
#endif #endif
@ -55,13 +57,10 @@ 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)
FILE *emfile; FILE *emfile;
extern FILE *codefile; extern FILE *codefile;
extern FILE *freopen();
int nextispseu,savetab1; int nextispseu,savetab1;
int opcode; int opcode;
@ -82,16 +81,14 @@ int regallowed=0;
extern char em_flag[]; extern char em_flag[];
extern short em_ptyp[]; extern short em_ptyp[];
extern double atof();
/* 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) long our_atol(char *s)
register char *s;
{ {
register long total = 0; long total = 0;
register unsigned digit; unsigned digit;
int minus = 0; int minus = 0;
while (*s == ' ' || *s == '\t') s++; while (*s == ' ' || *s == '\t') s++;
@ -110,15 +107,8 @@ register char *s;
#define sp_cstx sp_cst2 #define sp_cstx sp_cst2
string tostring(); void in_init(char *filename)
string holstr(); {
string strarg();
string mystrcpy();
string myalloc();
long get32();
in_init(filename) char *filename; {
emfile = stdin; emfile = stdin;
if (filename && (emfile=freopen(filename,"r",stdin))==NULL) if (filename && (emfile=freopen(filename,"r",stdin))==NULL)
error("Can't open %s",filename); error("Can't open %s",filename);
@ -127,18 +117,21 @@ in_init(filename) char *filename; {
str = myalloc(maxstrsiz=256); str = myalloc(maxstrsiz=256);
} }
in_start() { void in_start()
{
#ifdef modhead #ifdef modhead
fprintf(codefile,"%s",modhead) ; fprintf(codefile,"%s",modhead) ;
#endif #endif
} }
in_finish() { void in_finish()
{
} }
fillemlines() { void fillemlines()
register int t,i; {
register struct emline *lp; int t,i;
struct emline *lp;
while ((emlines+nemlines)-emp<MAXEMLINES-5) { while ((emlines+nemlines)-emp<MAXEMLINES-5) {
assert(nemlines<MAXEMLINES); assert(nemlines<MAXEMLINES);
@ -226,14 +219,13 @@ fillemlines() {
} }
} }
dopseudo() { void dopseudo() {
register b,t; int b,t;
register full n; full n;
register long save; long save;
word romcont[MAXROM+1]; word romcont[MAXROM+1];
int nromwords; int nromwords;
int rombit,rommask; int rombit,rommask;
unsigned stackupto();
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);
@ -445,8 +437,9 @@ int getarg(int typset)
return(argtyp); return(argtyp);
} }
int table1() { int table1()
register i; {
int i;
i = get8(); i = get8();
if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) { if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
@ -464,8 +457,9 @@ int table1() {
return(table3(i)); return(table3(i));
} }
int table2() { int table2()
register i; {
int i;
i = get8(); i = get8();
if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) { if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
@ -475,7 +469,8 @@ int table2() {
return(table3(i)); return(table3(i));
} }
int table3(i) { int table3(int i)
{
word consiz; word consiz;
switch(i) { switch(i) {
@ -518,8 +513,9 @@ int table3(i) {
return(i); return(i);
} }
int get16() { int get16()
register int l_byte, h_byte; {
int l_byte, h_byte;
l_byte = get8(); l_byte = get8();
h_byte = get8(); h_byte = get8();
@ -527,9 +523,10 @@ int get16() {
return l_byte | (h_byte*256) ; return l_byte | (h_byte*256) ;
} }
long get32() { long get32()
register long l; {
register int h_byte; long l;
int h_byte;
l = get8(); l = get8();
l |= ((unsigned) get8())*256 ; l |= ((unsigned) get8())*256 ;
@ -539,9 +536,10 @@ long get32() {
return l | (h_byte*256L*256*256L) ; return l | (h_byte*256L*256*256L) ;
} }
getstring() { void getstring()
register char *p; {
register n; char *p;
int n;
getarg(cst_ptyp); getarg(cst_ptyp);
if (argval < 0) if (argval < 0)
@ -558,8 +556,9 @@ getstring() {
*p++ = '\0'; *p++ = '\0';
} }
char *strarg(t) { char *strarg(int t)
register char *p; {
char *p;
switch (t) { switch (t) {
case sp_ilb1: case sp_ilb1:
@ -606,8 +605,9 @@ char *strarg(t) {
return(mystrcpy(argstr)); return(mystrcpy(argstr));
} }
bss(n,t,b) full n; { void bss(full n, int t, int b)
register long s = 0; {
long s = 0;
if (n % TEM_WSIZE) if (n % TEM_WSIZE)
fatal("bad BSS size"); fatal("bad BSS size");
@ -629,8 +629,9 @@ bss(n,t,b) full n; {
fatal("bad BSS initializer"); fatal("bad BSS initializer");
} }
long con(t) { long con(int t)
register i; {
int i;
strarg(t); strarg(t);
switch (t) { switch (t) {
@ -670,16 +671,18 @@ long con(t) {
} }
assert(FALSE); assert(FALSE);
/* NOTREACHED */ /* NOTREACHED */
return 0;
} }
extern char *segname[]; extern char *segname[];
swtxt() { void swtxt()
{
switchseg(SEGTXT); switchseg(SEGTXT);
} }
switchseg(s) { void switchseg(int s)
{
if (s == curseg) if (s == curseg)
return; return;
part_flush(); part_flush();
@ -687,8 +690,9 @@ switchseg(s) {
fprintf(codefile,"%s\n",segname[s]); fprintf(codefile,"%s\n",segname[s]);
} }
savelab() { void savelab()
register char *p,*q; {
char *p,*q;
part_flush(); part_flush();
if (labstr[0]) { if (labstr[0]) {
@ -697,12 +701,12 @@ savelab() {
} }
p = argstr; p = argstr;
q = labstr; q = labstr;
while (*q++ = *p++) while ( (*q++ = *p++) )
; ;
} }
dumplab() { void dumplab()
{
if (labstr[0] == 0) if (labstr[0] == 0)
return; return;
assert(part_size == 0); assert(part_size == 0);
@ -710,16 +714,16 @@ dumplab() {
labstr[0] = 0; labstr[0] = 0;
} }
xdumplab() { void xdumplab()
{
if (labstr[0] == 0) if (labstr[0] == 0)
return; return;
assert(part_size == 0); assert(part_size == 0);
newdlb(labstr); newdlb(labstr);
} }
part_flush() { void part_flush()
{
/* /*
* Each new data fragment and each data label starts at * Each new data fragment and each data label starts at
* a new target machine word * a new target machine word
@ -731,8 +735,8 @@ part_flush() {
part_word = 0; part_word = 0;
} }
string holstr(n) word n; { string holstr(word n)
{
sprintf(str,hol_off,n,holno); sprintf(str,hol_off,n,holno);
return(mystrcpy(str)); return(mystrcpy(str));
} }

34
mach/proto/ncg/fillem.h Normal file
View 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 */

View File

@ -1,8 +1,11 @@
#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 <unistd.h>
#include <stdio.h> #include <stdio.h>
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
@ -11,24 +14,17 @@ static char rcsid[] = "$Id$";
#include "data.h" #include "data.h"
#include "result.h" #include "result.h"
#include "extern.h" #include "extern.h"
#include "compute.h"
#include "utils.h"
#include "gencode.h"
#ifdef USE_TES #ifdef USE_TES
#include "mach.h" #include "mach.h"
#endif #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; FILE *codefile;
extern FILE *freopen();
out_init(filename) char *filename; {
void out_init(char *filename)
{
#ifndef NDEBUG #ifndef NDEBUG
static char stderrbuff[BUFSIZ]; static char stderrbuff[BUFSIZ];
@ -48,8 +44,8 @@ out_init(filename) char *filename; {
#endif #endif
} }
out_finish() { void out_finish()
{
#ifndef NDEBUG #ifndef NDEBUG
if (Debug) if (Debug)
fflush(stderr); fflush(stderr);
@ -61,18 +57,19 @@ out_finish() {
#endif #endif
} }
tstoutput() { void tstoutput()
{
if (ferror(codefile)) if (ferror(codefile))
error("Write error on output"); error("Write error on output");
} }
genstr(stringno) { void genstr(int stringno)
{
fputs(codestrings[stringno],codefile); fputs(codestrings[stringno],codefile);
} }
string ad2str(ad) addr_t ad; { string ad2str(addr_t ad)
{
static char buf[100]; static char buf[100];
if (ad.ea_str==0) if (ad.ea_str==0)
@ -87,8 +84,8 @@ string ad2str(ad) addr_t ad; {
return(mystrcpy(buf)); return(mystrcpy(buf));
} }
praddr(ad) addr_t ad; { void praddr(addr_t ad)
{
if (ad.ea_str==0 || *(ad.ea_str) == '\0') if (ad.ea_str==0 || *(ad.ea_str) == '\0')
fprintf(codefile,WRD_FMT,ad.ea_off); fprintf(codefile,WRD_FMT,ad.ea_off);
else { else {
@ -104,14 +101,16 @@ praddr(ad) addr_t ad; {
} }
} }
gennl() { void gennl()
{
putc('\n',codefile); putc('\n',codefile);
} }
prtoken(tp,leadingchar) token_p tp; { void prtoken(token_p tp, int leadingchar)
register c; {
register char *code; int c;
register tkdef_p tdp; char *code;
tkdef_p tdp;
putc(leadingchar,codefile); putc(leadingchar,codefile);
if (tp->t_token == -1) { if (tp->t_token == -1) {
@ -144,8 +143,7 @@ prtoken(tp,leadingchar) token_p tp; {
} }
#ifdef USE_TES #ifdef USE_TES
printlabel(labnum) void printlabel(int labnum)
int labnum;
{ {
newilb(dollar[labnum].e_v.e_addr.ea_str); newilb(dollar[labnum].e_v.e_addr.ea_str);
} }

20
mach/proto/ncg/gencode.h Normal file
View 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 */

View File

@ -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. * (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>
extern string myalloc(); #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; glosym_p glolist= (glosym_p) 0;
enterglo(name,romp) string name; word *romp; { void enterglo(string name, word *romp)
register glosym_p gp; {
register i; glosym_p gp;
int i;
gp = (glosym_p) myalloc(sizeof *gp); gp = (glosym_p) myalloc(sizeof *gp);
gp->gl_next = glolist; gp->gl_next = glolist;
@ -33,8 +29,9 @@ 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; {
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)
if (strcmp(gp->gl_name,name)==0) if (strcmp(gp->gl_name,name)==0)

View File

@ -3,6 +3,8 @@
* 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$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_GLOSYM_H
#define MACH_PROTO_NCG_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;
glosym_p lookglo(); void enterglo(string name, word *romp);
glosym_p lookglo(string name);
#endif /* MACH_PROTO_NCG_GLOSYM_H */

View File

@ -3,13 +3,15 @@
#include "types.h" #include "types.h"
#include "param.h" #include "param.h"
#include "label.h" #include "label.h"
#include "salloc.h"
#include "utils.h"
#include "label.h"
static label_p label_list = (label_p)0; 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 (height <= 0) return;
if (flth != TRUE && flth != FALSE) if (flth != TRUE && flth != FALSE)
@ -23,10 +25,9 @@ add_label(num, height, flth)
label_list = lbl; label_list = lbl;
} }
label_p get_label(num) label_p get_label(word num)
register word num;
{ {
register label_p tmp = label_list; label_p tmp = label_list;
while (tmp != (label_p)0) { while (tmp != (label_p)0) {
if (tmp->lb_number == num) return tmp; if (tmp->lb_number == num) return tmp;
@ -35,7 +36,7 @@ register word num;
return (label_p)0; return (label_p)0;
} }
kill_labels() void kill_labels()
{ {
label_p tmp; label_p tmp;

View File

@ -4,6 +4,8 @@
* *
* Author: Hans van Eck. * Author: Hans van Eck.
*/ */
#ifndef MACH_PROTO_NCG_LABEL_H
#define MACH_PROTO_NCG_LABEL_H
typedef struct label *label_p; typedef struct label *label_p;
@ -14,4 +16,8 @@ struct label {
short lb_fallthrough; 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
View 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 */

View File

@ -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. * (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 "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; char *progname;
extern char startupcode[]; extern char startupcode[];
extern unsigned codegen();
int maxply=1; int maxply=1;
#ifndef NDEBUG #ifndef NDEBUG
int Debug=0; int Debug=0;
char *strtdebug=""; char *strtdebug="";
#endif #endif
main(argc,argv) char **argv; { static unsigned int ggd(unsigned int a, unsigned int b)
register unsigned n; {
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; extern unsigned cc1,cc2,cc3,cc4;
unsigned ggd();
progname = argv[0]; progname = argv[0];
while (--argc && **++argv == '-') { while (--argc && **++argv == '-') {
@ -83,12 +99,3 @@ main(argc,argv) char **argv; {
codegen(startupcode,maxply,TRUE,MAXINT,0); codegen(startupcode,maxply,TRUE,MAXINT,0);
error("Bombed out of codegen"); 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);
}

View File

@ -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,21 +12,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 "utils.h"
#include "codegen.h"
/* #include "move.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
*/
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; { int move(token_p tp1, token_p tp2, int ply, int toplevel, unsigned int maxcost)
register move_p mp; {
unsigned t; move_p mp;
register struct reginfo *rp; unsigned int t;
register byte *tdpb; struct reginfo *rp;
byte *tdpb;
int i; int i;
unsigned codegen();
if (eqtoken(tp1,tp2)) if (eqtoken(tp1,tp2))
return(0); return(0);
@ -95,15 +96,15 @@ move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
#define cocoreg machregs[0].r_contents #define cocoreg machregs[0].r_contents
setcc(tp) token_p tp; { void setcc(token_p tp)
{
cocoreg = *tp; cocoreg = *tp;
} }
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; { int test(token_p tp, int ply, int toplevel, unsigned int maxcost)
register test_p mp; {
unsigned t; test_p mp;
unsigned codegen(); unsigned int t;
if (cocoreg.t_token!=0) { if (cocoreg.t_token!=0) {
if (eqtoken(tp,&cocoreg)) if (eqtoken(tp,&cocoreg))

14
mach/proto/ncg/move.h Normal file
View 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 */

View File

@ -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,18 @@ static char rcsid[] = "$Id$";
#include "data.h" #include "data.h"
#include "result.h" #include "result.h"
#include "extern.h" #include "extern.h"
#include "compute.h"
/* #include "fillem.h"
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. #include "nextem.h"
* 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; { byte *trypat(byte *bp, int len)
register patlen,i; {
int patlen,i;
result_t result; result_t result;
getint(patlen,bp); getint(patlen,bp);
@ -83,8 +82,8 @@ byte *trypat(bp,len) register byte *bp; {
extern char em_flag[]; extern char em_flag[];
argtyp(mn) { int argtyp(int mn)
{
switch(em_flag[mn-sp_fmnem]&EM_PAR) { switch(em_flag[mn-sp_fmnem]&EM_PAR) {
case PAR_W: case PAR_W:
case PAR_S: case PAR_S:
@ -101,13 +100,14 @@ argtyp(mn) {
} }
} }
byte *nextem(toplevel) { byte *nextem(int toplevel)
register i; {
int i;
short hash[3]; short hash[3];
register byte *bp; byte *bp;
byte *cp; byte *cp;
int index; int index;
register struct emline *ep; struct emline *ep;
if (toplevel) { if (toplevel) {
if (nemlines && emp>emlines) { if (nemlines && emp>emlines) {

14
mach/proto/ncg/nextem.h Normal file
View 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 */

View File

@ -3,6 +3,8 @@
* 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$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_PARAM_H
#define MACH_PROTO_NCG_PARAM_H
#define BMASK 0377 #define BMASK 0377
#define BSHIFT 8 #define BSHIFT 8
@ -24,3 +26,5 @@
#define MAXEMLINES 20 #define MAXEMLINES 20
#define MAXFSTACK 20 #define MAXFSTACK 20
#define MAXTDBUG 32 #define MAXTDBUG 32
#endif /* MACH_PROTO_NCG_PARAM_H */

View File

@ -41,6 +41,7 @@ proto_ncg = cprogram {
cfile_with_tables (d.."state.c"), cfile_with_tables (d.."state.c"),
cfile_with_tables (d.."subr.c"), cfile_with_tables (d.."subr.c"),
cfile_with_tables (d.."var.c"), cfile_with_tables (d.."var.c"),
cfile_with_tables (d.."utils.c"),
cfile { cfile {
ith { make_tables, i = 1 }, ith { make_tables, i = 1 },

View File

@ -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,18 +12,15 @@ static char rcsid[] = "$Id$";
#include "data.h" #include "data.h"
#include "result.h" #include "result.h"
#include "extern.h" #include "extern.h"
#include "utils.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
*/
chrefcount(regno,amount,tflag) { void chrefcount(int regno, int amount, int tflag)
register struct reginfo *rp; {
struct reginfo *rp;
#if MAXMEMBERS != 0 #if MAXMEMBERS != 0
register i, tmp; int i, tmp;
#endif #endif
rp= &machregs[regno]; rp= &machregs[regno];
@ -40,10 +39,11 @@ chrefcount(regno,amount,tflag) {
#endif #endif
} }
getrefcount(regno, tflag) { int getrefcount(int regno, int tflag)
register struct reginfo *rp; {
struct reginfo *rp;
#if MAXMEMBERS != 0 #if MAXMEMBERS != 0
register i,maxcount, tmp; int i,maxcount, tmp;
#endif #endif
rp= &machregs[regno]; rp= &machregs[regno];
@ -61,13 +61,15 @@ getrefcount(regno, tflag) {
} }
return(maxcount); return(maxcount);
} }
return 0;
#endif #endif
} }
erasereg(regno) { void erasereg(int regno)
register struct reginfo *rp = &machregs[regno]; {
register int i; struct reginfo *rp = &machregs[regno];
register byte *tdpb; int i;
byte *tdpb;
#if MAXMEMBERS==0 #if MAXMEMBERS==0
rp->r_contents.t_token = 0; rp->r_contents.t_token = 0;
@ -106,7 +108,7 @@ erasereg(regno) {
} }
#else #else
extern short clashlist[]; extern short clashlist[];
register short *sp = &clashlist[rp->r_iclash]; short *sp = &clashlist[rp->r_iclash];
rp->r_contents.t_token = 0; rp->r_contents.t_token = 0;
while (*sp) { while (*sp) {
@ -149,9 +151,10 @@ erasereg(regno) {
#endif #endif
} }
cleanregs() { void cleanregs()
register struct reginfo *rp; {
register i; struct reginfo *rp;
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;
@ -161,9 +164,10 @@ cleanregs() {
} }
#ifndef NDEBUG #ifndef NDEBUG
inctcount(regno) { void inctcount(int regno)
register struct reginfo *rp; {
register i; struct reginfo *rp;
int i;
rp = &machregs[regno]; rp = &machregs[regno];
#if MAXMEMBERS!=0 #if MAXMEMBERS!=0
@ -179,10 +183,11 @@ inctcount(regno) {
#endif #endif
} }
chkregs() { void chkregs()
register struct reginfo *rp; {
register token_p tp; struct reginfo *rp;
register byte *tdpb; token_p tp;
byte *tdpb;
int i; int i;
for (rp=machregs+1;rp<machregs+NREGS;rp++) { for (rp=machregs+1;rp<machregs+NREGS;rp++) {

17
mach/proto/ncg/reg.h Normal file
View 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 */

View File

@ -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 "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 <cgg_cg.h> #include <cgg_cg.h>
#include "data.h" #include "data.h"
@ -15,19 +17,17 @@ 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 "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 *rvlist;
struct regvar * struct regvar *linkreg(long of, int sz, int tp, int sc)
linkreg(of,sz,tp,sc) long of; { {
register struct regvar *rvlp; struct regvar *rvlp;
rvlp= (struct regvar *) myalloc(sizeof *rvlp); rvlp= (struct regvar *) myalloc(sizeof *rvlp);
rvlp->rv_next = rvlist; rvlp->rv_next = rvlist;
@ -40,10 +40,11 @@ linkreg(of,sz,tp,sc) long of; {
return(rvlp); return(rvlp);
} }
tryreg(rvlp,typ) register struct regvar *rvlp; { void tryreg(struct regvar *rvlp, int typ)
{
int score; int score;
register i; int i;
register struct regassigned *ra; struct regassigned *ra;
struct regvar *save; struct regvar *save;
if (typ != reg_any && nregvar[typ]!=0) { if (typ != reg_any && nregvar[typ]!=0) {
@ -85,10 +86,11 @@ tryreg(rvlp,typ) register struct regvar *rvlp; {
} }
} }
fixregvars(saveall) { void fixregvars(int saveall)
register struct regvar *rv; {
register rvtyp,i; struct regvar *rv;
int rvtyp,i;
swtxt(); swtxt();
i_regsave(); /* machine dependent initialization */ i_regsave(); /* machine dependent initialization */
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) { for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
@ -108,8 +110,9 @@ fixregvars(saveall) {
f_regsave(); f_regsave();
} }
isregvar(off) long off; { int isregvar(long off)
register struct regvar *rvlp; {
struct regvar *rvlp;
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next) for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
if(rvlp->rv_off == off) if(rvlp->rv_off == off)
@ -117,8 +120,9 @@ isregvar(off) long off; {
return(-1); return(-1);
} }
isregtyp(off) long off; { int isregtyp(long off)
register struct regvar *rvlp; {
struct regvar *rvlp;
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next) for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
if(rvlp->rv_off == off) if(rvlp->rv_off == off)
@ -126,9 +130,10 @@ isregtyp(off) long off; {
return(-1); return(-1);
} }
unlinkregs() { void unlinkregs()
register struct regvar *rvlp,*t; {
register struct regassigned *ra; struct regvar *rvlp,*t;
struct regassigned *ra;
int rvtyp,i; int rvtyp,i;
for(rvlp=rvlist;rvlp!=0;rvlp=t) { for(rvlp=rvlist;rvlp!=0;rvlp=t) {

View File

@ -3,6 +3,8 @@
* 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$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_REGVAR_H
#define MACH_PROTO_NCG_REGVAR_H
struct regvar { struct regvar {
struct regvar *rv_next; struct regvar *rv_next;
@ -21,3 +23,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);
int isregtyp(long off);
void unlinkregs();
#endif /* MACH_PROTO_NCG_REGVAR_H */

View File

@ -4,6 +4,9 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_RESULT_H
#define MACH_PROTO_NCG_RESULT_H
struct result { struct result {
int e_typ; /* EV_INT,EV_REG,EV_STR */ int e_typ; /* EV_INT,EV_REG,EV_STR */
union { union {
@ -19,3 +22,5 @@ struct result {
#define EV_ADDR 3 #define EV_ADDR 3
typedef struct result result_t; typedef struct result result_t;
#endif /* MACH_PROTO_NCG_RESULT_H */

View File

@ -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. * (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".
@ -24,6 +10,18 @@ static char rcsid[] = "$Id$";
* Call salloc(size) to get room for string. * Call salloc(size) to get room for string.
* Every now and then call garbage_collect() from toplevel. * 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 MAXSTAB 1500
#define THRESHOLD 200 #define THRESHOLD 200
@ -31,8 +29,9 @@ static char rcsid[] = "$Id$";
char *stab[MAXSTAB]; char *stab[MAXSTAB];
int nstab=0; int nstab=0;
string myalloc(size) { string myalloc(int size)
register string p; {
string p;
p = (string) malloc((unsigned)size); p = (string) malloc((unsigned)size);
if (p==0) if (p==0)
@ -40,21 +39,23 @@ string myalloc(size) {
return(p); return(p);
} }
myfree(p) string p; { void myfree(string p)
{
free(p); free(p);
} }
popstr(nnstab) { void popstr(int nnstab)
register i; {
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; {
char *p;
if (nstab==MAXSTAB) if (nstab==MAXSTAB)
fatal("String table overflow"); fatal("String table overflow");
@ -63,21 +64,24 @@ char *salloc(size) {
return(p); 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); assert(*p1 != *p2);
if (*p1 < *p2) if (*p1 < *p2)
return(-1); return(-1);
return(1); return(1);
} }
garbage_collect() { void garbage_collect()
register i; {
int i;
struct emline *emlp; struct emline *emlp;
token_p tp; token_p tp;
tkdef_p tdp; tkdef_p tdp;
struct reginfo *rp; struct reginfo *rp;
register char **fillp,**scanp; char **fillp,**scanp;
char used[MAXSTAB]; /* could be bitarray */ char used[MAXSTAB]; /* could be bitarray */
if (nstab<THRESHOLD) if (nstab<THRESHOLD)
@ -115,8 +119,9 @@ garbage_collect() {
nstab = fillp-stab; nstab = fillp-stab;
} }
chkstr(str,used) string str; char used[]; { void chkstr(string str, char used[])
register low,middle,high; {
int low,middle,high;
low=0; high=nstab-1; low=0; high=nstab-1;
while (high>low) { while (high>low) {

18
mach/proto/ncg/salloc.h Normal file
View 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 */

View File

@ -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,18 +13,15 @@ static char rcsid[] = "$Id$";
#include "result.h" #include "result.h"
#include "state.h" #include "state.h"
#include "extern.h" #include "extern.h"
#include "salloc.h"
#include "utils.h"
/* #include "state.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 */
savestatus(sp) register state_p sp; { void savestatus(state_p sp)
{
sp->st_sh = stackheight; sp->st_sh = stackheight;
bmove((short *)fakestack,(short *)sp->st_fs,stackheight*sizeof(token_t)); bmove((short *)fakestack,(short *)sp->st_fs,stackheight*sizeof(token_t));
sp->st_na = nallreg; sp->st_na = nallreg;
@ -38,8 +37,8 @@ savestatus(sp) register state_p sp; {
sp->st_ns = nstab; sp->st_ns = nstab;
} }
restorestatus(sp) register state_p sp; { void restorestatus(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;
@ -55,8 +54,8 @@ restorestatus(sp) register state_p sp; {
popstr(sp->st_ns); 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) if (nbytes<=0)
return; return;
assert(sizeof(short)==2 && (nbytes&1)==0); assert(sizeof(short)==2 && (nbytes&1)==0);

View File

@ -3,6 +3,8 @@
* 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$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_STATE_H
#define MACH_PROTO_NCG_STATE_H
typedef struct state { typedef struct state {
struct state *st_next; /* for linked list */ struct state *st_next; /* for linked list */
@ -20,3 +22,9 @@ typedef struct state {
int st_tl; /* tokpatlen */ int st_tl; /* tokpatlen */
int st_ns; /* nstab */ int st_ns; /* nstab */
} state_t,*state_p; } 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 */

View File

@ -1,9 +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 <stdio.h> #include <stdio.h>
#include <string.h>
#include "assert.h" #include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
@ -12,19 +15,17 @@ static char rcsid[] = "$Id$";
#include "data.h" #include "data.h"
#include "result.h" #include "result.h"
#include "extern.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"
/* int match(token_p tp, set_p tep, int optexp)
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. {
* See the copyright notice in the ACK home directory, in the file "Copyright". int bitno;
*
* Author: Hans van Staveren
*/
string myalloc();
unsigned codegen();
match(tp,tep,optexp) register token_p tp; register set_p tep; {
register bitno;
token_p ct; token_p ct;
result_t result; 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); return(result.e_v.e_con);
} }
instance(instno,token) register token_p token; { void instance(int instno, token_p token)
register inst_p inp; {
inst_p inp;
int i; int i;
register token_p tp; token_p tp;
#if MAXMEMBERS != 0 #if MAXMEMBERS != 0
struct reginfo *rp; struct reginfo *rp;
#endif #endif
@ -145,8 +147,9 @@ instance(instno,token) register token_p token; {
} }
} }
cinstance(instno,token,tp,regno) register token_p token,tp; { void cinstance(int instno,token_p token, token_p tp, int regno)
register inst_p inp; {
inst_p inp;
int i; int i;
#if MAXMEMBERS != 0 #if MAXMEMBERS != 0
struct reginfo *rp; struct reginfo *rp;
@ -240,9 +243,10 @@ 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 tkdef_p tdp; int i;
tkdef_p tdp;
if (tp1->t_token!=tp2->t_token) if (tp1->t_token!=tp2->t_token)
return(0); return(0);
@ -276,10 +280,11 @@ eqtoken(tp1,tp2) token_p tp1,tp2; {
return(1); return(1);
} }
distance(cindex) { int distance(int cindex)
register char *bp; {
register i; char *bp;
register token_p tp; int i;
token_p tp;
int tokexp,tpl; int tokexp,tpl;
int expsize,toksize,exact; int expsize,toksize,exact;
int xsekt=0; int xsekt=0;
@ -355,37 +360,38 @@ distance(cindex) {
extern set_t unstackset; extern set_t unstackset;
int from_stack(s1) int from_stack(set_p s1)
register set_p s1;
{ {
register set_p s2 = &unstackset; set_p s2 = &unstackset;
register int i; int i;
for (i = 0; i < SETSIZE; i++) { for (i = 0; i < SETSIZE; i++) {
if ((s1->set_val[i] & s2->set_val[i]) != 0) return 1; if ((s1->set_val[i] & s2->set_val[i]) != 0) return 1;
} }
return 0; return 0;
} }
unsigned costcalc(cost) cost_t cost; { unsigned int costcalc(cost_t cost)
{
extern unsigned cc1,cc2,cc3,cc4; extern unsigned cc1,cc2,cc3,cc4;
return(cost.ct_space*cc1/cc2 + cost.ct_time*cc3/cc4); return(cost.ct_space*cc1/cc2 + cost.ct_time*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(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;
@ -418,9 +424,10 @@ instsize(tinstno,tp) token_p tp; {
} }
#endif /* MAXSPLIT */ #endif /* MAXSPLIT */
tref(tp,amount) register token_p tp; { void tref(token_p tp, int amount)
register i; {
register byte *tdpb; int i;
byte *tdpb;
if (tp->t_token==-1) if (tp->t_token==-1)
chrefcount(tp->t_att[0].ar,amount,FALSE); chrefcount(tp->t_att[0].ar,amount,FALSE);
@ -440,7 +447,8 @@ tref(tp,amount) register token_p tp; {
token_t aside[MAXSAVE] ; token_t aside[MAXSAVE] ;
int aside_length = -1 ; int aside_length = -1 ;
save_stack(tp) register token_p tp ; { void save_stack(token_p tp)
{
int i ; int i ;
token_p tmp = &fakestack[stackheight - 1]; token_p tmp = &fakestack[stackheight - 1];
@ -458,10 +466,11 @@ save_stack(tp) register token_p tp ; {
stackheight -= aside_length; stackheight -= aside_length;
} }
in_stack(reg) { int in_stack(int reg)
register token_p tp ; {
register i ; token_p tp ;
register tkdef_p tdp ; int i ;
tkdef_p tdp ;
for ( i=0, tp=aside ; i<aside_length ; i++, tp++ ) for ( i=0, tp=aside ; i<aside_length ; i++, tp++ )
if (tp->t_token==-1) { if (tp->t_token==-1) {
@ -484,8 +493,9 @@ gotone:
return 1 ; return 1 ;
} }
rest_stack() { void rest_stack()
register int i ; {
int i ;
assert(aside_length!= -1); assert(aside_length!= -1);
#ifndef NDEBUG #ifndef NDEBUG
@ -499,11 +509,12 @@ rest_stack() {
} }
#ifdef MAXSPLIT #ifdef MAXSPLIT
split(tp,ip,ply,toplevel) token_p tp; register int *ip; { voir split(token_p tp, int *ip, int ply, int toplevel)
register c2_p cp; {
c2_p cp;
token_t savestack[MAXSAVE]; token_t savestack[MAXSAVE];
int ok; int ok;
register i; int i;
int diff; int diff;
token_p stp; token_p stp;
int tpl; int tpl;
@ -533,8 +544,9 @@ found:
} }
#endif /* MAXSPLIT */ #endif /* MAXSPLIT */
unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; register c3_p cp; { unsigned int docoerc(token_p tp, c3_p cp, int ply, int toplevel, int forced)
unsigned cost; {
unsigned int cost;
int tpl; /* saved tokpatlen */ int tpl; /* saved tokpatlen */
save_stack(tp) ; save_stack(tp) ;
@ -547,16 +559,17 @@ unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; register c3_p cp; {
return(cost); 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_t savestack[MAXFSTACK];
token_p stp; token_p stp;
int i,diff; int i,diff;
int tpl; /* saved tokpatlen */ int tpl; /* saved tokpatlen */
int nareg; /* saved nareg */ int nareg; /* saved nareg */
int areg[MAXALLREG]; int areg[MAXALLREG];
register c1_p cp; c1_p cp;
register token_p tp; token_p tp;
unsigned totalcost=0; int totalcost=0;
struct reginfo *rp,**rpp; struct reginfo *rp,**rpp;
for (tp=fakestack;tp<=limit;limit--) { for (tp=fakestack;tp<=limit;limit--) {
@ -611,11 +624,12 @@ 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; {
c3_p cp;
token_t rtoken; token_t rtoken;
register i; int i;
register struct reginfo **rpp; struct reginfo **rpp;
for (cp=c3coercs;cp->c3_texpno>=0; cp++) { for (cp=c3coercs;cp->c3_texpno>=0; cp++) {
if (tp!=(token_p) 0) { if (tp!=(token_p) 0) {
@ -648,63 +662,10 @@ c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
return(0); /* nothing found */ return(0); /* nothing found */
} }
itokcost() { void itokcost()
register tkdef_p tdp; {
tkdef_p tdp;
for(tdp=tokens+1;tdp->t_size!=0;tdp++) for(tdp=tokens+1;tdp->t_size!=0;tdp++)
tdp->t_cost.ct_space = costcalc(tdp->t_cost); 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
View 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 */

View File

@ -4,15 +4,17 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef MACH_PROTO_NCG_TYPES_H
#define MACH_PROTO_NCG_TYPES_H
#ifndef TEM_WSIZE #ifndef TEM_WSIZE
TEM_WSIZE should be defined at this point #warning TEM_WSIZE should be defined at this point
#endif #endif
#ifndef TEM_PSIZE #ifndef TEM_PSIZE
TEM_PSIZE should be defined at this point #warning TEM_PSIZE should be defined at this point
#endif #endif
#if TEM_WSIZE>4 || TEM_PSIZE>4 #if TEM_WSIZE>4 || TEM_PSIZE>4
Implementation will not be correct unless a long integer #error 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 char byte;
@ -21,10 +23,12 @@ typedef char * string;
#if TEM_WSIZE>2 || TEM_PSIZE>2 #if TEM_WSIZE>2 || TEM_PSIZE>2
#define full long #define full long
#else #else
#define full int #define full int
#endif #endif
#define word long #define word long
#ifndef WRD_FMT #ifndef WRD_FMT
#define WRD_FMT "%ld" #define WRD_FMT "%ld"
#endif /* WRD_FMT */ #endif /* WRD_FMT */
#endif /* MACH_PROTO_NCG_TYPES_H */

81
mach/proto/ncg/utils.c Normal file
View 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
View 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 */

View File

@ -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. * (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 "param.h"
#include "tables.h"
#include "types.h"
#include <cgg_cg.h>
#include "data.h"
#include "result.h"
int stackheight = 0; int stackheight = 0;
token_t fakestack[MAXFSTACK]; token_t fakestack[MAXFSTACK];