ANSI C conversion.

This commit is contained in:
carl 2019-05-11 01:13:43 +08:00
parent f9916fb680
commit dfefbcae86
4 changed files with 922 additions and 743 deletions

View file

@ -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 <stdio.h>
#include <string.h>
#include <assert.h>
#include <em_spec.h>
#include <em_flag.h>
#include <em_reg.h>
#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;i<SETSIZE;i++) $$.set_val[i]=0;
$$.set_val[($1->i_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<TOKENSIZE;i++)
$$.in_info[i] = 0;
}
| REGVAR '(' expr ')'
{ register i;
{ register int i;
MUST1BEINT($3);
$$.in_which = IN_REGVAR;
$$.in_info[0] = exp1;
@ -1090,7 +1090,7 @@ tokeninstance
$$.in_info[i] = 0;
}
| '%' '[' LCASELETTER subreg ']'
{ register i;
{ register int i;
if ($3 >= '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<narexp;i++) {

View file

@ -1,6 +1,6 @@
#include <local.h>
#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 <cg_pattern.h>
@ -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);

View file

@ -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 <stdio.h>
#include <assert.h>
#include <em_spec.h>
#include <em_flag.h>
#include <em_reg.h>
#include <stdarg.h>
#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++;
va_end(ap);
}

File diff suppressed because it is too large Load diff