1 /*-------------------------------------------------------------------------
2 SDCCsymt.c - Code file for Symbols table related structures and MACRO's.
3 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding!
22 -------------------------------------------------------------------------*/
28 char *nounName(sym_link *sl) {
29 switch (SPEC_NOUN(sl))
32 if (SPEC_LONG(sl)) return "long";
33 if (SPEC_SHORT(sl)) return "short";
36 case V_FLOAT: return "float";
37 case V_CHAR: return "char";
38 case V_VOID: return "void";
39 case V_STRUCT: return "struct";
40 case V_LABEL: return "label";
41 case V_BIT: return "bit";
42 case V_SBIT: return "sbit";
43 case V_DOUBLE: return "double";
48 bucket *SymbolTab[256]; /* the symbol table */
49 bucket *StructTab[256]; /* the structure table */
50 bucket *TypedefTab[256]; /* the typedef table */
51 bucket *LabelTab[256]; /* the Label table */
52 bucket *enumTab[256]; /* enumerated table */
54 /*------------------------------------------------------------------*/
55 /* initSymt () - initialises symbol table related stuff */
56 /*------------------------------------------------------------------*/
62 for (i = 0; i < 256; i++)
63 SymbolTab[i] = StructTab[i] = (void *) NULL;
67 /*-----------------------------------------------------------------*/
68 /* newBucket - allocates & returns a new bucket */
69 /*-----------------------------------------------------------------*/
75 bp = Safe_calloc (1, sizeof (bucket));
80 /*-----------------------------------------------------------------*/
81 /* hashKey - computes the hashkey given a symbol name */
82 /*-----------------------------------------------------------------*/
84 hashKey (const char *s)
86 unsigned long key = 0;
93 /*-----------------------------------------------------------------*/
94 /* addSym - adds a symbol to the hash Table */
95 /*-----------------------------------------------------------------*/
97 addSym (bucket ** stab,
103 int i; /* index into the hash Table */
104 bucket *bp; /* temp bucket * */
106 /* Make sure sym is a symbol and not a structdef */
107 if (StructTab!=stab) checkTypeSanity(((symbol *)sym)->etype, sname);
109 /* the symbols are always added at the head of the list */
111 /* get a free entry */
112 bp = Safe_calloc (1, sizeof (bucket));
114 bp->sym = sym; /* update the symbol pointer */
115 bp->level = level; /* update the nest level */
117 strcpy (bp->name, sname); /* copy the name into place */
119 /* if this is the first entry */
122 bp->prev = bp->next = (void *) NULL; /* point to nothing */
125 /* not first entry then add @ head of list */
135 /*-----------------------------------------------------------------*/
136 /* deleteSym - deletes a symbol from the hash Table entry */
137 /*-----------------------------------------------------------------*/
139 deleteSym (bucket ** stab, void *sym, char *sname)
147 /* find the symbol */
150 if (bp->sym == sym) /* found it then break out */
151 break; /* of the loop */
155 if (!bp) /* did not find it */
157 /* if this is the first one in the chain */
161 if (stab[i]) /* if chain ! empty */
162 stab[i]->prev = (void *) NULL;
164 /* middle || end of chain */
167 if (bp->next) /* if not end of chain */
168 bp->next->prev = bp->prev;
170 bp->prev->next = bp->next;
175 /*-----------------------------------------------------------------*/
176 /* findSym - finds a symbol in a table */
177 /*-----------------------------------------------------------------*/
179 findSym (bucket ** stab, void *sym, const char *sname)
183 bp = stab[hashKey (sname)];
186 if (bp->sym == sym || strcmp (bp->name, sname) == 0)
191 return (bp ? bp->sym : (void *) NULL);
194 /*-----------------------------------------------------------------*/
195 /* findSymWithLevel - finds a symbol with a name & level */
196 /*-----------------------------------------------------------------*/
198 findSymWithLevel (bucket ** stab, symbol * sym)
202 bp = stab[hashKey (sym->name)];
205 ** do the search from the head of the list since the
206 ** elements are added at the head it is ensured that
207 ** we will find the deeper definitions before we find
208 ** the global ones. we need to check for symbols with
209 ** level <= to the level given, if levels match then block
210 ** numbers need to match as well
215 if (strcmp (bp->name, sym->name) == 0 && bp->level <= sym->level)
217 /* if this is parameter then nothing else need to be checked */
218 if (((symbol *) (bp->sym))->_isparm)
220 /* if levels match then block numbers hsould also match */
221 if (bp->level && bp->level == sym->level && bp->block == sym->block)
223 /* if levels don't match then we are okay */
224 if (bp->level && bp->level != sym->level && bp->block <= sym->block)
226 /* if this is a global variable then we are ok too */
234 return (void *) NULL;
237 /*-----------------------------------------------------------------*/
238 /* findSymWithBlock - finds a symbol with name in with a block */
239 /*-----------------------------------------------------------------*/
241 findSymWithBlock (bucket ** stab, symbol * sym, int block)
245 bp = stab[hashKey (sym->name)];
248 if (strcmp (bp->name, sym->name) == 0 &&
254 return (bp ? bp->sym : (void *) NULL);
257 /*------------------------------------------------------------------*/
258 /* newSymbol () - returns a new pointer to a symbol */
259 /*------------------------------------------------------------------*/
261 newSymbol (char *name, int scope)
265 sym = Safe_calloc (1, sizeof (symbol));
267 strcpy (sym->name, name); /* copy the name */
268 sym->level = scope; /* set the level */
269 sym->block = currBlockno;
270 sym->lineDef = yylineno; /* set the line number */
274 /*------------------------------------------------------------------*/
275 /* newLink - creates a new link (declarator,specifier) */
276 /*------------------------------------------------------------------*/
282 p = Safe_calloc (1, sizeof (sym_link));
287 /*------------------------------------------------------------------*/
288 /* newStruct - creats a new structdef from the free list */
289 /*------------------------------------------------------------------*/
291 newStruct (char *tag)
295 s = Safe_calloc (1, sizeof (structdef));
297 strcpy (s->tag, tag); /* copy the tag */
301 /*------------------------------------------------------------------*/
302 /* pointerTypes - do the computation for the pointer types */
303 /*------------------------------------------------------------------*/
305 pointerTypes (sym_link * ptr, sym_link * type)
310 /* find the first pointer type */
311 while (ptr && !IS_PTR (ptr))
314 /* could not find it */
315 if (!ptr || IS_SPEC (ptr) ||
316 DCL_TYPE (ptr) != UPOINTER)
319 /* change the pointer type depending on the
320 storage class of the type */
323 DCL_PTR_CONST (ptr) = SPEC_CONST (type);
324 DCL_PTR_VOLATILE (ptr) = SPEC_VOLATILE (type);
325 switch (SPEC_SCLS (type))
328 DCL_TYPE (ptr) = FPOINTER;
331 DCL_TYPE (ptr) = IPOINTER;
334 DCL_TYPE (ptr) = PPOINTER;
337 DCL_TYPE (ptr) = POINTER;
340 DCL_PTR_CONST (ptr) = port->mem.code_ro;
341 DCL_TYPE (ptr) = CPOINTER;
344 DCL_TYPE (ptr) = EEPPOINTER;
347 DCL_TYPE (ptr) = GPOINTER;
350 /* the storage class of type ends here */
353 SPEC_VOLATILE (type) = 0;
356 /* now change all the remaining unknown pointers
357 to generic pointers */
360 if (!IS_SPEC (ptr) && DCL_TYPE (ptr) == UPOINTER)
361 DCL_TYPE (ptr) = GPOINTER;
365 /* same for the type although it is highly unlikely that
366 type will have a pointer */
369 if (!IS_SPEC (type) && DCL_TYPE (type) == UPOINTER)
370 DCL_TYPE (type) = GPOINTER;
376 /*------------------------------------------------------------------*/
377 /* addDecl - adds a declarator @ the end of a chain */
378 /*------------------------------------------------------------------*/
380 addDecl (symbol * sym, int type, sym_link * p)
386 /* if we are passed a link then set head & tail */
395 head = tail = newLink ();
396 DCL_TYPE (head) = type;
399 /* if this is the first entry */
407 if (IS_SPEC (sym->etype) && IS_SPEC (head) && head == tail)
409 sym->etype = mergeSpec (sym->etype, head);
413 if (IS_SPEC (sym->etype) && !IS_SPEC (head) && head == tail)
416 while (t->next != sym->etype)
419 tail->next = sym->etype;
423 sym->etype->next = head;
429 /* if the type is a unknown pointer and has
430 a tspec then take the storage class const & volatile
431 attribute from the tspec & make it those of this
435 DCL_TYPE (p) == UPOINTER &&
438 if (!IS_SPEC (sym->etype))
440 sym->etype = sym->etype->next = newLink ();
441 sym->etype->class = SPECIFIER;
443 SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p));
444 SPEC_CONST (sym->etype) = SPEC_CONST (DCL_TSPEC (p));
445 SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p));
446 DCL_TSPEC (p) = NULL;
451 /*------------------------------------------------------------------
452 checkTypeSanity: prevent the user from doing e.g.:
454 ------------------------------------------------------------------*/
455 void checkTypeSanity(sym_link *dest, char *name) {
459 //printf ("sanity check skipped for %s\n", name);
465 //printf ("checking sanity for %s\n", name);
467 if ((SPEC_NOUN(dest)==V_CHAR ||
468 SPEC_NOUN(dest)==V_FLOAT ||
469 SPEC_NOUN(dest)==V_DOUBLE ||
470 SPEC_NOUN(dest)==V_VOID) &&
471 (SPEC_SHORT(dest) || SPEC_LONG(dest))) {
472 // long or short for char float double or void
473 werror (E_LONG_OR_SHORT_INVALID, noun, name);
475 if ((SPEC_NOUN(dest)==V_FLOAT ||
476 SPEC_NOUN(dest)==V_DOUBLE ||
477 SPEC_NOUN(dest)==V_VOID) &&
478 (SPEC_SIGNED(dest) || SPEC_USIGN(dest))) {
479 // signed or unsigned for float double or void
480 werror (E_SIGNED_OR_UNSIGNED_INVALID, noun, name);
482 if (SPEC_SIGNED(dest) && SPEC_USIGN(dest)) {
483 // signed AND unsigned
484 werror (E_SIGNED_AND_UNSIGNED_INVALID, noun, name);
486 if (SPEC_SHORT(dest) && SPEC_LONG(dest)) {
488 werror (E_LONG_AND_SHORT_INVALID, noun, name);
493 /*------------------------------------------------------------------*/
494 /* mergeSpec - merges two specifiers and returns the new one */
495 /*------------------------------------------------------------------*/
497 mergeSpec (sym_link * dest, sym_link * src)
500 /* we shouldn't redeclare the type */
501 if ((SPEC_NOUN (dest) && SPEC_NOUN (src)) &&
502 (SPEC_NOUN(dest) != SPEC_NOUN(src))) {
503 werror(E_TWO_OR_MORE_DATA_TYPES, yylval.yychar);
506 /* if noun different then src overrides */
507 if (SPEC_NOUN (dest) != SPEC_NOUN (src) && !SPEC_NOUN (dest))
508 SPEC_NOUN (dest) = SPEC_NOUN (src);
510 /* if destination has no storage class */
511 if (!SPEC_SCLS (dest) ||
512 ((SPEC_SCLS(dest) == S_CONSTANT || SPEC_SCLS(dest) == S_REGISTER) &&
514 SPEC_SCLS (dest) = SPEC_SCLS (src);
515 /* special case for const */
516 /* copy all the specifications */
517 SPEC_LONG (dest) |= SPEC_LONG (src);
518 SPEC_SHORT (dest) |= SPEC_SHORT (src);
519 SPEC_USIGN (dest) |= SPEC_USIGN (src);
520 SPEC_SIGNED (dest) |= SPEC_SIGNED (src);
521 SPEC_STAT (dest) |= SPEC_STAT (src);
522 SPEC_EXTR (dest) |= SPEC_EXTR (src);
523 SPEC_ABSA (dest) |= SPEC_ABSA (src);
524 SPEC_RENT (dest) |= SPEC_RENT (src);
525 SPEC_INTN (dest) |= SPEC_INTN (src);
526 SPEC_BANK (dest) |= SPEC_BANK (src);
527 SPEC_VOLATILE (dest) |= SPEC_VOLATILE (src);
528 SPEC_CRTCL (dest) |= SPEC_CRTCL (src);
529 SPEC_ADDR (dest) |= SPEC_ADDR (src);
530 SPEC_OCLS (dest) = SPEC_OCLS (src);
531 SPEC_BLEN (dest) |= SPEC_BLEN (src);
532 SPEC_BSTR (dest) |= SPEC_BSTR (src);
533 SPEC_TYPEDEF (dest) |= SPEC_TYPEDEF (src);
534 SPEC_NONBANKED (dest) |= SPEC_NONBANKED (src);
535 SPEC_NAKED (dest) |= SPEC_NAKED (src);
537 if (IS_STRUCT (dest) && SPEC_STRUCT (dest) == NULL)
538 SPEC_STRUCT (dest) = SPEC_STRUCT (src);
543 /*------------------------------------------------------------------*/
544 /* cloneSpec - copies the entire spec and returns a new spec */
545 /*------------------------------------------------------------------*/
547 cloneSpec (sym_link * src)
551 /* go thru chain till we find the specifier */
552 while (src && src->class != SPECIFIER)
556 memcpy (spec, src, sizeof (sym_link));
560 /*------------------------------------------------------------------*/
561 /* genSymName - generates and returns a name used for anonymous vars */
562 /*------------------------------------------------------------------*/
564 genSymName (int level)
566 static int gCount = 0;
567 static char gname[SDCC_NAME_MAX + 1];
569 sprintf (gname, "__%04d%04d", level, gCount++);
573 /*------------------------------------------------------------------*/
574 /* getSpec - returns the specifier part from a declaration chain */
575 /*------------------------------------------------------------------*/
577 getSpec (sym_link * p)
582 while (p && !(IS_SPEC (p)))
588 /*------------------------------------------------------------------*/
589 /* newCharLink() - creates an char type */
590 /*------------------------------------------------------------------*/
597 p->class = SPECIFIER;
598 SPEC_NOUN (p) = V_CHAR;
603 /*------------------------------------------------------------------*/
604 /* newFloatLink - a new Float type */
605 /*------------------------------------------------------------------*/
612 p->class = SPECIFIER;
613 SPEC_NOUN (p) = V_FLOAT;
618 /*------------------------------------------------------------------*/
619 /* newLongLink() - new long type */
620 /*------------------------------------------------------------------*/
627 p->class = SPECIFIER;
628 SPEC_NOUN (p) = V_INT;
634 /*------------------------------------------------------------------*/
635 /* newIntLink() - creates an int type */
636 /*------------------------------------------------------------------*/
643 p->class = SPECIFIER;
644 SPEC_NOUN (p) = V_INT;
649 /*------------------------------------------------------------------*/
650 /* getSize - returns size of a type chain in bits */
651 /*------------------------------------------------------------------*/
653 getSize (sym_link * p)
655 /* if nothing return 0 */
659 { /* if this is the specifier then */
660 switch (SPEC_NOUN (p))
661 { /* depending on the specifier type */
663 return (IS_LONG (p) ? LONGSIZE : (IS_SHORT (p) ? SHORTSIZE : INTSIZE));
671 return SPEC_STRUCT (p)->size;
677 return ((SPEC_BLEN (p) / 8) + (SPEC_BLEN (p) % 8 ? 1 : 0));
683 /* this is a specifier */
684 switch (DCL_TYPE (p))
689 return DCL_ELEM (p) * getSize (p->next);
706 /*------------------------------------------------------------------*/
707 /* bitsForType - returns # of bits required to store this type */
708 /*------------------------------------------------------------------*/
710 bitsForType (sym_link * p)
712 /* if nothing return 0 */
717 { /* if this is the specifier then */
719 switch (SPEC_NOUN (p))
720 { /* depending on the specifier type */
722 return (IS_LONG (p) ? LONGSIZE * 8 : (IS_SHORT (p) ? SHORTSIZE * 8 : INTSIZE * 8));
724 return FLOATSIZE * 8;
730 return SPEC_STRUCT (p)->size * 8;
736 return SPEC_BLEN (p);
742 /* this is a specifier */
743 switch (DCL_TYPE (p))
748 return DCL_ELEM (p) * getSize (p->next) * 8;
752 return (PTRSIZE * 8);
756 return (FPTRSIZE * 8);
758 return (GPTRSIZE * 8);
765 /*------------------------------------------------------------------*/
766 /* copySymbolChain - copies a symbol chain */
767 /*------------------------------------------------------------------*/
769 copySymbolChain (symbol * src)
776 dest = copySymbol (src);
777 dest->next = copySymbolChain (src->next);
781 /*------------------------------------------------------------------*/
782 /* copySymbol - makes a copy of a symbol */
783 /*------------------------------------------------------------------*/
785 copySymbol (symbol * src)
792 dest = newSymbol (src->name, src->level);
793 memcpy (dest, src, sizeof (symbol));
794 dest->level = src->level;
795 dest->block = src->block;
796 dest->ival = copyIlist (src->ival);
797 dest->type = copyLinkChain (src->type);
798 dest->etype = getSpec (dest->type);
800 dest->args = copyValueChain (src->args);
801 dest->key = src->key;
802 dest->calleeSave = src->calleeSave;
803 dest->allocreq = src->allocreq;
807 /*------------------------------------------------------------------*/
808 /* reverseSyms - reverses the links for a symbol chain */
809 /*------------------------------------------------------------------*/
811 reverseSyms (symbol * sym)
813 symbol *prev, *curr, *next;
828 sym->next = (void *) NULL;
832 /*------------------------------------------------------------------*/
833 /* reverseLink - reverses the links for a type chain */
834 /*------------------------------------------------------------------*/
836 reverseLink (sym_link * type)
838 sym_link *prev, *curr, *next;
853 type->next = (void *) NULL;
857 /*------------------------------------------------------------------*/
858 /* addSymChain - adds a symbol chain to the symboltable */
859 /*------------------------------------------------------------------*/
861 addSymChain (symbol * symHead)
863 symbol *sym = symHead;
867 for (; sym != NULL; sym = sym->next)
871 /* if already exists in the symbol table then check if
872 the previous was an extern definition if yes then
873 then check if the type match, if the types match then
874 delete the current entry and add the new entry */
875 if ((csym = findSymWithLevel (SymbolTab, sym)) &&
876 csym->level == sym->level)
879 /* previous definition extern ? */
880 if (1 || IS_EXTERN (csym->etype))
882 /* do types match ? */
883 if (checkType (csym->type, sym->type) != 1)
885 werror (E_DUPLICATE, csym->name);
887 /* delete current entry */
888 deleteSym (SymbolTab, csym, csym->name);
890 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
892 else /* not extern */
893 werror (E_DUPLICATE, sym->name);
897 /* check if previously defined */
898 if (csym && csym->level == sym->level)
900 /* if the previous one was declared as extern */
901 /* then check the type with the current one */
902 if (IS_EXTERN (csym->etype))
904 if (checkType (csym->type, sym->type) <= 0)
905 werror (W_EXTERN_MISMATCH, csym->name);
908 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
913 /*------------------------------------------------------------------*/
914 /* funcInChain - DCL Type 'FUNCTION' found in type chain */
915 /*------------------------------------------------------------------*/
917 funcInChain (sym_link * lnk)
928 /*------------------------------------------------------------------*/
929 /* structElemType - returns the type info of a sturct member */
930 /*------------------------------------------------------------------*/
932 structElemType (sym_link * stype, value * id, value ** argsp)
934 symbol *fields = (SPEC_STRUCT (stype) ? SPEC_STRUCT (stype)->fields : NULL);
935 sym_link *type, *etype;
936 sym_link *petype = getSpec (stype);
941 /* look for the id */
944 if (strcmp (fields->rname, id->name) == 0)
948 *argsp = fields->args;
950 type = copyLinkChain (fields->type);
951 etype = getSpec (type);
952 SPEC_SCLS (etype) = (SPEC_SCLS (petype) == S_REGISTER ?
953 SPEC_SCLS (etype) : SPEC_SCLS (petype));
956 fields = fields->next;
958 werror (E_NOT_MEMBER, id->name);
963 /*------------------------------------------------------------------*/
964 /* getStructElement - returns element of a tructure definition */
965 /*------------------------------------------------------------------*/
967 getStructElement (structdef * sdef, symbol * sym)
971 for (field = sdef->fields; field; field = field->next)
972 if (strcmp (field->name, sym->name) == 0)
975 werror (E_NOT_MEMBER, sym->name);
980 /*------------------------------------------------------------------*/
981 /* compStructSize - computes the size of a structure */
982 /*------------------------------------------------------------------*/
984 compStructSize (int su, structdef * sdef)
986 int sum = 0, usum = 0;
990 /* for the identifiers */
994 /* create the internal name for this variable */
995 sprintf (loop->rname, "_%s", loop->name);
996 loop->offset = (su == UNION ? sum = 0 : sum);
997 SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
999 /* if this is a bit field */
1002 /* change it to a unsigned bit */
1003 SPEC_NOUN (loop->etype) = V_BIT;
1004 SPEC_USIGN (loop->etype) = 1;
1005 /* check if this fit into the remaining */
1006 /* bits of this byte else align it to the */
1007 /* next byte boundary */
1008 if ((SPEC_BLEN (loop->etype) = loop->bitVar) <= (8 - bitOffset)) {
1009 SPEC_BSTR (loop->etype) = bitOffset;
1010 if ((bitOffset += (loop->bitVar % 8)) == 8)
1013 else /* does not fit */ {
1015 SPEC_BSTR (loop->etype) = bitOffset;
1016 sum += (loop->bitVar / 8);
1017 bitOffset += (loop->bitVar % 8);
1019 /* if this is the last field then pad */
1020 if (!loop->next && bitOffset && bitOffset != 8) {
1027 sum += getSize (loop->type);
1030 /* if function then do the arguments for it */
1031 if (funcInChain (loop->type)) {
1032 processFuncArgs (loop, 1);
1037 /* if this is not a bitfield but the */
1038 /* previous one was and did not take */
1039 /* the whole byte then pad the rest */
1040 if ((loop && !loop->bitVar) && bitOffset) {
1045 /* if union then size = sizeof larget field */
1047 usum = max (usum, sum);
1051 return (su == UNION ? usum : sum);
1054 /*------------------------------------------------------------------*/
1055 /* checkSClass - check the storage class specification */
1056 /*------------------------------------------------------------------*/
1058 checkSClass (symbol * sym)
1060 /* type is literal can happen foe enums change
1062 if (SPEC_SCLS (sym->etype) == S_LITERAL && !SPEC_ENUM (sym->etype))
1063 SPEC_SCLS (sym->etype) = S_AUTO;
1065 /* if sfr or sbit then must also be */
1066 /* volatile the initial value will be xlated */
1067 /* to an absolute address */
1068 if (SPEC_SCLS (sym->etype) == S_SBIT ||
1069 SPEC_SCLS (sym->etype) == S_SFR)
1071 SPEC_VOLATILE (sym->etype) = 1;
1072 /* if initial value given */
1075 SPEC_ABSA (sym->etype) = 1;
1076 SPEC_ADDR (sym->etype) =
1077 (int) list2int (sym->ival);
1082 /* if absolute address given then it mark it as
1084 if (IS_ABSOLUTE (sym->etype))
1085 SPEC_VOLATILE (sym->etype) = 1;
1087 /* global variables declared const put into code */
1088 if (sym->level == 0 &&
1089 SPEC_SCLS (sym->etype) == S_CONSTANT)
1091 SPEC_SCLS (sym->etype) = S_CODE;
1092 SPEC_CONST (sym->etype) = 1;
1095 /* global variable in code space is a constant */
1096 if (sym->level == 0 &&
1097 SPEC_SCLS (sym->etype) == S_CODE &&
1099 SPEC_CONST (sym->etype) = 1;
1102 /* if bit variable then no storage class can be */
1103 /* specified since bit is already a storage */
1104 if (IS_BITVAR (sym->etype) &&
1105 (SPEC_SCLS (sym->etype) != S_FIXED &&
1106 SPEC_SCLS (sym->etype) != S_SBIT &&
1107 SPEC_SCLS (sym->etype) != S_BIT)
1110 werror (E_BITVAR_STORAGE, sym->name);
1111 SPEC_SCLS (sym->etype) = S_FIXED;
1114 /* extern variables cannot be initialized */
1115 if (IS_EXTERN (sym->etype) && sym->ival)
1117 werror (E_EXTERN_INIT, sym->name);
1121 /* if this is an automatic symbol then */
1122 /* storage class will be ignored and */
1123 /* symbol will be allocated on stack/ */
1124 /* data depending on flag */
1126 (options.stackAuto || reentrant) &&
1127 (SPEC_SCLS (sym->etype) != S_AUTO &&
1128 SPEC_SCLS (sym->etype) != S_FIXED &&
1129 SPEC_SCLS (sym->etype) != S_REGISTER &&
1130 SPEC_SCLS (sym->etype) != S_STACK &&
1131 SPEC_SCLS (sym->etype) != S_XSTACK &&
1132 SPEC_SCLS (sym->etype) != S_CONSTANT))
1134 werror (E_AUTO_ASSUMED, sym->name);
1135 SPEC_SCLS (sym->etype) = S_AUTO;
1138 /* automatic symbols cannot be given */
1139 /* an absolute address ignore it */
1141 SPEC_ABSA (sym->etype) &&
1142 (options.stackAuto || reentrant))
1144 werror (E_AUTO_ABSA, sym->name);
1145 SPEC_ABSA (sym->etype) = 0;
1148 /* arrays & pointers cannot be defined for bits */
1149 /* SBITS or SFRs or BIT */
1150 if ((IS_ARRAY (sym->type) || IS_PTR (sym->type)) &&
1151 (SPEC_NOUN (sym->etype) == V_BIT ||
1152 SPEC_NOUN (sym->etype) == V_SBIT ||
1153 SPEC_SCLS (sym->etype) == S_SFR))
1154 werror (E_BIT_ARRAY, sym->name);
1156 /* if this is a bit|sbit then set length & start */
1157 if (SPEC_NOUN (sym->etype) == V_BIT ||
1158 SPEC_NOUN (sym->etype) == V_SBIT)
1160 SPEC_BLEN (sym->etype) = 1;
1161 SPEC_BSTR (sym->etype) = 0;
1164 /* variables declared in CODE space must have */
1165 /* initializers if not an extern */
1166 if (SPEC_SCLS (sym->etype) == S_CODE &&
1167 sym->ival == NULL &&
1169 port->mem.code_ro &&
1170 !IS_EXTERN (sym->etype) &&
1171 !funcInChain (sym->type))
1172 werror (E_CODE_NO_INIT, sym->name);
1174 /* if parameter or local variable then change */
1175 /* the storage class to reflect where the var will go */
1176 if (sym->level && SPEC_SCLS (sym->etype) == S_FIXED &&
1177 !IS_STATIC(sym->etype))
1179 if (options.stackAuto || (currFunc && IS_RENT (currFunc->etype)))
1181 SPEC_SCLS (sym->etype) = (options.useXstack ?
1182 S_XSTACK : S_STACK);
1186 /* hack-o-matic! I see no reason why the useXstack option should ever
1187 * control this allcoation, but the code was originally that way, and
1188 * changing it for non-390 ports breaks the compiler badly.
1190 bool useXdata = TARGET_IS_DS390 ? 1 : options.useXstack;
1191 SPEC_SCLS (sym->etype) = (useXdata ?
1197 /*------------------------------------------------------------------*/
1198 /* changePointer - change pointer to functions */
1199 /*------------------------------------------------------------------*/
1201 changePointer (symbol * sym)
1205 /* go thru the chain of declarations */
1206 /* if we find a pointer to a function */
1207 /* unconditionally change it to a ptr */
1209 for (p = sym->type; p; p = p->next)
1211 if (!IS_SPEC (p) && DCL_TYPE (p) == UPOINTER)
1212 DCL_TYPE (p) = GPOINTER;
1213 if (IS_PTR (p) && IS_FUNC (p->next))
1214 DCL_TYPE (p) = CPOINTER;
1218 /*------------------------------------------------------------------*/
1219 /* checkDecl - does semantic validation of a declaration */
1220 /*------------------------------------------------------------------*/
1222 checkDecl (symbol * sym)
1225 checkSClass (sym); /* check the storage class */
1226 changePointer (sym); /* change pointers if required */
1228 /* if this is an array without any dimension
1229 then update the dimension from the initial value */
1230 if (IS_ARRAY (sym->type) && !DCL_ELEM (sym->type))
1231 DCL_ELEM (sym->type) = getNelements (sym->type, sym->ival);
1236 /*------------------------------------------------------------------*/
1237 /* copyLinkChain - makes a copy of the link chain & rets ptr 2 head */
1238 /*------------------------------------------------------------------*/
1240 copyLinkChain (sym_link * p)
1242 sym_link *head, *curr, *loop;
1245 head = loop = (curr ? newLink () : (void *) NULL);
1248 memcpy (loop, curr, sizeof (sym_link)); /* copy it */
1249 loop->next = (curr->next ? newLink () : (void *) NULL);
1258 /*------------------------------------------------------------------*/
1259 /* cleanUpBlock - cleansup the symbol table specified for all the */
1260 /* symbols in the given block */
1261 /*------------------------------------------------------------------*/
1263 cleanUpBlock (bucket ** table, int block)
1268 /* go thru the entire table */
1269 for (i = 0; i < 256; i++)
1271 for (chain = table[i]; chain; chain = chain->next)
1273 if (chain->block >= block)
1275 deleteSym (table, chain->sym, chain->name);
1281 /*------------------------------------------------------------------*/
1282 /* cleanUpLevel - cleansup the symbol table specified for all the */
1283 /* symbols in the given level */
1284 /*------------------------------------------------------------------*/
1286 cleanUpLevel (bucket ** table, int level)
1291 /* go thru the entire table */
1292 for (i = 0; i < 256; i++)
1294 for (chain = table[i]; chain; chain = chain->next)
1296 if (chain->level >= level)
1298 deleteSym (table, chain->sym, chain->name);
1304 /*------------------------------------------------------------------*/
1305 /* computeType - computes the resultant type from two types */
1306 /*------------------------------------------------------------------*/
1308 computeType (sym_link * type1, sym_link * type2)
1312 sym_link *etype1 = getSpec (type1);
1313 sym_link *etype2 = getSpec (type2);
1315 /* if one of them is a float then result is a float */
1316 /* here we assume that the types passed are okay */
1317 /* and can be cast to one another */
1318 /* which ever is greater in size */
1319 if (IS_FLOAT (etype1) || IS_FLOAT (etype2))
1320 rType = newFloatLink ();
1322 /* if only one of them is a bit variable
1323 then the other one prevails */
1324 if (IS_BITVAR (etype1) && !IS_BITVAR (etype2))
1325 rType = copyLinkChain (type2);
1326 else if (IS_BITVAR (etype2) && !IS_BITVAR (etype1))
1327 rType = copyLinkChain (type1);
1329 /* if one of them is a pointer then that
1332 rType = copyLinkChain (type1);
1333 else if (IS_PTR (type2))
1334 rType = copyLinkChain (type2);
1335 else if (getSize (type1) > getSize (type2))
1336 rType = copyLinkChain (type1);
1338 rType = copyLinkChain (type2);
1340 reType = getSpec (rType);
1342 /* if either of them unsigned then make this unsigned */
1343 if ((SPEC_USIGN (etype1) || SPEC_USIGN (etype2)) && !IS_FLOAT (reType))
1344 SPEC_USIGN (reType) = 1;
1346 /* if result is a literal then make not so */
1347 if (IS_LITERAL (reType))
1348 SPEC_SCLS (reType) = S_REGISTER;
1353 /*------------------------------------------------------------------*/
1354 /* checkType - will do type check return 1 if match */
1355 /*------------------------------------------------------------------*/
1357 checkType (sym_link * dest, sym_link * src)
1368 /* if dest is a declarator then */
1373 if (DCL_TYPE (src) == DCL_TYPE (dest))
1374 return checkType (dest->next, src->next);
1375 else if (IS_PTR (src) && IS_PTR (dest))
1377 else if (IS_PTR (dest) && IS_ARRAY (src))
1379 else if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
1380 return -1 * checkType (dest->next, src);
1384 else if (IS_PTR (dest) && IS_INTEGRAL (src))
1390 /* if one is a specifier and the other is not */
1391 if ((IS_SPEC (src) && !IS_SPEC (dest)) ||
1392 (IS_SPEC (dest) && !IS_SPEC (src)))
1395 /* if one of them is a void then ok */
1396 if (SPEC_NOUN (dest) == V_VOID &&
1397 SPEC_NOUN (src) != V_VOID)
1400 if (SPEC_NOUN (dest) != V_VOID &&
1401 SPEC_NOUN (src) == V_VOID)
1404 /* char === to short */
1405 if (SPEC_NOUN (dest) == V_CHAR &&
1406 SPEC_NOUN (src) == V_INT &&
1408 return (SPEC_USIGN (src) == SPEC_USIGN (dest) ? 1 : -2);
1410 if (SPEC_NOUN (src) == V_CHAR &&
1411 SPEC_NOUN (dest) == V_INT &&
1413 return (SPEC_USIGN (src) == SPEC_USIGN (dest) ? 1 : -2);
1415 /* if they are both bitfields then if the lengths
1416 and starts don't match */
1417 if (IS_BITFIELD (dest) && IS_BITFIELD (src) &&
1418 (SPEC_BLEN (dest) != SPEC_BLEN (src) ||
1419 SPEC_BSTR (dest) != SPEC_BSTR (src)))
1422 /* it is a specifier */
1423 if (SPEC_NOUN (dest) != SPEC_NOUN (src))
1425 if (SPEC_USIGN (dest) == SPEC_USIGN (src) &&
1426 IS_INTEGRAL (dest) && IS_INTEGRAL (src) &&
1427 getSize (dest) == getSize (src))
1429 else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src))
1434 else if (IS_STRUCT (dest))
1436 if (SPEC_STRUCT (dest) != SPEC_STRUCT (src))
1441 if (SPEC_LONG (dest) != SPEC_LONG (src))
1444 if (SPEC_SHORT (dest) != SPEC_SHORT (src))
1447 if (SPEC_USIGN (dest) != SPEC_USIGN (src))
1453 /*------------------------------------------------------------------*/
1454 /* inCalleeSaveList - return 1 if found in calle save list */
1455 /*------------------------------------------------------------------*/
1457 inCalleeSaveList (char *s)
1461 for (i = 0; options.calleeSaves[i]; i++)
1462 if (strcmp (options.calleeSaves[i], s) == 0)
1468 /*-----------------------------------------------------------------*/
1469 /* aggregateArgToPointer: change an agggregate type function */
1470 /* argument to a pointer to that type. */
1471 /*-----------------------------------------------------------------*/
1473 aggregateArgToPointer (value * val)
1475 if (IS_AGGREGATE (val->type))
1477 /* if this is a structure */
1478 /* then we need to add a new link */
1479 if (IS_STRUCT (val->type))
1481 /* first lets add DECLARATOR type */
1482 sym_link *p = val->type;
1484 werror (W_STRUCT_AS_ARG, val->name);
1485 val->type = newLink ();
1486 val->type->next = p;
1489 /* change to a pointer depending on the */
1490 /* storage class specified */
1491 switch (SPEC_SCLS (val->etype))
1494 DCL_TYPE (val->type) = IPOINTER;
1497 DCL_TYPE (val->type) = PPOINTER;
1500 if (TARGET_IS_DS390)
1502 /* The AUTO and REGISTER classes should probably
1503 * also become generic pointers, but I haven't yet
1504 * devised a test case for that.
1506 DCL_TYPE (val->type) = GPOINTER;
1513 DCL_TYPE (val->type) = POINTER;
1516 DCL_TYPE (val->type) = CPOINTER;
1519 DCL_TYPE (val->type) = FPOINTER;
1522 DCL_TYPE (val->type) = EEPPOINTER;
1525 DCL_TYPE (val->type) = GPOINTER;
1528 /* is there is a symbol associated then */
1529 /* change the type of the symbol as well */
1532 val->sym->type = copyLinkChain (val->type);
1533 val->sym->etype = getSpec (val->sym->type);
1537 /*------------------------------------------------------------------*/
1538 /* checkFunction - does all kinds of check on a function */
1539 /*------------------------------------------------------------------*/
1541 checkFunction (symbol * sym)
1544 value *exargs, *acargs;
1547 /* if not type then some kind of error */
1551 /* if the function has no type then make it return int */
1552 if (!sym->type->next)
1553 sym->type->next = sym->etype = newIntLink ();
1555 /* function cannot return aggregate */
1556 if (IS_AGGREGATE (sym->type->next))
1558 werror (E_FUNC_AGGR, sym->name);
1562 /* function cannot return bit */
1563 if (IS_BITVAR (sym->type->next))
1565 werror (E_FUNC_BIT, sym->name);
1569 /* check if this function is defined as calleeSaves
1570 then mark it as such */
1571 sym->calleeSave = inCalleeSaveList (sym->name);
1573 /* if interrupt service routine */
1574 /* then it cannot have arguments */
1575 if (sym->args && IS_ISR (sym->etype) && !IS_VOID (sym->args->type))
1577 werror (E_INT_ARGS, sym->name);
1581 if (!(csym = findSym (SymbolTab, sym, sym->name)))
1582 return 1; /* not defined nothing more to check */
1584 /* check if body already present */
1585 if (csym && csym->fbody)
1587 werror (E_FUNC_BODY, sym->name);
1591 /* check the return value type */
1592 if (checkType (csym->type, sym->type) <= 0)
1594 werror (E_PREV_DEF_CONFLICT, csym->name, "type");
1595 werror (E_CONTINUE, "previous definition type ");
1596 printTypeChain (csym->type, stderr);
1597 fprintf (stderr, "\n");
1598 werror (E_CONTINUE, "current definition type ");
1599 printTypeChain (sym->type, stderr);
1600 fprintf (stderr, "\n");
1604 if (SPEC_INTRTN (csym->etype) != SPEC_INTRTN (sym->etype))
1606 werror (E_PREV_DEF_CONFLICT, csym->name, "interrupt");
1610 if (SPEC_BANK (csym->etype) != SPEC_BANK (sym->etype))
1612 werror (E_PREV_DEF_CONFLICT, csym->name, "using");
1616 /* compare expected agrs with actual args */
1617 exargs = csym->args;
1620 /* for all the expected args do */
1623 exargs = exargs->next, acargs = acargs->next, argCnt++)
1626 /* If the actual argument is an array, any prototype
1627 * will have modified it to a pointer. Duplicate that
1630 if (IS_AGGREGATE (acargs->type))
1632 checkValue = copyValue (acargs);
1633 aggregateArgToPointer (checkValue);
1637 checkValue = acargs;
1640 if (checkType (exargs->type, checkValue->type) <= 0)
1642 werror (E_ARG_TYPE, argCnt);
1647 /* if one them ended we have a problem */
1648 if ((exargs && !acargs && !IS_VOID (exargs->type)) ||
1649 (!exargs && acargs && !IS_VOID (acargs->type)))
1650 werror (E_ARG_COUNT);
1652 /* replace with this defition */
1653 sym->cdef = csym->cdef;
1654 deleteSym (SymbolTab, csym, csym->name);
1655 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
1656 if (IS_EXTERN (csym->etype) && !
1657 IS_EXTERN (sym->etype))
1659 addSet (&publics, sym);
1664 /*-----------------------------------------------------------------*/
1665 /* processFuncArgs - does some processing with function args */
1666 /*-----------------------------------------------------------------*/
1668 processFuncArgs (symbol * func, int ignoreName)
1673 /* if this function has variable argument list */
1674 /* then make the function a reentrant one */
1676 SPEC_RENT (func->etype) = 1;
1678 /* check if this function is defined as calleeSaves
1679 then mark it as such */
1680 func->calleeSave = inCalleeSaveList (func->name);
1682 val = func->args; /* loop thru all the arguments */
1684 /* if it is void then remove parameters */
1685 if (val && IS_VOID (val->type))
1691 /* reset regparm for the port */
1692 (*port->reset_regparms) ();
1693 /* if any of the arguments is an aggregate */
1694 /* change it to pointer to the same type */
1697 /* mark it as a register parameter if
1698 the function does not have VA_ARG
1699 and as port dictates */
1700 if (!func->hasVargs &&
1701 (*port->reg_parm) (val->type))
1703 SPEC_REGPARM (val->etype) = 1;
1706 if (IS_AGGREGATE (val->type))
1708 aggregateArgToPointer (val);
1714 /* if this is an internal generated function call */
1716 /* ignore --stack-auto for this one, we don't know how it is compiled */
1717 /* simply trust on --int-long-reent or --float-reent */
1718 if (IS_RENT(func->etype)) {
1722 /* if this function is reentrant or */
1723 /* automatics r 2b stacked then nothing */
1724 if (IS_RENT (func->etype) || options.stackAuto)
1733 /* if a symbolname is not given */
1734 /* synthesize a variable name */
1738 sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
1739 val->sym = newSymbol (val->name, 1);
1740 SPEC_OCLS (val->etype) = port->mem.default_local_map;
1741 val->sym->type = copyLinkChain (val->type);
1742 val->sym->etype = getSpec (val->sym->type);
1743 val->sym->_isparm = 1;
1744 strcpy (val->sym->rname, val->name);
1745 SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
1746 SPEC_STAT (func->etype);
1747 addSymChain (val->sym);
1750 else /* symbol name given create synth name */
1753 sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
1754 strcpy (val->sym->rname, val->name);
1755 val->sym->_isparm = 1;
1756 SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
1757 (options.model != MODEL_SMALL ? xdata : data);
1758 SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
1759 SPEC_STAT (func->etype);
1765 /*-----------------------------------------------------------------*/
1766 /* isSymbolEqual - compares two symbols return 1 if they match */
1767 /*-----------------------------------------------------------------*/
1769 isSymbolEqual (symbol * dest, symbol * src)
1771 /* if pointers match then equal */
1775 /* if one of them is null then don't match */
1779 /* if both of them have rname match on rname */
1780 if (dest->rname[0] && src->rname[0])
1781 return (!strcmp (dest->rname, src->rname));
1783 /* otherwise match on name */
1784 return (!strcmp (dest->name, src->name));
1787 void PT(sym_link *type)
1789 printTypeChain(type,0);
1791 /*-----------------------------------------------------------------*/
1792 /* printTypeChain - prints the type chain in human readable form */
1793 /*-----------------------------------------------------------------*/
1795 printTypeChain (sym_link * type, FILE * of)
1809 if (DCL_PTR_VOLATILE(type)) {
1810 fprintf (of, "volatile ");
1812 switch (DCL_TYPE (type))
1815 fprintf (of, "function ");
1818 fprintf (of, "_generic * ");
1819 if (DCL_PTR_CONST (type))
1820 fprintf (of, "const ");
1823 fprintf (of, "_code * ");
1824 if (DCL_PTR_CONST (type))
1825 fprintf (of, "const ");
1828 fprintf (of, "_far * ");
1829 if (DCL_PTR_CONST (type))
1830 fprintf (of, "const ");
1833 fprintf (of, "_eeprom * ");
1834 if (DCL_PTR_CONST (type))
1835 fprintf (of, "const ");
1839 fprintf (of, "_near * ");
1840 if (DCL_PTR_CONST (type))
1841 fprintf (of, "const ");
1844 fprintf (of, "_idata *");
1845 if (DCL_PTR_CONST (type))
1846 fprintf (of, "const ");
1849 fprintf (of, "_pdata *");
1850 if (DCL_PTR_CONST (type))
1851 fprintf (of, "const ");
1854 fprintf (of, " _unkown *");
1855 if (DCL_PTR_CONST (type))
1856 fprintf (of, "const ");
1859 fprintf (of, "array of ");
1865 if (SPEC_VOLATILE (type))
1866 fprintf (of, "volatile ");
1867 if (SPEC_USIGN (type))
1868 fprintf (of, "unsigned ");
1869 if (SPEC_CONST (type))
1870 fprintf (of, "const ");
1872 switch (SPEC_NOUN (type))
1876 fprintf (of, "long ");
1877 if (IS_SHORT (type))
1878 fprintf (of, "short ");
1879 fprintf (of, "int ");
1883 fprintf (of, "char ");
1887 fprintf (of, "void ");
1891 fprintf (of, "float ");
1895 fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
1899 fprintf (of, "sbit ");
1903 fprintf (of, "bit {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
1907 fprintf (of, "double ");
1911 fprintf (of, "unknown type ");
1921 /*-----------------------------------------------------------------*/
1922 /* cdbTypeInfo - print the type information for debugger */
1923 /*-----------------------------------------------------------------*/
1925 cdbTypeInfo (sym_link * type, FILE * of)
1927 fprintf (of, "{%d}", getSize (type));
1932 switch (DCL_TYPE (type))
1935 fprintf (of, "DF,");
1938 fprintf (of, "DG,");
1941 fprintf (of, "DC,");
1944 fprintf (of, "DX,");
1947 fprintf (of, "DD,");
1950 fprintf (of, "DI,");
1953 fprintf (of, "DP,");
1956 fprintf (of, "DA,");
1959 fprintf (of, "DA%d,", DCL_ELEM (type));
1967 switch (SPEC_NOUN (type))
1972 else if (IS_SHORT (type))
1991 fprintf (of, "ST%s", SPEC_STRUCT (type)->tag);
1999 fprintf (of, "SB%d$%d", SPEC_BSTR (type), SPEC_BLEN (type));
2006 if (SPEC_USIGN (type))
2014 /*-----------------------------------------------------------------*/
2015 /* cdbSymbol - prints a symbol & its type information for debugger */
2016 /*-----------------------------------------------------------------*/
2018 cdbSymbol (symbol * sym, FILE * of, int isStructSym, int isFunc)
2030 fprintf (of, "S:"); /* symbol record */
2031 /* if this is not a structure symbol then
2032 we need to figure out the scope information */
2038 if (IS_STATIC (sym->etype))
2039 fprintf (of, "F%s$", moduleName); /* scope is file */
2041 fprintf (of, "G$"); /* scope is global */
2044 /* symbol is local */
2045 fprintf (of, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
2048 fprintf (of, "S$"); /* scope is structure */
2050 /* print the name, & mangled name */
2051 fprintf (of, "%s$%d$%d(", sym->name,
2052 sym->level, sym->block);
2054 cdbTypeInfo (sym->type, of);
2057 /* print the address space */
2058 map = SPEC_OCLS (sym->etype);
2059 fprintf (of, "%c,%d,%d",
2060 (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
2062 /* if assigned to registers then output register names */
2063 /* if this is a function then print
2064 if is it an interrupt routine & interrupt number
2065 and the register bank it is using */
2067 fprintf (of, ",%d,%d,%d", SPEC_INTRTN (sym->etype),
2068 SPEC_INTN (sym->etype), SPEC_BANK (sym->etype));
2069 /* alternate location to find this symbol @ : eg registers
2076 /*-----------------------------------------------------------------*/
2077 /* cdbStruct - print a structure for debugger */
2078 /*-----------------------------------------------------------------*/
2080 cdbStruct (structdef * sdef, int block, FILE * of,
2081 int inStruct, char *tag)
2086 /* if block # then must have function scope */
2087 fprintf (of, "F%s$", moduleName);
2088 fprintf (of, "%s[", (tag ? tag : sdef->tag));
2089 for (sym = sdef->fields; sym; sym = sym->next)
2091 fprintf (of, "({%d}", sym->offset);
2092 cdbSymbol (sym, of, TRUE, FALSE);
2100 /*------------------------------------------------------------------*/
2101 /* cdbStructBlock - calls struct printing for a blcks */
2102 /*------------------------------------------------------------------*/
2104 cdbStructBlock (int block, FILE * of)
2107 bucket **table = StructTab;
2111 /* go thru the entire table */
2112 for (i = 0; i < 256; i++)
2114 for (chain = table[i]; chain; chain = chain->next)
2116 if (chain->block >= block)
2118 cdbStruct ((structdef *) chain->sym, chain->block, of, 0, NULL);
2124 /*-----------------------------------------------------------------*/
2125 /* powof2 - returns power of two for the number if number is pow 2 */
2126 /*-----------------------------------------------------------------*/
2128 powof2 (unsigned long num)
2141 if (n1s > 1 || nshifts == 0)
2157 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
2158 symbol *__muldiv[3][3][2];
2159 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
2160 sym_link *__multypes[3][2];
2161 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
2162 symbol *__conv[2][3][2];
2164 sym_link *floatType;
2167 _makeRegParam (symbol * sym)
2171 val = sym->args; /* loop thru all the arguments */
2173 /* reset regparm for the port */
2174 (*port->reset_regparms) ();
2177 SPEC_REGPARM (val->etype) = 1;
2182 /*-----------------------------------------------------------------*/
2183 /* initCSupport - create functions for C support routines */
2184 /*-----------------------------------------------------------------*/
2188 const char *smuldivmod[] =
2192 const char *sbwd[] =
2194 "char", "int", "long"
2201 int bwd, su, muldivmod, tofrom;
2203 floatType = newFloatLink ();
2205 for (bwd = 0; bwd < 3; bwd++)
2222 __multypes[bwd][0] = l;
2223 __multypes[bwd][1] = copyLinkChain (l);
2224 SPEC_USIGN (__multypes[bwd][1]) = 1;
2227 __fsadd = funcOfType ("__fsadd", floatType, floatType, 2, options.float_rent);
2228 __fssub = funcOfType ("__fssub", floatType, floatType, 2, options.float_rent);
2229 __fsmul = funcOfType ("__fsmul", floatType, floatType, 2, options.float_rent);
2230 __fsdiv = funcOfType ("__fsdiv", floatType, floatType, 2, options.float_rent);
2231 __fseq = funcOfType ("__fseq", CHARTYPE, floatType, 2, options.float_rent);
2232 __fsneq = funcOfType ("__fsneq", CHARTYPE, floatType, 2, options.float_rent);
2233 __fslt = funcOfType ("__fslt", CHARTYPE, floatType, 2, options.float_rent);
2234 __fslteq = funcOfType ("__fslteq", CHARTYPE, floatType, 2, options.float_rent);
2235 __fsgt = funcOfType ("__fsgt", CHARTYPE, floatType, 2, options.float_rent);
2236 __fsgteq = funcOfType ("__fsgteq", CHARTYPE, floatType, 2, options.float_rent);
2238 for (tofrom = 0; tofrom < 2; tofrom++)
2240 for (bwd = 0; bwd < 3; bwd++)
2242 for (su = 0; su < 2; su++)
2246 sprintf (buffer, "__fs2%s%s", ssu[su], sbwd[bwd]);
2247 __conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
2251 sprintf (buffer, "__%s%s2fs", ssu[su], sbwd[bwd]);
2252 __conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
2258 for (muldivmod = 0; muldivmod < 3; muldivmod++)
2260 for (bwd = 0; bwd < 3; bwd++)
2262 for (su = 0; su < 2; su++)
2264 sprintf (buffer, "_%s%s%s",
2265 smuldivmod[muldivmod],
2268 __muldiv[muldivmod][bwd][su] = funcOfType (buffer, __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
2269 SPEC_NONBANKED (__muldiv[muldivmod][bwd][su]->etype) = 1;
2270 if (bwd < port->muldiv.force_reg_param_below)
2271 _makeRegParam (__muldiv[muldivmod][bwd][su]);