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 checkTypeSanity(((symbol *)sym)->etype, sname);
108 /* the symbols are always added at the head of the list */
110 /* get a free entry */
111 bp = Safe_calloc (1, sizeof (bucket));
113 bp->sym = sym; /* update the symbol pointer */
114 bp->level = level; /* update the nest level */
116 strcpy (bp->name, sname); /* copy the name into place */
118 /* if this is the first entry */
121 bp->prev = bp->next = (void *) NULL; /* point to nothing */
124 /* not first entry then add @ head of list */
134 /*-----------------------------------------------------------------*/
135 /* deleteSym - deletes a symbol from the hash Table entry */
136 /*-----------------------------------------------------------------*/
138 deleteSym (bucket ** stab, void *sym, char *sname)
146 /* find the symbol */
149 if (bp->sym == sym) /* found it then break out */
150 break; /* of the loop */
154 if (!bp) /* did not find it */
156 /* if this is the first one in the chain */
160 if (stab[i]) /* if chain ! empty */
161 stab[i]->prev = (void *) NULL;
163 /* middle || end of chain */
166 if (bp->next) /* if not end of chain */
167 bp->next->prev = bp->prev;
169 bp->prev->next = bp->next;
174 /*-----------------------------------------------------------------*/
175 /* findSym - finds a symbol in a table */
176 /*-----------------------------------------------------------------*/
178 findSym (bucket ** stab, void *sym, const char *sname)
182 bp = stab[hashKey (sname)];
185 if (bp->sym == sym || strcmp (bp->name, sname) == 0)
190 return (bp ? bp->sym : (void *) NULL);
193 /*-----------------------------------------------------------------*/
194 /* findSymWithLevel - finds a symbol with a name & level */
195 /*-----------------------------------------------------------------*/
197 findSymWithLevel (bucket ** stab, symbol * sym)
201 bp = stab[hashKey (sym->name)];
204 ** do the search from the head of the list since the
205 ** elements are added at the head it is ensured that
206 ** we will find the deeper definitions before we find
207 ** the global ones. we need to check for symbols with
208 ** level <= to the level given, if levels match then block
209 ** numbers need to match as well
214 if (strcmp (bp->name, sym->name) == 0 && bp->level <= sym->level)
216 /* if this is parameter then nothing else need to be checked */
217 if (((symbol *) (bp->sym))->_isparm)
219 /* if levels match then block numbers hsould also match */
220 if (bp->level && bp->level == sym->level && bp->block == sym->block)
222 /* if levels don't match then we are okay */
223 if (bp->level && bp->level != sym->level && bp->block <= sym->block)
225 /* if this is a global variable then we are ok too */
233 return (void *) NULL;
236 /*-----------------------------------------------------------------*/
237 /* findSymWithBlock - finds a symbol with name in with a block */
238 /*-----------------------------------------------------------------*/
240 findSymWithBlock (bucket ** stab, symbol * sym, int block)
244 bp = stab[hashKey (sym->name)];
247 if (strcmp (bp->name, sym->name) == 0 &&
253 return (bp ? bp->sym : (void *) NULL);
256 /*------------------------------------------------------------------*/
257 /* newSymbol () - returns a new pointer to a symbol */
258 /*------------------------------------------------------------------*/
260 newSymbol (char *name, int scope)
264 sym = Safe_calloc (1, sizeof (symbol));
266 strcpy (sym->name, name); /* copy the name */
267 sym->level = scope; /* set the level */
268 sym->block = currBlockno;
269 sym->lineDef = yylineno; /* set the line number */
273 /*------------------------------------------------------------------*/
274 /* newLink - creates a new link (declarator,specifier) */
275 /*------------------------------------------------------------------*/
281 p = Safe_calloc (1, sizeof (sym_link));
286 /*------------------------------------------------------------------*/
287 /* newStruct - creats a new structdef from the free list */
288 /*------------------------------------------------------------------*/
290 newStruct (char *tag)
294 s = Safe_calloc (1, sizeof (structdef));
296 strcpy (s->tag, tag); /* copy the tag */
300 /*------------------------------------------------------------------*/
301 /* pointerTypes - do the computation for the pointer types */
302 /*------------------------------------------------------------------*/
304 pointerTypes (sym_link * ptr, sym_link * type)
309 /* find the first pointer type */
310 while (ptr && !IS_PTR (ptr))
313 /* could not find it */
314 if (!ptr || IS_SPEC (ptr) ||
315 DCL_TYPE (ptr) != UPOINTER)
318 /* change the pointer type depending on the
319 storage class of the type */
322 DCL_PTR_CONST (ptr) = SPEC_CONST (type);
323 DCL_PTR_VOLATILE (ptr) = SPEC_VOLATILE (type);
324 switch (SPEC_SCLS (type))
327 DCL_TYPE (ptr) = FPOINTER;
330 DCL_TYPE (ptr) = IPOINTER;
333 DCL_TYPE (ptr) = PPOINTER;
336 DCL_TYPE (ptr) = POINTER;
339 DCL_PTR_CONST (ptr) = port->mem.code_ro;
340 DCL_TYPE (ptr) = CPOINTER;
343 DCL_TYPE (ptr) = EEPPOINTER;
346 DCL_TYPE (ptr) = GPOINTER;
349 /* the storage class of type ends here */
352 SPEC_VOLATILE (type) = 0;
355 /* now change all the remaining unknown pointers
356 to generic pointers */
359 if (!IS_SPEC (ptr) && DCL_TYPE (ptr) == UPOINTER)
360 DCL_TYPE (ptr) = GPOINTER;
364 /* same for the type although it is highly unlikely that
365 type will have a pointer */
368 if (!IS_SPEC (type) && DCL_TYPE (type) == UPOINTER)
369 DCL_TYPE (type) = GPOINTER;
375 /*------------------------------------------------------------------*/
376 /* addDecl - adds a declarator @ the end of a chain */
377 /*------------------------------------------------------------------*/
379 addDecl (symbol * sym, int type, sym_link * p)
385 /* if we are passed a link then set head & tail */
394 head = tail = newLink ();
395 DCL_TYPE (head) = type;
398 /* if this is the first entry */
406 if (IS_SPEC (sym->etype) && IS_SPEC (head) && head == tail)
408 sym->etype = mergeSpec (sym->etype, head);
412 if (IS_SPEC (sym->etype) && !IS_SPEC (head) && head == tail)
415 while (t->next != sym->etype)
418 tail->next = sym->etype;
422 sym->etype->next = head;
428 /* if the type is a unknown pointer and has
429 a tspec then take the storage class const & volatile
430 attribute from the tspec & make it those of this
434 DCL_TYPE (p) == UPOINTER &&
437 if (!IS_SPEC (sym->etype))
439 sym->etype = sym->etype->next = newLink ();
440 sym->etype->class = SPECIFIER;
442 SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p));
443 SPEC_CONST (sym->etype) = SPEC_CONST (DCL_TSPEC (p));
444 SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p));
445 DCL_TSPEC (p) = NULL;
450 /*------------------------------------------------------------------
451 checkTypeSanity: prevent the user from doing e.g.:
453 ------------------------------------------------------------------*/
454 void checkTypeSanity(sym_link *dest, char *name) {
458 //printf ("sanity check skipped for %s\n", name);
464 //printf ("checking sanity for %s\n", name);
466 if ((SPEC_NOUN(dest)==V_CHAR ||
467 SPEC_NOUN(dest)==V_FLOAT ||
468 SPEC_NOUN(dest)==V_DOUBLE ||
469 SPEC_NOUN(dest)==V_VOID) &&
470 (SPEC_SHORT(dest) || SPEC_LONG(dest))) {
471 // long or short for char float double or void
472 werror (E_LONG_OR_SHORT_INVALID, noun, name);
474 if ((SPEC_NOUN(dest)==V_FLOAT ||
475 SPEC_NOUN(dest)==V_DOUBLE ||
476 SPEC_NOUN(dest)==V_VOID) &&
477 (SPEC_SIGNED(dest) || SPEC_USIGN(dest))) {
478 // signed or unsigned for float double or void
479 werror (E_SIGNED_OR_UNSIGNED_INVALID, noun, name);
481 if (SPEC_SIGNED(dest) && SPEC_USIGN(dest)) {
482 // signed AND unsigned
483 werror (E_SIGNED_AND_UNSIGNED_INVALID, noun, name);
485 if (SPEC_SHORT(dest) && SPEC_LONG(dest)) {
487 werror (E_LONG_AND_SHORT_INVALID, noun, name);
492 /*------------------------------------------------------------------*/
493 /* mergeSpec - merges two specifiers and returns the new one */
494 /*------------------------------------------------------------------*/
496 mergeSpec (sym_link * dest, sym_link * src)
499 /* we shouldn't redeclare the type */
500 if ((SPEC_NOUN (dest) && SPEC_NOUN (src)) &&
501 (SPEC_NOUN(dest) != SPEC_NOUN(src))) {
502 werror(E_TWO_OR_MORE_DATA_TYPES, yylval.yychar);
505 /* if noun different then src overrides */
506 if (SPEC_NOUN (dest) != SPEC_NOUN (src) && !SPEC_NOUN (dest))
507 SPEC_NOUN (dest) = SPEC_NOUN (src);
509 /* if destination has no storage class */
510 if (!SPEC_SCLS (dest) ||
511 ((SPEC_SCLS(dest) == S_CONSTANT || SPEC_SCLS(dest) == S_REGISTER) &&
513 SPEC_SCLS (dest) = SPEC_SCLS (src);
514 /* special case for const */
515 /* copy all the specifications */
516 SPEC_LONG (dest) |= SPEC_LONG (src);
517 SPEC_SHORT (dest) |= SPEC_SHORT (src);
518 SPEC_USIGN (dest) |= SPEC_USIGN (src);
519 SPEC_SIGNED (dest) |= SPEC_SIGNED (src);
520 SPEC_STAT (dest) |= SPEC_STAT (src);
521 SPEC_EXTR (dest) |= SPEC_EXTR (src);
522 SPEC_ABSA (dest) |= SPEC_ABSA (src);
523 SPEC_RENT (dest) |= SPEC_RENT (src);
524 SPEC_INTN (dest) |= SPEC_INTN (src);
525 SPEC_BANK (dest) |= SPEC_BANK (src);
526 SPEC_VOLATILE (dest) |= SPEC_VOLATILE (src);
527 SPEC_CRTCL (dest) |= SPEC_CRTCL (src);
528 SPEC_ADDR (dest) |= SPEC_ADDR (src);
529 SPEC_OCLS (dest) = SPEC_OCLS (src);
530 SPEC_BLEN (dest) |= SPEC_BLEN (src);
531 SPEC_BSTR (dest) |= SPEC_BSTR (src);
532 SPEC_TYPEDEF (dest) |= SPEC_TYPEDEF (src);
533 SPEC_NONBANKED (dest) |= SPEC_NONBANKED (src);
534 SPEC_NAKED (dest) |= SPEC_NAKED (src);
536 if (IS_STRUCT (dest) && SPEC_STRUCT (dest) == NULL)
537 SPEC_STRUCT (dest) = SPEC_STRUCT (src);
542 /*------------------------------------------------------------------*/
543 /* cloneSpec - copies the entire spec and returns a new spec */
544 /*------------------------------------------------------------------*/
546 cloneSpec (sym_link * src)
550 /* go thru chain till we find the specifier */
551 while (src && src->class != SPECIFIER)
555 memcpy (spec, src, sizeof (sym_link));
559 /*------------------------------------------------------------------*/
560 /* genSymName - generates and returns a name used for anonymous vars */
561 /*------------------------------------------------------------------*/
563 genSymName (int level)
565 static int gCount = 0;
566 static char gname[SDCC_NAME_MAX + 1];
568 sprintf (gname, "__%04d%04d", level, gCount++);
572 /*------------------------------------------------------------------*/
573 /* getSpec - returns the specifier part from a declaration chain */
574 /*------------------------------------------------------------------*/
576 getSpec (sym_link * p)
581 while (p && !(IS_SPEC (p)))
587 /*------------------------------------------------------------------*/
588 /* newCharLink() - creates an char type */
589 /*------------------------------------------------------------------*/
596 p->class = SPECIFIER;
597 SPEC_NOUN (p) = V_CHAR;
602 /*------------------------------------------------------------------*/
603 /* newFloatLink - a new Float type */
604 /*------------------------------------------------------------------*/
611 p->class = SPECIFIER;
612 SPEC_NOUN (p) = V_FLOAT;
617 /*------------------------------------------------------------------*/
618 /* newLongLink() - new long type */
619 /*------------------------------------------------------------------*/
626 p->class = SPECIFIER;
627 SPEC_NOUN (p) = V_INT;
633 /*------------------------------------------------------------------*/
634 /* newIntLink() - creates an int type */
635 /*------------------------------------------------------------------*/
642 p->class = SPECIFIER;
643 SPEC_NOUN (p) = V_INT;
648 /*------------------------------------------------------------------*/
649 /* getSize - returns size of a type chain in bits */
650 /*------------------------------------------------------------------*/
652 getSize (sym_link * p)
654 /* if nothing return 0 */
658 { /* if this is the specifier then */
659 switch (SPEC_NOUN (p))
660 { /* depending on the specifier type */
662 return (IS_LONG (p) ? LONGSIZE : (IS_SHORT (p) ? SHORTSIZE : INTSIZE));
670 return SPEC_STRUCT (p)->size;
676 return ((SPEC_BLEN (p) / 8) + (SPEC_BLEN (p) % 8 ? 1 : 0));
682 /* this is a specifier */
683 switch (DCL_TYPE (p))
688 return DCL_ELEM (p) * getSize (p->next);
705 /*------------------------------------------------------------------*/
706 /* bitsForType - returns # of bits required to store this type */
707 /*------------------------------------------------------------------*/
709 bitsForType (sym_link * p)
711 /* if nothing return 0 */
716 { /* if this is the specifier then */
718 switch (SPEC_NOUN (p))
719 { /* depending on the specifier type */
721 return (IS_LONG (p) ? LONGSIZE * 8 : (IS_SHORT (p) ? SHORTSIZE * 8 : INTSIZE * 8));
723 return FLOATSIZE * 8;
729 return SPEC_STRUCT (p)->size * 8;
735 return SPEC_BLEN (p);
741 /* this is a specifier */
742 switch (DCL_TYPE (p))
747 return DCL_ELEM (p) * getSize (p->next) * 8;
751 return (PTRSIZE * 8);
755 return (FPTRSIZE * 8);
757 return (GPTRSIZE * 8);
764 /*------------------------------------------------------------------*/
765 /* copySymbolChain - copies a symbol chain */
766 /*------------------------------------------------------------------*/
768 copySymbolChain (symbol * src)
775 dest = copySymbol (src);
776 dest->next = copySymbolChain (src->next);
780 /*------------------------------------------------------------------*/
781 /* copySymbol - makes a copy of a symbol */
782 /*------------------------------------------------------------------*/
784 copySymbol (symbol * src)
791 dest = newSymbol (src->name, src->level);
792 memcpy (dest, src, sizeof (symbol));
793 dest->level = src->level;
794 dest->block = src->block;
795 dest->ival = copyIlist (src->ival);
796 dest->type = copyLinkChain (src->type);
797 dest->etype = getSpec (dest->type);
799 dest->args = copyValueChain (src->args);
800 dest->key = src->key;
801 dest->calleeSave = src->calleeSave;
802 dest->allocreq = src->allocreq;
806 /*------------------------------------------------------------------*/
807 /* reverseSyms - reverses the links for a symbol chain */
808 /*------------------------------------------------------------------*/
810 reverseSyms (symbol * sym)
812 symbol *prev, *curr, *next;
827 sym->next = (void *) NULL;
831 /*------------------------------------------------------------------*/
832 /* reverseLink - reverses the links for a type chain */
833 /*------------------------------------------------------------------*/
835 reverseLink (sym_link * type)
837 sym_link *prev, *curr, *next;
852 type->next = (void *) NULL;
856 /*------------------------------------------------------------------*/
857 /* addSymChain - adds a symbol chain to the symboltable */
858 /*------------------------------------------------------------------*/
860 addSymChain (symbol * symHead)
862 symbol *sym = symHead;
866 for (; sym != NULL; sym = sym->next)
870 /* if already exists in the symbol table then check if
871 the previous was an extern definition if yes then
872 then check if the type match, if the types match then
873 delete the current entry and add the new entry */
874 if ((csym = findSymWithLevel (SymbolTab, sym)) &&
875 csym->level == sym->level)
878 /* previous definition extern ? */
879 if (1 || IS_EXTERN (csym->etype))
881 /* do types match ? */
882 if (checkType (csym->type, sym->type) != 1)
884 werror (E_DUPLICATE, csym->name);
886 /* delete current entry */
887 deleteSym (SymbolTab, csym, csym->name);
889 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
891 else /* not extern */
892 werror (E_DUPLICATE, sym->name);
896 /* check if previously defined */
897 if (csym && csym->level == sym->level)
899 /* if the previous one was declared as extern */
900 /* then check the type with the current one */
901 if (IS_EXTERN (csym->etype))
903 if (checkType (csym->type, sym->type) <= 0)
904 werror (W_EXTERN_MISMATCH, csym->name);
907 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
912 /*------------------------------------------------------------------*/
913 /* funcInChain - DCL Type 'FUNCTION' found in type chain */
914 /*------------------------------------------------------------------*/
916 funcInChain (sym_link * lnk)
927 /*------------------------------------------------------------------*/
928 /* structElemType - returns the type info of a sturct member */
929 /*------------------------------------------------------------------*/
931 structElemType (sym_link * stype, value * id, value ** argsp)
933 symbol *fields = (SPEC_STRUCT (stype) ? SPEC_STRUCT (stype)->fields : NULL);
934 sym_link *type, *etype;
935 sym_link *petype = getSpec (stype);
940 /* look for the id */
943 if (strcmp (fields->rname, id->name) == 0)
947 *argsp = fields->args;
949 type = copyLinkChain (fields->type);
950 etype = getSpec (type);
951 SPEC_SCLS (etype) = (SPEC_SCLS (petype) == S_REGISTER ?
952 SPEC_SCLS (etype) : SPEC_SCLS (petype));
955 fields = fields->next;
957 werror (E_NOT_MEMBER, id->name);
962 /*------------------------------------------------------------------*/
963 /* getStructElement - returns element of a tructure definition */
964 /*------------------------------------------------------------------*/
966 getStructElement (structdef * sdef, symbol * sym)
970 for (field = sdef->fields; field; field = field->next)
971 if (strcmp (field->name, sym->name) == 0)
974 werror (E_NOT_MEMBER, sym->name);
979 /*------------------------------------------------------------------*/
980 /* compStructSize - computes the size of a structure */
981 /*------------------------------------------------------------------*/
983 compStructSize (int su, structdef * sdef)
985 int sum = 0, usum = 0;
989 /* for the identifiers */
993 /* create the internal name for this variable */
994 sprintf (loop->rname, "_%s", loop->name);
995 loop->offset = (su == UNION ? sum = 0 : sum);
996 SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
998 /* if this is a bit field */
1001 /* change it to a unsigned bit */
1002 SPEC_NOUN (loop->etype) = V_BIT;
1003 SPEC_USIGN (loop->etype) = 1;
1004 /* check if this fit into the remaining */
1005 /* bits of this byte else align it to the */
1006 /* next byte boundary */
1007 if ((SPEC_BLEN (loop->etype) = loop->bitVar) <= (8 - bitOffset)) {
1008 SPEC_BSTR (loop->etype) = bitOffset;
1009 if ((bitOffset += (loop->bitVar % 8)) == 8)
1012 else /* does not fit */ {
1014 SPEC_BSTR (loop->etype) = bitOffset;
1015 sum += (loop->bitVar / 8);
1016 bitOffset += (loop->bitVar % 8);
1018 /* if this is the last field then pad */
1019 if (!loop->next && bitOffset && bitOffset != 8) {
1026 sum += getSize (loop->type);
1029 /* if function then do the arguments for it */
1030 if (funcInChain (loop->type)) {
1031 processFuncArgs (loop, 1);
1036 /* if this is not a bitfield but the */
1037 /* previous one was and did not take */
1038 /* the whole byte then pad the rest */
1039 if ((loop && !loop->bitVar) && bitOffset) {
1044 /* if union then size = sizeof larget field */
1046 usum = max (usum, sum);
1050 return (su == UNION ? usum : sum);
1053 /*------------------------------------------------------------------*/
1054 /* checkSClass - check the storage class specification */
1055 /*------------------------------------------------------------------*/
1057 checkSClass (symbol * sym)
1059 /* type is literal can happen foe enums change
1061 if (SPEC_SCLS (sym->etype) == S_LITERAL && !SPEC_ENUM (sym->etype))
1062 SPEC_SCLS (sym->etype) = S_AUTO;
1064 /* if sfr or sbit then must also be */
1065 /* volatile the initial value will be xlated */
1066 /* to an absolute address */
1067 if (SPEC_SCLS (sym->etype) == S_SBIT ||
1068 SPEC_SCLS (sym->etype) == S_SFR)
1070 SPEC_VOLATILE (sym->etype) = 1;
1071 /* if initial value given */
1074 SPEC_ABSA (sym->etype) = 1;
1075 SPEC_ADDR (sym->etype) =
1076 (int) list2int (sym->ival);
1081 /* if absolute address given then it mark it as
1083 if (IS_ABSOLUTE (sym->etype))
1084 SPEC_VOLATILE (sym->etype) = 1;
1086 /* global variables declared const put into code */
1087 if (sym->level == 0 &&
1088 SPEC_SCLS (sym->etype) == S_CONSTANT)
1090 SPEC_SCLS (sym->etype) = S_CODE;
1091 SPEC_CONST (sym->etype) = 1;
1094 /* global variable in code space is a constant */
1095 if (sym->level == 0 &&
1096 SPEC_SCLS (sym->etype) == S_CODE &&
1098 SPEC_CONST (sym->etype) = 1;
1101 /* if bit variable then no storage class can be */
1102 /* specified since bit is already a storage */
1103 if (IS_BITVAR (sym->etype) &&
1104 (SPEC_SCLS (sym->etype) != S_FIXED &&
1105 SPEC_SCLS (sym->etype) != S_SBIT &&
1106 SPEC_SCLS (sym->etype) != S_BIT)
1109 werror (E_BITVAR_STORAGE, sym->name);
1110 SPEC_SCLS (sym->etype) = S_FIXED;
1113 /* extern variables cannot be initialized */
1114 if (IS_EXTERN (sym->etype) && sym->ival)
1116 werror (E_EXTERN_INIT, sym->name);
1120 /* if this is an automatic symbol then */
1121 /* storage class will be ignored and */
1122 /* symbol will be allocated on stack/ */
1123 /* data depending on flag */
1125 (options.stackAuto || reentrant) &&
1126 (SPEC_SCLS (sym->etype) != S_AUTO &&
1127 SPEC_SCLS (sym->etype) != S_FIXED &&
1128 SPEC_SCLS (sym->etype) != S_REGISTER &&
1129 SPEC_SCLS (sym->etype) != S_STACK &&
1130 SPEC_SCLS (sym->etype) != S_XSTACK &&
1131 SPEC_SCLS (sym->etype) != S_CONSTANT))
1133 werror (E_AUTO_ASSUMED, sym->name);
1134 SPEC_SCLS (sym->etype) = S_AUTO;
1137 /* automatic symbols cannot be given */
1138 /* an absolute address ignore it */
1140 SPEC_ABSA (sym->etype) &&
1141 (options.stackAuto || reentrant))
1143 werror (E_AUTO_ABSA, sym->name);
1144 SPEC_ABSA (sym->etype) = 0;
1147 /* arrays & pointers cannot be defined for bits */
1148 /* SBITS or SFRs or BIT */
1149 if ((IS_ARRAY (sym->type) || IS_PTR (sym->type)) &&
1150 (SPEC_NOUN (sym->etype) == V_BIT ||
1151 SPEC_NOUN (sym->etype) == V_SBIT ||
1152 SPEC_SCLS (sym->etype) == S_SFR))
1153 werror (E_BIT_ARRAY, sym->name);
1155 /* if this is a bit|sbit then set length & start */
1156 if (SPEC_NOUN (sym->etype) == V_BIT ||
1157 SPEC_NOUN (sym->etype) == V_SBIT)
1159 SPEC_BLEN (sym->etype) = 1;
1160 SPEC_BSTR (sym->etype) = 0;
1163 /* variables declared in CODE space must have */
1164 /* initializers if not an extern */
1165 if (SPEC_SCLS (sym->etype) == S_CODE &&
1166 sym->ival == NULL &&
1168 port->mem.code_ro &&
1169 !IS_EXTERN (sym->etype) &&
1170 !funcInChain (sym->type))
1171 werror (E_CODE_NO_INIT, sym->name);
1173 /* if parameter or local variable then change */
1174 /* the storage class to reflect where the var will go */
1175 if (sym->level && SPEC_SCLS (sym->etype) == S_FIXED &&
1176 !IS_STATIC(sym->etype))
1178 if (options.stackAuto || (currFunc && IS_RENT (currFunc->etype)))
1180 SPEC_SCLS (sym->etype) = (options.useXstack ?
1181 S_XSTACK : S_STACK);
1185 /* hack-o-matic! I see no reason why the useXstack option should ever
1186 * control this allcoation, but the code was originally that way, and
1187 * changing it for non-390 ports breaks the compiler badly.
1189 bool useXdata = TARGET_IS_DS390 ? 1 : options.useXstack;
1190 SPEC_SCLS (sym->etype) = (useXdata ?
1196 /*------------------------------------------------------------------*/
1197 /* changePointer - change pointer to functions */
1198 /*------------------------------------------------------------------*/
1200 changePointer (symbol * sym)
1204 /* go thru the chain of declarations */
1205 /* if we find a pointer to a function */
1206 /* unconditionally change it to a ptr */
1208 for (p = sym->type; p; p = p->next)
1210 if (!IS_SPEC (p) && DCL_TYPE (p) == UPOINTER)
1211 DCL_TYPE (p) = GPOINTER;
1212 if (IS_PTR (p) && IS_FUNC (p->next))
1213 DCL_TYPE (p) = CPOINTER;
1217 /*------------------------------------------------------------------*/
1218 /* checkDecl - does semantic validation of a declaration */
1219 /*------------------------------------------------------------------*/
1221 checkDecl (symbol * sym)
1224 checkSClass (sym); /* check the storage class */
1225 changePointer (sym); /* change pointers if required */
1227 /* if this is an array without any dimension
1228 then update the dimension from the initial value */
1229 if (IS_ARRAY (sym->type) && !DCL_ELEM (sym->type))
1230 DCL_ELEM (sym->type) = getNelements (sym->type, sym->ival);
1235 /*------------------------------------------------------------------*/
1236 /* copyLinkChain - makes a copy of the link chain & rets ptr 2 head */
1237 /*------------------------------------------------------------------*/
1239 copyLinkChain (sym_link * p)
1241 sym_link *head, *curr, *loop;
1244 head = loop = (curr ? newLink () : (void *) NULL);
1247 memcpy (loop, curr, sizeof (sym_link)); /* copy it */
1248 loop->next = (curr->next ? newLink () : (void *) NULL);
1257 /*------------------------------------------------------------------*/
1258 /* cleanUpBlock - cleansup the symbol table specified for all the */
1259 /* symbols in the given block */
1260 /*------------------------------------------------------------------*/
1262 cleanUpBlock (bucket ** table, int block)
1267 /* go thru the entire table */
1268 for (i = 0; i < 256; i++)
1270 for (chain = table[i]; chain; chain = chain->next)
1272 if (chain->block >= block)
1274 deleteSym (table, chain->sym, chain->name);
1280 /*------------------------------------------------------------------*/
1281 /* cleanUpLevel - cleansup the symbol table specified for all the */
1282 /* symbols in the given level */
1283 /*------------------------------------------------------------------*/
1285 cleanUpLevel (bucket ** table, int level)
1290 /* go thru the entire table */
1291 for (i = 0; i < 256; i++)
1293 for (chain = table[i]; chain; chain = chain->next)
1295 if (chain->level >= level)
1297 deleteSym (table, chain->sym, chain->name);
1303 /*------------------------------------------------------------------*/
1304 /* computeType - computes the resultant type from two types */
1305 /*------------------------------------------------------------------*/
1307 computeType (sym_link * type1, sym_link * type2)
1311 sym_link *etype1 = getSpec (type1);
1312 sym_link *etype2 = getSpec (type2);
1314 /* if one of them is a float then result is a float */
1315 /* here we assume that the types passed are okay */
1316 /* and can be cast to one another */
1317 /* which ever is greater in size */
1318 if (IS_FLOAT (etype1) || IS_FLOAT (etype2))
1319 rType = newFloatLink ();
1321 /* if only one of them is a bit variable
1322 then the other one prevails */
1323 if (IS_BITVAR (etype1) && !IS_BITVAR (etype2))
1324 rType = copyLinkChain (type2);
1325 else if (IS_BITVAR (etype2) && !IS_BITVAR (etype1))
1326 rType = copyLinkChain (type1);
1328 /* if one of them is a pointer then that
1331 rType = copyLinkChain (type1);
1332 else if (IS_PTR (type2))
1333 rType = copyLinkChain (type2);
1334 else if (getSize (type1) > getSize (type2))
1335 rType = copyLinkChain (type1);
1337 rType = copyLinkChain (type2);
1339 reType = getSpec (rType);
1341 /* if either of them unsigned then make this unsigned */
1342 if ((SPEC_USIGN (etype1) || SPEC_USIGN (etype2)) && !IS_FLOAT (reType))
1343 SPEC_USIGN (reType) = 1;
1345 /* if result is a literal then make not so */
1346 if (IS_LITERAL (reType))
1347 SPEC_SCLS (reType) = S_REGISTER;
1352 /*------------------------------------------------------------------*/
1353 /* checkType - will do type check return 1 if match */
1354 /*------------------------------------------------------------------*/
1356 checkType (sym_link * dest, sym_link * src)
1367 /* if dest is a declarator then */
1372 if (DCL_TYPE (src) == DCL_TYPE (dest))
1373 return checkType (dest->next, src->next);
1374 else if (IS_PTR (src) && IS_PTR (dest))
1376 else if (IS_PTR (dest) && IS_ARRAY (src))
1378 else if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
1379 return -1 * checkType (dest->next, src);
1383 else if (IS_PTR (dest) && IS_INTEGRAL (src))
1389 /* if one is a specifier and the other is not */
1390 if ((IS_SPEC (src) && !IS_SPEC (dest)) ||
1391 (IS_SPEC (dest) && !IS_SPEC (src)))
1394 /* if one of them is a void then ok */
1395 if (SPEC_NOUN (dest) == V_VOID &&
1396 SPEC_NOUN (src) != V_VOID)
1399 if (SPEC_NOUN (dest) != V_VOID &&
1400 SPEC_NOUN (src) == V_VOID)
1403 /* char === to short */
1404 if (SPEC_NOUN (dest) == V_CHAR &&
1405 SPEC_NOUN (src) == V_INT &&
1407 return (SPEC_USIGN (src) == SPEC_USIGN (dest) ? 1 : -2);
1409 if (SPEC_NOUN (src) == V_CHAR &&
1410 SPEC_NOUN (dest) == V_INT &&
1412 return (SPEC_USIGN (src) == SPEC_USIGN (dest) ? 1 : -2);
1414 /* if they are both bitfields then if the lengths
1415 and starts don't match */
1416 if (IS_BITFIELD (dest) && IS_BITFIELD (src) &&
1417 (SPEC_BLEN (dest) != SPEC_BLEN (src) ||
1418 SPEC_BSTR (dest) != SPEC_BSTR (src)))
1421 /* it is a specifier */
1422 if (SPEC_NOUN (dest) != SPEC_NOUN (src))
1424 if (SPEC_USIGN (dest) == SPEC_USIGN (src) &&
1425 IS_INTEGRAL (dest) && IS_INTEGRAL (src) &&
1426 getSize (dest) == getSize (src))
1428 else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src))
1433 else if (IS_STRUCT (dest))
1435 if (SPEC_STRUCT (dest) != SPEC_STRUCT (src))
1440 if (SPEC_LONG (dest) != SPEC_LONG (src))
1443 if (SPEC_SHORT (dest) != SPEC_SHORT (src))
1446 if (SPEC_USIGN (dest) != SPEC_USIGN (src))
1452 /*------------------------------------------------------------------*/
1453 /* inCalleeSaveList - return 1 if found in calle save list */
1454 /*------------------------------------------------------------------*/
1456 inCalleeSaveList (char *s)
1460 for (i = 0; options.calleeSaves[i]; i++)
1461 if (strcmp (options.calleeSaves[i], s) == 0)
1467 /*-----------------------------------------------------------------*/
1468 /* aggregateArgToPointer: change an agggregate type function */
1469 /* argument to a pointer to that type. */
1470 /*-----------------------------------------------------------------*/
1472 aggregateArgToPointer (value * val)
1474 if (IS_AGGREGATE (val->type))
1476 /* if this is a structure */
1477 /* then we need to add a new link */
1478 if (IS_STRUCT (val->type))
1480 /* first lets add DECLARATOR type */
1481 sym_link *p = val->type;
1483 werror (W_STRUCT_AS_ARG, val->name);
1484 val->type = newLink ();
1485 val->type->next = p;
1488 /* change to a pointer depending on the */
1489 /* storage class specified */
1490 switch (SPEC_SCLS (val->etype))
1493 DCL_TYPE (val->type) = IPOINTER;
1496 DCL_TYPE (val->type) = PPOINTER;
1499 if (TARGET_IS_DS390)
1501 /* The AUTO and REGISTER classes should probably
1502 * also become generic pointers, but I haven't yet
1503 * devised a test case for that.
1505 DCL_TYPE (val->type) = GPOINTER;
1512 DCL_TYPE (val->type) = POINTER;
1515 DCL_TYPE (val->type) = CPOINTER;
1518 DCL_TYPE (val->type) = FPOINTER;
1521 DCL_TYPE (val->type) = EEPPOINTER;
1524 DCL_TYPE (val->type) = GPOINTER;
1527 /* is there is a symbol associated then */
1528 /* change the type of the symbol as well */
1531 val->sym->type = copyLinkChain (val->type);
1532 val->sym->etype = getSpec (val->sym->type);
1536 /*------------------------------------------------------------------*/
1537 /* checkFunction - does all kinds of check on a function */
1538 /*------------------------------------------------------------------*/
1540 checkFunction (symbol * sym)
1543 value *exargs, *acargs;
1546 /* if not type then some kind of error */
1550 /* if the function has no type then make it return int */
1551 if (!sym->type->next)
1552 sym->type->next = sym->etype = newIntLink ();
1554 /* function cannot return aggregate */
1555 if (IS_AGGREGATE (sym->type->next))
1557 werror (E_FUNC_AGGR, sym->name);
1561 /* function cannot return bit */
1562 if (IS_BITVAR (sym->type->next))
1564 werror (E_FUNC_BIT, sym->name);
1568 /* check if this function is defined as calleeSaves
1569 then mark it as such */
1570 sym->calleeSave = inCalleeSaveList (sym->name);
1572 /* if interrupt service routine */
1573 /* then it cannot have arguments */
1574 if (sym->args && IS_ISR (sym->etype) && !IS_VOID (sym->args->type))
1576 werror (E_INT_ARGS, sym->name);
1580 if (!(csym = findSym (SymbolTab, sym, sym->name)))
1581 return 1; /* not defined nothing more to check */
1583 /* check if body already present */
1584 if (csym && csym->fbody)
1586 werror (E_FUNC_BODY, sym->name);
1590 /* check the return value type */
1591 if (checkType (csym->type, sym->type) <= 0)
1593 werror (E_PREV_DEF_CONFLICT, csym->name, "type");
1594 werror (E_CONTINUE, "previous definition type ");
1595 printTypeChain (csym->type, stderr);
1596 fprintf (stderr, "\n");
1597 werror (E_CONTINUE, "current definition type ");
1598 printTypeChain (sym->type, stderr);
1599 fprintf (stderr, "\n");
1603 if (SPEC_INTRTN (csym->etype) != SPEC_INTRTN (sym->etype))
1605 werror (E_PREV_DEF_CONFLICT, csym->name, "interrupt");
1609 if (SPEC_BANK (csym->etype) != SPEC_BANK (sym->etype))
1611 werror (E_PREV_DEF_CONFLICT, csym->name, "using");
1615 /* compare expected agrs with actual args */
1616 exargs = csym->args;
1619 /* for all the expected args do */
1622 exargs = exargs->next, acargs = acargs->next, argCnt++)
1625 /* If the actual argument is an array, any prototype
1626 * will have modified it to a pointer. Duplicate that
1629 if (IS_AGGREGATE (acargs->type))
1631 checkValue = copyValue (acargs);
1632 aggregateArgToPointer (checkValue);
1636 checkValue = acargs;
1639 if (checkType (exargs->type, checkValue->type) <= 0)
1641 werror (E_ARG_TYPE, argCnt);
1646 /* if one them ended we have a problem */
1647 if ((exargs && !acargs && !IS_VOID (exargs->type)) ||
1648 (!exargs && acargs && !IS_VOID (acargs->type)))
1649 werror (E_ARG_COUNT);
1651 /* replace with this defition */
1652 sym->cdef = csym->cdef;
1653 deleteSym (SymbolTab, csym, csym->name);
1654 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
1655 if (IS_EXTERN (csym->etype) && !
1656 IS_EXTERN (sym->etype))
1658 addSet (&publics, sym);
1663 /*-----------------------------------------------------------------*/
1664 /* processFuncArgs - does some processing with function args */
1665 /*-----------------------------------------------------------------*/
1667 processFuncArgs (symbol * func, int ignoreName)
1672 /* if this function has variable argument list */
1673 /* then make the function a reentrant one */
1675 SPEC_RENT (func->etype) = 1;
1677 /* check if this function is defined as calleeSaves
1678 then mark it as such */
1679 func->calleeSave = inCalleeSaveList (func->name);
1681 val = func->args; /* loop thru all the arguments */
1683 /* if it is void then remove parameters */
1684 if (val && IS_VOID (val->type))
1690 /* reset regparm for the port */
1691 (*port->reset_regparms) ();
1692 /* if any of the arguments is an aggregate */
1693 /* change it to pointer to the same type */
1696 /* mark it as a register parameter if
1697 the function does not have VA_ARG
1698 and as port dictates */
1699 if (!func->hasVargs &&
1700 (*port->reg_parm) (val->type))
1702 SPEC_REGPARM (val->etype) = 1;
1705 if (IS_AGGREGATE (val->type))
1707 aggregateArgToPointer (val);
1713 /* if this is an internal generated function call */
1715 /* ignore --stack-auto for this one, we don't know how it is compiled */
1716 /* simply trust on --int-long-reent or --float-reent */
1717 if (IS_RENT(func->etype)) {
1721 /* if this function is reentrant or */
1722 /* automatics r 2b stacked then nothing */
1723 if (IS_RENT (func->etype) || options.stackAuto)
1732 /* if a symbolname is not given */
1733 /* synthesize a variable name */
1737 sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
1738 val->sym = newSymbol (val->name, 1);
1739 SPEC_OCLS (val->etype) = port->mem.default_local_map;
1740 val->sym->type = copyLinkChain (val->type);
1741 val->sym->etype = getSpec (val->sym->type);
1742 val->sym->_isparm = 1;
1743 strcpy (val->sym->rname, val->name);
1744 SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
1745 SPEC_STAT (func->etype);
1746 addSymChain (val->sym);
1749 else /* symbol name given create synth name */
1752 sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
1753 strcpy (val->sym->rname, val->name);
1754 val->sym->_isparm = 1;
1755 SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
1756 (options.model != MODEL_SMALL ? xdata : data);
1757 SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
1758 SPEC_STAT (func->etype);
1764 /*-----------------------------------------------------------------*/
1765 /* isSymbolEqual - compares two symbols return 1 if they match */
1766 /*-----------------------------------------------------------------*/
1768 isSymbolEqual (symbol * dest, symbol * src)
1770 /* if pointers match then equal */
1774 /* if one of them is null then don't match */
1778 /* if both of them have rname match on rname */
1779 if (dest->rname[0] && src->rname[0])
1780 return (!strcmp (dest->rname, src->rname));
1782 /* otherwise match on name */
1783 return (!strcmp (dest->name, src->name));
1786 void PT(sym_link *type)
1788 printTypeChain(type,0);
1790 /*-----------------------------------------------------------------*/
1791 /* printTypeChain - prints the type chain in human readable form */
1792 /*-----------------------------------------------------------------*/
1794 printTypeChain (sym_link * type, FILE * of)
1808 if (DCL_PTR_VOLATILE(type)) {
1809 fprintf (of, "volatile ");
1811 switch (DCL_TYPE (type))
1814 fprintf (of, "function ");
1817 fprintf (of, "_generic * ");
1818 if (DCL_PTR_CONST (type))
1819 fprintf (of, "const ");
1822 fprintf (of, "_code * ");
1823 if (DCL_PTR_CONST (type))
1824 fprintf (of, "const ");
1827 fprintf (of, "_far * ");
1828 if (DCL_PTR_CONST (type))
1829 fprintf (of, "const ");
1832 fprintf (of, "_eeprom * ");
1833 if (DCL_PTR_CONST (type))
1834 fprintf (of, "const ");
1838 fprintf (of, "_near * ");
1839 if (DCL_PTR_CONST (type))
1840 fprintf (of, "const ");
1843 fprintf (of, "_idata *");
1844 if (DCL_PTR_CONST (type))
1845 fprintf (of, "const ");
1848 fprintf (of, "_pdata *");
1849 if (DCL_PTR_CONST (type))
1850 fprintf (of, "const ");
1853 fprintf (of, " _unkown *");
1854 if (DCL_PTR_CONST (type))
1855 fprintf (of, "const ");
1858 fprintf (of, "array of ");
1864 if (SPEC_VOLATILE (type))
1865 fprintf (of, "volatile ");
1866 if (SPEC_USIGN (type))
1867 fprintf (of, "unsigned ");
1868 if (SPEC_CONST (type))
1869 fprintf (of, "const ");
1871 switch (SPEC_NOUN (type))
1875 fprintf (of, "long ");
1876 if (IS_SHORT (type))
1877 fprintf (of, "short ");
1878 fprintf (of, "int ");
1882 fprintf (of, "char ");
1886 fprintf (of, "void ");
1890 fprintf (of, "float ");
1894 fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
1898 fprintf (of, "sbit ");
1902 fprintf (of, "bit {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
1906 fprintf (of, "double ");
1910 fprintf (of, "unknown type ");
1920 /*-----------------------------------------------------------------*/
1921 /* cdbTypeInfo - print the type information for debugger */
1922 /*-----------------------------------------------------------------*/
1924 cdbTypeInfo (sym_link * type, FILE * of)
1926 fprintf (of, "{%d}", getSize (type));
1931 switch (DCL_TYPE (type))
1934 fprintf (of, "DF,");
1937 fprintf (of, "DG,");
1940 fprintf (of, "DC,");
1943 fprintf (of, "DX,");
1946 fprintf (of, "DD,");
1949 fprintf (of, "DI,");
1952 fprintf (of, "DP,");
1955 fprintf (of, "DA,");
1958 fprintf (of, "DA%d,", DCL_ELEM (type));
1966 switch (SPEC_NOUN (type))
1971 else if (IS_SHORT (type))
1990 fprintf (of, "ST%s", SPEC_STRUCT (type)->tag);
1998 fprintf (of, "SB%d$%d", SPEC_BSTR (type), SPEC_BLEN (type));
2005 if (SPEC_USIGN (type))
2013 /*-----------------------------------------------------------------*/
2014 /* cdbSymbol - prints a symbol & its type information for debugger */
2015 /*-----------------------------------------------------------------*/
2017 cdbSymbol (symbol * sym, FILE * of, int isStructSym, int isFunc)
2029 fprintf (of, "S:"); /* symbol record */
2030 /* if this is not a structure symbol then
2031 we need to figure out the scope information */
2037 if (IS_STATIC (sym->etype))
2038 fprintf (of, "F%s$", moduleName); /* scope is file */
2040 fprintf (of, "G$"); /* scope is global */
2043 /* symbol is local */
2044 fprintf (of, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
2047 fprintf (of, "S$"); /* scope is structure */
2049 /* print the name, & mangled name */
2050 fprintf (of, "%s$%d$%d(", sym->name,
2051 sym->level, sym->block);
2053 cdbTypeInfo (sym->type, of);
2056 /* print the address space */
2057 map = SPEC_OCLS (sym->etype);
2058 fprintf (of, "%c,%d,%d",
2059 (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
2061 /* if assigned to registers then output register names */
2062 /* if this is a function then print
2063 if is it an interrupt routine & interrupt number
2064 and the register bank it is using */
2066 fprintf (of, ",%d,%d,%d", SPEC_INTRTN (sym->etype),
2067 SPEC_INTN (sym->etype), SPEC_BANK (sym->etype));
2068 /* alternate location to find this symbol @ : eg registers
2075 /*-----------------------------------------------------------------*/
2076 /* cdbStruct - print a structure for debugger */
2077 /*-----------------------------------------------------------------*/
2079 cdbStruct (structdef * sdef, int block, FILE * of,
2080 int inStruct, char *tag)
2085 /* if block # then must have function scope */
2086 fprintf (of, "F%s$", moduleName);
2087 fprintf (of, "%s[", (tag ? tag : sdef->tag));
2088 for (sym = sdef->fields; sym; sym = sym->next)
2090 fprintf (of, "({%d}", sym->offset);
2091 cdbSymbol (sym, of, TRUE, FALSE);
2099 /*------------------------------------------------------------------*/
2100 /* cdbStructBlock - calls struct printing for a blcks */
2101 /*------------------------------------------------------------------*/
2103 cdbStructBlock (int block, FILE * of)
2106 bucket **table = StructTab;
2110 /* go thru the entire table */
2111 for (i = 0; i < 256; i++)
2113 for (chain = table[i]; chain; chain = chain->next)
2115 if (chain->block >= block)
2117 cdbStruct ((structdef *) chain->sym, chain->block, of, 0, NULL);
2123 /*-----------------------------------------------------------------*/
2124 /* powof2 - returns power of two for the number if number is pow 2 */
2125 /*-----------------------------------------------------------------*/
2127 powof2 (unsigned long num)
2140 if (n1s > 1 || nshifts == 0)
2156 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
2157 symbol *__muldiv[3][3][2];
2158 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
2159 sym_link *__multypes[3][2];
2160 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
2161 symbol *__conv[2][3][2];
2163 sym_link *floatType;
2166 _makeRegParam (symbol * sym)
2170 val = sym->args; /* loop thru all the arguments */
2172 /* reset regparm for the port */
2173 (*port->reset_regparms) ();
2176 SPEC_REGPARM (val->etype) = 1;
2181 /*-----------------------------------------------------------------*/
2182 /* initCSupport - create functions for C support routines */
2183 /*-----------------------------------------------------------------*/
2187 const char *smuldivmod[] =
2191 const char *sbwd[] =
2193 "char", "int", "long"
2200 int bwd, su, muldivmod, tofrom;
2202 floatType = newFloatLink ();
2204 for (bwd = 0; bwd < 3; bwd++)
2221 __multypes[bwd][0] = l;
2222 __multypes[bwd][1] = copyLinkChain (l);
2223 SPEC_USIGN (__multypes[bwd][1]) = 1;
2226 __fsadd = funcOfType ("__fsadd", floatType, floatType, 2, options.float_rent);
2227 __fssub = funcOfType ("__fssub", floatType, floatType, 2, options.float_rent);
2228 __fsmul = funcOfType ("__fsmul", floatType, floatType, 2, options.float_rent);
2229 __fsdiv = funcOfType ("__fsdiv", floatType, floatType, 2, options.float_rent);
2230 __fseq = funcOfType ("__fseq", CHARTYPE, floatType, 2, options.float_rent);
2231 __fsneq = funcOfType ("__fsneq", CHARTYPE, floatType, 2, options.float_rent);
2232 __fslt = funcOfType ("__fslt", CHARTYPE, floatType, 2, options.float_rent);
2233 __fslteq = funcOfType ("__fslteq", CHARTYPE, floatType, 2, options.float_rent);
2234 __fsgt = funcOfType ("__fsgt", CHARTYPE, floatType, 2, options.float_rent);
2235 __fsgteq = funcOfType ("__fsgteq", CHARTYPE, floatType, 2, options.float_rent);
2237 for (tofrom = 0; tofrom < 2; tofrom++)
2239 for (bwd = 0; bwd < 3; bwd++)
2241 for (su = 0; su < 2; su++)
2245 sprintf (buffer, "__fs2%s%s", ssu[su], sbwd[bwd]);
2246 __conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
2250 sprintf (buffer, "__%s%s2fs", ssu[su], sbwd[bwd]);
2251 __conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
2257 for (muldivmod = 0; muldivmod < 3; muldivmod++)
2259 for (bwd = 0; bwd < 3; bwd++)
2261 for (su = 0; su < 2; su++)
2263 sprintf (buffer, "_%s%s%s",
2264 smuldivmod[muldivmod],
2267 __muldiv[muldivmod][bwd][su] = funcOfType (buffer, __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
2268 SPEC_NONBANKED (__muldiv[muldivmod][bwd][su]->etype) = 1;
2269 if (bwd < port->muldiv.force_reg_param_below)
2270 _makeRegParam (__muldiv[muldivmod][bwd][su]);