From dfefbcae86100dddc837c3c9e55e614e61f2c454 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:13:43 +0800 Subject: [PATCH] ANSI C conversion. --- util/cgg/bootgram.y | 42 +- util/cgg/booth.h | 197 +++--- util/cgg/bootlex.l | 23 +- util/cgg/main.c | 1403 ++++++++++++++++++++++++------------------- 4 files changed, 922 insertions(+), 743 deletions(-) diff --git a/util/cgg/bootgram.y b/util/cgg/bootgram.y index d1ff22cfb..8f530713f 100644 --- a/util/cgg/bootgram.y +++ b/util/cgg/bootgram.y @@ -1,9 +1,5 @@ %{ -#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". @@ -15,13 +11,17 @@ static char rcsid[]="$Id$"; #include #include #include -#include -#include -#include +#include "em_spec.h" +#include "em_flag.h" +#include "em_reg.h" -#define extern +#define INIT_VAR +#define EXTERN #include "booth.h" -#undef extern +#undef INIT_VAR +#undef EXTERN + +extern int yylex(void); %} @@ -268,7 +268,7 @@ tokenexpression : PIDENT { $$ = machprops[$1->i_i.i_prpno].propset; } | TIDENT - { register i; + { register int i; for(i=0;ii_i.i_tokno+nmachregs+1)>>4] |= @@ -278,7 +278,7 @@ tokenexpression | EIDENT { $$=machsets[$1->i_i.i_expno]; } | tokenexpression '*' tokenexpression - { register i; + { register int i; if (($$.set_size=$1.set_size)==0) $$.set_size = $3.set_size; @@ -286,7 +286,7 @@ tokenexpression $$.set_val[i] = $1.set_val[i] & $3.set_val[i]; } | tokenexpression '+' tokenexpression - { register i; + { register int i; if ($1.set_size == -1) $$.set_size = $3.set_size; @@ -300,7 +300,7 @@ tokenexpression $$.set_val[i] = $1.set_val[i] | $3.set_val[i]; } | tokenexpression '-' tokenexpression - { register i; + { register int i; if ($1.set_size == -1) $$.set_size = $3.set_size; @@ -403,7 +403,7 @@ empattern : /* empty */ { empatlen=0; } | mnemlist optboolexpr - { register i; + { register int i; empatexpr = $2; patbyte(0); @@ -441,7 +441,7 @@ mnem : IDENT stackpattern : optnocoerc tokenexpressionlist optstack - { register i; + { register int i; if (tokpatlen != 0) { outbyte(($1 ? ( $3 ? DO_XXMATCH: DO_XMATCH ) : DO_MATCH)+(tokpatlen<<5)); @@ -1053,7 +1053,7 @@ tokeninstanceno tokeninstance : '%' '[' tokargno subreg ']' - { register i; + { register int i; if ($4!=0) chkregexp(pattokexp[$3]); @@ -1065,7 +1065,7 @@ tokeninstance } | '%' '[' tokargno '.' IDENT ']' { int typ; - register i; + register int i; $$.in_which = IN_COPY; $$.in_info[0] = $3; $$.in_info[1] = findstructel(pattokexp[$3],$5,&typ); @@ -1075,14 +1075,14 @@ tokeninstance $$.in_info[i] = 0; } | RIDENT - { register i; + { register int i; $$.in_which = IN_RIDENT; $$.in_info[0] = $1->i_i.i_regno; for (i=1;i= 'a'+nallreg) yyerror("Bad letter in %[x] construct"); $$.in_which = IN_ALLOC; @@ -1100,7 +1100,7 @@ tokeninstance $$.in_info[i] = 0; } | '{' TIDENT attlist '}' - { register i; + { register int i; $$.in_which = IN_DESCR; $$.in_info[0] = $2->i_i.i_tokno; for(i=0;i -#ifdef extern +#ifdef INIT_VAR #define INIT(x) = x #else #define INIT(x) /* empty */ @@ -33,9 +33,9 @@ #define MAXSPLIT 4 /* Maximum degree of split */ #define MAXNSTR 40 /* Maximum consecutive strings in coderule */ -extern char *hname INIT("tables.h"); -extern char *cname INIT("tables.c"); -extern char *iname; /* stdin */ +EXTERN char *hname INIT("tables.h"); +EXTERN char *cname INIT("tables.c"); +EXTERN char *iname; /* stdin */ /* Derived constants */ @@ -53,7 +53,7 @@ extern char *iname; /* stdin */ typedef char byte; typedef char * string; -extern char *myalloc(); +EXTERN char *myalloc(); #include @@ -108,7 +108,7 @@ typedef struct ident { } ident_t,*ident_p; #define ITABSIZE 32 -extern ident_p identtab[ITABSIZE]; +EXTERN ident_p identtab[ITABSIZE]; #define LOOKUP 0 #define HALFWAY 1 @@ -125,90 +125,90 @@ typedef struct expr { int expr_index; } expr_t,*expr_p; -extern unsigned cc1 INIT(1),cc2 INIT(1),cc3 INIT(1),cc4 INIT(1); +EXTERN unsigned cc1 INIT(1),cc2 INIT(1),cc3 INIT(1),cc4 INIT(1); -extern node_t nodes[MAXNODES]; -extern node_p lastnode INIT(nodes+1); +EXTERN node_t nodes[MAXNODES]; +EXTERN node_p lastnode INIT(nodes+1); -extern string codestrings[MAXSTRINGS]; -extern int ncodestrings; +EXTERN string codestrings[MAXSTRINGS]; +EXTERN int ncodestrings; -extern int strar[MAXNSTR]; -extern int nstr; +EXTERN int strar[MAXNSTR]; +EXTERN int nstr; -extern int pathash[256]; +EXTERN int pathash[256]; -extern reginfo machregs[MAXREGS]; -extern char stregclass[MAXREGS]; -extern int nmachregs INIT(1); -extern int nregclasses INIT(1); -extern int maxmembers; -extern struct { +EXTERN reginfo machregs[MAXREGS]; +EXTERN char stregclass[MAXREGS]; +EXTERN int nmachregs INIT(1); +EXTERN int nregclasses INIT(1); +EXTERN int maxmembers; +EXTERN struct { ident_p propname; set_t propset; } machprops[MAXPROPS]; -extern int nprops; -extern token_t machtokens[MAXTOKENS]; -extern int nmachtokens INIT(1); -extern set_t machsets[MAXSETS]; -extern int nmachsets; -extern int patmnem[MAXEMPATLEN]; -extern int empatlen; -extern int maxempatlen; -extern int empatexpr; -extern int maxrule INIT(1); -extern int pattokexp[MAXPATLEN]; -extern int tokpatlen; -extern int lookident; /* lexical analyzer flag */ -extern list3 structpool; -extern int nallreg; -extern int allreg[MAXALLREG]; -extern int maxallreg; -extern int lino; -extern int nerrors; -extern int curtokexp; -extern expr_t arexp[TOKENSIZE]; -extern int narexp; -extern inst_t arinstance[MAXINSTANCE]; -extern int narinstance INIT(1); -extern move_t machmoves[NMOVES]; -extern int nmoves; -extern byte pattern[MAXPATTERN]; -extern int npatbytes; -extern int prevind; -extern int rulecount; /* Temporary index for ... construct */ -extern int ncoderules; -extern int codebytes; -extern FILE *cfile; -extern FILE *hfile; -extern int maxtokensize; -extern int dealflag; -extern int emrepllen; -extern int replmnem[MAXEMPATLEN]; -extern int tokrepllen; -extern int replinst[MAXPATLEN]; -extern int replexpr[MAXPATLEN]; -extern c1_t c1coercs[MAXC1]; -extern c2_t c2coercs[MAXC2]; -extern c3_t c3coercs[MAXC3]; -extern int nc1,nc2,nc3; -extern int maxsplit; -extern int wsize INIT(-1); -extern int psize INIT(-1); -extern int bsize INIT(-1); -extern char *fmt; +EXTERN int nprops; +EXTERN token_t machtokens[MAXTOKENS]; +EXTERN int nmachtokens INIT(1); +EXTERN set_t machsets[MAXSETS]; +EXTERN int nmachsets; +EXTERN int patmnem[MAXEMPATLEN]; +EXTERN int empatlen; +EXTERN int maxempatlen; +EXTERN int empatexpr; +EXTERN int maxrule INIT(1); +EXTERN int pattokexp[MAXPATLEN]; +EXTERN int tokpatlen; +EXTERN int lookident; /* lexical analyzer flag */ +EXTERN list3 structpool; +EXTERN int nallreg; +EXTERN int allreg[MAXALLREG]; +EXTERN int maxallreg; +EXTERN int lino; +EXTERN int nerrors; +EXTERN int curtokexp; +EXTERN expr_t arexp[TOKENSIZE]; +EXTERN int narexp; +EXTERN inst_t arinstance[MAXINSTANCE]; +EXTERN int narinstance INIT(1); +EXTERN move_t machmoves[NMOVES]; +EXTERN int nmoves; +EXTERN byte pattern[MAXPATTERN]; +EXTERN int npatbytes; +EXTERN int prevind; +EXTERN int rulecount; /* Temporary index for ... construct */ +EXTERN int ncoderules; +EXTERN int codebytes; +EXTERN FILE *cfile; +EXTERN FILE *hfile; +EXTERN int maxtokensize; +EXTERN int dealflag; +EXTERN int emrepllen; +EXTERN int replmnem[MAXEMPATLEN]; +EXTERN int tokrepllen; +EXTERN int replinst[MAXPATLEN]; +EXTERN int replexpr[MAXPATLEN]; +EXTERN c1_t c1coercs[MAXC1]; +EXTERN c2_t c2coercs[MAXC2]; +EXTERN c3_t c3coercs[MAXC3]; +EXTERN int nc1,nc2,nc3; +EXTERN int maxsplit; +EXTERN int wsize INIT(-1); +EXTERN int psize INIT(-1); +EXTERN int bsize INIT(-1); +EXTERN char *fmt; -extern int cchandled; -extern int ccspoiled; -extern int ccregexpr; -extern int ccinstanceno; -extern int cocopropno; -extern int cocosetno; -extern int allexpno; +EXTERN int cchandled; +EXTERN int ccspoiled; +EXTERN int ccregexpr; +EXTERN int ccinstanceno; +EXTERN int cocopropno; +EXTERN int cocosetno; +EXTERN int allexpno; -extern int rvused; /* regvars used */ -extern int nregvar[4]; /* # of register variables of all kinds */ -extern int rvnumbers[4][MAXREGVARS]; /* The register numbers */ +EXTERN int rvused; /* regvars used */ +EXTERN int nregvar[4]; /* # of register variables of all kinds */ +EXTERN int rvnumbers[4][MAXREGVARS]; /* The register numbers */ #define chktabsiz(size,maxsize,which) if(size>=maxsize) tabovf(which) @@ -217,7 +217,36 @@ extern int rvnumbers[4][MAXREGVARS]; /* The register numbers */ #define MUST1BEBOOL(e) int exp1=e.expr_index;tstbool(e) #define MUST2BEBOOL(e1,e2) int exp1=e1.expr_index,exp2=e2.expr_index;tstbool(e1);tstbool(e2) -extern ident_p ilookup(); -extern list2 lookstruct(); -extern string scopy(); -extern unsigned hash(); +ident_p ilookup(string name, int enterf); +unsigned hash(register string name); +int lookup(int comm, int operator, int lnode, int rnode); +list2 lookstruct(list2 ll); +string scopy(string s); +void tabovf(string tablename); +int strlookup(string s); +int structsize(register list2 s); +void yyerror(string s, ...); +int instno(inst_t inst); +int yyparse(void); +int stringno(register string s); +int exprlookup(set_t sett); +void tstint(expr_t e); +void tstbool(expr_t e); +void inbetween(void); +int formconversion(register char *p, register token_p tp); +void setfields(register token_p tp, string format); +void chkregexp(int number); +int findstructel(int number, string name, int *t); +int argtyp(int mn); +int commontype(expr_t e1, expr_t e2); +void inithash(void); +void enter(char *name, int value); +int mlookup(char *name); +void hashpatterns(void); +int max(int a, int b); +void out(int n); +void outbyte(int n); +void pat(int n); +void patshort(int n); +void patbyte(int n); + diff --git a/util/cgg/bootlex.l b/util/cgg/bootlex.l index 3fba33c7e..07599eeb3 100644 --- a/util/cgg/bootlex.l +++ b/util/cgg/bootlex.l @@ -1,8 +1,5 @@ %{ -#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". @@ -14,11 +11,14 @@ static char rcsid2[]="$Id$"; #include #include -#include -#include -#include +#include +#include "em_spec.h" +#include "em_flag.h" +#include "em_reg.h" +#define EXTERN extern #include "booth.h" +#undef EXTERN #include "y.tab.h" int lineno = 1; @@ -158,10 +158,15 @@ return return(RETURN); . return(yytext[0]); %% -yyerror(s,a1,a2,a3,a4) string s; { +void yyerror(string s, ...) +{ + va_list ap; + va_start(ap, s); + fprintf(stderr,"\"%s\", line %d:",iname ? iname : "",lineno); - fprintf(stderr,s,a1,a2,a3,a4); + vfprintf(stderr,s,ap); fprintf(stderr,"\n"); - nerrors++; + nerrors++; + va_end(ap); } diff --git a/util/cgg/main.c b/util/cgg/main.c index 86375b776..75a066e5e 100644 --- a/util/cgg/main.c +++ b/util/cgg/main.c @@ -3,248 +3,316 @@ #include #include #include -#include -#include -#include +#include "em_spec.h" +#include "em_flag.h" +#include "em_reg.h" +#define EXTERN extern #include "booth.h" +#undef EXTERN -char * myalloc(n) { +/* Forward local declarations. */ +static void debug(void); +static void verbose(void); +static void outregvar(void); +static void finishio(void); +static void inittables(void); +static void initio(void); +static int eqregclass(int r1, int r2); +static void compueq(void); + + + +char *myalloc(int n) +{ register char *p; - p= malloc((unsigned)n); - if (p==0) { + p = malloc((unsigned) n); + if (p == 0) + { yyerror("Out of core"); exit(1); } - return(p); + return (p); } -tstint(e) expr_t e; { +void tstint(expr_t e) +{ - if(e.expr_typ != TYPINT) + if (e.expr_typ != TYPINT) yyerror("Must be integer expression"); } -tstbool(e) expr_t e; { +void tstbool(expr_t e) +{ - if(e.expr_typ != TYPBOOL) + if (e.expr_typ != TYPBOOL) yyerror("Must be boolean expression"); } -structsize(s) register list2 s; { +int structsize(register list2 s) +{ register list1 l; - register sum; + register int sum; sum = 0; - while ( s != 0 ) { + while (s != 0) + { l = s->l2list->l1next; - while ( l != 0 ) { + while (l != 0) + { sum++; l = l->l1next; } s = s->l2next; } - return(sum); + return (sum); } -list2 lookstruct(ll) list2 ll; { - list3 l3; - list2 l21,l22; - list1 l11,l12; +static int isasc(int c) +{ + if ((c >= 0 && c <= 0177)) + return 1; + return 0; +} - for (l3=structpool;l3 != 0;l3=l3->l3next) { - for (l21=l3->l3list,l22=ll;l21!=0 && l22!=0; - l21=l21->l2next,l22=l22->l2next) { - for(l11=l21->l2list,l12=l22->l2list; - l11!=0 && l12!=0 && strcmp(l11->l1name,l12->l1name)==0; - l11=l11->l1next,l12=l12->l1next) +list2 lookstruct(list2 ll) +{ + list3 l3; + list2 l21, l22; + list1 l11, l12; + + for (l3 = structpool; l3 != 0; l3 = l3->l3next) + { + for (l21 = l3->l3list, l22 = ll; l21 != 0 && l22 != 0; l21 = + l21->l2next, l22 = l22->l2next) + { + for (l11 = l21->l2list, l12 = l22->l2list; + l11 != 0 && l12 != 0 + && strcmp(l11->l1name, l12->l1name) == 0; + l11 = l11->l1next, l12 = l12->l1next) ; - if (l11!=0 || l12!=0) + if (l11 != 0 || l12 != 0) goto contin; } - if(l21==0 && l22==0) - return(l3->l3list); - contin:; + if (l21 == 0 && l22 == 0) + return (l3->l3list); + contin: ; } l3 = (list3) myalloc(sizeof(struct list3str)); - l3->l3next=structpool; - l3->l3list=ll; - structpool=l3; - return(ll); + l3->l3next = structpool; + l3->l3list = ll; + structpool = l3; + return (ll); } -instno(inst) inst_t inst; { - register i,j; +int instno(inst_t inst) +{ + register int i, j; - for(i=1;itokpatlen) - yyerror("Number within %[] out of range"); - if (*s == ']') { + case '$': s++; - *p++ = PR_TOK; - *p++ = num; - } else if (*s++ != '.') - yyerror("Bad character following %%[digit in codestring"); - else { - char field[256]; - register char *f=field; - int type,offset; - - while( *s != ']' && *s != 0) - *f++ = *s++; - *f++ = 0; - if (*s != ']') - yyerror("Unterminated %[] construction in codestring"); + switch (*s) + { + default: + yyerror("Bad character after $ in codestring"); + case '$': + *p++ = *s++; + continue; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + *p++ = argtyp(patmnem[*s - '0']) == TYPINT ? + PR_EMINT : PR_EMSTR; + *p++ = *s++ - '0'; + continue; + } + case '%': + s++; + if (*s != '[') + { + if (*s == '%') + { + *p++ = *s++; + continue; + } + else + yyerror("Bad character following %% in codestring"); + } else s++; - if (isdigit(field[0])) { - chkregexp(pattokexp[num]); - *p++ = PR_SUBREG; - *p++ = num; - *p++ = atoi(field); - } else { - offset = findstructel(pattokexp[num],field,&type); - *p++ = PR_TOKFLD; - *p++ = num; - *p++ = offset; + if (isdigit(*s)) + { + int num; + num = *s++ - '0'; + if (num < 1 || num > tokpatlen) + yyerror("Number within %[] out of range"); + if (*s == ']') + { + s++; + *p++ = PR_TOK; + *p++ = num; + } + else if (*s++ != '.') + yyerror( + "Bad character following %%[digit in codestring"); + else + { + char field[256]; + register char *f = field; + int type, offset; + + while (*s != ']' && *s != 0) + *f++ = *s++; + *f++ = 0; + if (*s != ']') + yyerror( + "Unterminated %[] construction in codestring"); + else + s++; + if (isdigit(field[0])) + { + chkregexp(pattokexp[num]); + *p++ = PR_SUBREG; + *p++ = num; + *p++ = atoi(field); + } + else + { + offset = findstructel(pattokexp[num], field, &type); + *p++ = PR_TOKFLD; + *p++ = num; + *p++ = offset; + } + } } - } - } else if (*s >= 'a' && *s < 'a'+nallreg) { - int reg,subreg; - reg = *s++ -'a'+1; - if(*s == ']') - subreg = 255; - else { - if (*s != '.') - yyerror("Bad character following %%[x in codestring"); - s++; - if(!isdigit(*s)) - yyerror("Bad character following %%[x. in codestring"); - subreg = *s - '0'; - s++; - if(*s != ']') - yyerror("Bad character following %%[x.y in codestring"); - } - s++; - *p++ = PR_ALLREG; - *p++ = reg; - *p++ = subreg; - } else - yyerror("Bad character following %%[ in codestring"); - } + else if (*s >= 'a' && *s < 'a' + nallreg) + { + int reg, subreg; + reg = *s++ - 'a' + 1; + if (*s == ']') + subreg = 255; + else + { + if (*s != '.') + yyerror( + "Bad character following %%[x in codestring"); + s++; + if (!isdigit(*s)) + yyerror( + "Bad character following %%[x. in codestring"); + subreg = *s - '0'; + s++; + if (*s != ']') + yyerror( + "Bad character following %%[x.y in codestring"); + } + s++; + *p++ = PR_ALLREG; + *p++ = reg; + *p++ = subreg; + } + else + yyerror("Bad character following %%[ in codestring"); + } *p++ = 0; - return(strlookup(buf)); + return (strlookup(buf)); } -tabovf(tablename) string tablename; { +void tabovf(string tablename) +{ char buf[256]; - sprintf(buf,"%s overflow",tablename); + sprintf(buf, "%s overflow", tablename); yyerror(buf); - exit(-1); + exit(EXIT_FAILURE); } -main(argc,argv) char *argv[]; { +int main(int argc, char *argv[]) +{ - while (--argc) { + while (--argc) + { ++argv; - if (argv[0][0]=='-') { - switch (argv[0][1]) { - case 'h': - hname= &argv[0][2]; - break; - case 'c': - cname= &argv[0][2]; - break; - default: - fprintf(stderr,"Bad flag %s\n",argv[0]); - break; + if (argv[0][0] == '-') + { + switch (argv[0][1]) + { + case 'h': + hname = &argv[0][2]; + break; + case 'c': + cname = &argv[0][2]; + break; + default: + fprintf(stderr, "Bad flag %s\n", argv[0]); + break; } - } else { - iname= argv[0]; + } + else + { + iname = argv[0]; } } inithash(); initio(); inittables(); yyparse(); - if (nerrors==0) { + if (nerrors == 0) + { compueq(); hashpatterns(); finishio(); @@ -254,16 +322,18 @@ main(argc,argv) char *argv[]; { exit(nerrors); } -lookup(comm,operator,lnode,rnode) { +int lookup(int comm, int operator, int lnode, int rnode) +{ register node_p p; - for (p=nodes+1;pex_operator != operator) continue; - if (!(p->ex_lnode == lnode && p->ex_rnode == rnode || - comm && p->ex_lnode == rnode && p->ex_rnode == lnode)) + if (!((p->ex_lnode == lnode && p->ex_rnode == rnode) + || (comm && p->ex_lnode == rnode && p->ex_rnode == lnode))) continue; - return(p-nodes); + return (p - nodes); } if (lastnode >= &nodes[MAXNODES]) yyerror("node table overflow"); @@ -271,444 +341,481 @@ lookup(comm,operator,lnode,rnode) { p->ex_operator = operator; p->ex_lnode = lnode; p->ex_rnode = rnode; - return(p-nodes); + return (p - nodes); } -compueq() { - register i,j; +static void compueq(void) +{ + register int i, j; - for (i=1;i>4]; +static int eqregclass(int r1, int r2) +{ + register reginfo rp1, rp2; + register int i; + short regbits[(MAXREGS + 15) >> 4]; int member; - rp1 = machregs[r1]; rp2 = machregs[r2]; - for (i=0;i<((nprops+15)>>4);i++) + rp1 = machregs[r1]; + rp2 = machregs[r2]; + for (i = 0; i < ((nprops + 15) >> 4); i++) if (rp1->rprop[i] != rp2->rprop[i]) - return(0); - for (i=0;i<((MAXREGS+15)>>4);i++) + return (0); + for (i = 0; i < ((MAXREGS + 15) >> 4); i++) regbits[i] = 0; - for (i=0;irmembers[i]) - regbits[member>>4] |= (1<<(member&017)); + for (i = 0; i < maxmembers; i++) + { + if ((member = rp1->rmembers[i])) + regbits[member >> 4] |= (1 << (member & 017)); } - for (i=0;irmembers[i]; - if (regbits[member>>4]&(1<<(member&017))) - return(0); + if (regbits[member >> 4] & (1 << (member & 017))) + return (0); } - return(1); + return (1); } -unsigned hash(name) register string name; { +unsigned hash(register string name) +{ register unsigned sum; - register i; + register int i; - for (sum=i=0;*name;i+=3) - sum ^= (*name++)<<(i&07); - return(sum); + for (sum = i = 0; *name; i += 3) + sum ^= (*name++) << (i & 07); + return (sum); } -ident_p ilookup(name,enterf) string name; int enterf; { - register ident_p p,*pp; +ident_p ilookup(string name, int enterf) +{ + register ident_p p, *pp; - pp = &identtab[hash(name)%ITABSIZE]; - while (*pp != 0) { - if (strcmp((*pp)->i_name,name)==0) + pp = &identtab[hash(name) % ITABSIZE]; + while (*pp != 0) + { + if (strcmp((*pp)->i_name, name) == 0) + { if (enterf != ENTER) - return(*pp); + return (*pp); else yyerror("Multiply defined symbol"); + } pp = &(*pp)->i_next; } if (enterf == LOOKUP) yyerror("Undefined symbol"); if (enterf == JUSTLOOKING) - return(0); + return (0); p = *pp = (ident_p) myalloc(sizeof(ident_t)); p->i_name = name; p->i_next = 0; p->i_type = 0; - return(p); + return (p); } -initio() { +static void initio(void) +{ - if (iname!=0 && freopen(iname,"r",stdin)==NULL) { - fprintf(stderr,"Can't open %s\n",iname); + if (iname != 0 && freopen(iname, "r", stdin) == NULL) + { + fprintf(stderr, "Can't open %s\n", iname); exit(-1); } - if ((cfile=fopen(cname,"w"))==NULL) { - fprintf(stderr,"Can't create %s\n",cname); + if ((cfile = fopen(cname, "w")) == NULL) + { + fprintf(stderr, "Can't create %s\n", cname); exit(-1); } - if ((hfile=fopen(hname,"w"))==NULL) { - fprintf(stderr,"Can't create %s\n",hname); + if ((hfile = fopen(hname, "w")) == NULL) + { + fprintf(stderr, "Can't create %s\n", hname); exit(-1); } - fprintf(cfile,"#include \"param.h\"\n"); - fprintf(cfile,"#include \"tables.h\"\n"); - fprintf(cfile,"#include \"types.h\"\n"); - fprintf(cfile,"#include \n"); - fprintf(cfile,"#include \"data.h\"\n"); - fprintf(cfile,"\nbyte coderules[] = {\n"); + fprintf(cfile, "#include \"param.h\"\n"); + fprintf(cfile, "#include \"tables.h\"\n"); + fprintf(cfile, "#include \"types.h\"\n"); + fprintf(cfile, "#include \n"); + fprintf(cfile, "#include \"data.h\"\n"); + fprintf(cfile, "\nbyte coderules[] = {\n"); patbyte(0); } -exprlookup(sett) set_t sett; { - register i,j,ok; +int exprlookup(set_t sett) +{ + register int i, j, ok; - for(i=0;irname = "cc reg"; r->rrepr = "CC"; r->rsize = -1; - r->rregvar= -1; - for(i=0;irregvar = -1; + for (i = 0; i < MAXMEMBERS; i++) r->rmembers[i] = 0; - for(i=0;irprop[i] = 0; - r->rprop[cocopropno>>4] |= (1<<(cocopropno&017)); - chktabsiz(nmachregs,MAXREGS,"Register table"); - machregs[nmachregs++] = r; + r->rprop[cocopropno >> 4] |= (1 << (cocopropno & 017)); + chktabsiz(nmachregs, MAXREGS, "Register table"); + machregs[nmachregs++] = r; inst.in_which = IN_RIDENT; - inst.in_info[0] = nmachregs-1; - for(i=1;i>4] |= (01<<(nmachregs&017)); - cocosetno=exprlookup(sett); + inst.in_info[0] = nmachregs - 1; + for (i = 1; i < TOKENSIZE; i++) + inst.in_info[i] = 0; + ccinstanceno = instno(inst); + ccregexpr = lookup(0, EX_REG, nmachregs - 1, 0); + sett.set_size = 0; + for (i = 0; i < SETSIZE; i++) + sett.set_val[i] = 0; + sett.set_val[nmachregs >> 4] |= (01 << (nmachregs & 017)); + cocosetno = exprlookup(sett); } -outregs() { - register i,j,k; - static short rset[(MAXREGS+15)>>4]; - int t,ready; +static void outregs(void) +{ + register int i, j, k; + static short rset[(MAXREGS + 15) >> 4]; + int t, ready; - fprintf(cfile,"char stregclass[] = {\n"); - for (i=0;irrepr), - machregs[i]->rsize); - if (maxmembers!=0) { - fprintf(cfile,",{"); - for(j=0;jrmembers[j]); + fprintf(cfile, "char stregclass[] = {\n"); + for (i = 0; i < nmachregs; i++) + fprintf(cfile, "\t%d,\n", stregclass[i]); + fprintf(cfile, "};\n\nstruct reginfo machregs[] = {\n{0},\n"); + for (i = 1; i < nmachregs; i++) + { + fprintf(cfile, "{%d,%d", strlookup(machregs[i]->rrepr), + machregs[i]->rsize); + if (maxmembers != 0) + { + fprintf(cfile, ",{"); + for (j = 0; j < maxmembers; j++) + fprintf(cfile, "%d,", machregs[i]->rmembers[j]); /* now compute and print set of registers * that clashes with this register. * A register clashes with al its children (and theirs) * and with all their parents. */ - for (j=0;j<((MAXREGS+15)>>4);j++) - rset[j]=0; - rset[i>>4] |= (1<<(i&017)); - do { - ready=1; - for (j=1;j>4]&(1<<(j&017))) - for (k=0;krmembers[k])!=0) { - if ((rset[t>>4]&(1<<(t&017)))==0) - ready=0; - rset[t>>4] |= (1<<(t&017)); - } + for (j = 0; j < ((MAXREGS + 15) >> 4); j++) + rset[j] = 0; + rset[i >> 4] |= (1 << (i & 017)); + do + { + ready = 1; + for (j = 1; j < nmachregs; j++) + if (rset[j >> 4] & (1 << (j & 017))) + for (k = 0; k < maxmembers; k++) + if ((t = machregs[j]->rmembers[k]) != 0) + { + if ((rset[t >> 4] & (1 << (t & 017))) == 0) + ready = 0; + rset[t >> 4] |= (1 << (t & 017)); + } } while (!ready); - do { - ready=1; - for (j=1;jrmembers[k])!=0) - if (rset[t>>4]&(1<<(t&017))) { - if (rset[j>>4]&(1<<(j&017))==0) - ready=0; - rset[j>>4] |= (1<<(j&017)); - } + do + { + ready = 1; + for (j = 1; j < nmachregs; j++) + for (k = 0; k < maxmembers; k++) + if ((t = machregs[j]->rmembers[k]) != 0) + if (rset[t >> 4] & (1 << (t & 017))) + { + if ((rset[j >> 4] & (1 << (j & 017))) == 0) + ready = 0; + rset[j >> 4] |= (1 << (j & 017)); + } } while (!ready); - fprintf(cfile,"},{"); - for (j=0;j<((nmachregs+15)>>4);j++) - fprintf(cfile,"%d,",rset[j]); - fprintf(cfile,"}"); + fprintf(cfile, "},{"); + for (j = 0; j < ((nmachregs + 15) >> 4); j++) + fprintf(cfile, "%d,", rset[j]); + fprintf(cfile, "}"); } - if (machregs[i]->rregvar>=0) - fprintf(cfile,",1"); - fprintf(cfile,"},\n"); + if (machregs[i]->rregvar >= 0) + fprintf(cfile, ",1"); + fprintf(cfile, "},\n"); } - fprintf(cfile,"};\n\n"); + fprintf(cfile, "};\n\n"); } -finishio() { - register i; +static void finishio(void) +{ + register int i; register node_p np; int j; int setsize; register move_p mp; - fprintf(cfile,"};\n\n"); - if (wsize>0) - fprintf(hfile,"#define TEM_WSIZE %d\n",wsize); + fprintf(cfile, "};\n\n"); + if (wsize > 0) + fprintf(hfile, "#define TEM_WSIZE %d\n", wsize); else yyerror("Wordsize undefined"); - if (psize>0) - fprintf(hfile,"#define TEM_PSIZE %d\n",psize); + if (psize > 0) + fprintf(hfile, "#define TEM_PSIZE %d\n", psize); else yyerror("Pointersize undefined"); - if (bsize>=0) - fprintf(hfile,"#define TEM_BSIZE %d\n",bsize); + if (bsize >= 0) + fprintf(hfile, "#define TEM_BSIZE %d\n", bsize); else yyerror("EM_BSIZE undefined"); - if (fmt!=0) - fprintf(hfile,"#define WRD_FMT \"%s\"\n",fmt); - fprintf(hfile,"#define MAXALLREG %d\n",maxallreg); - setsize = (nmachregs+1 + nmachtokens + 15)>>4; - fprintf(hfile,"#define SETSIZE %d\n",setsize); - fprintf(hfile,"#define NPROPS %d\n",nprops); - fprintf(hfile,"#define NREGS %d\n",nmachregs); - fprintf(hfile,"#define REGSETSIZE %d\n",(nmachregs+15)>>4); - fprintf(hfile,"#define TOKENSIZE %d\n",maxtokensize); - fprintf(hfile,"#define MAXMEMBERS %d\n",maxmembers); - fprintf(hfile,"#define LONGESTPATTERN %d\n",maxempatlen); - fprintf(hfile,"#define MAXRULE %d\n",maxrule); - fprintf(hfile,"#define NMOVES %d\n",nmoves); - fprintf(hfile,"#define NC1 %d\n",nc1); - if (nc2) { - assert(maxsplit!=0); - fprintf(hfile,"#define NC2 %d\n",nc2); - fprintf(hfile,"#define MAXSPLIT %d\n",maxsplit); + if (fmt != 0) + fprintf(hfile, "#define WRD_FMT \"%s\"\n", fmt); + fprintf(hfile, "#define MAXALLREG %d\n", maxallreg); + setsize = (nmachregs + 1 + nmachtokens + 15) >> 4; + fprintf(hfile, "#define SETSIZE %d\n", setsize); + fprintf(hfile, "#define NPROPS %d\n", nprops); + fprintf(hfile, "#define NREGS %d\n", nmachregs); + fprintf(hfile, "#define REGSETSIZE %d\n", (nmachregs + 15) >> 4); + fprintf(hfile, "#define TOKENSIZE %d\n", maxtokensize); + fprintf(hfile, "#define MAXMEMBERS %d\n", maxmembers); + fprintf(hfile, "#define LONGESTPATTERN %d\n", maxempatlen); + fprintf(hfile, "#define MAXRULE %d\n", maxrule); + fprintf(hfile, "#define NMOVES %d\n", nmoves); + fprintf(hfile, "#define NC1 %d\n", nc1); + if (nc2) + { + assert(maxsplit != 0); + fprintf(hfile, "#define NC2 %d\n", nc2); + fprintf(hfile, "#define MAXSPLIT %d\n", maxsplit); } - fprintf(hfile,"#define NC3 %d\n",nc3); + fprintf(hfile, "#define NC3 %d\n", nc3); outregs(); - fprintf(cfile,"tkdef_t tokens[] = {\n"); - for(i=0;iex_operator,np->ex_lnode, + fprintf(cfile, "};\n\nnode_t enodes[] = {\n"); + for (np = nodes; np < lastnode; np++) + fprintf(cfile, "{%d,%d,%d},\n", np->ex_operator, np->ex_lnode, np->ex_rnode); - fprintf(cfile,"};\n\nstring codestrings[] = {\n"); - for(i=0;i>6)&03, - but this triggered a bug in GCC 2.4.5 - on SPARC. - */ - fprintf(cfile,"\\%c%c%c",((*p>>6) &03)+'0', - ((c>>3)&07)+'0',(c&07)+'0'); + but this triggered a bug in GCC 2.4.5 + on SPARC. + */ + fprintf(cfile, "\\%c%c%c", ((*p >> 6) & 03) + '0', + ((c >> 3) & 07) + '0', (c & 07) + '0'); } - else putc(c, cfile); + else + putc(c, cfile); p++; } - fprintf(cfile,"\",\n"); + fprintf(cfile, "\",\n"); } - fprintf(cfile,"};\n\nset_t machsets[] = {\n"); - for(i=0;im_set1, mp->m_expr1, - mp->m_set2, mp->m_expr2, - mp->m_cindex, - mp->m_cost.c_size,mp->m_cost.c_time); + fprintf(cfile, "{%d,%d,%d,%d,%d,{%d,%d}},\n", mp->m_set1, mp->m_expr1, + mp->m_set2, mp->m_expr2, mp->m_cindex, mp->m_cost.c_size, + mp->m_cost.c_time); } - fprintf(cfile,"};\n\nbyte pattern[] = {\n"); - for (i=0;irregvar<0 && - (machprops[i].propset.set_val[j>>4]&(1<<(j&017)))) - fprintf(cfile,"\t&machregs[%d],\n",j-1); + fprintf(cfile, "};\n\nc3_t c3coercs[] = {\n"); + for (i = 0; i < nc3; i++) + fprintf(cfile, "{%d,%d,%d,%d},\n", c3coercs[i].c3_texpno, + c3coercs[i].c3_prop, c3coercs[i].c3_repl, c3coercs[i].c3_codep); + fprintf(cfile, "};\n\n"); + for (i = 0; i < nprops; i++) + { + fprintf(cfile, "struct reginfo *rlist%d[] = {\n", i); + for (j = 2; j <= nmachregs; j++) + { + if (machregs[j - 1]->rregvar < 0 + && (machprops[i].propset.set_val[j >> 4] & (1 << (j & 017)))) + fprintf(cfile, "\t&machregs[%d],\n", j - 1); } - fprintf(cfile,"\t0\n};\n"); + fprintf(cfile, "\t0\n};\n"); } - fprintf(cfile,"struct reginfo **reglist[] = {\n"); - for (i=0;i0) - fprintf(cfile,"struct regassigned ratar%d[%d];\n", - i,nregvar[i]); - for (i=0;i<4;i++) if (nregvar[i]>0) { - fprintf(cfile,"int rvtar%d[] = {",i); - for (j=0;j0) - fprintf(cfile,"\trvtar%d,\n",i); + fprintf(hfile, "#define REGVARS\n"); + fprintf(cfile, "#include \"regvar.h\"\n"); + fprintf(cfile, "int nregvar[4] = { "); + for (i = 0; i < 4; i++) + fprintf(cfile, "%d, ", nregvar[i]); + fprintf(cfile, "};\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(cfile, "struct regassigned ratar%d[%d];\n", i, nregvar[i]); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + { + fprintf(cfile, "int rvtar%d[] = {", i); + for (j = 0; j < nregvar[i]; j++) + fprintf(cfile, "%d,", rvnumbers[i][j]); + fprintf(cfile, "};\n"); + } + fprintf(cfile, "\nint *rvnumbers[] = {\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(cfile, "\trvtar%d,\n", i); else - fprintf(cfile,"\t0,\n"); - fprintf(cfile,"};\n\nstruct regassigned *regassigned[] = {\n"); - for (i=0;i<4;i++) - if (nregvar[i]>0) - fprintf(cfile,"\tratar%d,\n",i); + fprintf(cfile, "\t0,\n"); + fprintf(cfile, "};\n\nstruct regassigned *regassigned[] = {\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(cfile, "\tratar%d,\n", i); else - fprintf(cfile,"\t0,\n"); - fprintf(cfile,"};\n"); + fprintf(cfile, "\t0,\n"); + fprintf(cfile, "};\n"); } -verbose() { +static void verbose(void) +{ - fprintf(stderr,"Codebytes %d\n",codebytes); - fprintf(stderr,"Registers %d(%d)\n",nmachregs,MAXREGS); - fprintf(stderr,"Properties %d(%d)\n",nprops,MAXPROPS); - fprintf(stderr,"Tokens %d(%d)\n",nmachtokens,MAXTOKENS); - fprintf(stderr,"Sets %d(%d)\n",nmachsets,MAXSETS); - fprintf(stderr,"Tokeninstances %d(%d)\n",narinstance,MAXINSTANCE); - fprintf(stderr,"Strings %d(%d)\n",ncodestrings,MAXSTRINGS); - fprintf(stderr,"Enodes %d(%d)\n",lastnode-nodes,MAXNODES); - fprintf(stderr,"Patbytes %d(%d)\n",npatbytes,MAXPATTERN); + fprintf(stderr, "Codebytes %d\n", codebytes); + fprintf(stderr, "Registers %d(%d)\n", nmachregs, MAXREGS); + fprintf(stderr, "Properties %d(%d)\n", nprops, MAXPROPS); + fprintf(stderr, "Tokens %d(%d)\n", nmachtokens, MAXTOKENS); + fprintf(stderr, "Sets %d(%d)\n", nmachsets, MAXSETS); + fprintf(stderr, "Tokeninstances %d(%d)\n", narinstance, MAXINSTANCE); + fprintf(stderr, "Strings %d(%d)\n", ncodestrings, MAXSTRINGS); + fprintf(stderr, "Enodes %d(%d)\n", lastnode - nodes, MAXNODES); + fprintf(stderr, "Patbytes %d(%d)\n", npatbytes, MAXPATTERN); } -inbetween() { +void inbetween(void) +{ register ident_p ip; - register i,j; + register int i, j; register move_p mp; - lookident=1; /* for lexical analysis */ + lookident = 1; /* for lexical analysis */ - chktabsiz(nmachsets+1,MAXSETS,"Expressiontable"); - for (i=0;ii_type=IEXP; + ip = ilookup("SCRATCH", ENTER); + ip->i_type = IEXP; ip->i_i.i_expno = nmachsets++; - for (i=0;ii_type=IEXP; + ip = ilookup("ALL", ENTER); + ip->i_type = IEXP; allexpno = ip->i_i.i_expno = nmachsets++; mp = &machmoves[nmoves++]; mp->m_set1 = cocosetno; mp->m_expr1 = 0; - mp->m_set2 = nmachsets-1; + mp->m_set2 = nmachsets - 1; mp->m_expr2 = 0; mp->m_cindex = 0; mp->m_cost.c_size = 0; @@ -718,299 +825,337 @@ inbetween() { * Create sets of registers per property */ - for (i=0;irprop[i>>4]&(1<<(i&017))) - sp[j>>4] |= (1<<(j&017)); + for (j = 2; j <= nmachregs; j++) + if (machregs[j - 1]->rprop[i >> 4] & (1 << (i & 017))) + sp[j >> 4] |= (1 << (j & 017)); } } -formconversion(p,tp) register char *p; register token_p tp; { +int formconversion(register char *p, register token_p tp) +{ char buf[256]; - register char *q=buf; + register char *q = buf; char field[256]; register char *f; int i; - if (p==0) - return(0); - while (*p) switch(*p) { - default: *q++ = *p++; continue; - case '%': - p++; - if(*p == '%') { - *q++ = *p++; - continue; + if (p == 0) + return (0); + while (*p) + switch (*p) + { + default: + *q++ = *p++; + continue; + case '%': + p++; + if (*p == '%') + { + *q++ = *p++; + continue; + } + if (*p == '[') + p++; + else + yyerror("Bad character after % in format"); + f = field; + while (*p != 0 && *p != ']') + *f++ = *p++; + *f++ = 0; + if (*p == ']') + p++; + else + yyerror("Unterminated %[] construct in format"); + for (i = 0; i < TOKENSIZE - 1; i++) + if (strcmp(field, tp->t_fields[i].t_sname) == 0) + break; + if (i == TOKENSIZE - 1) + yyerror("Unknown field in %[] construct in format"); + *q++ = i + 1; } - if (*p == '[') - p++; - else - yyerror("Bad character after % in format"); - f=field; - while (*p != 0 && *p != ']') - *f++ = *p++; - *f++ = 0; - if (*p == ']') - p++; - else - yyerror("Unterminated %[] construct in format"); - for (i=0;it_fields[i].t_sname)==0) - break; - if (i==TOKENSIZE-1) - yyerror("Unknown field in %[] construct in format"); - *q++ = i+1; - } *q++ = 0; - return(strlookup(buf)); + return (strlookup(buf)); } -setfields(tp,format) register token_p tp; string format; { - register i; +void setfields(register token_p tp, string format) +{ + register int i; list2 ll; register list1 l; int type; - for(i=0;it_fields[i].t_type = 0; - i=0; - for(ll=tp->t_struct;ll!=0;ll=ll->l2next) { - l=ll->l2list; - if(strcmp(l->l1name,"REGISTER")==0) + i = 0; + for (ll = tp->t_struct; ll != 0; ll = ll->l2next) + { + l = ll->l2list; + if (strcmp(l->l1name, "REGISTER") == 0) type = TYPREG; - else if (strcmp(l->l1name,"INT")==0) + else if (strcmp(l->l1name, "INT") == 0) type = TYPINT; - else type = TYPSTR; - for(l=l->l1next;l!=0;l=l->l1next) { + else + type = TYPSTR; + for (l = l->l1next; l != 0; l = l->l1next) + { tp->t_fields[i].t_type = type; tp->t_fields[i].t_sname = l->l1name; i++; } } if (format != 0) - tp->t_format = formconversion(format,tp); + tp->t_format = formconversion(format, tp); else tp->t_format = -1; } -chkregexp(number) { - register i; +void chkregexp(int number) +{ + register int i; - for(i=nmachregs+1;i>4]&(01<<(i&017))) + for (i = nmachregs + 1; i < nmachregs + 1 + nmachtokens; i++) + if (machsets[number].set_val[i >> 4] & (01 << (i & 017))) yyerror("No tokens allowed in this set"); } -findstructel(number,name,t) string name; int *t; { - register i; +int findstructel(int number, string name, int *t) +{ + register int i; register token_p tp; register list2 structdecl; int offset; - for(i=1;i<=nmachregs;i++) - if (machsets[number].set_val[i>>4]&(01<<(i&017))) + for (i = 1; i <= nmachregs; i++) + if (machsets[number].set_val[i >> 4] & (01 << (i & 017))) yyerror("No registers allowed in this set"); structdecl = 0; - for (i=nmachregs+1;i>4]&(01<<(i&017))) { - if (structdecl == 0) { - structdecl = machtokens[i-(nmachregs+1)].t_struct; - tp = &machtokens[i-(nmachregs+1)]; - } else if(structdecl != machtokens[i-(nmachregs+1)].t_struct) - yyerror("Multiple structs in this set"); + for (i = nmachregs + 1; i < nmachregs + 1 + nmachtokens; i++) + { + if (machsets[number].set_val[i >> 4] & (01 << (i & 017))) + { + if (structdecl == 0) + { + structdecl = machtokens[i - (nmachregs + 1)].t_struct; + tp = &machtokens[i - (nmachregs + 1)]; + } + else if (structdecl != machtokens[i - (nmachregs + 1)].t_struct) + yyerror("Multiple structs in this set"); } } - if (structdecl == 0) { + if (structdecl == 0) + { yyerror("No structs in this set"); - return(0); + return (0); } - for(offset=0;offsett_fields[offset].t_type != 0 && - strcmp(tp->t_fields[offset].t_sname,name)==0) { + for (offset = 0; offset < TOKENSIZE - 1; offset++) + if (tp->t_fields[offset].t_type != 0 + && strcmp(tp->t_fields[offset].t_sname, name) == 0) + { *t = tp->t_fields[offset].t_type; - return(offset+1); + return (offset + 1); } yyerror("No such field in this struct"); - return(0); + return (0); } extern char em_flag[]; -argtyp(mn) { +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(TYPINT); - default: - return(TYPSTR); + 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 (TYPINT); + default: + return (TYPSTR); } } -commontype(e1,e2) expr_t e1,e2; { - - if(e1.expr_typ != e2.expr_typ) +int commontype(expr_t e1, expr_t e2) +{ + if (e1.expr_typ != e2.expr_typ) yyerror("Type incompatibility"); - return(e1.expr_typ); + return (e1.expr_typ); } extern char em_mnem[][4]; #define HASHSIZE (2*(sp_lmnem-sp_fmnem)) -struct hashmnem { +struct hashmnem +{ char h_name[3]; byte h_value; } hashmnem[HASHSIZE]; -inithash() { - register i; +void inithash(void) +{ + register int i; - for(i=0;i<=sp_lmnem-sp_fmnem;i++) - enter(em_mnem[i],i+sp_fmnem); + for (i = 0; i <= sp_lmnem - sp_fmnem; i++) + enter(em_mnem[i], i + sp_fmnem); } -enter(name,value) char *name; { +void enter(char *name, int value) +{ register unsigned h; - h=hash(name)%HASHSIZE; + h = hash(name) % HASHSIZE; while (hashmnem[h].h_name[0] != 0) - h = (h+1)%HASHSIZE; - strncpy(hashmnem[h].h_name,name,3); + h = (h + 1) % HASHSIZE; + strncpy(hashmnem[h].h_name, name, 3); hashmnem[h].h_value = value; } -int mlookup(name) char *name; { - register unsigned h; +int mlookup(char *name) +{ + register unsigned int h; - h = hash(name)%HASHSIZE; - while (strncmp(hashmnem[h].h_name,name,3) != 0 && - hashmnem[h].h_name[0] != 0) - h = (h+1)%HASHSIZE; - return(hashmnem[h].h_value&BMASK); /* 0 if not found */ + h = hash(name) % HASHSIZE; + while (strncmp(hashmnem[h].h_name, name, 3) != 0 + && hashmnem[h].h_name[0] != 0) + h = (h + 1) % HASHSIZE; + return (hashmnem[h].h_value & BMASK); /* 0 if not found */ } -hashpatterns() { +void hashpatterns(void) +{ short index; - register byte *bp,*tp; + register byte *bp, *tp; register short i; unsigned short hashvalue; int patlen; index = prevind; - while (index != 0) { + while (index != 0) + { bp = &pattern[index]; tp = &bp[PO_MATCH]; - i = *tp++&BMASK; - if (i==BMASK) { - i = *tp++&BMASK; - i |= (*tp++&BMASK)<>BSHIFT; + i = index; + index = (bp[PO_NEXT] & BMASK) | (bp[PO_NEXT + 1] << BSHIFT); + bp[PO_HASH] = hashvalue >> BSHIFT; hashvalue &= BMASK; - bp[PO_NEXT] = pathash[hashvalue]&BMASK; - bp[PO_NEXT+1] = pathash[hashvalue]>>BSHIFT; + bp[PO_NEXT] = pathash[hashvalue] & BMASK; + bp[PO_NEXT + 1] = pathash[hashvalue] >> BSHIFT; pathash[hashvalue] = i; } } -debug() { - register i,j; +static void debug(void) +{ + register int i, j; - for(i=0;ii_next) - printf("%-14s %1d %3d\n",ip->i_name, - ip->i_type,ip->i_i.i_regno); + for (ip = identtab[i]; ip != 0; ip = ip->i_next) + printf("%-14s %1d %3d\n", ip->i_name, ip->i_type, ip->i_i.i_regno); } - for(i=2;irname,rp->rrepr,rp->rsize); - for(j=0;jrmembers[j] != 0) - printf(", %s",machregs[rp->rmembers[j]]->rname); + rp = machregs[i]; + printf("%s = (\"%s\", %d", rp->rname, rp->rrepr, rp->rsize); + for (j = 0; j < MAXMEMBERS; j++) + if (rp->rmembers[j] != 0) + printf(", %s", machregs[rp->rmembers[j]]->rname); printf(")"); - for(j=0;jrprop[j>>4]&(1<<(j&017))) - printf(", %s",machprops[j].propname->i_name); + for (j = 0; j < nprops; j++) + if (rp->rprop[j >> 4] & (1 << (j & 017))) + printf(", %s", machprops[j].propname->i_name); printf(".\n"); } } -out(n) { +void out(int n) +{ - assert(n>=0); - if (n<128) + assert(n >= 0); + if (n < 128) outbyte(n); - else { - outbyte(n/256+128); - outbyte(n%256); + else + { + outbyte(n / 256 + 128); + outbyte(n % 256); } } -outbyte(n) { +void outbyte(int n) +{ - fprintf(cfile,"%d, ",n&BMASK); + fprintf(cfile, "%d, ", n & BMASK); codebytes++; } -pat(n) { +void pat(int n) +{ - assert(n>=0); - if (n<128) + assert(n >= 0); + if (n < 128) patbyte(n); - else { - patbyte(n/256+128); - patbyte(n%256); + else + { + patbyte(n / 256 + 128); + patbyte(n % 256); } } -patshort(n) { +void patshort(int n) +{ - patbyte(n&BMASK); - patbyte(n>>BSHIFT); + patbyte(n & BMASK); + patbyte(n >> BSHIFT); } -patbyte(n) { - - chktabsiz(npatbytes,MAXPATTERN,"Pattern table"); +void patbyte(int n) +{ + chktabsiz(npatbytes, MAXPATTERN, "Pattern table"); pattern[npatbytes++] = n; } -max(a,b) { - - if (a>b) - return(a); - return(b); +int max(int a, int b) +{ + if (a > b) + return (a); + return (b); } -int yywrap(void) { +int yywrap(void) +{ return 1; }