Some bug fixes and minor extensions

This commit is contained in:
ceriel 1987-01-16 13:51:42 +00:00
parent 382c88eb17
commit 45238eea0f
9 changed files with 140 additions and 41 deletions

View file

@ -3,23 +3,25 @@
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
@ -43,8 +45,8 @@ clean:
pr:
pr $(SOURCES)
lpr:
make pr|lpr
opr:
-make pr|opr
depend:
makedepend

View file

@ -18,6 +18,7 @@ extern int lineno;
int instline,saveline;
int startline;
int npatterns;
int att_type;
int patindex[MAXPATTERNS];
int emhere=0; /* lexical analyzer flag */
@ -27,6 +28,9 @@ int saferulefound=0;
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();
@ -35,7 +39,7 @@ expr_t perc_ident_expr(),sum_expr(),regvar_expr();
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[];
@ -81,7 +85,7 @@ iocc_t iops[20];
%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
@ -300,10 +304,24 @@ att_list
{ $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;
}
;
@ -446,7 +464,8 @@ erase_list_el
/* Now the moves */
moves
: MOVES movedeflist
: MOVES
movedeflist
| /* empty */
;
movedeflist
@ -457,19 +476,30 @@ movedeflist_el
: 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
;
@ -477,7 +507,10 @@ movedeflist_el
/* Now the test part */
tests
: TESTS testdeflist
: TESTS
{ Xstackflag = 1; }
testdeflist
{ Xstackflag = 0; }
| /* empty */
;
testdeflist
@ -498,6 +531,7 @@ testdeflist_el
tokpatro[0] = 0;
n_test($4,$6,$8);
freevi($8);
cursetno = -1;
}
| error
;
@ -505,7 +539,10 @@ testdeflist_el
/* Now the stacks */
stacks
: STACKINGRULES stackdeflist
: STACKINGRULES
{ Xstackflag = 1; }
stackdeflist
{ Xstackflag = 0; }
;
stackdeflist
: stackdeflist_el
@ -524,6 +561,7 @@ stackdeflist_el
{ tokpatro[0] = 0;
n_stack($3,$5,$8,$10);
freevi($10);
cursetno = -1;
}
;
optuses
@ -536,7 +574,10 @@ optuses
/* Now the one-to-one coercion rules */
coercs
: COERCIONS coercdeflist
: COERCIONS
{ Xstackflag = 1; }
coercdeflist
{ Xstackflag = 0; }
;
coercdeflist
: coercdeflist_el
@ -566,6 +607,7 @@ coercdeflist_el
n_coerc($3,$5,$6,$7,$8);
freevi($6);
freevi($7);
cursetno = -1;
}
;
@ -722,6 +764,7 @@ kill_list_el
$$->vi_next = 0;
$$->vi_int[0]=$1;
$$->vi_int[1]=$3;
cursetno = -1;
}
;
allocates
@ -864,6 +907,13 @@ tokeninstance
{ $$ = 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); }
;
@ -883,12 +933,12 @@ emarg
;
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
@ -928,7 +978,12 @@ expr
| 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 ')'
@ -943,6 +998,13 @@ 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

View file

@ -68,7 +68,8 @@ expr_t subreg_expr(tokarg,subreg) {
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);
}
@ -106,6 +107,7 @@ int *typp;
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",
@ -167,9 +169,10 @@ expr_t memb_expr(setno,name,appearance,tokarg) char *name,*appearance; {
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; {

View file

@ -55,6 +55,7 @@ onlyreg(argno) {
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))
@ -65,6 +66,7 @@ onlyreg(argno) {
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]];

View file

@ -30,6 +30,7 @@ iocc_t subr_iocc(tokarg,subreg) {
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];
@ -48,17 +49,36 @@ iocc_t tokm_iocc(tokarg,ident) char *ident; {
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;

View file

@ -155,7 +155,7 @@ codenl() {
}
#endif
int prevind=0;
int npatbytes=0;
int npatbytes= -1;
char pattern[MAXPATBYTES];
int pathash[256];
@ -170,7 +170,7 @@ outpatterns() {
if (!inproc) {
patbyte(0);
patshort(prevind);
prevind = npatbytes-3;
prevind = npatbytes-2;
patbyte(empatlen);
for(i=0;i<empatlen;i++)
patbyte(emmnem[i]);
@ -207,7 +207,8 @@ patshort(n) {
patbyte(n) {
pattern[npatbytes++]=n;
NEXT(npatbytes, MAXPATBYTES, "Pattern bytes");
pattern[npatbytes]=n;
}
hashpatterns() {
@ -572,8 +573,8 @@ outars() {
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");
@ -851,7 +852,7 @@ statistics() {
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);

View file

@ -114,5 +114,14 @@ set_t setdiff(s1,s2) set_t s1,s2; {
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);
}

View file

@ -20,7 +20,7 @@ n_proc(name) char *name; {
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 *

View file

@ -23,7 +23,7 @@ int empatlen,emmnem[EMPATMAX];
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;