Compare commits
3 Commits
saniya_dat
...
unlabeled-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eebf6cca33 | ||
|
|
f92167796a | ||
|
|
5ca4cd622f |
155
mach/proto/cg/regvar.c
Normal file
155
mach/proto/cg/regvar.c
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
#include "assert.h"
|
||||||
|
#include "param.h"
|
||||||
|
#include "tables.h"
|
||||||
|
|
||||||
|
#ifdef REGVARS
|
||||||
|
|
||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
#include <cg_pattern.h>
|
||||||
|
#include "data.h"
|
||||||
|
#include "regvar.h"
|
||||||
|
#include <em_reg.h>
|
||||||
|
#include "result.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
extern string myalloc();
|
||||||
|
struct regvar *rvlist;
|
||||||
|
|
||||||
|
struct regvar *
|
||||||
|
linkreg(of,sz,tp,sc) long of; {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
tryreg(rvlp,typ) struct regvar *rvlp; {
|
||||||
|
int score;
|
||||||
|
register i;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixregvars(saveall) {
|
||||||
|
register struct regvar *rv;
|
||||||
|
register rvtyp,i;
|
||||||
|
|
||||||
|
swtxt();
|
||||||
|
i_regsave(); /* machine dependent initialization */
|
||||||
|
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
|
||||||
|
for(i=0;i<nregvar[rvtyp];i++)
|
||||||
|
if (saveall) {
|
||||||
|
struct reginfo *rp;
|
||||||
|
rp= &machregs[rvnumbers[rvtyp][i]];
|
||||||
|
regsave(codestrings[rp->r_repr],(long)-TEM_WSIZE,rp->r_size);
|
||||||
|
} else if(regassigned[rvtyp][i].ra_score>0) {
|
||||||
|
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();
|
||||||
|
#ifndef TEM_BSIZE
|
||||||
|
for(rv=rvlist;rv!=0;rv=rv->rv_next)
|
||||||
|
if (rv->rv_off >= 0) rv->rv_off += TEM_BSIZE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
isregvar(off) long off; {
|
||||||
|
register struct regvar *rvlp;
|
||||||
|
|
||||||
|
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
||||||
|
if(rvlp->rv_off == off)
|
||||||
|
return(rvlp->rv_reg);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unlinkregs() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif REGVARS
|
||||||
|
|
||||||
|
/* nothing after this */
|
||||||
@@ -1,339 +0,0 @@
|
|||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
chtabgen - character table generator
|
|
||||||
|
|
||||||
Author: Erik Baalbergen (..tjalk!erikb)
|
|
||||||
Many mods by Ceriel Jacobs
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#ifndef NORCSID
|
|
||||||
static char *RcsId = "$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAXBUF 256
|
|
||||||
#define MAXTAB 10000
|
|
||||||
#define COMCOM '-'
|
|
||||||
#define FILECOM '%'
|
|
||||||
|
|
||||||
int InputForm = 'c'; /* default input format (and, currently, only one) */
|
|
||||||
char OutputForm[MAXBUF] = "%s,\n";
|
|
||||||
/* format for spitting out a string */
|
|
||||||
char *Table[MAXTAB];
|
|
||||||
char *ProgCall; /* callname of this program */
|
|
||||||
int TabSize = 128; /* default size of generated table */
|
|
||||||
char *InitialValue; /* initial value of all table entries */
|
|
||||||
|
|
||||||
extern char *malloc(), *strcpy();
|
|
||||||
|
|
||||||
main(argc, argv)
|
|
||||||
char *argv[];
|
|
||||||
{
|
|
||||||
|
|
||||||
ProgCall = *argv++;
|
|
||||||
argc--;
|
|
||||||
while (argc-- > 0) {
|
|
||||||
if (**argv == COMCOM) {
|
|
||||||
option(*argv++);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (! process(*argv++, InputForm)) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exit(0);
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
Salloc(s)
|
|
||||||
char *s;
|
|
||||||
{
|
|
||||||
char *ns = malloc((unsigned)strlen(s) + 1);
|
|
||||||
|
|
||||||
if (ns) {
|
|
||||||
strcpy(ns, s);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "%s: out of memory\n", ProgCall);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return ns;
|
|
||||||
}
|
|
||||||
|
|
||||||
option(str)
|
|
||||||
char *str;
|
|
||||||
{
|
|
||||||
/* note that *str indicates the source of the option:
|
|
||||||
either COMCOM (from command line) or FILECOM (from a file).
|
|
||||||
*/
|
|
||||||
switch (*++str) {
|
|
||||||
|
|
||||||
case ' ': /* command */
|
|
||||||
case '\t':
|
|
||||||
case '\0':
|
|
||||||
break;
|
|
||||||
case 'I': /* for future extension */
|
|
||||||
InputForm = *++str;
|
|
||||||
break;
|
|
||||||
case 'f': /* input from file ... */
|
|
||||||
if (*++str == '\0') {
|
|
||||||
fprintf(stderr, "%s: -f: name expected\n", ProgCall);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
DoFile(str);
|
|
||||||
break;
|
|
||||||
case 'F': /* new output format string */
|
|
||||||
sprintf(OutputForm, "%s\n", ++str);
|
|
||||||
break;
|
|
||||||
case 'T': /* insert text literally */
|
|
||||||
printf("%s\n", ++str);
|
|
||||||
break;
|
|
||||||
case 'p': /* print table */
|
|
||||||
PrintTable();
|
|
||||||
break;
|
|
||||||
case 'C': /* clear table */
|
|
||||||
InitTable((char *)0);
|
|
||||||
break;
|
|
||||||
case 'i': /* initialize table with given value */
|
|
||||||
if (*++str == '\0') {
|
|
||||||
InitTable((char *)0);
|
|
||||||
}
|
|
||||||
else InitTable(str);
|
|
||||||
break;
|
|
||||||
case 'S':
|
|
||||||
{
|
|
||||||
int i = atoi(++str);
|
|
||||||
|
|
||||||
if (i <= 0 || i > MAXTAB) {
|
|
||||||
fprintf(stderr, "%s: size would exceed maximum\n",
|
|
||||||
ProgCall);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TabSize = i;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: bad option -%s\n", ProgCall, str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
InitTable(ival)
|
|
||||||
char *ival;
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < TabSize; i++) {
|
|
||||||
Table[i] = 0;
|
|
||||||
}
|
|
||||||
InitialValue = 0;
|
|
||||||
if (ival) {
|
|
||||||
InitialValue = Salloc(ival);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintTable()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < TabSize; i++) {
|
|
||||||
if (Table[i]) {
|
|
||||||
printf(OutputForm, Table[i]);
|
|
||||||
}
|
|
||||||
else if (InitialValue) {
|
|
||||||
printf(OutputForm, InitialValue);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(OutputForm, "0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
process(str, format)
|
|
||||||
char *str;
|
|
||||||
{
|
|
||||||
char *cstr = str;
|
|
||||||
char *Name = cstr; /* overwrite original string! */
|
|
||||||
|
|
||||||
/* strip of the entry name
|
|
||||||
*/
|
|
||||||
while (*str && *str != ':') {
|
|
||||||
if (*str == '\\') {
|
|
||||||
++str;
|
|
||||||
}
|
|
||||||
*cstr++ = *str++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*str != ':') {
|
|
||||||
fprintf(stderr, "%s: bad specification: \"%s\", ignored\n",
|
|
||||||
ProgCall, Name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*cstr = '\0';
|
|
||||||
str++;
|
|
||||||
|
|
||||||
switch (format) {
|
|
||||||
|
|
||||||
case 'c':
|
|
||||||
return c_proc(str, Name);
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: bad input format\n", ProgCall);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
c_proc(str, Name)
|
|
||||||
char *str;
|
|
||||||
char *Name;
|
|
||||||
{
|
|
||||||
int ch, ch2;
|
|
||||||
int quoted();
|
|
||||||
char *name = Salloc(Name);
|
|
||||||
|
|
||||||
while (*str) {
|
|
||||||
if (*str == '\\') {
|
|
||||||
ch = quoted(&str);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ch = *str++ & 0377;
|
|
||||||
}
|
|
||||||
if (*str == '-') {
|
|
||||||
if (*++str == '\\') {
|
|
||||||
ch2 = quoted(&str);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (ch2 = (*str++ & 0377));
|
|
||||||
else str--;
|
|
||||||
}
|
|
||||||
if (ch > ch2) {
|
|
||||||
fprintf(stderr, "%s: bad range\n", ProgCall);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
while (ch <= ch2) {
|
|
||||||
if (! setval(ch, name)) return 0;
|
|
||||||
ch++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (! setval(ch, name)) return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
setval(ch, nm)
|
|
||||||
char *nm;
|
|
||||||
{
|
|
||||||
char **p = &Table[ch];
|
|
||||||
|
|
||||||
if (ch < 0 || ch >= TabSize) {
|
|
||||||
fprintf(stderr, "Illegal index: %d\n", ch);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (*(p = &Table[ch])) {
|
|
||||||
fprintf(stderr, "Warning: redefinition of index %d\n", ch);
|
|
||||||
}
|
|
||||||
*p = nm;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
quoted(pstr)
|
|
||||||
char **pstr;
|
|
||||||
{
|
|
||||||
int ch;
|
|
||||||
int i;
|
|
||||||
char *str = *pstr;
|
|
||||||
|
|
||||||
if ((*++str >= '0') && (*str <= '9')) {
|
|
||||||
ch = 0;
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
ch = 8 * ch + (*str - '0');
|
|
||||||
if (*++str < '0' || *str > '9')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
switch (*str++) {
|
|
||||||
case 'n':
|
|
||||||
ch = '\n';
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
ch = '\t';
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
ch = '\b';
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
ch = '\r';
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
ch = '\f';
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
ch = 013;
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
ch = *(str - 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*pstr = str;
|
|
||||||
return ch & 0377;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
getline(s, n, fp)
|
|
||||||
char *s;
|
|
||||||
FILE *fp;
|
|
||||||
{
|
|
||||||
int c = getc(fp);
|
|
||||||
char *str = s;
|
|
||||||
|
|
||||||
while (n--) {
|
|
||||||
if (c == EOF) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (c == '\n') {
|
|
||||||
*str++ = '\0';
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
*str++ = c;
|
|
||||||
c = getc(fp);
|
|
||||||
}
|
|
||||||
s[n - 1] = '\0';
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BUFSIZE 1024
|
|
||||||
|
|
||||||
DoFile(name)
|
|
||||||
char *name;
|
|
||||||
{
|
|
||||||
char text[BUFSIZE];
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
if ((fp = fopen(name, "r")) == NULL) {
|
|
||||||
fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
while (getline(text, BUFSIZE, fp) != NULL) {
|
|
||||||
if (text[0] == FILECOM) {
|
|
||||||
option(text);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (! process(text, InputForm)) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user