ANSI C conversion
This commit is contained in:
parent
708c1ba1b0
commit
de45c1036d
File diff suppressed because it is too large
Load diff
13
mach/proto/cg/codegen.h
Normal file
13
mach/proto/cg/codegen.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-14
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef CODEGEN_H_
|
||||||
|
#define CODEGEN_H_
|
||||||
|
|
||||||
|
unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, int forced);
|
||||||
|
|
||||||
|
#endif /* CODEGEN_H_ */
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -14,13 +16,9 @@ static char rcsid[] = "$Id$";
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "glosym.h"
|
#include "glosym.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define LLEAF 01
|
#define LLEAF 01
|
||||||
#define LDEF 02
|
#define LDEF 02
|
||||||
|
@ -73,9 +71,10 @@ char opdesc[] = {
|
||||||
LLDEF, /* EX_REGVAR */
|
LLDEF, /* EX_REGVAR */
|
||||||
};
|
};
|
||||||
|
|
||||||
string salloc();
|
|
||||||
|
|
||||||
string mycat(s1,s2) string s1,s2; {
|
|
||||||
|
string mycat(string s1,string s2)
|
||||||
|
{
|
||||||
register string s;
|
register string s;
|
||||||
|
|
||||||
s=salloc(strlen(s1)+strlen(s2));
|
s=salloc(strlen(s1)+strlen(s2));
|
||||||
|
@ -84,7 +83,8 @@ string mycat(s1,s2) string s1,s2; {
|
||||||
return(s);
|
return(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
string mystrcpy(s) string s; {
|
string mystrcpy(string s)
|
||||||
|
{
|
||||||
register string r;
|
register string r;
|
||||||
|
|
||||||
r=salloc(strlen(s));
|
r=salloc(strlen(s));
|
||||||
|
@ -94,7 +94,8 @@ string mystrcpy(s) string s; {
|
||||||
|
|
||||||
char digstr[21][15];
|
char digstr[21][15];
|
||||||
|
|
||||||
string tostring(n) word n; {
|
string tostring(word n)
|
||||||
|
{
|
||||||
char buf[25];
|
char buf[25];
|
||||||
|
|
||||||
if (n>=-20 && n<=20 && (n&1)==0) {
|
if (n>=-20 && n<=20 && (n&1)==0) {
|
||||||
|
@ -108,7 +109,8 @@ string tostring(n) word n; {
|
||||||
|
|
||||||
result_t undefres= {EV_UNDEF};
|
result_t undefres= {EV_UNDEF};
|
||||||
|
|
||||||
result_t compute(node) register node_p node; {
|
result_t compute(register node_p node)
|
||||||
|
{
|
||||||
result_t leaf1,leaf2,result;
|
result_t leaf1,leaf2,result;
|
||||||
token_p tp;
|
token_p tp;
|
||||||
int desc;
|
int desc;
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef DATA_H_
|
||||||
|
#define DATA_H_
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int t_token; /* kind of token, -1 for register */
|
int t_token; /* kind of token, -1 for register */
|
||||||
|
@ -56,3 +59,5 @@ typedef struct {
|
||||||
int rl_n; /* number in list */
|
int rl_n; /* number in list */
|
||||||
int rl_list[NREGS];
|
int rl_list[NREGS];
|
||||||
} rl_t,*rl_p;
|
} rl_t,*rl_p;
|
||||||
|
|
||||||
|
#endif /* DATA_H_ */
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "equiv.h"
|
#include "equiv.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
@ -11,15 +13,12 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
#include "reg.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern string myalloc();
|
|
||||||
|
|
||||||
int rar[MAXCREG];
|
int rar[MAXCREG];
|
||||||
rl_p* lar;
|
rl_p* lar;
|
||||||
|
@ -27,12 +26,12 @@ int maxindex;
|
||||||
int regclass[NREGS];
|
int regclass[NREGS];
|
||||||
struct perm* perms;
|
struct perm* perms;
|
||||||
|
|
||||||
void permute(int index);
|
static void permute(int index);
|
||||||
|
|
||||||
struct perm* tuples(rl_p* regls, int nregneeded)
|
struct perm* tuples(rl_p* regls, int nregneeded)
|
||||||
{
|
{
|
||||||
int class = 0;
|
int class = 0;
|
||||||
register i, j;
|
register int i, j;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First compute equivalence classes of registers.
|
* First compute equivalence classes of registers.
|
||||||
|
@ -66,11 +65,11 @@ struct perm* tuples(rl_p* regls, int nregneeded)
|
||||||
return (perms);
|
return (perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void permute(int index)
|
static void permute(int index)
|
||||||
{
|
{
|
||||||
register struct perm* pp;
|
register struct perm* pp;
|
||||||
register rl_p rlp;
|
register rl_p rlp;
|
||||||
register i, j;
|
register int i, j;
|
||||||
|
|
||||||
if (index == maxindex)
|
if (index == maxindex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef EQUIV_H_
|
||||||
|
#define EQUIV_H_
|
||||||
|
|
||||||
|
|
||||||
#define MAXCREG 4
|
#define MAXCREG 4
|
||||||
|
|
||||||
|
@ -10,3 +12,6 @@ struct perm {
|
||||||
struct perm *p_next;
|
struct perm *p_next;
|
||||||
int p_rar[MAXCREG];
|
int p_rar[MAXCREG];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* EQUIV_H_ */
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid2[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -18,23 +20,48 @@ static char rcsid2[] = "$Id$";
|
||||||
#include <cg_pattern.h>
|
#include <cg_pattern.h>
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "reg.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
#include "gencode.h"
|
||||||
|
#include "glosym.h"
|
||||||
#ifdef REGVARS
|
#ifdef REGVARS
|
||||||
#include "regvar.h"
|
#include "regvar.h"
|
||||||
#include <em_reg.h>
|
#include <em_reg.h>
|
||||||
#endif
|
#endif
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef newplb /* retrofit for older mach.h */
|
#ifndef newplb /* retrofit for older mach.h */
|
||||||
#define newplb newilb
|
#define newplb newilb
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
string tostring();
|
||||||
|
static string holstr(word n);
|
||||||
|
static char *strarg(int t);
|
||||||
|
string mystrcpy();
|
||||||
|
static int get16(void);
|
||||||
|
static long get32(void);
|
||||||
|
static int getarg(int typset);
|
||||||
|
static void getstring(void);
|
||||||
|
static void switchseg(int s);
|
||||||
|
static int table1(void);
|
||||||
|
static int table2(void);
|
||||||
|
static int table3(int i);
|
||||||
|
static void bss(full n, int t, int b);
|
||||||
|
void swtxt(void);
|
||||||
|
static void savelab(void);
|
||||||
|
static void dumplab(void);
|
||||||
|
static void xdumplab(void);
|
||||||
|
static void part_flush(void);
|
||||||
|
static long con(int t);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef fmt_id
|
#ifdef fmt_id
|
||||||
#ifdef id_first
|
#ifdef id_first
|
||||||
It is an error to define both fmt_id and id_first.
|
It is an error to define both fmt_id and id_first.
|
||||||
|
@ -55,7 +82,7 @@ Read the documentation.
|
||||||
#define SEGROM 2
|
#define SEGROM 2
|
||||||
#define SEGBSS 3
|
#define SEGBSS 3
|
||||||
|
|
||||||
long con();
|
|
||||||
|
|
||||||
#define get8() getc(emfile)
|
#define get8() getc(emfile)
|
||||||
|
|
||||||
|
@ -63,7 +90,6 @@ long con();
|
||||||
|
|
||||||
FILE *emfile;
|
FILE *emfile;
|
||||||
extern FILE *codefile;
|
extern FILE *codefile;
|
||||||
extern FILE *freopen();
|
|
||||||
|
|
||||||
int nextispseu,savetab1;
|
int nextispseu,savetab1;
|
||||||
int opcode;
|
int opcode;
|
||||||
|
@ -84,14 +110,14 @@ int regallowed=0;
|
||||||
|
|
||||||
extern char em_flag[];
|
extern char em_flag[];
|
||||||
extern short em_ptyp[];
|
extern short em_ptyp[];
|
||||||
extern double atof();
|
|
||||||
extern void con_float(void);
|
|
||||||
|
|
||||||
|
|
||||||
/* Own version of atol that continues computing on overflow.
|
/* Own version of atol that continues computing on overflow.
|
||||||
We don't know that about the ANSI C one.
|
We don't know that about the ANSI C one.
|
||||||
*/
|
*/
|
||||||
long our_atol(s)
|
static long our_atol(register char *s)
|
||||||
register char *s;
|
|
||||||
{
|
{
|
||||||
register long total = 0;
|
register long total = 0;
|
||||||
register unsigned digit;
|
register unsigned digit;
|
||||||
|
@ -112,13 +138,8 @@ register char *s;
|
||||||
|
|
||||||
#define sp_cstx sp_cst2
|
#define sp_cstx sp_cst2
|
||||||
|
|
||||||
string tostring();
|
|
||||||
string holstr();
|
|
||||||
string strarg();
|
|
||||||
string mystrcpy();
|
|
||||||
long get32();
|
|
||||||
|
|
||||||
in_init(filename) char *filename; {
|
void in_init(char *filename) {
|
||||||
|
|
||||||
if ((emfile=freopen(filename,"r",stdin))==NULL)
|
if ((emfile=freopen(filename,"r",stdin))==NULL)
|
||||||
error("Can't open %s",filename);
|
error("Can't open %s",filename);
|
||||||
|
@ -126,16 +147,16 @@ in_init(filename) char *filename; {
|
||||||
error("Bad format %s",filename);
|
error("Bad format %s",filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
in_start() {
|
void in_start(void) {
|
||||||
#ifdef modhead
|
#ifdef modhead
|
||||||
fprintf(codefile,"%s",modhead) ;
|
fprintf(codefile,"%s",modhead) ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
in_finish() {
|
void in_finish(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fillemlines() {
|
void fillemlines(void) {
|
||||||
int t,i;
|
int t,i;
|
||||||
register struct emline *lp;
|
register struct emline *lp;
|
||||||
|
|
||||||
|
@ -214,14 +235,14 @@ fillemlines() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dopseudo() {
|
void dopseudo(void) {
|
||||||
register b,t;
|
register int b,t;
|
||||||
register full n;
|
register full n;
|
||||||
register long save;
|
register long save;
|
||||||
word romcont[MAXROM+1];
|
word romcont[MAXROM+1];
|
||||||
int nromwords;
|
int nromwords;
|
||||||
int rombit,rommask;
|
int rombit,rommask;
|
||||||
unsigned dummy,stackupto();
|
int dummy;
|
||||||
|
|
||||||
if (nextispseu==0 || nemlines>0)
|
if (nextispseu==0 || nemlines>0)
|
||||||
error("No table entry for %d",emlines[0].em_instr);
|
error("No table entry for %d",emlines[0].em_instr);
|
||||||
|
@ -396,8 +417,8 @@ dopseudo() {
|
||||||
|
|
||||||
/* ----- input ----- */
|
/* ----- input ----- */
|
||||||
|
|
||||||
int getarg(typset) {
|
static int getarg(int typset) {
|
||||||
register t,argtyp;
|
register int t,argtyp;
|
||||||
|
|
||||||
argtyp = t = table2();
|
argtyp = t = table2();
|
||||||
if (t == EOF)
|
if (t == EOF)
|
||||||
|
@ -409,8 +430,8 @@ int getarg(typset) {
|
||||||
return(argtyp);
|
return(argtyp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int table1() {
|
static int table1(void) {
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
i = get8();
|
i = get8();
|
||||||
if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
|
if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
|
||||||
|
@ -428,8 +449,8 @@ int table1() {
|
||||||
return(table3(i));
|
return(table3(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
int table2() {
|
static int table2(void) {
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
i = get8();
|
i = get8();
|
||||||
if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
|
if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
|
||||||
|
@ -439,7 +460,7 @@ int table2() {
|
||||||
return(table3(i));
|
return(table3(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
int table3(i) {
|
static int table3(int i) {
|
||||||
word consiz;
|
word consiz;
|
||||||
|
|
||||||
switch(i) {
|
switch(i) {
|
||||||
|
@ -482,7 +503,7 @@ int table3(i) {
|
||||||
return(i);
|
return(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get16() {
|
static int get16(void) {
|
||||||
register int l_byte, h_byte;
|
register int l_byte, h_byte;
|
||||||
|
|
||||||
l_byte = get8();
|
l_byte = get8();
|
||||||
|
@ -491,7 +512,7 @@ int get16() {
|
||||||
return l_byte | (h_byte*256) ;
|
return l_byte | (h_byte*256) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
long get32() {
|
static long get32(void) {
|
||||||
register long l;
|
register long l;
|
||||||
register int h_byte;
|
register int h_byte;
|
||||||
|
|
||||||
|
@ -503,9 +524,9 @@ long get32() {
|
||||||
return l | (h_byte*256L*256*256L) ;
|
return l | (h_byte*256L*256*256L) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
getstring() {
|
static void getstring(void) {
|
||||||
register char *p;
|
register char *p;
|
||||||
register n;
|
register int n;
|
||||||
|
|
||||||
getarg(cst_ptyp);
|
getarg(cst_ptyp);
|
||||||
if (argval < 0 || argval > MAXSTR-1)
|
if (argval < 0 || argval > MAXSTR-1)
|
||||||
|
@ -517,7 +538,7 @@ getstring() {
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strarg(t) {
|
static char *strarg(int t) {
|
||||||
register char *p;
|
register char *p;
|
||||||
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
|
@ -565,7 +586,8 @@ char *strarg(t) {
|
||||||
return(mystrcpy(argstr));
|
return(mystrcpy(argstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
bss(n,t,b) full n; {
|
static void bss(full n, int t, int b)
|
||||||
|
{
|
||||||
register long s;
|
register long s;
|
||||||
|
|
||||||
if (n % TEM_WSIZE)
|
if (n % TEM_WSIZE)
|
||||||
|
@ -588,8 +610,8 @@ bss(n,t,b) full n; {
|
||||||
fatal("bad BSS initializer");
|
fatal("bad BSS initializer");
|
||||||
}
|
}
|
||||||
|
|
||||||
long con(t) {
|
static long con(int t) {
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
strarg(t);
|
strarg(t);
|
||||||
switch (t) {
|
switch (t) {
|
||||||
|
@ -633,11 +655,11 @@ long con(t) {
|
||||||
|
|
||||||
extern char *segname[];
|
extern char *segname[];
|
||||||
|
|
||||||
swtxt() {
|
void swtxt(void) {
|
||||||
switchseg(SEGTXT);
|
switchseg(SEGTXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
switchseg(s) {
|
static void switchseg(int s) {
|
||||||
|
|
||||||
if (s == curseg)
|
if (s == curseg)
|
||||||
return;
|
return;
|
||||||
|
@ -646,9 +668,9 @@ switchseg(s) {
|
||||||
fprintf(codefile,"%s\n",segname[s]);
|
fprintf(codefile,"%s\n",segname[s]);
|
||||||
}
|
}
|
||||||
|
|
||||||
savelab() {
|
static void savelab(void)
|
||||||
|
{
|
||||||
register char *p,*q;
|
register char *p,*q;
|
||||||
|
|
||||||
part_flush();
|
part_flush();
|
||||||
if (labstr[0]) {
|
if (labstr[0]) {
|
||||||
dlbdlb(argstr,labstr);
|
dlbdlb(argstr,labstr);
|
||||||
|
@ -656,11 +678,11 @@ savelab() {
|
||||||
}
|
}
|
||||||
p = argstr;
|
p = argstr;
|
||||||
q = labstr;
|
q = labstr;
|
||||||
while (*q++ = *p++)
|
while ((*q++ = *p++))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
dumplab() {
|
static void dumplab(void) {
|
||||||
|
|
||||||
if (labstr[0] == 0)
|
if (labstr[0] == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -669,7 +691,7 @@ dumplab() {
|
||||||
labstr[0] = 0;
|
labstr[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
xdumplab() {
|
static void xdumplab(void) {
|
||||||
|
|
||||||
if (labstr[0] == 0)
|
if (labstr[0] == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -677,7 +699,7 @@ xdumplab() {
|
||||||
newdlb(labstr);
|
newdlb(labstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
part_flush() {
|
static void part_flush(void) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each new data fragment and each data label starts at
|
* Each new data fragment and each data label starts at
|
||||||
|
@ -690,7 +712,7 @@ part_flush() {
|
||||||
part_word = 0;
|
part_word = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
string holstr(n) word n; {
|
static string holstr(word n) {
|
||||||
|
|
||||||
sprintf(str,hol_off,n,holno);
|
sprintf(str,hol_off,n,holno);
|
||||||
return(mystrcpy(str));
|
return(mystrcpy(str));
|
||||||
|
|
22
mach/proto/cg/fillem.h
Normal file
22
mach/proto/cg/fillem.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-14
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef FILLEM_H_
|
||||||
|
#define FILLEM_H_
|
||||||
|
|
||||||
|
/** Switch to text segment. */
|
||||||
|
void swtxt(void);
|
||||||
|
|
||||||
|
|
||||||
|
void in_init(char *filename);
|
||||||
|
void in_start(void);
|
||||||
|
void in_finish(void);
|
||||||
|
void fillemlines(void);
|
||||||
|
|
||||||
|
void dopseudo(void);
|
||||||
|
|
||||||
|
#endif /* FILLEM_H_ */
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
@ -11,39 +13,35 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
/*
|
#include "gencode.h"
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
#include "fillem.h"
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
FILE *codefile;
|
FILE *codefile;
|
||||||
extern FILE *freopen();
|
|
||||||
|
|
||||||
out_init(filename) char *filename; {
|
|
||||||
|
void out_init(char *filename)
|
||||||
|
{
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
static char stderrbuff[BUFSIZ];
|
|
||||||
|
|
||||||
if (Debug) {
|
if (Debug)
|
||||||
codefile = stderr;
|
{
|
||||||
if (!isatty(2))
|
codefile = stderr;
|
||||||
setbuf(stderr,stderrbuff);
|
}
|
||||||
} else {
|
|
||||||
#endif
|
|
||||||
if (filename == (char *) 0)
|
|
||||||
codefile = stdout;
|
|
||||||
else
|
else
|
||||||
if ((codefile=freopen(filename,"w",stdout))==NULL)
|
{
|
||||||
error("Can't create %s",filename);
|
#endif
|
||||||
|
if (filename == (char *) 0)
|
||||||
|
codefile = stdout;
|
||||||
|
else if ((codefile = freopen(filename, "w", stdout)) == NULL)
|
||||||
|
error("Can't create %s", filename);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
out_finish() {
|
void out_finish(void) {
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (Debug)
|
if (Debug)
|
||||||
|
@ -53,14 +51,15 @@ out_finish() {
|
||||||
fclose(codefile);
|
fclose(codefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
tstoutput() {
|
void tstoutput(void) {
|
||||||
|
|
||||||
if (ferror(codefile))
|
if (ferror(codefile))
|
||||||
error("Write error on output");
|
error("Write error on output");
|
||||||
}
|
}
|
||||||
|
|
||||||
gencode(code) register char *code; {
|
void gencode(register char *code)
|
||||||
register c;
|
{
|
||||||
|
register int c;
|
||||||
int tokno,fldno,insno,regno,subno;
|
int tokno,fldno,insno,regno,subno;
|
||||||
register token_p tp;
|
register token_p tp;
|
||||||
|
|
||||||
|
@ -131,7 +130,8 @@ gencode(code) register char *code; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
genexpr(nodeno) {
|
void genexpr(int nodeno)
|
||||||
|
{
|
||||||
result_t result;
|
result_t result;
|
||||||
|
|
||||||
result= compute(&enodes[nodeno]);
|
result= compute(&enodes[nodeno]);
|
||||||
|
@ -149,12 +149,14 @@ genexpr(nodeno) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gennl() {
|
void gennl(void)
|
||||||
|
{
|
||||||
fputc('\n',codefile);
|
fputc('\n',codefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
prtoken(tp) token_p tp; {
|
void prtoken(token_p tp)
|
||||||
register c;
|
{
|
||||||
|
register int c;
|
||||||
register char *code;
|
register char *code;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
|
|
||||||
|
|
22
mach/proto/cg/gencode.h
Normal file
22
mach/proto/cg/gencode.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-12
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef GENCODE_H_
|
||||||
|
#define GENCODE_H_
|
||||||
|
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
void out_init(char *filename);
|
||||||
|
void out_finish(void);
|
||||||
|
void tstoutput(void);
|
||||||
|
void gencode(register char *code);
|
||||||
|
void genexpr(int nodeno);
|
||||||
|
void gennl(void);
|
||||||
|
void prtoken(token_p tp);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* GENCODE_H_ */
|
|
@ -1,28 +1,26 @@
|
||||||
#ifndef NORCSID
|
|
||||||
static char rcsid[] = "$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "param.h"
|
|
||||||
#include "tables.h"
|
|
||||||
#include "types.h"
|
|
||||||
#include "glosym.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*
|
*
|
||||||
* Author: Hans van Staveren
|
* Author: Hans van Staveren
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "glosym.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern string myalloc();
|
|
||||||
|
|
||||||
glosym_p glolist= (glosym_p) 0;
|
glosym_p glolist= (glosym_p) 0;
|
||||||
|
|
||||||
enterglo(name,romp) string name; word *romp; {
|
void enterglo(string name,word *romp)
|
||||||
|
{
|
||||||
register glosym_p gp;
|
register glosym_p gp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
gp = (glosym_p) myalloc(sizeof *gp);
|
gp = (glosym_p) myalloc(sizeof *gp);
|
||||||
gp->gl_next = glolist;
|
gp->gl_next = glolist;
|
||||||
|
@ -33,7 +31,8 @@ enterglo(name,romp) string name; word *romp; {
|
||||||
glolist = gp;
|
glolist = gp;
|
||||||
}
|
}
|
||||||
|
|
||||||
glosym_p lookglo(name) string name; {
|
glosym_p lookglo(string name)
|
||||||
|
{
|
||||||
register glosym_p gp;
|
register glosym_p gp;
|
||||||
|
|
||||||
for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next)
|
for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next)
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef GLOSYM_H_
|
||||||
|
#define GLOSYM_H_
|
||||||
|
|
||||||
|
|
||||||
typedef struct glosym {
|
typedef struct glosym {
|
||||||
struct glosym *gl_next;
|
struct glosym *gl_next;
|
||||||
|
@ -10,4 +12,7 @@ typedef struct glosym {
|
||||||
word gl_rom[MAXROM+1];
|
word gl_rom[MAXROM+1];
|
||||||
} glosym_t,*glosym_p;
|
} glosym_t,*glosym_p;
|
||||||
|
|
||||||
|
void enterglo(string name, word *romp);
|
||||||
glosym_p lookglo();
|
glosym_p lookglo();
|
||||||
|
|
||||||
|
#endif /* GLOSYM_H_ */
|
||||||
|
|
|
@ -1,19 +1,24 @@
|
||||||
#ifndef NORCSID
|
|
||||||
static char rcsid[] = "$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "param.h"
|
|
||||||
#include "mach.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*
|
*
|
||||||
* Author: Hans van Staveren
|
* Author: Hans van Staveren
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "tables.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "tables.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "mach.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "fillem.h"
|
||||||
|
#include "gencode.h"
|
||||||
|
#include "codegen.h"
|
||||||
|
|
||||||
char *progname;
|
char *progname;
|
||||||
extern char startupcode[];
|
extern byte startupcode[];
|
||||||
int maxply=1;
|
int maxply=1;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
int Debug=0;
|
int Debug=0;
|
||||||
|
@ -21,10 +26,23 @@ int Debug=0;
|
||||||
|
|
||||||
extern int endofprog;
|
extern int endofprog;
|
||||||
|
|
||||||
main(argc,argv) char **argv; {
|
|
||||||
|
unsigned ggd(unsigned int a,unsigned int b)
|
||||||
|
{
|
||||||
|
register unsigned c;
|
||||||
|
|
||||||
|
do {
|
||||||
|
c = a%b; a=b; b=c;
|
||||||
|
} while (c!=0);
|
||||||
|
return(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
register unsigned n;
|
register unsigned n;
|
||||||
extern unsigned cc1,cc2,cc3,cc4;
|
extern unsigned cc1,cc2,cc3,cc4;
|
||||||
unsigned ggd();
|
|
||||||
|
|
||||||
progname = argv[0];
|
progname = argv[0];
|
||||||
while (--argc && **++argv == '-') {
|
while (--argc && **++argv == '-') {
|
||||||
|
@ -70,11 +88,3 @@ main(argc,argv) char **argv; {
|
||||||
out_finish();
|
out_finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned ggd(a,b) register unsigned a,b; {
|
|
||||||
register unsigned c;
|
|
||||||
|
|
||||||
do {
|
|
||||||
c = a%b; a=b; b=c;
|
|
||||||
} while (c!=0);
|
|
||||||
return(a);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
@ -10,23 +12,18 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "reg.h"
|
||||||
|
#include "codegen.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned costcalc();
|
int move(token_p tp1,token_p tp2,int ply,int toplevel,unsigned int maxcost)
|
||||||
|
{
|
||||||
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
|
|
||||||
register move_p mp;
|
register move_p mp;
|
||||||
register unsigned t;
|
register unsigned t;
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
tkdef_p tdp;
|
tkdef_p tdp;
|
||||||
int i;
|
int i;
|
||||||
unsigned codegen();
|
|
||||||
|
|
||||||
if (eqtoken(tp1,tp2))
|
if (eqtoken(tp1,tp2))
|
||||||
return(0);
|
return(0);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <em_spec.h>
|
#include <em_spec.h>
|
||||||
#include <em_flag.h>
|
#include <em_flag.h>
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
@ -12,21 +14,36 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "fillem.h"
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
extern char em_mnem[][4];
|
extern char em_mnem[][4];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
byte *trypat(bp,len) register byte *bp; {
|
extern char em_flag[];
|
||||||
register patlen,i;
|
|
||||||
|
static int argtyp(int mn) {
|
||||||
|
|
||||||
|
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
|
||||||
|
case PAR_W:
|
||||||
|
case PAR_S:
|
||||||
|
case PAR_Z:
|
||||||
|
case PAR_O:
|
||||||
|
case PAR_N:
|
||||||
|
case PAR_L:
|
||||||
|
case PAR_F:
|
||||||
|
case PAR_R:
|
||||||
|
case PAR_C:
|
||||||
|
return(EV_INT);
|
||||||
|
default:
|
||||||
|
return(EV_STR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte *trypat(register byte *bp, int len)
|
||||||
|
{
|
||||||
|
register int patlen,i;
|
||||||
result_t result;
|
result_t result;
|
||||||
|
|
||||||
getint(patlen,bp);
|
getint(patlen,bp);
|
||||||
|
@ -71,28 +88,10 @@ byte *trypat(bp,len) register byte *bp; {
|
||||||
return(bp);
|
return(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char em_flag[];
|
|
||||||
|
|
||||||
argtyp(mn) {
|
|
||||||
|
|
||||||
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
|
byte *nextem(int toplevel) {
|
||||||
case PAR_W:
|
register int i;
|
||||||
case PAR_S:
|
|
||||||
case PAR_Z:
|
|
||||||
case PAR_O:
|
|
||||||
case PAR_N:
|
|
||||||
case PAR_L:
|
|
||||||
case PAR_F:
|
|
||||||
case PAR_R:
|
|
||||||
case PAR_C:
|
|
||||||
return(EV_INT);
|
|
||||||
default:
|
|
||||||
return(EV_STR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte *nextem(toplevel) {
|
|
||||||
register i;
|
|
||||||
short hash[3];
|
short hash[3];
|
||||||
register byte *bp;
|
register byte *bp;
|
||||||
byte *cp;
|
byte *cp;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
@ -10,17 +12,16 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "reg.h"
|
||||||
|
|
||||||
/*
|
/* Froward local declarations */
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
static void awayreg(int);
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
chrefcount(regno,amount,tflag) {
|
void chrefcount(int regno, int amount, int tflag)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
rp= &machregs[regno];
|
rp= &machregs[regno];
|
||||||
#if MAXMEMBERS!=0
|
#if MAXMEMBERS!=0
|
||||||
|
@ -38,9 +39,10 @@ chrefcount(regno,amount,tflag) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
getrefcount(regno, tflag) {
|
int getrefcount(int regno, int tflag)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register i,maxcount;
|
register int i,maxcount;
|
||||||
|
|
||||||
rp= &machregs[regno];
|
rp= &machregs[regno];
|
||||||
#if MAXMEMBERS!=0
|
#if MAXMEMBERS!=0
|
||||||
|
@ -58,7 +60,8 @@ getrefcount(regno, tflag) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
erasereg(regno) {
|
void erasereg(int regno)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
|
@ -83,10 +86,11 @@ erasereg(regno) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
awayreg(regno) {
|
static void awayreg(int regno)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
/* Now erase recursively all registers containing
|
/* Now erase recursively all registers containing
|
||||||
* something using this one
|
* something using this one
|
||||||
|
@ -107,9 +111,10 @@ awayreg(regno) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanregs() {
|
void cleanregs(void)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||||
rp->r_contents.t_token = 0;
|
rp->r_contents.t_token = 0;
|
||||||
|
@ -119,9 +124,10 @@ cleanregs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
inctcount(regno) {
|
void inctcount(int regno)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register i;
|
register int i;
|
||||||
|
|
||||||
rp = &machregs[regno];
|
rp = &machregs[regno];
|
||||||
#if MAXMEMBERS!=0
|
#if MAXMEMBERS!=0
|
||||||
|
@ -137,7 +143,8 @@ inctcount(regno) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
chkregs() {
|
void chkregs(void)
|
||||||
|
{
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register token_p tp;
|
register token_p tp;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
|
|
17
mach/proto/cg/reg.h
Normal file
17
mach/proto/cg/reg.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-14
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef REG_H_
|
||||||
|
#define REG_H_
|
||||||
|
|
||||||
|
void chrefcount(int regno, int amount, int tflag);
|
||||||
|
int getrefcount(int regno, int tflag);
|
||||||
|
void erasereg(int regno);
|
||||||
|
void cleanregs(void);
|
||||||
|
void chkregs(void);
|
||||||
|
|
||||||
|
#endif /* REG_H_ */
|
|
@ -1,12 +1,16 @@
|
||||||
|
/*
|
||||||
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
|
||||||
#ifdef REGVARS
|
#ifdef REGVARS
|
||||||
|
|
||||||
#ifndef NORCSID
|
|
||||||
static char rcsid[] = "$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <cg_pattern.h>
|
#include <cg_pattern.h>
|
||||||
|
@ -15,18 +19,20 @@ static char rcsid[] = "$Id$";
|
||||||
#include <em_reg.h>
|
#include <em_reg.h>
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
#include "fillem.h"
|
||||||
|
#include "regvar.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
extern string myalloc();
|
|
||||||
struct regvar *rvlist;
|
struct regvar *rvlist;
|
||||||
|
|
||||||
struct regvar *
|
/* Defined in mach.c of the specific machine. */
|
||||||
linkreg(of,sz,tp,sc) long of; {
|
extern int regscore(long off,int size,int typ,int score,int totyp);
|
||||||
|
extern void i_regsave(void);
|
||||||
|
extern void f_regsave(void);
|
||||||
|
void regsave(char *regstr,long off,int size);
|
||||||
|
|
||||||
|
struct regvar *linkreg(long of,int sz,int tp,int sc)
|
||||||
|
{
|
||||||
struct regvar *rvlp;
|
struct regvar *rvlp;
|
||||||
|
|
||||||
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
|
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
|
||||||
|
@ -40,9 +46,10 @@ linkreg(of,sz,tp,sc) long of; {
|
||||||
return(rvlp);
|
return(rvlp);
|
||||||
}
|
}
|
||||||
|
|
||||||
tryreg(rvlp,typ) struct regvar *rvlp; {
|
void tryreg(struct regvar *rvlp, int typ)
|
||||||
|
{
|
||||||
int score;
|
int score;
|
||||||
register i;
|
register int i;
|
||||||
struct regassigned *ra;
|
struct regassigned *ra;
|
||||||
struct regvar *save;
|
struct regvar *save;
|
||||||
|
|
||||||
|
@ -85,9 +92,10 @@ tryreg(rvlp,typ) struct regvar *rvlp; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fixregvars(saveall) {
|
void fixregvars(int saveall)
|
||||||
|
{
|
||||||
register struct regvar *rv;
|
register struct regvar *rv;
|
||||||
register rvtyp,i;
|
register int rvtyp,i;
|
||||||
|
|
||||||
swtxt();
|
swtxt();
|
||||||
i_regsave(); /* machine dependent initialization */
|
i_regsave(); /* machine dependent initialization */
|
||||||
|
@ -107,7 +115,8 @@ fixregvars(saveall) {
|
||||||
f_regsave();
|
f_regsave();
|
||||||
}
|
}
|
||||||
|
|
||||||
isregvar(off) long off; {
|
int isregvar(long off)
|
||||||
|
{
|
||||||
register struct regvar *rvlp;
|
register struct regvar *rvlp;
|
||||||
|
|
||||||
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
||||||
|
@ -116,7 +125,7 @@ isregvar(off) long off; {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
unlinkregs() {
|
void unlinkregs(void) {
|
||||||
register struct regvar *rvlp,*t;
|
register struct regvar *rvlp,*t;
|
||||||
register struct regassigned *ra;
|
register struct regassigned *ra;
|
||||||
int rvtyp,i;
|
int rvtyp,i;
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef REGVAR_H_
|
||||||
|
#define REGVAR_H_
|
||||||
|
|
||||||
struct regvar {
|
struct regvar {
|
||||||
struct regvar *rv_next;
|
struct regvar *rv_next;
|
||||||
|
@ -21,3 +22,12 @@ struct regassigned {
|
||||||
extern struct regvar *rvlist;
|
extern struct regvar *rvlist;
|
||||||
extern int nregvar[];
|
extern int nregvar[];
|
||||||
extern struct regassigned *regassigned[];
|
extern struct regassigned *regassigned[];
|
||||||
|
|
||||||
|
|
||||||
|
struct regvar *linkreg(long of,int sz,int tp,int sc);
|
||||||
|
void tryreg(struct regvar *rvlp, int typ);
|
||||||
|
void fixregvars(int saveall);
|
||||||
|
int isregvar(long off);
|
||||||
|
void unlinkregs(void);
|
||||||
|
|
||||||
|
#endif /* REGVAR_H_ */
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
@ -11,13 +13,10 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Package for string allocation and garbage collection.
|
* Package for string allocation and garbage collection.
|
||||||
|
@ -31,7 +30,33 @@ static char rcsid[] = "$Id$";
|
||||||
char *stab[MAXSTAB];
|
char *stab[MAXSTAB];
|
||||||
int nstab=0;
|
int nstab=0;
|
||||||
|
|
||||||
string myalloc(size) {
|
static void chkstr(string str,char used[])
|
||||||
|
{
|
||||||
|
register int low,middle,high;
|
||||||
|
|
||||||
|
low=0; high=nstab-1;
|
||||||
|
while (high>low) {
|
||||||
|
middle= (low+high)>>1;
|
||||||
|
if (str==stab[middle]) {
|
||||||
|
used[middle]=1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (str<stab[middle])
|
||||||
|
high = middle-1;
|
||||||
|
else
|
||||||
|
low = middle+1;
|
||||||
|
}
|
||||||
|
if (low==high) {
|
||||||
|
if (str==stab[low]) {
|
||||||
|
used[low]=1;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string myalloc(int size)
|
||||||
|
{
|
||||||
register string p;
|
register string p;
|
||||||
|
|
||||||
p = (string) malloc(size);
|
p = (string) malloc(size);
|
||||||
|
@ -40,22 +65,22 @@ string myalloc(size) {
|
||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
myfree(p) string p; {
|
void myfree(void* p)
|
||||||
|
{
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
popstr(nnstab) {
|
void popstr(int nnstab)
|
||||||
register i;
|
{
|
||||||
|
register int i;
|
||||||
for (i=nnstab;i<nstab;i++)
|
for (i=nnstab;i<nstab;i++)
|
||||||
myfree(stab[i]);
|
myfree(stab[i]);
|
||||||
nstab = nnstab;
|
nstab = nnstab;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *salloc(size) {
|
char *salloc(int size)
|
||||||
|
{
|
||||||
register char *p;
|
register char *p;
|
||||||
|
|
||||||
if (nstab==MAXSTAB)
|
if (nstab==MAXSTAB)
|
||||||
fatal("String table overflow");
|
fatal("String table overflow");
|
||||||
p = myalloc(size+1); /* extra room for terminating zero */
|
p = myalloc(size+1); /* extra room for terminating zero */
|
||||||
|
@ -63,16 +88,16 @@ char *salloc(size) {
|
||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
compar(p1,p2) char **p1,**p2; {
|
int compar(char **p1, char **p2)
|
||||||
|
{
|
||||||
assert(*p1 != *p2);
|
assert(*p1 != *p2);
|
||||||
if (*p1 < *p2)
|
if (*p1 < *p2)
|
||||||
return(-1);
|
return(-1);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
garbage_collect() {
|
void garbage_collect(void) {
|
||||||
register i;
|
register int i;
|
||||||
struct emline *emlp;
|
struct emline *emlp;
|
||||||
token_p tp;
|
token_p tp;
|
||||||
tkdef_p tdp;
|
tkdef_p tdp;
|
||||||
|
@ -115,25 +140,3 @@ garbage_collect() {
|
||||||
nstab = fillp-stab;
|
nstab = fillp-stab;
|
||||||
}
|
}
|
||||||
|
|
||||||
chkstr(str,used) string str; char used[]; {
|
|
||||||
register low,middle,high;
|
|
||||||
|
|
||||||
low=0; high=nstab-1;
|
|
||||||
while (high>low) {
|
|
||||||
middle= (low+high)>>1;
|
|
||||||
if (str==stab[middle]) {
|
|
||||||
used[middle]=1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (str<stab[middle])
|
|
||||||
high = middle-1;
|
|
||||||
else
|
|
||||||
low = middle+1;
|
|
||||||
}
|
|
||||||
if (low==high) {
|
|
||||||
if (str==stab[low]) {
|
|
||||||
used[low]=1;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
20
mach/proto/cg/salloc.h
Normal file
20
mach/proto/cg/salloc.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-14
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef SALLOC_H_
|
||||||
|
#define SALLOC_H_
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
string myalloc(int size);
|
||||||
|
void myfree(void* p);
|
||||||
|
void popstr(int nnstab);
|
||||||
|
char *salloc(int size);
|
||||||
|
int compar(char **p1, char **p2);
|
||||||
|
void garbage_collect(void);
|
||||||
|
|
||||||
|
#endif /* SALLOC_H_ */
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
@ -11,13 +13,10 @@ static char rcsid[] = "$Id$";
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern int nstab; /* salloc.c */
|
extern int nstab; /* salloc.c */
|
||||||
|
|
||||||
|
@ -27,10 +26,24 @@ extern string myalloc();
|
||||||
state_p stlist=0;
|
state_p stlist=0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static void bmove(register short *from, register short *to, register int nbytes)
|
||||||
|
{
|
||||||
|
if (nbytes<=0)
|
||||||
|
return;
|
||||||
|
assert(sizeof(short)==2 && (nbytes&1)==0);
|
||||||
|
nbytes>>=1;
|
||||||
|
do
|
||||||
|
*to++ = *from++;
|
||||||
|
while (--nbytes);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef STONSTACK
|
#ifdef STONSTACK
|
||||||
savestatus(sp) register state_p sp; {
|
state_p savestatus(register state_p sp)
|
||||||
|
{
|
||||||
#else
|
#else
|
||||||
state_p savestatus() {
|
state_p state_p savestatus(void)
|
||||||
|
{
|
||||||
register state_p sp;
|
register state_p sp;
|
||||||
|
|
||||||
if ((sp=stlist)==0)
|
if ((sp=stlist)==0)
|
||||||
|
@ -56,8 +69,8 @@ state_p savestatus() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
restorestatus(sp) register state_p sp; {
|
void restorestatus(register state_p sp)
|
||||||
|
{
|
||||||
stackheight = sp->st_sh;
|
stackheight = sp->st_sh;
|
||||||
bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
|
bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
|
||||||
nallreg = sp->st_na;
|
nallreg = sp->st_na;
|
||||||
|
@ -74,20 +87,11 @@ restorestatus(sp) register state_p sp; {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef STONSTACK
|
#ifndef STONSTACK
|
||||||
freestatus(sp) state_p sp; {
|
void freestatus(state_p sp)
|
||||||
|
{
|
||||||
sp->st_next = stlist;
|
sp->st_next = stlist;
|
||||||
stlist = sp;
|
stlist = sp;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bmove(from,to,nbytes) register short *from,*to; register nbytes; {
|
|
||||||
|
|
||||||
if (nbytes<=0)
|
|
||||||
return;
|
|
||||||
assert(sizeof(short)==2 && (nbytes&1)==0);
|
|
||||||
nbytes>>=1;
|
|
||||||
do
|
|
||||||
*to++ = *from++;
|
|
||||||
while (--nbytes);
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef STATE_H_
|
||||||
|
#define STATE_H_
|
||||||
|
|
||||||
|
|
||||||
#define STONSTACK /* if defined state is saved in stackframe */
|
#define STONSTACK /* if defined state is saved in stackframe */
|
||||||
|
|
||||||
|
@ -24,5 +26,10 @@ typedef struct state {
|
||||||
} state_t,*state_p;
|
} state_t,*state_p;
|
||||||
|
|
||||||
#ifndef STONSTACK
|
#ifndef STONSTACK
|
||||||
state_p savestatus();
|
state_p state_p savestatus(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void restorestatus(register state_p sp);
|
||||||
|
state_p savestatus(register state_p sp);
|
||||||
|
|
||||||
|
#endif /* STATE_H_ */
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
@ -12,19 +16,20 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "subr.h"
|
||||||
|
#include "reg.h"
|
||||||
|
#include "salloc.h"
|
||||||
|
#include "gencode.h"
|
||||||
|
#include "regvar.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern string myalloc();
|
|
||||||
unsigned codegen();
|
unsigned codegen();
|
||||||
|
extern unsigned cc1,cc2,cc3,cc4;
|
||||||
|
|
||||||
match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
|
||||||
register bitno;
|
int match(register token_p tp, register set_p tep, int optexp)
|
||||||
|
{
|
||||||
|
register int bitno;
|
||||||
token_p ct;
|
token_p ct;
|
||||||
result_t result;
|
result_t result;
|
||||||
|
|
||||||
|
@ -49,7 +54,8 @@ match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
||||||
return(result.e_v.e_con);
|
return(result.e_v.e_con);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance(instno,token) register token_p token; {
|
void instance(int instno,register token_p token)
|
||||||
|
{
|
||||||
register inst_p inp;
|
register inst_p inp;
|
||||||
int i;
|
int i;
|
||||||
token_p tp;
|
token_p tp;
|
||||||
|
@ -128,7 +134,9 @@ instance(instno,token) register token_p token; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cinstance(instno,token,tp,regno) register token_p token,tp; {
|
void cinstance(int instno,register token_p token,
|
||||||
|
register token_p tp,int regno)
|
||||||
|
{
|
||||||
register inst_p inp;
|
register inst_p inp;
|
||||||
int i;
|
int i;
|
||||||
struct reginfo *rp;
|
struct reginfo *rp;
|
||||||
|
@ -195,8 +203,9 @@ cinstance(instno,token,tp,regno) register token_p token,tp; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eqtoken(tp1,tp2) token_p tp1,tp2; {
|
int eqtoken(token_p tp1,token_p tp2)
|
||||||
register i;
|
{
|
||||||
|
register int i;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
|
|
||||||
if (tp1->t_token!=tp2->t_token)
|
if (tp1->t_token!=tp2->t_token)
|
||||||
|
@ -229,9 +238,9 @@ eqtoken(tp1,tp2) token_p tp1,tp2; {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
distance(cindex) {
|
int distance(int cindex) {
|
||||||
register char *bp;
|
register byte *bp;
|
||||||
register i;
|
register int i;
|
||||||
register token_p tp;
|
register token_p tp;
|
||||||
int tokexp,tpl;
|
int tokexp,tpl;
|
||||||
int expsize,toksize,exact;
|
int expsize,toksize,exact;
|
||||||
|
@ -281,9 +290,9 @@ distance(cindex) {
|
||||||
return(20-exact);
|
return(20-exact);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned costcalc(cost) cost_t cost; {
|
unsigned costcalc(cost_t cost)
|
||||||
|
{
|
||||||
result_t result1,result2;
|
result_t result1,result2;
|
||||||
extern unsigned cc1,cc2,cc3,cc4;
|
|
||||||
|
|
||||||
result1=compute(&enodes[cost.c_size]);
|
result1=compute(&enodes[cost.c_size]);
|
||||||
result2=compute(&enodes[cost.c_time]);
|
result2=compute(&enodes[cost.c_time]);
|
||||||
|
@ -291,20 +300,20 @@ unsigned costcalc(cost) cost_t cost; {
|
||||||
return(result1.e_v.e_con*cc1/cc2 + result2.e_v.e_con*cc3/cc4);
|
return(result1.e_v.e_con*cc1/cc2 + result2.e_v.e_con*cc3/cc4);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize(tokexpno) {
|
int ssize(int tokexpno) {
|
||||||
|
|
||||||
return(machsets[tokexpno].set_size);
|
return(machsets[tokexpno].set_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsize(tp) register token_p tp; {
|
int tsize(register token_p tp)
|
||||||
|
{
|
||||||
if (tp->t_token==-1)
|
if (tp->t_token==-1)
|
||||||
return(machregs[tp->t_att[0].ar].r_size);
|
return(machregs[tp->t_att[0].ar].r_size);
|
||||||
return(tokens[tp->t_token].t_size);
|
return(tokens[tp->t_token].t_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MAXSPLIT
|
#ifdef MAXSPLIT
|
||||||
instsize(tinstno,tp) token_p tp; {
|
int instsize(int tinstno,token_p tp) {
|
||||||
inst_p inp;
|
inst_p inp;
|
||||||
struct reginfo *rp;
|
struct reginfo *rp;
|
||||||
|
|
||||||
|
@ -335,8 +344,8 @@ instsize(tinstno,tp) token_p tp; {
|
||||||
}
|
}
|
||||||
#endif /* MAXSPLIT */
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
tref(tp,amount) register token_p tp; {
|
void tref(register token_p tp,int amount) {
|
||||||
register i;
|
register int i;
|
||||||
register tkdef_p tdp;
|
register tkdef_p tdp;
|
||||||
|
|
||||||
if (tp->t_token==-1)
|
if (tp->t_token==-1)
|
||||||
|
@ -352,11 +361,12 @@ tref(tp,amount) register token_p tp; {
|
||||||
#define MAXSAVE 10
|
#define MAXSAVE 10
|
||||||
|
|
||||||
#ifdef MAXSPLIT
|
#ifdef MAXSPLIT
|
||||||
split(tp,ip,ply,toplevel) token_p tp; int *ip; {
|
int split(token_p tp,int *ip,int ply,int toplevel)
|
||||||
|
{
|
||||||
c2_p cp;
|
c2_p cp;
|
||||||
token_t savestack[MAXSAVE];
|
token_t savestack[MAXSAVE];
|
||||||
int ok;
|
int ok;
|
||||||
register i;
|
register int i;
|
||||||
int diff;
|
int diff;
|
||||||
token_p stp;
|
token_p stp;
|
||||||
int tpl;
|
int tpl;
|
||||||
|
@ -392,11 +402,12 @@ found:
|
||||||
}
|
}
|
||||||
#endif /* MAXSPLIT */
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; c3_p cp; {
|
unsigned docoerc(token_p tp,c3_p cp,int ply,int toplevel,int forced)
|
||||||
|
{
|
||||||
token_t savestack[MAXSAVE];
|
token_t savestack[MAXSAVE];
|
||||||
token_p stp;
|
token_p stp;
|
||||||
int i,diff;
|
int i,diff;
|
||||||
unsigned cost;
|
unsigned int cost;
|
||||||
int tpl; /* saved tokpatlen */
|
int tpl; /* saved tokpatlen */
|
||||||
|
|
||||||
stp = &fakestack[stackheight-1];
|
stp = &fakestack[stackheight-1];
|
||||||
|
@ -415,7 +426,8 @@ unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; c3_p cp; {
|
||||||
return(cost);
|
return(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
unsigned stackupto(token_p limit,int ply,int toplevel)
|
||||||
|
{
|
||||||
token_t savestack[MAXFSTACK];
|
token_t savestack[MAXFSTACK];
|
||||||
token_p stp;
|
token_p stp;
|
||||||
int i,diff;
|
int i,diff;
|
||||||
|
@ -473,10 +485,11 @@ unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
||||||
return(totalcost);
|
return(totalcost);
|
||||||
}
|
}
|
||||||
|
|
||||||
c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
c3_p findcoerc(token_p tp,set_p tep)
|
||||||
|
{
|
||||||
register c3_p cp;
|
register c3_p cp;
|
||||||
token_t rtoken;
|
token_t rtoken;
|
||||||
register i;
|
register int i;
|
||||||
register struct reginfo **rpp;
|
register struct reginfo **rpp;
|
||||||
|
|
||||||
for (cp=c3coercs;cp< &c3coercs[NC3]; cp++) {
|
for (cp=c3coercs;cp< &c3coercs[NC3]; cp++) {
|
||||||
|
@ -508,30 +521,42 @@ c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
||||||
return(0); /* nothing found */
|
return(0); /* nothing found */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void error_str(char *s, va_list argptr)
|
||||||
error(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; {
|
{
|
||||||
|
|
||||||
fatal(s,a1,a2,a3,a4,a5,a6,a7,a8);
|
|
||||||
}
|
|
||||||
|
|
||||||
fatal(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; {
|
|
||||||
|
|
||||||
fprintf(stderr,"Error: ");
|
fprintf(stderr,"Error: ");
|
||||||
fprintf(stderr,s,a1,a2,a3,a4,a5,a6,a7,a8);
|
vfprintf(stderr, s, argptr);
|
||||||
fprintf(stderr,"\n");
|
fprintf(stderr,"\n");
|
||||||
out_finish();
|
out_finish();
|
||||||
abort();
|
abort();
|
||||||
exit(-1);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
void error(char *s, ...)
|
||||||
badassertion(asstr,file,line) char *asstr, *file; {
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, s);
|
||||||
|
error_str(s, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fatal(char *s, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, s);
|
||||||
|
error_str(s, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
void badassertion(char* asstr,char *file,int line)
|
||||||
|
{
|
||||||
fatal("Assertion \"%s\" failed %s(%d)",asstr,file,line);
|
fatal("Assertion \"%s\" failed %s(%d)",asstr,file,line);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
max(a,b) {
|
int max(int a,int b)
|
||||||
|
{
|
||||||
return(a>b ? a : b);
|
return(a>b ? a : b);
|
||||||
}
|
}
|
||||||
|
|
47
mach/proto/cg/subr.h
Normal file
47
mach/proto/cg/subr.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/* Copyright (c) 2019 ACK Project.
|
||||||
|
* See the copyright notice in the ACK home directory,
|
||||||
|
* in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Created on: 2019-04-12
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef SUBR_H_
|
||||||
|
#define SUBR_H_
|
||||||
|
|
||||||
|
#include "data.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
int match(register token_p tp, register set_p tep, int optexp);
|
||||||
|
void instance(int instno,register token_p token);
|
||||||
|
void cinstance(int instno,register token_p token,
|
||||||
|
register token_p tp,int regno);
|
||||||
|
int eqtoken(token_p tp1,token_p tp2);
|
||||||
|
int distance(int cindex);
|
||||||
|
unsigned costcalc(cost_t cost);
|
||||||
|
int ssize(int tokexpno);
|
||||||
|
int tsize(register token_p tp);
|
||||||
|
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
int instsize(int tinstno,token_p tp);
|
||||||
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
|
void tref(register token_p tp,int amount);
|
||||||
|
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
int split(token_p tp,int *ip,int ply,int toplevel);
|
||||||
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
|
unsigned docoerc(token_p tp,c3_p cp,int ply,int toplevel,int forced);
|
||||||
|
unsigned stackupto(token_p limit,int ply,int toplevel);
|
||||||
|
c3_p findcoerc(token_p tp,set_p tep);
|
||||||
|
void error(char *s, ...);
|
||||||
|
void fatal(char *s, ...);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
void badassertion(char* asstr,char *file,int line);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int max(int a,int b);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* SUBR_H_ */
|
|
@ -2,7 +2,9 @@
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
#ifndef TYPES_H_
|
||||||
|
#define TYPES_H_
|
||||||
|
|
||||||
|
|
||||||
#ifndef TEM_WSIZE
|
#ifndef TEM_WSIZE
|
||||||
TEM_WSIZE should be defined at this point
|
TEM_WSIZE should be defined at this point
|
||||||
|
@ -15,7 +17,7 @@ Implementation will not be correct unless a long integer
|
||||||
has more then 4 bytes of precision.
|
has more then 4 bytes of precision.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef char byte;
|
typedef unsigned char byte;
|
||||||
typedef char * string;
|
typedef char * string;
|
||||||
|
|
||||||
#if TEM_WSIZE>2 || TEM_PSIZE>2
|
#if TEM_WSIZE>2 || TEM_PSIZE>2
|
||||||
|
@ -28,3 +30,5 @@ typedef char * string;
|
||||||
#ifndef WRD_FMT
|
#ifndef WRD_FMT
|
||||||
#define WRD_FMT "%ld"
|
#define WRD_FMT "%ld"
|
||||||
#endif /* WRD_FMT */
|
#endif /* WRD_FMT */
|
||||||
|
|
||||||
|
#endif /* TYPES_H_ */
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef NORCSID
|
/*
|
||||||
static char rcsid[] = "$Id$";
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
#endif
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
@ -9,12 +11,6 @@ static char rcsid[] = "$Id$";
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*
|
|
||||||
* Author: Hans van Staveren
|
|
||||||
*/
|
|
||||||
|
|
||||||
int stackheight = 0;
|
int stackheight = 0;
|
||||||
token_t fakestack[MAXFSTACK];
|
token_t fakestack[MAXFSTACK];
|
||||||
|
|
Loading…
Reference in a new issue