CFILES=cgg.c subr.c main.c coerc.c enterkeyw.c error.c emlookup.c expr.c instruct.c iocc.c lookup.c output.c set.c strlookup.c var.c hall.c
OFILES=cgg.o subr.o main.o coerc.o enterkeyw.o error.o emlookup.o expr.o instruct.o iocc.o lookup.o set.o strlookup.o var.o hall.o
SOURCES=*.h cgg.y scan.l cvtkeywords keywords coerc.c emlookup.c error.c expr.c hall.c instruct.c iocc.c lookup.c main.c output.c set.c strlookup.c subr.c var.c
-EMH=../../h
-CFLAGS=-I$(EMH)
+EMHOME=../..
+EMH=$(EMHOME)/h
+CFLAGS=-O -I$(EMH)
YFLAGS=-v -d
LDFLAGS=-i
cgg: cgg.o $(OFILES) output.o
- cc $(LDFLAGS) $(OFILES) output.o ../../lib/em_data.a -ll -o cgg
+ cc $(LDFLAGS) $(OFILES) output.o $(EMHOME)/lib/em_data.a -ll -o cgg
install: cgg
- cp cgg ../../lib/ncgg
+ rm -f $(EMHOME)/lib/ncgg
+ cp cgg $(EMHOME)/lib/ncgg
cmp: cgg
- cmp cgg ../../lib/ncgg
+ cmp cgg $(EMHOME)/lib/ncgg
debugcgg: cgg.o $(OFILES) debugoutput.o
- cc $(LDFLAGS) $(OFILES) debugoutput.o ../../lib/em_data.a -ll -o cgg
+ cc $(LDFLAGS) $(OFILES) debugoutput.o $(EMHOME)/lib/em_data.a -ll -o cgg
cgg.o: scan.c
pr:
pr $(SOURCES)
-lpr:
- make pr|lpr
+opr:
+ -make pr|opr
depend:
makedepend
int instline,saveline;
int startline;
int npatterns;
+int att_type;
int patindex[MAXPATTERNS];
int emhere=0; /* lexical analyzer flag */
int maxempatlen=0;
int maxrule=0;
struct varinfo *defcost;
+int Xstackflag=0; /* set in coercions, moves, and tests. %1 means something
+ different then.
+ */
struct varinfo *gen_inst(),*gen_move(),*gen_test(),*gen_preturn(),*gen_tlab();
struct varinfo *make_erase();
set_t ident_to_set(),setproduct(),setsum(),setdiff();
-iocc_t subr_iocc(),tokm_iocc(),ident_iocc(),all_iocc(),descr_iocc();
+iocc_t subr_iocc(),tokm_iocc(),ident_iocc(),all_iocc(),percident_iocc(), descr_iocc();
extern int narexpr;
extern expr_t arexp[];
%token TIMEFACTOR SIZEFACTOR
%token COST
%type <yy_varinfo> prop_list property ident_list ident_list_el
-%type <yy_varinfo> att_list att_list_el structdecl optcost optformat
+%type <yy_varinfo> att_list att_list_el att_list_el_list structdecl optcost optformat
%type <yy_varinfo> kills allocates yields leaving
%type <yy_varinfo> generates kill_list kill_list_el uselist uselist_el genlist yieldlist
%type <yy_varinfo> leavelist leavelist_el gen_instruction
{ $1->vi_next = $2; $$ = $1; }
;
att_list_el
- : att_list_el_type IDENT ';'
- { NEW ($$,struct varinfo);
- $$->vi_next = 0;
- $$->vi_int[0] = $1;
+ : att_list_el_type IDENT
+ { NEW ($<yy_varinfo>$,struct varinfo);
+ $<yy_varinfo>$->vi_int[0] = $1;
+ $<yy_varinfo>$->vi_str[0] = $2;
+ att_type = $1;
+ }
+ att_list_el_list ';'
+ { $<yy_varinfo>3->vi_next = $4;
+ $$ = $<yy_varinfo>3;
+ }
+ ;
+att_list_el_list
+ : /* empty */
+ { $$ = 0; }
+ | ',' IDENT att_list_el_list
+ { NEW($$, struct varinfo);
+ $$->vi_next = $3;
+ $$->vi_int[0] = att_type;
$$->vi_str[0] = $2;
}
;
/* Now the moves */
moves
- : MOVES movedeflist
+ : MOVES
+ movedeflist
| /* empty */
;
movedeflist
: FROM
{startline = lineno; }
tokenset_no
- { cursetno = $3; }
- optexpr TO tokenset_no
- { cursetno = $7;
+ { Xstackflag = 1;
+ cursetno = $3;
+ }
+ optexpr
+ { Xstackflag = 0;
+ cursetno = -1;
+ }
+ TO tokenset_no
+ { cursetno = $8;
tokpatlen=2;
tokpatset[0] = $3;
- tokpatset[1] = $7;
+ tokpatset[1] = $8;
tokpatro[0] = 1;
+ Xstackflag = 1;
}
- optexpr GEN genlist
+ optexpr
+ { Xstackflag = 0;
+ cursetno = -1;
+ }
+ GEN genlist
{ tokpatlen=0;
tokpatro[0]=0;
- n_move($3,$5,$7,$9,$11);
- freevi($11);
+ n_move($3,$5,$8,$10,$13);
+ freevi($13);
}
| error
;
/* Now the test part */
tests
- : TESTS testdeflist
+ : TESTS
+ { Xstackflag = 1; }
+ testdeflist
+ { Xstackflag = 0; }
| /* empty */
;
testdeflist
tokpatro[0] = 0;
n_test($4,$6,$8);
freevi($8);
+ cursetno = -1;
}
| error
;
/* Now the stacks */
stacks
- : STACKINGRULES stackdeflist
+ : STACKINGRULES
+ { Xstackflag = 1; }
+ stackdeflist
+ { Xstackflag = 0; }
;
stackdeflist
: stackdeflist_el
{ tokpatro[0] = 0;
n_stack($3,$5,$8,$10);
freevi($10);
+ cursetno = -1;
}
;
optuses
/* Now the one-to-one coercion rules */
coercs
- : COERCIONS coercdeflist
+ : COERCIONS
+ { Xstackflag = 1; }
+ coercdeflist
+ { Xstackflag = 0; }
;
coercdeflist
: coercdeflist_el
n_coerc($3,$5,$6,$7,$8);
freevi($6);
freevi($7);
+ cursetno = -1;
}
;
$$->vi_next = 0;
$$->vi_int[0]=$1;
$$->vi_int[1]=$3;
+ cursetno = -1;
}
;
allocates
{ $$ = ident_iocc($1); free($1);}
| allreg subreg
{ $$ = all_iocc($1,$2); }
+ | PERC_IDENT
+ { if (cursetno < 0) {
+ error("%%<ident> not allowed here");
+ }
+ $$ = percident_iocc($1);
+ free($1);
+ }
| '{' IDENT attlist '}'
{ $$ = descr_iocc($2); free($2); }
;
;
tokarg
: PERCENT
- { if ($1<1 || $1>tokpatlen) {
+ { $$ = $1;
+ if ($1<1 || $1>tokpatlen) {
error("Only %d tokens in stackpattern",tokpatlen);
$$ =1;
- } else {
- $$ = $1;
}
+ if (Xstackflag) $$ = 0;
}
;
subreg
| allreg subreg
{ $$ = all_expr($1,$2); }
| PERC_IDENT
- { $$ = perc_ident_expr($1); free($1); }
+ { if (cursetno < 0) {
+ error("%%<ident> not allowed here");
+ }
+ $$ = perc_ident_expr($1);
+ free($1);
+ }
| DEFINED '(' expr ')'
{ $$ = make_expr(TYPBOOL,EX_DEFINED,i_expr($3),0); }
| SAMESIGN '(' expr ',' expr ')'
{ $$ = make_expr(TYPINT,EX_LOWW,$3-1,0); }
| HIGHW '(' emarg ')'
{ $$ = make_expr(TYPINT,EX_HIGHW,$3-1,0); }
+/* Excluded, because it causes a shift-reduce conflict
+ (problems with a tokenset_no followed by an optexpr)
+ | '-' expr %prec UMINUS
+ { $$ = make_expr(TYPINT,EX_CON, 0, 0);
+ $$ = make_expr(TYPINT,EX_MINUS,i_expr($$),i_expr($2));
+ }
+*/
| '(' expr ')'
{ $$ = $2; }
| expr CMPEQ expr
expr_t result;
result.ex_typ = TYPREG;
- subregset(l_sets[tokpatset[tokarg-1]].set_val,subreg,result.ex_regset);
+ subregset(l_sets[tokpatset[tokarg > 0 ? tokarg-1 : tokarg]].set_val,
+ subreg,result.ex_regset);
result.ex_index = ex_lookup(EX_SUBREG,tokarg,subreg);
return(result);
}
int typesdiffer=0;
int res_j= -1;
+ if (setno < 0) return 0;
sp = l_sets[setno].set_val;
for (i=1;i<nregs;i++) if (BIT(sp,i)) {
error("Set in %s contains %s, which is not a token",
expr_t tokm_expr(tokarg,name) char *name; {
char app[100];
+ int tokarg1 = tokarg > 0 ? tokarg : 1;
- sprintf(app,"%%%d.%s",tokarg,name);
- return(memb_expr(tokpatset[tokarg-1],name,app,tokarg));
+ sprintf(app,"%%%d.%s",tokarg1,name);
+ return(memb_expr(tokpatset[tokarg1-1],name,app,tokarg));
}
expr_t perc_ident_expr(name) char *name; {
register bitno;
register short *sp;
+ if (! argno) argno++;
sp = l_sets[tokpatset[argno-1]].set_val;
for(bitno=nregs;bitno<nregs+ntokens;bitno++)
if (BIT(sp,bitno))
makescratch(argno) {
set_t s;
+ if (! argno) argno++;
if (tokpatro[argno-1])
error("Instruction destroys %%%d, not allowed here",argno);
s = l_sets[tokpatset[argno-1]];
insta.in_info[0] = tokarg;
insta.in_info[1] = subreg;
result.in_index = instalookup(insta,2);
+ if (tokarg < 1) tokarg = 1;
if (subreg==0)
for (i=0;i<SETSIZE;i++)
result.in_set[i] = l_sets[tokpatset[tokarg-1]].set_val[i];
char app[100];
int dummy;
- sprintf(app,"%%%d.%s",tokarg,ident);
for(i=0;i<SETSIZE;i++)
result.in_set[i] = 0;
insta.in_which = IN_MEMB;
insta.in_info[0] = tokarg;
+ if (tokarg < 1) tokarg = 1;
+ sprintf(app,"%%%d.%s",tokarg,ident);
insta.in_info[1] = 1+membset(tokpatset[tokarg-1],ident,result.in_set,
app,TYPREG,&dummy);
result.in_index = instalookup(insta,2);
return(result);
}
+
+iocc_t percident_iocc(ident) char *ident; {
+ iocc_t result;
+ inst_t insta;
+ register i;
+ char app[100];
+ int dummy;
+ for(i=0;i<SETSIZE;i++)
+ result.in_set[i] = 0;
+ insta.in_which = IN_MEMB;
+ insta.in_info[0] = 0;
+ sprintf(app,"%%%s",ident);
+ insta.in_info[1] = 1+membset(cursetno,ident,result.in_set,
+ app,TYPREG,&dummy);
+ result.in_index = instalookup(insta,2);
+ return(result);
+}
+
iocc_t ident_iocc(ident) char *ident; {
iocc_t result;
inst_t insta;
}
#endif
int prevind=0;
-int npatbytes=0;
+int npatbytes= -1;
char pattern[MAXPATBYTES];
int pathash[256];
if (!inproc) {
patbyte(0);
patshort(prevind);
- prevind = npatbytes-3;
+ prevind = npatbytes-2;
patbyte(empatlen);
for(i=0;i<empatlen;i++)
patbyte(emmnem[i]);
patbyte(n) {
- pattern[npatbytes++]=n;
+ NEXT(npatbytes, MAXPATBYTES, "Pattern bytes");
+ pattern[npatbytes]=n;
}
hashpatterns() {
fprintf(ctable,"char coderules[%d];\n",codeindex);
fprintf(ctable,"int ncodebytes=%d;\n",codeindex);
}
- fprintf(ctable,"char pattern[%d]={\n",npatbytes);
- for(i=0;i<npatbytes;i++) {
+ fprintf(ctable,"char pattern[%d]={\n",npatbytes+1);
+ for(i=0;i<=npatbytes;i++) {
fprintf(ctable,"%d,%c",pattern[i]&BMASK,i%16==15 ? '\n' : ' ');
}
fprintf(ctable,"};\n\n");
used("1->1 Coercions",ncoercs,MAXCOERCS);
used("Splitting coercions",nsplit,MAXSPLCOERC);
used("Register variables",maxregvars,MAXREGVAR);
- used("Pat bytes",npatbytes,MAXPATBYTES);
+ used("Pat bytes",npatbytes+1,MAXPATBYTES);
if (tabledebug)
used("Source lines",maxline,MAXSOURCELINES);
fprintf(stderr,"%ldK heap used\n",((long) (sbrk(0)-end+1023))/1024);
result.set_size = 0;
for(i=0;i<SETSIZE;i++)
result.set_val[i] = s1.set_val[i] & ~ s2.set_val[i];
+ /* make sure that we don't loose the lowest bit of the set, which
+ indicates that it contains registers
+ */
+ for (i=1;i <= nregs; i++) {
+ if (BIT(result.set_val, i)) {
+ BIS(result.set_val,0);
+ break;
+ }
+ }
return(result);
}
extern int npatbytes;
sy_p = lookup(name,symproc,newsymbol);
- sy_p->sy_value.syv_procoff = npatbytes;
+ sy_p->sy_value.syv_procoff = npatbytes + 1;
}
struct varinfo *
int empatexpr;
int tokpatlen,tokpatset[TOKPATMAX],tokpatro[TOKPATMAX];
int nallreg,allreg[MAXALLREG];
-int cursetno;
+int cursetno = -1;
int allsetno;
int inproc=0; /* scanning "procedure" */
int callproc=0;