%{
|
%{
|
#include "c.h"
|
#include "c.h"
|
typedef Node NODEPTR_TYPE;
|
typedef Node NODEPTR_TYPE;
|
#define OP_LABEL(p) (specific((p)->op))
|
#define OP_LABEL(p) (specific((p)->op))
|
#define LEFT_CHILD(p) ((p)->kids[0])
|
#define LEFT_CHILD(p) ((p)->kids[0])
|
#define RIGHT_CHILD(p) ((p)->kids[1])
|
#define RIGHT_CHILD(p) ((p)->kids[1])
|
#define STATE_LABEL(p) ((p)->x.state)
|
#define STATE_LABEL(p) ((p)->x.state)
|
#define PANIC error
|
#define PANIC error
|
%}
|
%}
|
%term CNSTF=17 CNSTI=21 CNSTP=23 CNSTU=22
|
%term CNSTF=17 CNSTI=21 CNSTP=23 CNSTU=22
|
%term ARGB=41 ARGF=33 ARGI=37 ARGP=39 ARGU=38
|
%term ARGB=41 ARGF=33 ARGI=37 ARGP=39 ARGU=38
|
%term ASGNB=57 ASGNF=49 ASGNI=53 ASGNP=55 ASGNU=54
|
%term ASGNB=57 ASGNF=49 ASGNI=53 ASGNP=55 ASGNU=54
|
%term INDIRB=73 INDIRF=65 INDIRI=69 INDIRP=71 INDIRU=70
|
%term INDIRB=73 INDIRF=65 INDIRI=69 INDIRP=71 INDIRU=70
|
%term CVFF=113 CVFI=117
|
%term CVFF=113 CVFI=117
|
%term CVIF=129 CVII=133 CVIU=134
|
%term CVIF=129 CVII=133 CVIU=134
|
%term CVPP=151 CVPU=150
|
%term CVPP=151 CVPU=150
|
%term CVUI=181 CVUP=183 CVUU=182
|
%term CVUI=181 CVUP=183 CVUU=182
|
%term NEGF=193 NEGI=197
|
%term NEGF=193 NEGI=197
|
%term CALLB=217 CALLF=209 CALLI=213 CALLP=215 CALLU=214 CALLV=216
|
%term CALLB=217 CALLF=209 CALLI=213 CALLP=215 CALLU=214 CALLV=216
|
%term RETF=241 RETI=245 RETP=247 RETU=246 RETV=248
|
%term RETF=241 RETI=245 RETP=247 RETU=246 RETV=248
|
%term ADDRGP=263
|
%term ADDRGP=263
|
%term ADDRFP=279
|
%term ADDRFP=279
|
%term ADDRLP=295
|
%term ADDRLP=295
|
%term ADDF=305 ADDI=309 ADDP=311 ADDU=310
|
%term ADDF=305 ADDI=309 ADDP=311 ADDU=310
|
%term SUBF=321 SUBI=325 SUBP=327 SUBU=326
|
%term SUBF=321 SUBI=325 SUBP=327 SUBU=326
|
%term LSHI=341 LSHU=342
|
%term LSHI=341 LSHU=342
|
%term MODI=357 MODU=358
|
%term MODI=357 MODU=358
|
%term RSHI=373 RSHU=374
|
%term RSHI=373 RSHU=374
|
%term BANDI=389 BANDU=390
|
%term BANDI=389 BANDU=390
|
%term BCOMI=405 BCOMU=406
|
%term BCOMI=405 BCOMU=406
|
%term BORI=421 BORU=422
|
%term BORI=421 BORU=422
|
%term BXORI=437 BXORU=438
|
%term BXORI=437 BXORU=438
|
%term DIVF=449 DIVI=453 DIVU=454
|
%term DIVF=449 DIVI=453 DIVU=454
|
%term MULF=465 MULI=469 MULU=470
|
%term MULF=465 MULI=469 MULU=470
|
%term EQF=481 EQI=485 EQU=486
|
%term EQF=481 EQI=485 EQU=486
|
%term GEF=497 GEI=501 GEU=502
|
%term GEF=497 GEI=501 GEU=502
|
%term GTF=513 GTI=517 GTU=518
|
%term GTF=513 GTI=517 GTU=518
|
%term LEF=529 LEI=533 LEU=534
|
%term LEF=529 LEI=533 LEU=534
|
%term LTF=545 LTI=549 LTU=550
|
%term LTF=545 LTI=549 LTU=550
|
%term NEF=561 NEI=565 NEU=566
|
%term NEF=561 NEI=565 NEU=566
|
%term JUMPV=584
|
%term JUMPV=584
|
%term LABELV=600
|
%term LABELV=600
|
%%
|
%%
|
stmt: INDIRB(P) ""
|
stmt: INDIRB(P) ""
|
stmt: INDIRF(P) ""
|
stmt: INDIRF(P) ""
|
stmt: INDIRI(P) ""
|
stmt: INDIRI(P) ""
|
stmt: INDIRU(P) ""
|
stmt: INDIRU(P) ""
|
stmt: INDIRP(P) ""
|
stmt: INDIRP(P) ""
|
stmt: CALLF(P) ""
|
stmt: CALLF(P) ""
|
stmt: CALLI(P) ""
|
stmt: CALLI(P) ""
|
stmt: CALLU(P) ""
|
stmt: CALLU(P) ""
|
stmt: CALLP(P) ""
|
stmt: CALLP(P) ""
|
stmt: V ""
|
stmt: V ""
|
bogus: I "" 1
|
bogus: I "" 1
|
bogus: U "" 1
|
bogus: U "" 1
|
bogus: P "" 1
|
bogus: P "" 1
|
bogus: F "" 1
|
bogus: F "" 1
|
bogus: B "" 1
|
bogus: B "" 1
|
bogus: V "" 1
|
bogus: V "" 1
|
I: bogus "" 1
|
I: bogus "" 1
|
U: bogus "" 1
|
U: bogus "" 1
|
P: bogus "" 1
|
P: bogus "" 1
|
F: bogus "" 1
|
F: bogus "" 1
|
B: bogus "" 1
|
B: bogus "" 1
|
V: bogus "" 1
|
V: bogus "" 1
|
F: CNSTF ""
|
F: CNSTF ""
|
I: CNSTI ""
|
I: CNSTI ""
|
P: CNSTP ""
|
P: CNSTP ""
|
U: CNSTU ""
|
U: CNSTU ""
|
V: ARGB(B) ""
|
V: ARGB(B) ""
|
V: ARGF(F) ""
|
V: ARGF(F) ""
|
V: ARGI(I) ""
|
V: ARGI(I) ""
|
V: ARGU(U) ""
|
V: ARGU(U) ""
|
V: ARGP(P) ""
|
V: ARGP(P) ""
|
V: ASGNB(P,B) ""
|
V: ASGNB(P,B) ""
|
V: ASGNF(P,F) ""
|
V: ASGNF(P,F) ""
|
V: ASGNI(P,I) ""
|
V: ASGNI(P,I) ""
|
V: ASGNU(P,U) ""
|
V: ASGNU(P,U) ""
|
V: ASGNP(P,P) ""
|
V: ASGNP(P,P) ""
|
B: INDIRB(P) ""
|
B: INDIRB(P) ""
|
F: INDIRF(P) ""
|
F: INDIRF(P) ""
|
I: INDIRI(P) ""
|
I: INDIRI(P) ""
|
U: INDIRU(P) ""
|
U: INDIRU(P) ""
|
P: INDIRP(P) ""
|
P: INDIRP(P) ""
|
I: CVII(I) ""
|
I: CVII(I) ""
|
I: CVUI(U) ""
|
I: CVUI(U) ""
|
I: CVFI(F) ""
|
I: CVFI(F) ""
|
U: CVIU(I) ""
|
U: CVIU(I) ""
|
U: CVUU(U) ""
|
U: CVUU(U) ""
|
U: CVPU(P) ""
|
U: CVPU(P) ""
|
F: CVIF(I) ""
|
F: CVIF(I) ""
|
F: CVFF(F) ""
|
F: CVFF(F) ""
|
P: CVUP(U) ""
|
P: CVUP(U) ""
|
P: CVPP(P) ""
|
P: CVPP(P) ""
|
F: NEGF(F) ""
|
F: NEGF(F) ""
|
I: NEGI(I) ""
|
I: NEGI(I) ""
|
V: CALLB(P,P) ""
|
V: CALLB(P,P) ""
|
F: CALLF(P) ""
|
F: CALLF(P) ""
|
I: CALLI(P) ""
|
I: CALLI(P) ""
|
U: CALLU(P) ""
|
U: CALLU(P) ""
|
P: CALLP(P) ""
|
P: CALLP(P) ""
|
V: CALLV(P) ""
|
V: CALLV(P) ""
|
V: RETF(F) ""
|
V: RETF(F) ""
|
V: RETI(I) ""
|
V: RETI(I) ""
|
V: RETU(U) ""
|
V: RETU(U) ""
|
V: RETP(P) ""
|
V: RETP(P) ""
|
V: RETV ""
|
V: RETV ""
|
P: ADDRGP ""
|
P: ADDRGP ""
|
P: ADDRFP ""
|
P: ADDRFP ""
|
P: ADDRLP ""
|
P: ADDRLP ""
|
F: ADDF(F,F) ""
|
F: ADDF(F,F) ""
|
I: ADDI(I,I) ""
|
I: ADDI(I,I) ""
|
P: ADDP(P,I) ""
|
P: ADDP(P,I) ""
|
P: ADDP(I,P) ""
|
P: ADDP(I,P) ""
|
P: ADDP(U,P) ""
|
P: ADDP(U,P) ""
|
P: ADDP(P,U) ""
|
P: ADDP(P,U) ""
|
U: ADDU(U,U) ""
|
U: ADDU(U,U) ""
|
F: SUBF(F,F) ""
|
F: SUBF(F,F) ""
|
I: SUBI(I,I) ""
|
I: SUBI(I,I) ""
|
P: SUBP(P,I) ""
|
P: SUBP(P,I) ""
|
P: SUBP(P,U) ""
|
P: SUBP(P,U) ""
|
U: SUBU(U,U) ""
|
U: SUBU(U,U) ""
|
I: LSHI(I,I) ""
|
I: LSHI(I,I) ""
|
U: LSHU(U,I) ""
|
U: LSHU(U,I) ""
|
I: MODI(I,I) ""
|
I: MODI(I,I) ""
|
U: MODU(U,U) ""
|
U: MODU(U,U) ""
|
I: RSHI(I,I) ""
|
I: RSHI(I,I) ""
|
U: RSHU(U,I) ""
|
U: RSHU(U,I) ""
|
U: BANDU(U,U) ""
|
U: BANDU(U,U) ""
|
I: BANDI(I,I) ""
|
I: BANDI(I,I) ""
|
U: BCOMU(U) ""
|
U: BCOMU(U) ""
|
I: BCOMI(I) ""
|
I: BCOMI(I) ""
|
I: BORI(I,I) ""
|
I: BORI(I,I) ""
|
U: BORU(U,U) ""
|
U: BORU(U,U) ""
|
U: BXORU(U,U) ""
|
U: BXORU(U,U) ""
|
I: BXORI(I,I) ""
|
I: BXORI(I,I) ""
|
F: DIVF(F,F) ""
|
F: DIVF(F,F) ""
|
I: DIVI(I,I) ""
|
I: DIVI(I,I) ""
|
U: DIVU(U,U) ""
|
U: DIVU(U,U) ""
|
F: MULF(F,F) ""
|
F: MULF(F,F) ""
|
I: MULI(I,I) ""
|
I: MULI(I,I) ""
|
U: MULU(U,U) ""
|
U: MULU(U,U) ""
|
V: EQF(F,F) ""
|
V: EQF(F,F) ""
|
V: EQI(I,I) ""
|
V: EQI(I,I) ""
|
V: EQU(U,U) ""
|
V: EQU(U,U) ""
|
V: GEF(F,F) ""
|
V: GEF(F,F) ""
|
V: GEI(I,I) ""
|
V: GEI(I,I) ""
|
V: GEU(U,U) ""
|
V: GEU(U,U) ""
|
V: GTF(F,F) ""
|
V: GTF(F,F) ""
|
V: GTI(I,I) ""
|
V: GTI(I,I) ""
|
V: GTU(U,U) ""
|
V: GTU(U,U) ""
|
V: LEF(F,F) ""
|
V: LEF(F,F) ""
|
V: LEI(I,I) ""
|
V: LEI(I,I) ""
|
V: LEU(U,U) ""
|
V: LEU(U,U) ""
|
V: LTF(F,F) ""
|
V: LTF(F,F) ""
|
V: LTI(I,I) ""
|
V: LTI(I,I) ""
|
V: LTU(U,U) ""
|
V: LTU(U,U) ""
|
V: NEF(F,F) ""
|
V: NEF(F,F) ""
|
V: NEI(I,I) ""
|
V: NEI(I,I) ""
|
V: NEU(U,U) ""
|
V: NEU(U,U) ""
|
V: JUMPV(P) ""
|
V: JUMPV(P) ""
|
V: LABELV ""
|
V: LABELV ""
|
%%
|
%%
|
|
|
static void reduce(NODEPTR_TYPE p, int goalnt) {
|
static void reduce(NODEPTR_TYPE p, int goalnt) {
|
int i, sz = opsize(p->op), rulenumber = _rule(p->x.state, goalnt);
|
int i, sz = opsize(p->op), rulenumber = _rule(p->x.state, goalnt);
|
short *nts = _nts[rulenumber];
|
short *nts = _nts[rulenumber];
|
NODEPTR_TYPE kids[10];
|
NODEPTR_TYPE kids[10];
|
|
|
assert(rulenumber);
|
assert(rulenumber);
|
_kids(p, rulenumber, kids);
|
_kids(p, rulenumber, kids);
|
for (i = 0; nts[i]; i++)
|
for (i = 0; nts[i]; i++)
|
reduce(kids[i], nts[i]);
|
reduce(kids[i], nts[i]);
|
switch (optype(p->op)) {
|
switch (optype(p->op)) {
|
#define xx(ty) if (sz == ty->size) return
|
#define xx(ty) if (sz == ty->size) return
|
case I:
|
case I:
|
case U:
|
case U:
|
xx(chartype);
|
xx(chartype);
|
xx(shorttype);
|
xx(shorttype);
|
xx(inttype);
|
xx(inttype);
|
xx(longtype);
|
xx(longtype);
|
xx(longlong);
|
xx(longlong);
|
xx(signedptr);
|
xx(signedptr);
|
xx(unsignedptr);
|
xx(unsignedptr);
|
break;
|
break;
|
case F:
|
case F:
|
xx(floattype);
|
xx(floattype);
|
xx(doubletype);
|
xx(doubletype);
|
xx(longdouble);
|
xx(longdouble);
|
break;
|
break;
|
case P:
|
case P:
|
xx(voidptype);
|
xx(voidptype);
|
xx(funcptype);
|
xx(funcptype);
|
break;
|
break;
|
case V:
|
case V:
|
case B: if (sz == 0) return;
|
case B: if (sz == 0) return;
|
#undef xx
|
#undef xx
|
}
|
}
|
printdag(p, 2);
|
printdag(p, 2);
|
assert(0);
|
assert(0);
|
}
|
}
|
|
|
void check(Node p) {
|
void check(Node p) {
|
struct _state { short cost[1]; };
|
struct _state { short cost[1]; };
|
|
|
_label(p);
|
_label(p);
|
if (((struct _state *)p->x.state)->cost[1] > 0) {
|
if (((struct _state *)p->x.state)->cost[1] > 0) {
|
printdag(p, 2);
|
printdag(p, 2);
|
assert(0);
|
assert(0);
|
}
|
}
|
reduce(p, 1);
|
reduce(p, 1);
|
}
|
}
|
|
|