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