%{ #ifndef NORCSID static char rcsid[] = "$Id$"; #endif #include #include #include #include "param.h" #include "types.h" #include "pattern.h" #include #include #include "optim.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 op_CBO (op_plast+1) #define MAXNODES 1000 expr_t nodes[MAXNODES]; expr_p lastnode = nodes+1; int curind,prevind; int patlen,maxpatlen,rpllen; int lino = 1; int patno=1; #define MAX 100 int patmnem[MAX],rplmnem[MAX],rplexpr[MAX]; byte nparam[N_EX_OPS]; bool nonumlab[N_EX_OPS]; bool onlyconst[N_EX_OPS]; int nerrors=0; char patid[128]; int CBO_instrs[] = { op_adi, op_adu, op_and, op_ior, op_xor /* don't add op_mli and op_mlu! */ }; int patCBO; int rplCBO; %} %union { int y_int; } %left OR2 %left AND2 %left OR1 %left XOR1 %left AND1 %left CMPEQ CMPNE %left CMPLT CMPLE CMPGT CMPGE %left RSHIFT LSHIFT %left ARPLUS ARMINUS %left ARTIMES ARDIVIDE ARMOD %nonassoc NOT COMP UMINUS %nonassoc '$' %token SFIT UFIT NOTREG PSIZE WSIZE DEFINED SAMESIGN ROM ROTATE STRING %token MNEM %token NUMBER %type expr argno optexpr %start patternlist %% patternlist : /* empty */ | STRING '\n' | patternlist '\n' | patternlist pattern ; pattern : mnemlist optexpr ':' replacement '\n' { if (patCBO) { register int i; if (! rplCBO) { yyerror("No CBO in replacement"); } for (i=0; ipatlen) { YYERROR; } $$ = (int) $1; } ; %% extern char em_mnem[][4]; #define HASHSIZE (2*(sp_lmnem-sp_fmnem)) struct hashmnem { char h_name[3]; byte h_value; } hashmnem[HASHSIZE]; inithash() { register i; enter("lab",op_lab); enter("LLP",op_LLP); enter("LEP",op_LEP); enter("SLP",op_SLP); enter("SEP",op_SEP); enter("CBO",op_CBO); for(i=0;i<=sp_lmnem-sp_fmnem;i++) enter(em_mnem[i],i+sp_fmnem); } unsigned hashname(name) register char *name; { register unsigned h; h = (*name++)&BMASK; h = (h<<4)^((*name++)&BMASK); h = (h<<4)^((*name++)&BMASK); return(h); } enter(name,value) char *name; { register unsigned h; h=hashname(name)%HASHSIZE; while (hashmnem[h].h_name[0] != 0) h = (h+1)%HASHSIZE; strncpy(hashmnem[h].h_name,name,3); hashmnem[h].h_value = value; } int mlookup(name) char *name; { register unsigned h; h = hashname(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 */ } main() { inithash(); initio(); yyparse(); if (nerrors==0) printnodes(); return nerrors; } yyerror(s) char *s; { fprintf(stderr,"line %d: %s\n",lino,s); nerrors++; } lookup(comm,operator,lnode,rnode) { register expr_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)) continue; return(p-nodes); } if (lastnode >= &nodes[MAXNODES]) yyerror("node table overflow"); lastnode++; p->ex_operator = operator; p->ex_lnode = lnode; p->ex_rnode = rnode; return(p-nodes); } printnodes() { register expr_p p; printf("};\n\nshort lastind = %d;\n\nexpr_t enodes[] = {\n",prevind); for (p=nodes;pex_operator,p->ex_lnode,p->ex_rnode); printf("};\n\niarg_t iargs[%d];\n", (maxpatlen>0 ? maxpatlen : 1)); if (patid[0]) printf("static char rcsid[] = %s;\n",patid); } initio() { register i; printf("#include \"param.h\"\n#include \"types.h\"\n"); printf("#include \"pattern.h\"\n\n"); for(i=0;imaxpatlen) maxpatlen=patlen; } outbyte(b) { printf(",%3d",b); curind++; } outshort(s) { outbyte(s&0377); outbyte((s>>8)&0377); } out(w) { if (w<255) { outbyte(w); } else { outbyte(255); outshort(w); } } #include "scan.c"