2019-05-10 17:11:54 +00:00
|
|
|
/*
|
|
|
|
* (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
|
|
|
|
*/
|
1984-05-18 21:27:39 +00:00
|
|
|
#include "assert.h"
|
|
|
|
#include "param.h"
|
|
|
|
#include "tables.h"
|
1984-05-19 11:49:37 +00:00
|
|
|
|
|
|
|
#ifdef REGVARS
|
|
|
|
|
2019-05-10 17:11:54 +00:00
|
|
|
|
1984-10-16 13:45:16 +00:00
|
|
|
|
1984-05-18 21:27:39 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include <cg_pattern.h>
|
|
|
|
#include "data.h"
|
|
|
|
#include "regvar.h"
|
|
|
|
#include <em_reg.h>
|
|
|
|
#include "result.h"
|
|
|
|
#include "extern.h"
|
2019-05-10 17:11:54 +00:00
|
|
|
#include "salloc.h"
|
|
|
|
#include "fillem.h"
|
|
|
|
#include "regvar.h"
|
1984-05-18 21:27:39 +00:00
|
|
|
|
|
|
|
struct regvar *rvlist;
|
|
|
|
|
2019-05-10 17:11:54 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
1984-05-18 21:27:39 +00:00
|
|
|
struct regvar *rvlp;
|
|
|
|
|
|
|
|
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
|
|
|
|
rvlp->rv_next = rvlist;
|
|
|
|
rvlist=rvlp;
|
|
|
|
rvlp->rv_off = of;
|
|
|
|
rvlp->rv_size = sz;
|
|
|
|
rvlp->rv_type = tp;
|
|
|
|
rvlp->rv_score = sc;
|
|
|
|
rvlp->rv_reg = 0; /* no register assigned yet */
|
|
|
|
return(rvlp);
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:11:54 +00:00
|
|
|
void tryreg(struct regvar *rvlp, int typ)
|
|
|
|
{
|
1984-05-18 21:27:39 +00:00
|
|
|
int score;
|
2019-05-10 17:11:54 +00:00
|
|
|
register int i;
|
1984-05-18 21:27:39 +00:00
|
|
|
struct regassigned *ra;
|
|
|
|
struct regvar *save;
|
|
|
|
|
|
|
|
if (typ != reg_any && nregvar[typ]!=0) {
|
|
|
|
if (machregs[rvnumbers[typ][0]].r_size!=rvlp->rv_size)
|
|
|
|
score = -1;
|
|
|
|
else
|
|
|
|
score = regscore(rvlp->rv_off,
|
|
|
|
rvlp->rv_size,
|
|
|
|
rvlp->rv_type,
|
|
|
|
rvlp->rv_score,
|
|
|
|
typ); /* machine dependent */
|
|
|
|
ra = regassigned[typ];
|
|
|
|
if (score>ra[nregvar[typ]-1].ra_score) {
|
|
|
|
save = ra[nregvar[typ]-1].ra_rv;
|
|
|
|
for (i=nregvar[typ]-1;i>0 && ra[i-1].ra_score<score;i--)
|
|
|
|
ra[i] = ra[i-1];
|
|
|
|
ra[i].ra_rv = rvlp;
|
|
|
|
ra[i].ra_score = score;
|
|
|
|
if((rvlp=save)==0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nregvar[reg_any]==0)
|
|
|
|
return;
|
|
|
|
if (machregs[rvnumbers[reg_any][0]].r_size!=rvlp->rv_size)
|
|
|
|
score = -1;
|
|
|
|
else
|
|
|
|
score = regscore(rvlp->rv_off,
|
|
|
|
rvlp->rv_size,
|
|
|
|
rvlp->rv_type,
|
|
|
|
rvlp->rv_score,
|
|
|
|
reg_any); /* machine dependent */
|
|
|
|
ra = regassigned[reg_any];
|
|
|
|
if (score>ra[nregvar[reg_any]-1].ra_score) {
|
|
|
|
for (i=nregvar[reg_any]-1;i>0 && ra[i-1].ra_score<score;i--)
|
|
|
|
ra[i] = ra[i-1];
|
|
|
|
ra[i].ra_rv = rvlp;
|
|
|
|
ra[i].ra_score = score;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:11:54 +00:00
|
|
|
void fixregvars(int saveall)
|
|
|
|
{
|
1984-05-18 21:27:39 +00:00
|
|
|
register struct regvar *rv;
|
2019-05-10 17:11:54 +00:00
|
|
|
register int rvtyp,i;
|
1984-05-18 21:27:39 +00:00
|
|
|
|
|
|
|
swtxt();
|
|
|
|
i_regsave(); /* machine dependent initialization */
|
|
|
|
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
|
|
|
|
for(i=0;i<nregvar[rvtyp];i++)
|
1984-05-19 11:49:37 +00:00
|
|
|
if (saveall) {
|
|
|
|
struct reginfo *rp;
|
|
|
|
rp= &machregs[rvnumbers[rvtyp][i]];
|
1984-10-23 15:04:24 +00:00
|
|
|
regsave(codestrings[rp->r_repr],(long)-TEM_WSIZE,rp->r_size);
|
1984-05-19 11:49:37 +00:00
|
|
|
} else if(regassigned[rvtyp][i].ra_score>0) {
|
1984-05-18 21:27:39 +00:00
|
|
|
rv=regassigned[rvtyp][i].ra_rv;
|
|
|
|
rv->rv_reg=rvnumbers[rvtyp][i];
|
|
|
|
regsave(codestrings[machregs[rv->rv_reg].r_repr],
|
|
|
|
rv->rv_off,rv->rv_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f_regsave();
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:11:54 +00:00
|
|
|
int isregvar(long off)
|
|
|
|
{
|
1984-05-18 21:27:39 +00:00
|
|
|
register struct regvar *rvlp;
|
|
|
|
|
|
|
|
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
|
|
|
if(rvlp->rv_off == off)
|
|
|
|
return(rvlp->rv_reg);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:11:54 +00:00
|
|
|
void unlinkregs(void) {
|
1984-05-18 21:27:39 +00:00
|
|
|
register struct regvar *rvlp,*t;
|
|
|
|
register struct regassigned *ra;
|
|
|
|
int rvtyp,i;
|
|
|
|
|
|
|
|
for(rvlp=rvlist;rvlp!=0;rvlp=t) {
|
|
|
|
t=rvlp->rv_next;
|
|
|
|
myfree(rvlp);
|
|
|
|
}
|
|
|
|
rvlist=0;
|
|
|
|
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
|
|
|
|
for(i=0;i<nregvar[rvtyp];i++) {
|
|
|
|
ra= ®assigned[rvtyp][i];
|
|
|
|
ra->ra_rv = 0;
|
|
|
|
ra->ra_score = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1991-12-17 15:05:43 +00:00
|
|
|
#endif /* REGVARS */
|
1984-05-18 21:27:39 +00:00
|
|
|
|
|
|
|
/* nothing after this */
|