]> git.sur5r.net Git - cc65/blob - src/cc65/codeinfo.c
Improved implementation of OptPushPop
[cc65] / src / cc65 / codeinfo.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                codeinfo.c                                 */
4 /*                                                                           */
5 /*                  Additional information about 6502 code                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001-2002 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <stdlib.h>
37 #include <string.h>
38
39 /* common */
40 #include "coll.h"
41
42 /* cc65 */
43 #include "codeent.h"
44 #include "codeseg.h"
45 #include "datatype.h"
46 #include "error.h"
47 #include "reginfo.h"
48 #include "symtab.h"
49 #include "codeinfo.h"
50
51
52
53 /*****************************************************************************/
54 /*                                   Data                                    */
55 /*****************************************************************************/
56
57
58
59 /* Table with the compare suffixes */
60 static const char CmpSuffixTab [][4] = {
61     "eq", "ne", "gt", "ge", "lt", "le", "ugt", "uge", "ult", "ule"
62 };
63
64 /* Table listing the function names and code info values for known internally
65  * used functions. This table should get auto-generated in the future.
66  */
67 typedef struct FuncInfo FuncInfo;
68 struct FuncInfo {
69     const char*     Name;       /* Function name */
70     unsigned short  Use;        /* Register usage */
71     unsigned short  Chg;        /* Changed/destroyed registers */
72 };
73
74 static const FuncInfo FuncInfoTable[] = {
75     { "addysp",         REG_Y,                REG_NONE                       },
76     { "aslax1",         REG_AX,               REG_AX | REG_TMP1              },
77     { "aslax2",         REG_AX,               REG_AX | REG_TMP1              },
78     { "aslax3",         REG_AX,               REG_AX | REG_TMP1              },
79     { "aslax4",         REG_AX,               REG_AX | REG_TMP1              },
80     { "bnega",          REG_A,                REG_AX                         },
81     { "bnegax",         REG_AX,               REG_AX                         },
82     { "bnegeax",        REG_EAX,              REG_EAX                        },
83     { "booleq",         REG_NONE,             REG_AX                         },
84     { "boolge",         REG_NONE,             REG_AX                         },
85     { "boolgt",         REG_NONE,             REG_AX                         },
86     { "boolle",         REG_NONE,             REG_AX                         },
87     { "boollt",         REG_NONE,             REG_AX                         },
88     { "boolne",         REG_NONE,             REG_AX                         },
89     { "booluge",        REG_NONE,             REG_AX                         },
90     { "boolugt",        REG_NONE,             REG_AX                         },
91     { "boolule",        REG_NONE,             REG_AX                         },
92     { "boolult",        REG_NONE,             REG_AX                         },
93     { "complax",        REG_AX,               REG_AX                         },
94     { "decax1",         REG_AX,               REG_AX                         },
95     { "decax2",         REG_AX,               REG_AX                         },
96     { "decax3",         REG_AX,               REG_AX                         },
97     { "decax4",         REG_AX,               REG_AX                         },
98     { "decax5",         REG_AX,               REG_AX                         },
99     { "decax6",         REG_AX,               REG_AX                         },
100     { "decax7",         REG_AX,               REG_AX                         },
101     { "decax8",         REG_AX,               REG_AX                         },
102     { "decaxy",         REG_AXY,              REG_AX | REG_TMP1              },
103     { "deceaxy",        REG_EAXY,             REG_EAX                        },
104     { "decsp1",         REG_NONE,             REG_Y                          },
105     { "decsp2",         REG_NONE,             REG_A                          },
106     { "decsp3",         REG_NONE,             REG_A                          },
107     { "decsp4",         REG_NONE,             REG_A                          },
108     { "decsp5",         REG_NONE,             REG_A                          },
109     { "decsp6",         REG_NONE,             REG_A                          },
110     { "decsp7",         REG_NONE,             REG_A                          },
111     { "decsp8",         REG_NONE,             REG_A                          },
112     { "incax1",         REG_AX,               REG_AX                         },
113     { "incax2",         REG_AX,               REG_AX                         },
114     { "incsp1",         REG_NONE,             REG_NONE                       },
115     { "incsp2",         REG_NONE,             REG_Y                          },
116     { "incsp3",         REG_NONE,             REG_Y                          },
117     { "incsp4",         REG_NONE,             REG_Y                          },
118     { "incsp5",         REG_NONE,             REG_Y                          },
119     { "incsp6",         REG_NONE,             REG_Y                          },
120     { "incsp7",         REG_NONE,             REG_Y                          },
121     { "incsp8",         REG_NONE,             REG_Y                          },
122     { "laddeq",         REG_EAXY|REG_PTR1_LO, REG_EAXY | REG_PTR1_HI         },
123     { "laddeq1",        REG_Y | REG_PTR1_LO,  REG_EAXY | REG_PTR1_HI         },
124     { "laddeqa",        REG_AY | REG_PTR1_LO, REG_EAXY | REG_PTR1_HI         },
125     { "ldaidx",         REG_AXY,              REG_AX | REG_PTR1              },
126     { "ldauidx",        REG_AXY,              REG_AX | REG_PTR1              },
127     { "ldax0sp",        REG_Y,                REG_AX                         },
128     { "ldaxi",          REG_AX,               REG_AXY | REG_PTR1             },
129     { "ldaxidx",        REG_AXY,              REG_AXY | REG_PTR1             },
130     { "ldaxysp",        REG_Y,                REG_AXY                        },
131     { "leaasp",         REG_A,                REG_AX                         },
132     { "lsubeq",         REG_EAXY|REG_PTR1_LO, REG_EAXY | REG_PTR1_HI         },
133     { "lsubeq0sp",      REG_EAX,              REG_EAXY                       },
134     { "lsubeq1",        REG_Y | REG_PTR1_LO,  REG_EAXY | REG_PTR1_HI         },
135     { "lsubeqa",        REG_AY | REG_PTR1_LO, REG_EAXY | REG_PTR1_HI         },
136     { "lsubeqysp",      REG_EAXY,             REG_EAXY                       },
137     { "negax",          REG_AX,               REG_AX                         },
138     { "pusha",          REG_A,                REG_Y                          },
139     { "pusha0",         REG_A,                REG_XY                         },
140     { "pushax",         REG_AX,               REG_Y                          },
141     { "pusheax",        REG_EAX,              REG_Y                          },
142     { "pushw0sp",       REG_NONE,             REG_AXY                        },
143     { "pushwysp",       REG_Y,                REG_AXY                        },
144     { "shlax1",         REG_AX,               REG_AX | REG_TMP1              },
145     { "shlax2",         REG_AX,               REG_AX | REG_TMP1              },
146     { "shlax3",         REG_AX,               REG_AX | REG_TMP1              },
147     { "shlax4",         REG_AX,               REG_AX | REG_TMP1              },
148     { "shrax1",         REG_AX,               REG_AX | REG_TMP1              },
149     { "shrax2",         REG_AX,               REG_AX | REG_TMP1              },
150     { "shrax3",         REG_AX,               REG_AX | REG_TMP1              },
151     { "shrax4",         REG_AX,               REG_AX | REG_TMP1              },
152     { "shreax1",        REG_EAX,              REG_AX | REG_TMP1              },
153     { "shreax2",        REG_EAX,              REG_AX | REG_TMP1              },
154     { "shreax3",        REG_EAX,              REG_AX | REG_TMP1              },
155     { "shreax4",        REG_EAX,              REG_AX | REG_TMP1              },
156     { "staspidx",       REG_A | REG_Y,        REG_Y | REG_TMP1 | REG_PTR1    },
157     { "stax0sp",        REG_AX,               REG_Y                          },
158     { "staxysp",        REG_AXY,              REG_Y                          },
159     { "subeq0sp",       REG_AX,               REG_AXY                        },
160     { "subeqysp",       REG_AXY,              REG_AXY                        },
161     { "tsteax",         REG_EAX,              REG_Y                          },
162     { "tosadda0",       REG_A,                REG_AXY                        },
163     { "tosaddax",       REG_AX,               REG_AXY                        },
164     { "tosicmp",        REG_AX,               REG_AXY | REG_SREG             },
165     { "tosdiva0",       REG_AX,               REG_ALL                        },
166     { "tosdivax",       REG_AX,               REG_ALL                        },
167     { "tosdiveax",      REG_EAX,              REG_ALL                        },
168     { "toseqeax",       REG_EAX,              REG_AXY | REG_PTR1             },
169     { "tosgeeax",       REG_EAX,              REG_AXY | REG_PTR1             },
170     { "tosgteax",       REG_EAX,              REG_AXY | REG_PTR1             },
171     { "toslcmp",        REG_EAX,              REG_A | REG_Y | REG_PTR1       },
172     { "tosleeax",       REG_EAX,              REG_AXY | REG_PTR1             },
173     { "toslteax",       REG_EAX,              REG_AXY | REG_PTR1             },
174     { "tosmula0",       REG_AX,               REG_ALL                        },
175     { "tosmulax",       REG_AX,               REG_ALL                        },
176     { "tosmuleax",      REG_EAX,              REG_ALL                        },
177     { "tosneeax",       REG_EAX,              REG_AXY | REG_PTR1             },
178     { "tosshreax",      REG_EAX,              REG_EAXY | REG_PTR1 | REG_PTR2 },
179     { "tossuba0",       REG_A,                REG_AXY                        },
180     { "tossubax",       REG_AX,               REG_AXY                        },
181     { "tossubeax",      REG_EAX,              REG_EAXY                       },
182     { "tosugeeax",      REG_EAX,              REG_AXY | REG_PTR1             },
183     { "tosugteax",      REG_EAX,              REG_AXY | REG_PTR1             },
184     { "tosuleeax",      REG_EAX,              REG_AXY | REG_PTR1             },
185     { "tosulteax",      REG_EAX,              REG_AXY | REG_PTR1             },
186     { "tosumula0",      REG_AX,               REG_ALL                        },
187     { "tosumulax",      REG_AX,               REG_ALL                        },
188     { "tosumuleax",     REG_EAX,              REG_ALL                        },
189     { "utsteax",        REG_EAX,              REG_Y                          },
190 };
191 #define FuncInfoCount   (sizeof(FuncInfoTable) / sizeof(FuncInfoTable[0]))
192
193 /* Table with names of zero page locations used by the compiler */
194 static const ZPInfo ZPInfoTable[] = {
195     {   0, "ptr1",      REG_PTR1_LO,    REG_PTR1        },
196     {   0, "ptr1+1",    REG_PTR1_HI,    REG_PTR1        },
197     {   0, "ptr2",      REG_PTR2_LO,    REG_PTR2        },
198     {   0, "ptr2+1",    REG_PTR2_HI,    REG_PTR2        },
199     {   4, "ptr3",      REG_NONE,       REG_NONE        },
200     {   4, "ptr4",      REG_NONE,       REG_NONE        },
201     {   7, "regbank",   REG_NONE,       REG_NONE        },
202     {   0, "regsave",   REG_SAVE_LO,    REG_SAVE        },
203     {   0, "regsave+1", REG_SAVE_HI,    REG_SAVE        },
204     {   0, "sp",        REG_SP_LO,      REG_SP          },
205     {   0, "sp+1",      REG_SP_HI,      REG_SP          },
206     {   0, "sreg",      REG_SREG_LO,    REG_SREG        },
207     {   0, "sreg+1",    REG_SREG_HI,    REG_SREG        },
208     {   0, "tmp1",      REG_TMP1,       REG_TMP1        },
209     {   0, "tmp2",      REG_NONE,       REG_NONE        },
210     {   0, "tmp3",      REG_NONE,       REG_NONE        },
211     {   0, "tmp4",      REG_NONE,       REG_NONE        },
212 };
213 #define ZPInfoCount     (sizeof(ZPInfoTable) / sizeof(ZPInfoTable[0]))
214
215
216
217 /*****************************************************************************/
218 /*                                   Code                                    */
219 /*****************************************************************************/
220
221
222
223 static int CompareFuncInfo (const void* Key, const void* Info)
224 /* Compare function for bsearch */
225 {
226     return strcmp (Key, ((const FuncInfo*) Info)->Name);
227 }
228
229
230
231 void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg)
232 /* For the given function, lookup register information and store it into
233  * the given variables. If the function is unknown, assume it will use and
234  * load all registers.
235  */
236 {
237     /* If the function name starts with an underline, it is an external
238      * function. Search for it in the symbol table. If the function does
239      * not start with an underline, it may be a runtime support function.
240      * Search for it in the list of builtin functions.
241      */
242     if (Name[0] == '_') {
243
244         /* Search in the symbol table, skip the leading underscore */
245         SymEntry* E = FindGlobalSym (Name+1);
246
247         /* Did we find it in the top level table? */
248         if (E && IsTypeFunc (E->Type)) {
249
250             /* A function may use the A or A/X registers if it is a fastcall
251              * function. If it is not a fastcall function but a variadic one,
252              * it will use the Y register (the parameter size is passed here).
253              * In all other cases, no registers are used. However, we assume
254              * that any function will destroy all registers.
255              */
256             FuncDesc* D = E->V.F.Func;
257             if ((D->Flags & FD_FASTCALL) != 0 && D->ParamCount > 0) {
258                 /* Will use registers depending on the last param */
259                 SymEntry* LastParam = D->SymTab->SymTail;
260                 unsigned LastParamSize = CheckedSizeOf (LastParam->Type);
261                 if (LastParamSize == 1) {
262                     *Use = REG_A;
263                 } else if (LastParamSize == 2) {
264                     *Use = REG_AX;
265                 } else {
266                     *Use = REG_EAX;
267                 }
268             } else if ((D->Flags & FD_VARIADIC) != 0) {
269                 *Use = REG_Y;
270             } else {
271                 /* Will not use any registers */
272                 *Use = REG_NONE;
273             }
274
275             /* Will destroy all registers */
276             *Chg = REG_ALL;
277
278             /* Done */
279             return;
280         }
281
282     } else {
283
284         /* Search for the function in the list of builtin functions */
285         const FuncInfo* Info = bsearch (Name, FuncInfoTable, FuncInfoCount,
286                                         sizeof(FuncInfo), CompareFuncInfo);
287
288         /* Do we know the function? */
289         if (Info) {
290             /* Use the information we have */
291             *Use = Info->Use;
292             *Chg = Info->Chg;
293             return;
294         }
295     }
296
297     /* Function not found - assume that the primary register is input, and all
298      * registers are changed
299      */
300     *Use = REG_EAXY;
301     *Chg = REG_ALL;
302 }
303
304
305
306 static int CompareZPInfo (const void* Name, const void* Info)
307 /* Compare function for bsearch */
308 {
309     /* Cast the pointers to the correct data type */
310     const char* N   = (const char*) Name;
311     const ZPInfo* E = (const ZPInfo*) Info;
312
313     /* Do the compare. Be careful because of the length (Info may contain
314      * more than just the zeropage name).
315      */
316     if (E->Len == 0) {
317         /* Do a full compare */
318         return strcmp (N, E->Name);
319     } else {
320         /* Only compare the first part */
321         int Res = strncmp (N, E->Name, E->Len);
322         if (Res == 0 && (N[E->Len] != '\0' && N[E->Len] != '+')) {
323             /* Name is actually longer than Info->Name */
324             Res = -1;
325         }
326         return Res;
327     }
328 }
329
330
331
332 const ZPInfo* GetZPInfo (const char* Name)
333 /* If the given name is a zero page symbol, return a pointer to the info
334  * struct for this symbol, otherwise return NULL.
335  */
336 {
337     /* Search for the zp location in the list */
338     return bsearch (Name, ZPInfoTable, ZPInfoCount,
339                     sizeof(ZPInfo), CompareZPInfo);
340 }
341
342
343
344 static unsigned GetRegInfo2 (CodeSeg* S,
345                              CodeEntry* E,
346                              int Index,
347                              Collection* Visited,
348                              unsigned Used,
349                              unsigned Unused,
350                              unsigned Wanted)
351 /* Recursively called subfunction for GetRegInfo. */
352 {
353     /* Follow the instruction flow recording register usage. */
354     while (1) {
355
356         unsigned R;
357
358         /* Check if we have already visited the current code entry. If so,
359          * bail out.
360          */
361         if (CE_HasMark (E)) {
362             break;
363         }
364
365         /* Mark this entry as already visited */
366         CE_SetMark (E);
367         CollAppend (Visited, E);
368
369         /* Evaluate the used registers */
370         R = E->Use;
371         if (E->OPC == OP65_RTS ||
372             ((E->Info & OF_BRA) != 0 && E->JumpTo == 0)) {
373             /* This instruction will leave the function */
374             R |= S->ExitRegs;
375         }
376         if (R != REG_NONE) {
377             /* We are not interested in the use of any register that has been
378              * used before.
379              */
380             R &= ~Unused;
381             /* Remember the remaining registers */
382             Used |= R;
383         }
384
385         /* Evaluate the changed registers */
386         if ((R = E->Chg) != REG_NONE) {
387             /* We are not interested in the use of any register that has been
388              * used before.
389              */
390             R &= ~Used;
391             /* Remember the remaining registers */
392             Unused |= R;
393         }
394
395         /* If we know about all registers now, bail out */
396         if (((Used | Unused) & Wanted) == Wanted) {
397             break;
398         }
399
400         /* If the instruction is an RTS or RTI, we're done */
401         if ((E->Info & OF_RET) != 0) {
402             break;
403         }
404
405         /* If we have an unconditional branch, follow this branch if possible,
406          * otherwise we're done.
407          */
408         if ((E->Info & OF_UBRA) != 0) {
409
410             /* Does this jump have a valid target? */
411             if (E->JumpTo) {
412
413                 /* Unconditional jump */
414                 E     = E->JumpTo->Owner;
415                 Index = -1;             /* Invalidate */
416
417             } else {
418                 /* Jump outside means we're done */
419                 break;
420             }
421
422         /* In case of conditional branches, follow the branch if possible and
423          * follow the normal flow (branch not taken) afterwards. If we cannot
424          * follow the branch, we're done.
425          */
426         } else if ((E->Info & OF_CBRA) != 0) {
427
428             if (E->JumpTo) {
429
430                 /* Recursively determine register usage at the branch target */
431                 unsigned U1;
432                 unsigned U2;
433
434                 U1 = GetRegInfo2 (S, E->JumpTo->Owner, -1, Visited, Used, Unused, Wanted);
435                 if (U1 == REG_ALL) {
436                     /* All registers used, no need for second call */
437                     return REG_AXY;
438                 }
439                 if (Index < 0) {
440                     Index = CS_GetEntryIndex (S, E);
441                 }
442                 if ((E = CS_GetEntry (S, ++Index)) == 0) {
443                     Internal ("GetRegInfo2: No next entry!");
444                 }
445                 U2 = GetRegInfo2 (S, E, Index, Visited, Used, Unused, Wanted);
446                 return U1 | U2;         /* Used in any of the branches */
447
448             } else {
449                 /* Jump to global symbol */
450                 break;
451             }
452
453         } else {
454
455             /* Just go to the next instruction */
456             if (Index < 0) {
457                 Index = CS_GetEntryIndex (S, E);
458             }
459             E = CS_GetEntry (S, ++Index);
460             if (E == 0) {
461                 /* No next entry */
462                 Internal ("GetRegInfo2: No next entry!");
463             }
464
465         }
466
467     }
468
469     /* Return to the caller the complement of all unused registers */
470     return Used;
471 }
472
473
474
475 static unsigned GetRegInfo1 (CodeSeg* S,
476                              CodeEntry* E,
477                              int Index,
478                              Collection* Visited,
479                              unsigned Used,
480                              unsigned Unused,
481                              unsigned Wanted)
482 /* Recursively called subfunction for GetRegInfo. */
483 {
484     /* Remember the current count of the line collection */
485     unsigned Count = CollCount (Visited);
486
487     /* Call the worker routine */
488     unsigned R = GetRegInfo2 (S, E, Index, Visited, Used, Unused, Wanted);
489
490     /* Restore the old count, unmarking all new entries */
491     unsigned NewCount = CollCount (Visited);
492     while (NewCount-- > Count) {
493         CodeEntry* E = CollAt (Visited, NewCount);
494         CE_ResetMark (E);
495         CollDelete (Visited, NewCount);
496     }
497
498     /* Return the registers used */
499     return R;
500 }
501
502
503
504 unsigned GetRegInfo (struct CodeSeg* S, unsigned Index, unsigned Wanted)
505 /* Determine register usage information for the instructions starting at the
506  * given index.
507  */
508 {
509     CodeEntry*      E;
510     Collection      Visited;    /* Visited entries */
511     unsigned        R;
512
513     /* Get the code entry for the given index */
514     if (Index >= CS_GetEntryCount (S)) {
515         /* There is no such code entry */
516         return REG_NONE;
517     }
518     E = CS_GetEntry (S, Index);
519
520     /* Initialize the data structure used to collection information */
521     InitCollection (&Visited);
522
523     /* Call the recursive subfunction */
524     R = GetRegInfo1 (S, E, Index, &Visited, REG_NONE, REG_NONE, Wanted);
525
526     /* Delete the line collection */
527     DoneCollection (&Visited);
528
529     /* Return the registers used */
530     return R;
531 }
532
533
534
535 int RegAUsed (struct CodeSeg* S, unsigned Index)
536 /* Check if the value in A is used. */
537 {
538     return (GetRegInfo (S, Index, REG_A) & REG_A) != 0;
539 }
540
541
542
543 int RegXUsed (struct CodeSeg* S, unsigned Index)
544 /* Check if the value in X is used. */
545 {
546     return (GetRegInfo (S, Index, REG_X) & REG_X) != 0;
547 }
548
549
550
551 int RegYUsed (struct CodeSeg* S, unsigned Index)
552 /* Check if the value in Y is used. */
553 {
554     return (GetRegInfo (S, Index, REG_Y) & REG_Y) != 0;
555 }
556
557
558
559 int RegAXUsed (struct CodeSeg* S, unsigned Index)
560 /* Check if the value in A or(!) the value in X are used. */
561 {
562     return (GetRegInfo (S, Index, REG_AX) & REG_AX) != 0;
563 }
564
565
566
567 unsigned GetKnownReg (unsigned Use, const RegContents* RC)
568 /* Return the register or zero page location from the set in Use, thats
569  * contents are known. If Use does not contain any register, or if the
570  * register in question does not have a known value, return REG_NONE.
571  */
572 {
573     if ((Use & REG_A) != 0) {
574         return (RC == 0 || RC->RegA >= 0)? REG_A : REG_NONE;
575     } else if ((Use & REG_X) != 0) {
576         return (RC == 0 || RC->RegX >= 0)? REG_X : REG_NONE;
577     } else if ((Use & REG_Y) != 0) {
578         return (RC == 0 || RC->RegY >= 0)? REG_Y : REG_NONE;
579     } else if ((Use & REG_TMP1) != 0) {
580         return (RC == 0 || RC->Tmp1 >= 0)? REG_TMP1 : REG_NONE;
581     } else if ((Use & REG_SREG_LO) != 0) {
582         return (RC == 0 || RC->SRegLo >= 0)? REG_SREG_LO : REG_NONE;
583     } else if ((Use & REG_SREG_HI) != 0) {
584         return (RC == 0 || RC->SRegHi >= 0)? REG_SREG_HI : REG_NONE;
585     } else {
586         return REG_NONE;
587     }
588 }
589
590
591
592 static cmp_t FindCmpCond (const char* Code, unsigned CodeLen)
593 /* Search for a compare condition by the given code using the given length */
594 {
595     unsigned I;
596
597     /* Linear search */
598     for (I = 0; I < sizeof (CmpSuffixTab) / sizeof (CmpSuffixTab [0]); ++I) {
599         if (strncmp (Code, CmpSuffixTab [I], CodeLen) == 0) {
600             /* Found */
601             return I;
602         }
603     }
604
605     /* Not found */
606     return CMP_INV;
607 }
608
609
610
611 cmp_t FindBoolCmpCond (const char* Name)
612 /* Check if the given string is the name of one of the boolean transformer
613  * subroutine, and if so, return the condition that is evaluated by this
614  * routine. Return CMP_INV if the condition is not recognised.
615  */
616 {
617     /* Check for the correct subroutine name */
618     if (strncmp (Name, "bool", 4) == 0) {
619         /* Name is ok, search for the code in the table */
620         return FindCmpCond (Name+4, strlen(Name)-4);
621     } else {
622         /* Not found */
623         return CMP_INV;
624     }
625 }
626
627
628
629 cmp_t FindTosCmpCond (const char* Name)
630 /* Check if this is a call to one of the TOS compare functions (tosgtax).
631  * Return the condition code or CMP_INV on failure.
632  */
633 {
634     unsigned Len = strlen (Name);
635
636     /* Check for the correct subroutine name */
637     if (strncmp (Name, "tos", 3) == 0 && strcmp (Name+Len-2, "ax") == 0) {
638         /* Name is ok, search for the code in the table */
639         return FindCmpCond (Name+3, Len-3-2);
640     } else {
641         /* Not found */
642         return CMP_INV;
643     }
644 }
645
646
647