6
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
7
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
8
* company may do whatever they wish with source code distributed with
9
* PCCTS or the code generated by PCCTS, including the incorporation of
10
* PCCTS, or its output, into commerical software.
12
* We encourage users to develop software with PCCTS. However, we do ask
13
* that credit is given to us for developing PCCTS. By "credit",
14
* we mean that if you incorporate our source code into one of your
15
* programs (commercial product, research project, or otherwise) that you
16
* acknowledge this fact somewhere in the documentation, research report,
17
* etc... If you like PCCTS and have developed a nice tool with the
18
* output, please mention that you developed it using PCCTS. In
19
* addition, we ask that this header remain intact in our source code.
20
* As long as these guidelines are kept, we expect to continue enhancing
21
* this system and expect to make other tools available as they are
38
static ExceptionGroup **egArray=NULL; /* ExceptionGroup by BlkLevel */
39
static LabelEntry **leArray=NULL; /* LabelEntry by BlkLevel */
40
static Junction **altArray=NULL; /* start of alternates */
41
static int arraySize=0;
42
static int highWater=0;
43
static ExceptionGroup *lastEG=NULL; /* used in altFixup() */
44
static int lastBlkLevel=0; /* used in altFixup() */
47
static void arrayCheck(void);
49
static void arrayCheck();
52
/* Called to add an exception group for an alternative EG */
55
void egAdd(ExceptionGroup * eg)
63
ExceptionGroup *nextEG;
64
ExceptionGroup *innerEG;
73
lastBlkLevel=BlkLevel;
76
eg->pendingLink=egArray[BlkLevel];
79
/* EG for alternates already have their atlID filled in */
81
for (i=BlkLevel+1; i<=highWater ; i++) {
82
for (innerEG=egArray[i]; innerEG != NULL ; innerEG=nextEG) {
83
nextEG=innerEG->pendingLink;
84
innerEG->pendingLink=NULL;
91
* for patching up the LabelEntry you might use an EG for the
92
* current alternative - unlike patching up an alternative EG
93
* i.e. start the loop at BlkLevel rather than (BlkLevel+1)
94
* fill it in only if the EG and the LE are for the very
95
* same alternative if they're at the same BlkLevel
96
* it's easier to leave the LE on this list (filled in) rather than
97
* trying to selectively remove it. It will eventually be
98
* removed anyway when the BlkLevel gets small enough.
101
for (i=BlkLevel; i<=highWater ; i++) {
102
for (innerLE=leArray[i]; innerLE != NULL ; innerLE=nextLE) {
103
nextLE=innerLE->pendingLink;
105
innerLE->curAltNum == CurAltNum) {
106
if (innerLE->outerEG == NULL) {
111
if (BlkLevel != i) leArray[i]=NULL;
115
* For the start of alternatives it is necessary to make a
116
* distinction between the exception group for the current
117
* alternative and the "fallback" EG for the block which
118
* contains the alternative
120
* The fallback outerEG is used to handle the case where
121
* no alternative of a block matches. In that case the
122
* signal is "NoViableAlt" (or "NoSemViableAlt" and the
123
* generator needs the EG of the block CONTAINING the
135
for (i=BlkLevel; i <= highWater ; i++) {
136
for (innerAlt=altArray[i]; innerAlt != NULL ; innerAlt=nextAlt) {
137
nextAlt=innerAlt->pendingLink;
139
/* first fill in the EG for the current alternative */
140
/* but leave it on the list in order to get the fallback EG */
141
/* if the EG is at the same LEVEL as the alternative then */
142
/* fill it in only if in the very same alternative */
146
/* | c exception ... */
149
/* if the EG is outside the alternative (e.g. BlkLevel < i) */
150
/* then it doesn't matter about the alternative */
155
/* ) exception ... */
159
printf("BlkLevel=%d i=%d altnum=%d CurAltNum=%d altID=%s\n",
160
BlkLevel,i,innerAlt->curAltNum,CurAltNum,eg->altID);
163
innerAlt->curAltNum == CurAltNum) {
164
if (innerAlt->exception_label == NULL) {
165
innerAlt->exception_label=eg->altID;
169
/* ocurs at a later pass then for the exception_label */
170
/* if an outerEG has been found then fill in the outer EG */
171
/* remove if from the list when the BlkLevel gets smaller */
174
if (innerAlt->outerEG == NULL) {
175
innerAlt->outerEG=eg;
179
if (BlkLevel != i) altArray[i]=NULL;
184
void leAdd(LabelEntry * le)
192
le->pendingLink=leArray[BlkLevel];
193
le->curAltNum=CurAltNum;
194
leArray[BlkLevel]=le;
198
void altAdd(Junction *alt)
207
printf("BlkLevel=%d CurAltNum=%d\n",
210
alt->curAltNum=CurAltNum;
211
alt->pendingLink=altArray[BlkLevel];
212
altArray[BlkLevel]=alt;
222
ExceptionGroup **egArrayNew;
223
LabelEntry **leArrayNew;
224
Junction **altArrayNew;
228
if (BlkLevel > highWater) highWater=BlkLevel;
230
if (BlkLevel >= arraySize) {
231
arraySizeNew=BlkLevel+5; /* MR20 */
232
egArrayNew=(ExceptionGroup **)
233
calloc(arraySizeNew,sizeof(ExceptionGroup *));
234
leArrayNew=(LabelEntry **)
235
calloc(arraySizeNew,sizeof(LabelEntry *));
236
altArrayNew=(Junction **)
237
calloc(arraySizeNew,sizeof(Junction *));
238
for (i=0; i<arraySize ; i++) {
239
egArrayNew[i]=egArray[i];
240
leArrayNew[i]=leArray[i];
241
altArrayNew[i]=altArray[i];
243
arraySize=arraySizeNew;
244
if (egArray != NULL) free( (char *) egArray);
245
if (leArray != NULL) free( (char *) leArray);
246
if (altArray != NULL) free( (char *) altArray);
249
altArray=altArrayNew;
253
/* always call leFixup() BEFORE egFixup() */
263
ExceptionGroup *nextEG;
264
ExceptionGroup *innerEG;
266
for (i=1; i<=highWater ; i++) {
267
for (innerEG=egArray[i]; innerEG != NULL ; innerEG=nextEG) {
268
nextEG=innerEG->pendingLink;
269
innerEG->pendingLink=NULL;
277
/* always call leFixup() BEFORE egFixup() */
290
for (i=BlkLevel; i<=highWater ; i++) {
291
for (innerLE=leArray[i]; innerLE != NULL ; innerLE=nextLE) {
292
nextLE=innerLE->pendingLink;
293
innerLE->pendingLink=NULL;
299
/* always call altFixup() BEFORE egFixup() */
312
for (i=BlkLevel; i<=highWater ; i++) {
313
for (innerAlt=altArray[i]; innerAlt != NULL ; innerAlt=nextAlt) {
315
/* if an outerEG has been found then fill in the outer EG */
317
if (lastBlkLevel <= i) {
318
if (innerAlt->outerEG == NULL) {
319
innerAlt->outerEG=lastEG;
322
nextAlt=innerAlt->pendingLink;
323
innerAlt->pendingLink=NULL;