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 if (getenv("DEBUG_SANITY")) {
107 fprintf (stderr, "addSym: %s\n", sname);
109 /* Make sure sym is a symbol and not a structdef */
110 if (StructTab!=stab) checkTypeSanity((symbol *)sym);
112 /* the symbols are always added at the head of the list */
114 /* get a free entry */
115 bp = Safe_calloc (1, sizeof (bucket));
117 bp->sym = sym; /* update the symbol pointer */
118 bp->level = level; /* update the nest level */
120 strcpy (bp->name, sname); /* copy the name into place */
122 /* if this is the first entry */
125 bp->prev = bp->next = (void *) NULL; /* point to nothing */
128 /* not first entry then add @ head of list */
138 /*-----------------------------------------------------------------*/
139 /* deleteSym - deletes a symbol from the hash Table entry */
140 /*-----------------------------------------------------------------*/
142 deleteSym (bucket ** stab, void *sym, char *sname)
150 /* find the symbol */
153 if (bp->sym == sym) /* found it then break out */
154 break; /* of the loop */
158 if (!bp) /* did not find it */
160 /* if this is the first one in the chain */
164 if (stab[i]) /* if chain ! empty */
165 stab[i]->prev = (void *) NULL;
167 /* middle || end of chain */
170 if (bp->next) /* if not end of chain */
171 bp->next->prev = bp->prev;
173 bp->prev->next = bp->next;
178 /*-----------------------------------------------------------------*/
179 /* findSym - finds a symbol in a table */
180 /*-----------------------------------------------------------------*/
182 findSym (bucket ** stab, void *sym, const char *sname)
186 bp = stab[hashKey (sname)];
189 if (bp->sym == sym || strcmp (bp->name, sname) == 0)
194 return (bp ? bp->sym : (void *) NULL);
197 /*-----------------------------------------------------------------*/
198 /* findSymWithLevel - finds a symbol with a name & level */
199 /*-----------------------------------------------------------------*/
201 findSymWithLevel (bucket ** stab, symbol * sym)
205 bp = stab[hashKey (sym->name)];
208 ** do the search from the head of the list since the
209 ** elements are added at the head it is ensured that
210 ** we will find the deeper definitions before we find
211 ** the global ones. we need to check for symbols with
212 ** level <= to the level given, if levels match then block
213 ** numbers need to match as well
218 if (strcmp (bp->name, sym->name) == 0 && bp->level <= sym->level)
220 /* if this is parameter then nothing else need to be checked */
221 if (((symbol *) (bp->sym))->_isparm)
223 /* if levels match then block numbers hsould also match */
224 if (bp->level && bp->level == sym->level && bp->block == sym->block)
226 /* if levels don't match then we are okay */
227 if (bp->level && bp->level != sym->level && bp->block <= sym->block)
229 /* if this is a global variable then we are ok too */
237 return (void *) NULL;
240 /*-----------------------------------------------------------------*/
241 /* findSymWithBlock - finds a symbol with name in with a block */
242 /*-----------------------------------------------------------------*/
244 findSymWithBlock (bucket ** stab, symbol * sym, int block)
248 bp = stab[hashKey (sym->name)];
251 if (strcmp (bp->name, sym->name) == 0 &&
257 return (bp ? bp->sym : (void *) NULL);
260 /*------------------------------------------------------------------*/
261 /* newSymbol () - returns a new pointer to a symbol */
262 /*------------------------------------------------------------------*/
264 newSymbol (char *name, int scope)
268 sym = Safe_calloc (1, sizeof (symbol));
270 strcpy (sym->name, name); /* copy the name */
271 sym->level = scope; /* set the level */
272 sym->block = currBlockno;
273 sym->lineDef = yylineno; /* set the line number */
277 /*------------------------------------------------------------------*/
278 /* newLink - creates a new link (declarator,specifier) */
279 /*------------------------------------------------------------------*/
285 p = Safe_calloc (1, sizeof (sym_link));
290 /*------------------------------------------------------------------*/
291 /* newStruct - creats a new structdef from the free list */
292 /*------------------------------------------------------------------*/
294 newStruct (char *tag)
298 s = Safe_calloc (1, sizeof (structdef));
300 strcpy (s->tag, tag); /* copy the tag */
304 /*------------------------------------------------------------------*/
305 /* pointerTypes - do the computation for the pointer types */
306 /*------------------------------------------------------------------*/
308 pointerTypes (sym_link * ptr, sym_link * type)
313 /* find the first pointer type */
314 while (ptr && !IS_PTR (ptr))
317 /* could not find it */
318 if (!ptr || IS_SPEC (ptr) ||
319 DCL_TYPE (ptr) != UPOINTER)
322 /* change the pointer type depending on the
323 storage class of the type */
326 DCL_PTR_CONST (ptr) = SPEC_CONST (type);
327 DCL_PTR_VOLATILE (ptr) = SPEC_VOLATILE (type);
328 switch (SPEC_SCLS (type))
331 DCL_TYPE (ptr) = FPOINTER;
334 DCL_TYPE (ptr) = IPOINTER;
337 DCL_TYPE (ptr) = PPOINTER;
340 DCL_TYPE (ptr) = POINTER;
343 DCL_PTR_CONST (ptr) = port->mem.code_ro;
344 DCL_TYPE (ptr) = CPOINTER;
347 DCL_TYPE (ptr) = EEPPOINTER;
350 DCL_TYPE (ptr) = GPOINTER;
353 /* the storage class of type ends here */
356 SPEC_VOLATILE (type) = 0;
359 /* now change all the remaining unknown pointers
360 to generic pointers */
363 if (!IS_SPEC (ptr) && DCL_TYPE (ptr) == UPOINTER)
364 DCL_TYPE (ptr) = GPOINTER;
368 /* same for the type although it is highly unlikely that
369 type will have a pointer */
372 if (!IS_SPEC (type) && DCL_TYPE (type) == UPOINTER)
373 DCL_TYPE (type) = GPOINTER;
379 /*------------------------------------------------------------------*/
380 /* addDecl - adds a declarator @ the end of a chain */
381 /*------------------------------------------------------------------*/
383 addDecl (symbol * sym, int type, sym_link * p)
389 /* if we are passed a link then set head & tail */
398 head = tail = newLink ();
399 DCL_TYPE (head) = type;
402 /* if this is the first entry */
410 if (IS_SPEC (sym->etype) && IS_SPEC (head) && head == tail)
412 sym->etype = mergeSpec (sym->etype, head);
416 if (IS_SPEC (sym->etype) && !IS_SPEC (head) && head == tail)
419 while (t->next != sym->etype)
422 tail->next = sym->etype;
426 sym->etype->next = head;
432 /* if the type is a unknown pointer and has
433 a tspec then take the storage class const & volatile
434 attribute from the tspec & make it those of this
438 DCL_TYPE (p) == UPOINTER &&
441 if (!IS_SPEC (sym->etype))
443 sym->etype = sym->etype->next = newLink ();
444 sym->etype->class = SPECIFIER;
446 SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p));
447 SPEC_CONST (sym->etype) = SPEC_CONST (DCL_TSPEC (p));
448 SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p));
449 DCL_TSPEC (p) = NULL;
454 /*------------------------------------------------------------------
455 checkTypeSanity: prevent the user from doing e.g.:
457 ------------------------------------------------------------------*/
458 void checkTypeSanity(symbol *sym) {
460 sym_link *etype=sym->etype;
461 char *name=sym->name;
464 if (getenv("DEBUG_SANITY")) {
465 printf ("sanity check skipped for %s\n", name);
470 noun=nounName(etype);
472 if (getenv("DEBUG_SANITY")) {
473 printf ("checking sanity for %s\n", name);
476 if ((SPEC_NOUN(etype)==V_CHAR ||
477 SPEC_NOUN(etype)==V_FLOAT ||
478 SPEC_NOUN(etype)==V_DOUBLE ||
479 SPEC_NOUN(etype)==V_VOID) &&
480 (SPEC_SHORT(etype) || SPEC_LONG(etype))) {
481 // long or short for char float double or void
482 werror (E_LONG_OR_SHORT_INVALID, noun, name);
484 if ((SPEC_NOUN(etype)==V_FLOAT ||
485 SPEC_NOUN(etype)==V_DOUBLE ||
486 SPEC_NOUN(etype)==V_VOID) &&
487 (SPEC_SIGNED(etype) || SPEC_USIGN(etype))) {
488 // signed or unsigned for float double or void
489 werror (E_SIGNED_OR_UNSIGNED_INVALID, noun, name);
492 // special case for "signed" and "unsigned"
493 if (!SPEC_NOUN(etype) && (SPEC_SIGNED(etype) || SPEC_USIGN(etype))) {
494 SPEC_NOUN(etype)=V_INT;
497 // special case for const globals
498 if (!SPEC_SCLS(etype) && SPEC_CONST(etype) && sym->level==0) {
499 SPEC_SCLS(etype)=S_CODE;
502 if (SPEC_SIGNED(etype) && SPEC_USIGN(etype)) {
503 // signed AND unsigned
504 werror (E_SIGNED_AND_UNSIGNED_INVALID, noun, name);
506 if (SPEC_SHORT(etype) && SPEC_LONG(etype)) {
508 werror (E_LONG_AND_SHORT_INVALID, noun, name);
513 /*------------------------------------------------------------------*/
514 /* mergeSpec - merges two specifiers and returns the new one */
515 /*------------------------------------------------------------------*/
517 mergeSpec (sym_link * dest, sym_link * src)
520 if (SPEC_NOUN(src)) {
521 if (!SPEC_NOUN(dest)) {
522 SPEC_NOUN(dest)=SPEC_NOUN(src);
524 /* we shouldn't redeclare the type */
525 if (getenv("DEBUG_SANITY")) {
526 fprintf (stderr, "mergeSpec: ");
527 werror(E_TWO_OR_MORE_DATA_TYPES, yylval.yychar);
532 if (SPEC_SCLS(src)) {
533 /* if destination has no storage class */
534 if (!SPEC_SCLS (dest) || SPEC_SCLS(dest)==S_REGISTER) {
535 SPEC_SCLS (dest) = SPEC_SCLS (src);
537 if (getenv("DEBUG_SANITY")) {
538 fprintf (stderr, "mergeSpec: ");
540 werror(E_TWO_OR_MORE_STORAGE_CLASSES, yylval.yychar);
544 /* copy all the specifications */
546 // we really should do:
548 if (SPEC_what(src)) {
549 if (SPEC_what(dest)) {
550 werror(W_DUPLICATE_SPEC, "what");
552 SPEC_what(dst)=SPEC_what(src);
555 // but there are more important thing right now
557 SPEC_LONG (dest) |= SPEC_LONG (src);
558 SPEC_SHORT (dest) |= SPEC_SHORT (src);
559 SPEC_USIGN (dest) |= SPEC_USIGN (src);
560 SPEC_SIGNED (dest) |= SPEC_SIGNED (src);
561 SPEC_STAT (dest) |= SPEC_STAT (src);
562 SPEC_EXTR (dest) |= SPEC_EXTR (src);
563 SPEC_ABSA (dest) |= SPEC_ABSA (src);
564 SPEC_RENT (dest) |= SPEC_RENT (src);
565 SPEC_INTN (dest) |= SPEC_INTN (src);
566 SPEC_BANK (dest) |= SPEC_BANK (src);
567 SPEC_VOLATILE (dest) |= SPEC_VOLATILE (src);
568 SPEC_CRTCL (dest) |= SPEC_CRTCL (src);
569 SPEC_ADDR (dest) |= SPEC_ADDR (src);
570 SPEC_OCLS (dest) = SPEC_OCLS (src);
571 SPEC_BLEN (dest) |= SPEC_BLEN (src);
572 SPEC_BSTR (dest) |= SPEC_BSTR (src);
573 SPEC_TYPEDEF (dest) |= SPEC_TYPEDEF (src);
574 SPEC_NONBANKED (dest) |= SPEC_NONBANKED (src);
575 SPEC_NAKED (dest) |= SPEC_NAKED (src);
577 if (IS_STRUCT (dest) && SPEC_STRUCT (dest) == NULL)
578 SPEC_STRUCT (dest) = SPEC_STRUCT (src);
583 /*------------------------------------------------------------------*/
584 /* cloneSpec - copies the entire spec and returns a new spec */
585 /*------------------------------------------------------------------*/
587 cloneSpec (sym_link * src)
591 /* go thru chain till we find the specifier */
592 while (src && src->class != SPECIFIER)
596 memcpy (spec, src, sizeof (sym_link));
600 /*------------------------------------------------------------------*/
601 /* genSymName - generates and returns a name used for anonymous vars */
602 /*------------------------------------------------------------------*/
604 genSymName (int level)
606 static int gCount = 0;
607 static char gname[SDCC_NAME_MAX + 1];
609 sprintf (gname, "__%04d%04d", level, gCount++);
613 /*------------------------------------------------------------------*/
614 /* getSpec - returns the specifier part from a declaration chain */
615 /*------------------------------------------------------------------*/
617 getSpec (sym_link * p)
622 while (p && !(IS_SPEC (p)))
628 /*------------------------------------------------------------------*/
629 /* newCharLink() - creates an char type */
630 /*------------------------------------------------------------------*/
637 p->class = SPECIFIER;
638 SPEC_NOUN (p) = V_CHAR;
643 /*------------------------------------------------------------------*/
644 /* newFloatLink - a new Float type */
645 /*------------------------------------------------------------------*/
652 p->class = SPECIFIER;
653 SPEC_NOUN (p) = V_FLOAT;
658 /*------------------------------------------------------------------*/
659 /* newLongLink() - new long type */
660 /*------------------------------------------------------------------*/
667 p->class = SPECIFIER;
668 SPEC_NOUN (p) = V_INT;
674 /*------------------------------------------------------------------*/
675 /* newIntLink() - creates an int type */
676 /*------------------------------------------------------------------*/
683 p->class = SPECIFIER;
684 SPEC_NOUN (p) = V_INT;
689 /*------------------------------------------------------------------*/
690 /* getSize - returns size of a type chain in bits */
691 /*------------------------------------------------------------------*/
693 getSize (sym_link * p)
695 /* if nothing return 0 */
699 { /* if this is the specifier then */
700 switch (SPEC_NOUN (p))
701 { /* depending on the specifier type */
703 return (IS_LONG (p) ? LONGSIZE : (IS_SHORT (p) ? SHORTSIZE : INTSIZE));
711 return SPEC_STRUCT (p)->size;
717 return ((SPEC_BLEN (p) / 8) + (SPEC_BLEN (p) % 8 ? 1 : 0));
723 /* this is a specifier */
724 switch (DCL_TYPE (p))
729 return DCL_ELEM (p) * getSize (p->next);
746 /*------------------------------------------------------------------*/
747 /* bitsForType - returns # of bits required to store this type */
748 /*------------------------------------------------------------------*/
750 bitsForType (sym_link * p)
752 /* if nothing return 0 */
757 { /* if this is the specifier then */
759 switch (SPEC_NOUN (p))
760 { /* depending on the specifier type */
762 return (IS_LONG (p) ? LONGSIZE * 8 : (IS_SHORT (p) ? SHORTSIZE * 8 : INTSIZE * 8));
764 return FLOATSIZE * 8;
770 return SPEC_STRUCT (p)->size * 8;
776 return SPEC_BLEN (p);
782 /* this is a specifier */
783 switch (DCL_TYPE (p))
788 return DCL_ELEM (p) * getSize (p->next) * 8;
792 return (PTRSIZE * 8);
796 return (FPTRSIZE * 8);
798 return (GPTRSIZE * 8);
805 /*------------------------------------------------------------------*/
806 /* copySymbolChain - copies a symbol chain */
807 /*------------------------------------------------------------------*/
809 copySymbolChain (symbol * src)
816 dest = copySymbol (src);
817 dest->next = copySymbolChain (src->next);
821 /*------------------------------------------------------------------*/
822 /* copySymbol - makes a copy of a symbol */
823 /*------------------------------------------------------------------*/
825 copySymbol (symbol * src)
832 dest = newSymbol (src->name, src->level);
833 memcpy (dest, src, sizeof (symbol));
834 dest->level = src->level;
835 dest->block = src->block;
836 dest->ival = copyIlist (src->ival);
837 dest->type = copyLinkChain (src->type);
838 dest->etype = getSpec (dest->type);
840 dest->args = copyValueChain (src->args);
841 dest->key = src->key;
842 dest->calleeSave = src->calleeSave;
843 dest->allocreq = src->allocreq;
847 /*------------------------------------------------------------------*/
848 /* reverseSyms - reverses the links for a symbol chain */
849 /*------------------------------------------------------------------*/
851 reverseSyms (symbol * sym)
853 symbol *prev, *curr, *next;
868 sym->next = (void *) NULL;
872 /*------------------------------------------------------------------*/
873 /* reverseLink - reverses the links for a type chain */
874 /*------------------------------------------------------------------*/
876 reverseLink (sym_link * type)
878 sym_link *prev, *curr, *next;
893 type->next = (void *) NULL;
897 /*------------------------------------------------------------------*/
898 /* addSymChain - adds a symbol chain to the symboltable */
899 /*------------------------------------------------------------------*/
901 addSymChain (symbol * symHead)
903 symbol *sym = symHead;
907 for (; sym != NULL; sym = sym->next)
911 /* if already exists in the symbol table then check if
912 the previous was an extern definition if yes then
913 then check if the type match, if the types match then
914 delete the current entry and add the new entry */
915 if ((csym = findSymWithLevel (SymbolTab, sym)) &&
916 csym->level == sym->level)
919 /* previous definition extern ? */
920 if (1 || IS_EXTERN (csym->etype))
922 /* do types match ? */
923 if (checkType (csym->type, sym->type) != 1)
925 werror (E_DUPLICATE, csym->name);
927 /* delete current entry */
928 deleteSym (SymbolTab, csym, csym->name);
930 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
932 else /* not extern */
933 werror (E_DUPLICATE, sym->name);
937 /* check if previously defined */
938 if (csym && csym->level == sym->level)
940 /* if the previous one was declared as extern */
941 /* then check the type with the current one */
942 if (IS_EXTERN (csym->etype))
944 if (checkType (csym->type, sym->type) <= 0)
945 werror (W_EXTERN_MISMATCH, csym->name);
948 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
953 /*------------------------------------------------------------------*/
954 /* funcInChain - DCL Type 'FUNCTION' found in type chain */
955 /*------------------------------------------------------------------*/
957 funcInChain (sym_link * lnk)
968 /*------------------------------------------------------------------*/
969 /* structElemType - returns the type info of a sturct member */
970 /*------------------------------------------------------------------*/
972 structElemType (sym_link * stype, value * id, value ** argsp)
974 symbol *fields = (SPEC_STRUCT (stype) ? SPEC_STRUCT (stype)->fields : NULL);
975 sym_link *type, *etype;
976 sym_link *petype = getSpec (stype);
981 /* look for the id */
984 if (strcmp (fields->rname, id->name) == 0)
988 *argsp = fields->args;
990 type = copyLinkChain (fields->type);
991 etype = getSpec (type);
992 SPEC_SCLS (etype) = (SPEC_SCLS (petype) == S_REGISTER ?
993 SPEC_SCLS (etype) : SPEC_SCLS (petype));
996 fields = fields->next;
998 werror (E_NOT_MEMBER, id->name);
1003 /*------------------------------------------------------------------*/
1004 /* getStructElement - returns element of a tructure definition */
1005 /*------------------------------------------------------------------*/
1007 getStructElement (structdef * sdef, symbol * sym)
1011 for (field = sdef->fields; field; field = field->next)
1012 if (strcmp (field->name, sym->name) == 0)
1015 werror (E_NOT_MEMBER, sym->name);
1017 return sdef->fields;
1020 /*------------------------------------------------------------------*/
1021 /* compStructSize - computes the size of a structure */
1022 /*------------------------------------------------------------------*/
1024 compStructSize (int su, structdef * sdef)
1026 int sum = 0, usum = 0;
1030 /* for the identifiers */
1031 loop = sdef->fields;
1034 /* create the internal name for this variable */
1035 sprintf (loop->rname, "_%s", loop->name);
1036 loop->offset = (su == UNION ? sum = 0 : sum);
1037 SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
1039 /* if this is a bit field */
1042 /* change it to a unsigned bit */
1043 SPEC_NOUN (loop->etype) = V_BIT;
1044 SPEC_USIGN (loop->etype) = 1;
1045 /* check if this fit into the remaining */
1046 /* bits of this byte else align it to the */
1047 /* next byte boundary */
1048 if ((SPEC_BLEN (loop->etype) = loop->bitVar) <= (8 - bitOffset)) {
1049 SPEC_BSTR (loop->etype) = bitOffset;
1050 if ((bitOffset += (loop->bitVar % 8)) == 8)
1053 else /* does not fit */ {
1055 SPEC_BSTR (loop->etype) = bitOffset;
1056 sum += (loop->bitVar / 8);
1057 bitOffset += (loop->bitVar % 8);
1059 /* if this is the last field then pad */
1060 if (!loop->next && bitOffset && bitOffset != 8) {
1067 sum += getSize (loop->type);
1070 /* if function then do the arguments for it */
1071 if (funcInChain (loop->type)) {
1072 processFuncArgs (loop, 1);
1077 /* if this is not a bitfield but the */
1078 /* previous one was and did not take */
1079 /* the whole byte then pad the rest */
1080 if ((loop && !loop->bitVar) && bitOffset) {
1085 /* if union then size = sizeof larget field */
1087 usum = max (usum, sum);
1091 return (su == UNION ? usum : sum);
1094 /*------------------------------------------------------------------*/
1095 /* checkSClass - check the storage class specification */
1096 /*------------------------------------------------------------------*/
1098 checkSClass (symbol * sym)
1100 /* type is literal can happen foe enums change
1102 if (SPEC_SCLS (sym->etype) == S_LITERAL && !SPEC_ENUM (sym->etype))
1103 SPEC_SCLS (sym->etype) = S_AUTO;
1105 /* if sfr or sbit then must also be */
1106 /* volatile the initial value will be xlated */
1107 /* to an absolute address */
1108 if (SPEC_SCLS (sym->etype) == S_SBIT ||
1109 SPEC_SCLS (sym->etype) == S_SFR)
1111 SPEC_VOLATILE (sym->etype) = 1;
1112 /* if initial value given */
1115 SPEC_ABSA (sym->etype) = 1;
1116 SPEC_ADDR (sym->etype) =
1117 (int) list2int (sym->ival);
1122 /* if absolute address given then it mark it as
1124 if (IS_ABSOLUTE (sym->etype))
1125 SPEC_VOLATILE (sym->etype) = 1;
1127 /* global variables declared const put into code */
1128 if (sym->level == 0 &&
1129 SPEC_SCLS (sym->etype) == S_CONSTANT)
1131 SPEC_SCLS (sym->etype) = S_CODE;
1132 SPEC_CONST (sym->etype) = 1;
1135 /* global variable in code space is a constant */
1136 if (sym->level == 0 &&
1137 SPEC_SCLS (sym->etype) == S_CODE &&
1139 SPEC_CONST (sym->etype) = 1;
1142 /* if bit variable then no storage class can be */
1143 /* specified since bit is already a storage */
1144 if (IS_BITVAR (sym->etype) &&
1145 (SPEC_SCLS (sym->etype) != S_FIXED &&
1146 SPEC_SCLS (sym->etype) != S_SBIT &&
1147 SPEC_SCLS (sym->etype) != S_BIT)
1150 werror (E_BITVAR_STORAGE, sym->name);
1151 SPEC_SCLS (sym->etype) = S_FIXED;
1154 /* extern variables cannot be initialized */
1155 if (IS_EXTERN (sym->etype) && sym->ival)
1157 werror (E_EXTERN_INIT, sym->name);
1161 /* if this is an automatic symbol then */
1162 /* storage class will be ignored and */
1163 /* symbol will be allocated on stack/ */
1164 /* data depending on flag */
1166 (options.stackAuto || reentrant) &&
1167 (SPEC_SCLS (sym->etype) != S_AUTO &&
1168 SPEC_SCLS (sym->etype) != S_FIXED &&
1169 SPEC_SCLS (sym->etype) != S_REGISTER &&
1170 SPEC_SCLS (sym->etype) != S_STACK &&
1171 SPEC_SCLS (sym->etype) != S_XSTACK &&
1172 SPEC_SCLS (sym->etype) != S_CONSTANT))
1174 werror (E_AUTO_ASSUMED, sym->name);
1175 SPEC_SCLS (sym->etype) = S_AUTO;
1178 /* automatic symbols cannot be given */
1179 /* an absolute address ignore it */
1181 SPEC_ABSA (sym->etype) &&
1182 (options.stackAuto || reentrant))
1184 werror (E_AUTO_ABSA, sym->name);
1185 SPEC_ABSA (sym->etype) = 0;
1188 /* arrays & pointers cannot be defined for bits */
1189 /* SBITS or SFRs or BIT */
1190 if ((IS_ARRAY (sym->type) || IS_PTR (sym->type)) &&
1191 (SPEC_NOUN (sym->etype) == V_BIT ||
1192 SPEC_NOUN (sym->etype) == V_SBIT ||
1193 SPEC_SCLS (sym->etype) == S_SFR))
1194 werror (E_BIT_ARRAY, sym->name);
1196 /* if this is a bit|sbit then set length & start */
1197 if (SPEC_NOUN (sym->etype) == V_BIT ||
1198 SPEC_NOUN (sym->etype) == V_SBIT)
1200 SPEC_BLEN (sym->etype) = 1;
1201 SPEC_BSTR (sym->etype) = 0;
1204 /* variables declared in CODE space must have */
1205 /* initializers if not an extern */
1206 if (SPEC_SCLS (sym->etype) == S_CODE &&
1207 sym->ival == NULL &&
1209 port->mem.code_ro &&
1210 !IS_EXTERN (sym->etype) &&
1211 !funcInChain (sym->type))
1212 werror (E_CODE_NO_INIT, sym->name);
1214 /* if parameter or local variable then change */
1215 /* the storage class to reflect where the var will go */
1216 if (sym->level && SPEC_SCLS (sym->etype) == S_FIXED &&
1217 !IS_STATIC(sym->etype))
1219 if (options.stackAuto || (currFunc && IS_RENT (currFunc->etype)))
1221 SPEC_SCLS (sym->etype) = (options.useXstack ?
1222 S_XSTACK : S_STACK);
1226 /* hack-o-matic! I see no reason why the useXstack option should ever
1227 * control this allcoation, but the code was originally that way, and
1228 * changing it for non-390 ports breaks the compiler badly.
1230 bool useXdata = TARGET_IS_DS390 ? 1 : options.useXstack;
1231 SPEC_SCLS (sym->etype) = (useXdata ?
1237 /*------------------------------------------------------------------*/
1238 /* changePointer - change pointer to functions */
1239 /*------------------------------------------------------------------*/
1241 changePointer (symbol * sym)
1245 /* go thru the chain of declarations */
1246 /* if we find a pointer to a function */
1247 /* unconditionally change it to a ptr */
1249 for (p = sym->type; p; p = p->next)
1251 if (!IS_SPEC (p) && DCL_TYPE (p) == UPOINTER)
1252 DCL_TYPE (p) = GPOINTER;
1253 if (IS_PTR (p) && IS_FUNC (p->next))
1254 DCL_TYPE (p) = CPOINTER;
1258 /*------------------------------------------------------------------*/
1259 /* checkDecl - does semantic validation of a declaration */
1260 /*------------------------------------------------------------------*/
1262 checkDecl (symbol * sym)
1265 checkSClass (sym); /* check the storage class */
1266 changePointer (sym); /* change pointers if required */
1268 /* if this is an array without any dimension
1269 then update the dimension from the initial value */
1270 if (IS_ARRAY (sym->type) && !DCL_ELEM (sym->type))
1271 DCL_ELEM (sym->type) = getNelements (sym->type, sym->ival);
1276 /*------------------------------------------------------------------*/
1277 /* copyLinkChain - makes a copy of the link chain & rets ptr 2 head */
1278 /*------------------------------------------------------------------*/
1280 copyLinkChain (sym_link * p)
1282 sym_link *head, *curr, *loop;
1285 head = loop = (curr ? newLink () : (void *) NULL);
1288 memcpy (loop, curr, sizeof (sym_link)); /* copy it */
1289 loop->next = (curr->next ? newLink () : (void *) NULL);
1298 /*------------------------------------------------------------------*/
1299 /* cleanUpBlock - cleansup the symbol table specified for all the */
1300 /* symbols in the given block */
1301 /*------------------------------------------------------------------*/
1303 cleanUpBlock (bucket ** table, int block)
1308 /* go thru the entire table */
1309 for (i = 0; i < 256; i++)
1311 for (chain = table[i]; chain; chain = chain->next)
1313 if (chain->block >= block)
1315 deleteSym (table, chain->sym, chain->name);
1321 /*------------------------------------------------------------------*/
1322 /* cleanUpLevel - cleansup the symbol table specified for all the */
1323 /* symbols in the given level */
1324 /*------------------------------------------------------------------*/
1326 cleanUpLevel (bucket ** table, int level)
1331 /* go thru the entire table */
1332 for (i = 0; i < 256; i++)
1334 for (chain = table[i]; chain; chain = chain->next)
1336 if (chain->level >= level)
1338 deleteSym (table, chain->sym, chain->name);
1344 /*------------------------------------------------------------------*/
1345 /* computeType - computes the resultant type from two types */
1346 /*------------------------------------------------------------------*/
1348 computeType (sym_link * type1, sym_link * type2)
1352 sym_link *etype1 = getSpec (type1);
1353 sym_link *etype2 = getSpec (type2);
1355 /* if one of them is a float then result is a float */
1356 /* here we assume that the types passed are okay */
1357 /* and can be cast to one another */
1358 /* which ever is greater in size */
1359 if (IS_FLOAT (etype1) || IS_FLOAT (etype2))
1360 rType = newFloatLink ();
1362 /* if only one of them is a bit variable
1363 then the other one prevails */
1364 if (IS_BITVAR (etype1) && !IS_BITVAR (etype2))
1365 rType = copyLinkChain (type2);
1366 else if (IS_BITVAR (etype2) && !IS_BITVAR (etype1))
1367 rType = copyLinkChain (type1);
1369 /* if one of them is a pointer then that
1372 rType = copyLinkChain (type1);
1373 else if (IS_PTR (type2))
1374 rType = copyLinkChain (type2);
1375 else if (getSize (type1) > getSize (type2))
1376 rType = copyLinkChain (type1);
1378 rType = copyLinkChain (type2);
1380 reType = getSpec (rType);
1382 /* if either of them unsigned then make this unsigned */
1383 if ((SPEC_USIGN (etype1) || SPEC_USIGN (etype2)) && !IS_FLOAT (reType))
1384 SPEC_USIGN (reType) = 1;
1386 /* if result is a literal then make not so */
1387 if (IS_LITERAL (reType))
1388 SPEC_SCLS (reType) = S_REGISTER;
1393 /*------------------------------------------------------------------*/
1394 /* checkType - will do type check return 1 if match */
1395 /*------------------------------------------------------------------*/
1397 checkType (sym_link * dest, sym_link * src)
1408 /* if dest is a declarator then */
1413 if (DCL_TYPE (src) == DCL_TYPE (dest))
1414 return checkType (dest->next, src->next);
1415 else if (IS_PTR (src) && IS_PTR (dest))
1417 else if (IS_PTR (dest) && IS_ARRAY (src))
1419 else if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
1420 return -1 * checkType (dest->next, src);
1424 else if (IS_PTR (dest) && IS_INTEGRAL (src))
1430 /* if one is a specifier and the other is not */
1431 if ((IS_SPEC (src) && !IS_SPEC (dest)) ||
1432 (IS_SPEC (dest) && !IS_SPEC (src)))
1435 /* if one of them is a void then ok */
1436 if (SPEC_NOUN (dest) == V_VOID &&
1437 SPEC_NOUN (src) != V_VOID)
1440 if (SPEC_NOUN (dest) != V_VOID &&
1441 SPEC_NOUN (src) == V_VOID)
1444 /* char === to short */
1445 if (SPEC_NOUN (dest) == V_CHAR &&
1446 SPEC_NOUN (src) == V_INT &&
1448 return (SPEC_USIGN (src) == SPEC_USIGN (dest) ? 1 : -2);
1450 if (SPEC_NOUN (src) == V_CHAR &&
1451 SPEC_NOUN (dest) == V_INT &&
1453 return (SPEC_USIGN (src) == SPEC_USIGN (dest) ? 1 : -2);
1455 /* if they are both bitfields then if the lengths
1456 and starts don't match */
1457 if (IS_BITFIELD (dest) && IS_BITFIELD (src) &&
1458 (SPEC_BLEN (dest) != SPEC_BLEN (src) ||
1459 SPEC_BSTR (dest) != SPEC_BSTR (src)))
1462 /* it is a specifier */
1463 if (SPEC_NOUN (dest) != SPEC_NOUN (src))
1465 if (SPEC_USIGN (dest) == SPEC_USIGN (src) &&
1466 IS_INTEGRAL (dest) && IS_INTEGRAL (src) &&
1467 getSize (dest) == getSize (src))
1469 else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src))
1474 else if (IS_STRUCT (dest))
1476 if (SPEC_STRUCT (dest) != SPEC_STRUCT (src))
1481 if (SPEC_LONG (dest) != SPEC_LONG (src))
1484 if (SPEC_SHORT (dest) != SPEC_SHORT (src))
1487 if (SPEC_USIGN (dest) != SPEC_USIGN (src))
1493 /*------------------------------------------------------------------*/
1494 /* inCalleeSaveList - return 1 if found in calle save list */
1495 /*------------------------------------------------------------------*/
1497 inCalleeSaveList (char *s)
1501 for (i = 0; options.calleeSaves[i]; i++)
1502 if (strcmp (options.calleeSaves[i], s) == 0)
1508 /*-----------------------------------------------------------------*/
1509 /* aggregateArgToPointer: change an agggregate type function */
1510 /* argument to a pointer to that type. */
1511 /*-----------------------------------------------------------------*/
1513 aggregateArgToPointer (value * val)
1515 if (IS_AGGREGATE (val->type))
1517 /* if this is a structure */
1518 /* then we need to add a new link */
1519 if (IS_STRUCT (val->type))
1521 /* first lets add DECLARATOR type */
1522 sym_link *p = val->type;
1524 werror (W_STRUCT_AS_ARG, val->name);
1525 val->type = newLink ();
1526 val->type->next = p;
1529 /* change to a pointer depending on the */
1530 /* storage class specified */
1531 switch (SPEC_SCLS (val->etype))
1534 DCL_TYPE (val->type) = IPOINTER;
1537 DCL_TYPE (val->type) = PPOINTER;
1540 if (TARGET_IS_DS390)
1542 /* The AUTO and REGISTER classes should probably
1543 * also become generic pointers, but I haven't yet
1544 * devised a test case for that.
1546 DCL_TYPE (val->type) = GPOINTER;
1553 DCL_TYPE (val->type) = POINTER;
1556 DCL_TYPE (val->type) = CPOINTER;
1559 DCL_TYPE (val->type) = FPOINTER;
1562 DCL_TYPE (val->type) = EEPPOINTER;
1565 DCL_TYPE (val->type) = GPOINTER;
1568 /* is there is a symbol associated then */
1569 /* change the type of the symbol as well */
1572 val->sym->type = copyLinkChain (val->type);
1573 val->sym->etype = getSpec (val->sym->type);
1577 /*------------------------------------------------------------------*/
1578 /* checkFunction - does all kinds of check on a function */
1579 /*------------------------------------------------------------------*/
1581 checkFunction (symbol * sym)
1584 value *exargs, *acargs;
1587 /* if not type then some kind of error */
1591 /* if the function has no type then make it return int */
1592 if (!sym->type->next)
1593 sym->type->next = sym->etype = newIntLink ();
1595 /* function cannot return aggregate */
1596 if (IS_AGGREGATE (sym->type->next))
1598 werror (E_FUNC_AGGR, sym->name);
1602 /* function cannot return bit */
1603 if (IS_BITVAR (sym->type->next))
1605 werror (E_FUNC_BIT, sym->name);
1609 /* check if this function is defined as calleeSaves
1610 then mark it as such */
1611 sym->calleeSave = inCalleeSaveList (sym->name);
1613 /* if interrupt service routine */
1614 /* then it cannot have arguments */
1615 if (sym->args && IS_ISR (sym->etype) && !IS_VOID (sym->args->type))
1617 werror (E_INT_ARGS, sym->name);
1621 if (!(csym = findSym (SymbolTab, sym, sym->name)))
1622 return 1; /* not defined nothing more to check */
1624 /* check if body already present */
1625 if (csym && csym->fbody)
1627 werror (E_FUNC_BODY, sym->name);
1631 /* check the return value type */
1632 if (checkType (csym->type, sym->type) <= 0)
1634 werror (E_PREV_DEF_CONFLICT, csym->name, "type");
1635 werror (E_CONTINUE, "previous definition type ");
1636 printTypeChain (csym->type, stderr);
1637 fprintf (stderr, "\n");
1638 werror (E_CONTINUE, "current definition type ");
1639 printTypeChain (sym->type, stderr);
1640 fprintf (stderr, "\n");
1644 if (SPEC_INTRTN (csym->etype) != SPEC_INTRTN (sym->etype))
1646 werror (E_PREV_DEF_CONFLICT, csym->name, "interrupt");
1650 if (SPEC_BANK (csym->etype) != SPEC_BANK (sym->etype))
1652 werror (E_PREV_DEF_CONFLICT, csym->name, "using");
1656 /* compare expected agrs with actual args */
1657 exargs = csym->args;
1660 /* for all the expected args do */
1663 exargs = exargs->next, acargs = acargs->next, argCnt++)
1666 /* If the actual argument is an array, any prototype
1667 * will have modified it to a pointer. Duplicate that
1670 if (IS_AGGREGATE (acargs->type))
1672 checkValue = copyValue (acargs);
1673 aggregateArgToPointer (checkValue);
1677 checkValue = acargs;
1680 if (checkType (exargs->type, checkValue->type) <= 0)
1682 werror (E_ARG_TYPE, argCnt);
1687 /* if one them ended we have a problem */
1688 if ((exargs && !acargs && !IS_VOID (exargs->type)) ||
1689 (!exargs && acargs && !IS_VOID (acargs->type)))
1690 werror (E_ARG_COUNT);
1692 /* replace with this defition */
1693 sym->cdef = csym->cdef;
1694 deleteSym (SymbolTab, csym, csym->name);
1695 addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
1696 if (IS_EXTERN (csym->etype) && !
1697 IS_EXTERN (sym->etype))
1699 addSet (&publics, sym);
1704 /*-----------------------------------------------------------------*/
1705 /* processFuncArgs - does some processing with function args */
1706 /*-----------------------------------------------------------------*/
1708 processFuncArgs (symbol * func, int ignoreName)
1713 /* if this function has variable argument list */
1714 /* then make the function a reentrant one */
1716 SPEC_RENT (func->etype) = 1;
1718 /* check if this function is defined as calleeSaves
1719 then mark it as such */
1720 func->calleeSave = inCalleeSaveList (func->name);
1722 val = func->args; /* loop thru all the arguments */
1724 /* if it is void then remove parameters */
1725 if (val && IS_VOID (val->type))
1731 /* reset regparm for the port */
1732 (*port->reset_regparms) ();
1733 /* if any of the arguments is an aggregate */
1734 /* change it to pointer to the same type */
1737 /* mark it as a register parameter if
1738 the function does not have VA_ARG
1739 and as port dictates */
1740 if (!func->hasVargs &&
1741 (*port->reg_parm) (val->type))
1743 SPEC_REGPARM (val->etype) = 1;
1746 if (IS_AGGREGATE (val->type))
1748 aggregateArgToPointer (val);
1754 /* if this is an internal generated function call */
1756 /* ignore --stack-auto for this one, we don't know how it is compiled */
1757 /* simply trust on --int-long-reent or --float-reent */
1758 if (IS_RENT(func->etype)) {
1762 /* if this function is reentrant or */
1763 /* automatics r 2b stacked then nothing */
1764 if (IS_RENT (func->etype) || options.stackAuto)
1773 /* if a symbolname is not given */
1774 /* synthesize a variable name */
1778 sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
1779 val->sym = newSymbol (val->name, 1);
1780 SPEC_OCLS (val->etype) = port->mem.default_local_map;
1781 val->sym->type = copyLinkChain (val->type);
1782 val->sym->etype = getSpec (val->sym->type);
1783 val->sym->_isparm = 1;
1784 strcpy (val->sym->rname, val->name);
1785 SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
1786 SPEC_STAT (func->etype);
1787 addSymChain (val->sym);
1790 else /* symbol name given create synth name */
1793 sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
1794 strcpy (val->sym->rname, val->name);
1795 val->sym->_isparm = 1;
1796 SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
1797 (options.model != MODEL_SMALL ? xdata : data);
1798 SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
1799 SPEC_STAT (func->etype);
1805 /*-----------------------------------------------------------------*/
1806 /* isSymbolEqual - compares two symbols return 1 if they match */
1807 /*-----------------------------------------------------------------*/
1809 isSymbolEqual (symbol * dest, symbol * src)
1811 /* if pointers match then equal */
1815 /* if one of them is null then don't match */
1819 /* if both of them have rname match on rname */
1820 if (dest->rname[0] && src->rname[0])
1821 return (!strcmp (dest->rname, src->rname));
1823 /* otherwise match on name */
1824 return (!strcmp (dest->name, src->name));
1827 void PT(sym_link *type)
1829 printTypeChain(type,0);
1831 /*-----------------------------------------------------------------*/
1832 /* printTypeChain - prints the type chain in human readable form */
1833 /*-----------------------------------------------------------------*/
1835 printTypeChain (sym_link * type, FILE * of)
1849 if (DCL_PTR_VOLATILE(type)) {
1850 fprintf (of, "volatile ");
1852 switch (DCL_TYPE (type))
1855 fprintf (of, "function ");
1858 fprintf (of, "_generic * ");
1859 if (DCL_PTR_CONST (type))
1860 fprintf (of, "const ");
1863 fprintf (of, "_code * ");
1864 if (DCL_PTR_CONST (type))
1865 fprintf (of, "const ");
1868 fprintf (of, "_far * ");
1869 if (DCL_PTR_CONST (type))
1870 fprintf (of, "const ");
1873 fprintf (of, "_eeprom * ");
1874 if (DCL_PTR_CONST (type))
1875 fprintf (of, "const ");
1879 fprintf (of, "_near * ");
1880 if (DCL_PTR_CONST (type))
1881 fprintf (of, "const ");
1884 fprintf (of, "_idata *");
1885 if (DCL_PTR_CONST (type))
1886 fprintf (of, "const ");
1889 fprintf (of, "_pdata *");
1890 if (DCL_PTR_CONST (type))
1891 fprintf (of, "const ");
1894 fprintf (of, " _unkown *");
1895 if (DCL_PTR_CONST (type))
1896 fprintf (of, "const ");
1899 fprintf (of, "array of ");
1905 if (SPEC_VOLATILE (type))
1906 fprintf (of, "volatile ");
1907 if (SPEC_USIGN (type))
1908 fprintf (of, "unsigned ");
1909 if (SPEC_CONST (type))
1910 fprintf (of, "const ");
1912 switch (SPEC_NOUN (type))
1916 fprintf (of, "long ");
1917 if (IS_SHORT (type))
1918 fprintf (of, "short ");
1919 fprintf (of, "int ");
1923 fprintf (of, "char ");
1927 fprintf (of, "void ");
1931 fprintf (of, "float ");
1935 fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
1939 fprintf (of, "sbit ");
1943 fprintf (of, "bit {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
1947 fprintf (of, "double ");
1951 fprintf (of, "unknown type ");
1961 /*-----------------------------------------------------------------*/
1962 /* cdbTypeInfo - print the type information for debugger */
1963 /*-----------------------------------------------------------------*/
1965 cdbTypeInfo (sym_link * type, FILE * of)
1967 fprintf (of, "{%d}", getSize (type));
1972 switch (DCL_TYPE (type))
1975 fprintf (of, "DF,");
1978 fprintf (of, "DG,");
1981 fprintf (of, "DC,");
1984 fprintf (of, "DX,");
1987 fprintf (of, "DD,");
1990 fprintf (of, "DI,");
1993 fprintf (of, "DP,");
1996 fprintf (of, "DA,");
1999 fprintf (of, "DA%d,", DCL_ELEM (type));
2007 switch (SPEC_NOUN (type))
2012 else if (IS_SHORT (type))
2031 fprintf (of, "ST%s", SPEC_STRUCT (type)->tag);
2039 fprintf (of, "SB%d$%d", SPEC_BSTR (type), SPEC_BLEN (type));
2046 if (SPEC_USIGN (type))
2054 /*-----------------------------------------------------------------*/
2055 /* cdbSymbol - prints a symbol & its type information for debugger */
2056 /*-----------------------------------------------------------------*/
2058 cdbSymbol (symbol * sym, FILE * of, int isStructSym, int isFunc)
2070 fprintf (of, "S:"); /* symbol record */
2071 /* if this is not a structure symbol then
2072 we need to figure out the scope information */
2078 if (IS_STATIC (sym->etype))
2079 fprintf (of, "F%s$", moduleName); /* scope is file */
2081 fprintf (of, "G$"); /* scope is global */
2084 /* symbol is local */
2085 fprintf (of, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
2088 fprintf (of, "S$"); /* scope is structure */
2090 /* print the name, & mangled name */
2091 fprintf (of, "%s$%d$%d(", sym->name,
2092 sym->level, sym->block);
2094 cdbTypeInfo (sym->type, of);
2097 /* print the address space */
2098 map = SPEC_OCLS (sym->etype);
2099 fprintf (of, "%c,%d,%d",
2100 (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
2102 /* if assigned to registers then output register names */
2103 /* if this is a function then print
2104 if is it an interrupt routine & interrupt number
2105 and the register bank it is using */
2107 fprintf (of, ",%d,%d,%d", SPEC_INTRTN (sym->etype),
2108 SPEC_INTN (sym->etype), SPEC_BANK (sym->etype));
2109 /* alternate location to find this symbol @ : eg registers
2116 /*-----------------------------------------------------------------*/
2117 /* cdbStruct - print a structure for debugger */
2118 /*-----------------------------------------------------------------*/
2120 cdbStruct (structdef * sdef, int block, FILE * of,
2121 int inStruct, char *tag)
2126 /* if block # then must have function scope */
2127 fprintf (of, "F%s$", moduleName);
2128 fprintf (of, "%s[", (tag ? tag : sdef->tag));
2129 for (sym = sdef->fields; sym; sym = sym->next)
2131 fprintf (of, "({%d}", sym->offset);
2132 cdbSymbol (sym, of, TRUE, FALSE);
2140 /*------------------------------------------------------------------*/
2141 /* cdbStructBlock - calls struct printing for a blcks */
2142 /*------------------------------------------------------------------*/
2144 cdbStructBlock (int block, FILE * of)
2147 bucket **table = StructTab;
2151 /* go thru the entire table */
2152 for (i = 0; i < 256; i++)
2154 for (chain = table[i]; chain; chain = chain->next)
2156 if (chain->block >= block)
2158 cdbStruct ((structdef *) chain->sym, chain->block, of, 0, NULL);
2164 /*-----------------------------------------------------------------*/
2165 /* powof2 - returns power of two for the number if number is pow 2 */
2166 /*-----------------------------------------------------------------*/
2168 powof2 (unsigned long num)
2181 if (n1s > 1 || nshifts == 0)
2197 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
2198 symbol *__muldiv[3][3][2];
2199 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
2200 sym_link *__multypes[3][2];
2201 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
2202 symbol *__conv[2][3][2];
2204 sym_link *floatType;
2207 _makeRegParam (symbol * sym)
2211 val = sym->args; /* loop thru all the arguments */
2213 /* reset regparm for the port */
2214 (*port->reset_regparms) ();
2217 SPEC_REGPARM (val->etype) = 1;
2222 /*-----------------------------------------------------------------*/
2223 /* initCSupport - create functions for C support routines */
2224 /*-----------------------------------------------------------------*/
2228 const char *smuldivmod[] =
2232 const char *sbwd[] =
2234 "char", "int", "long"
2241 int bwd, su, muldivmod, tofrom;
2243 floatType = newFloatLink ();
2245 for (bwd = 0; bwd < 3; bwd++)
2262 __multypes[bwd][0] = l;
2263 __multypes[bwd][1] = copyLinkChain (l);
2264 SPEC_USIGN (__multypes[bwd][1]) = 1;
2267 __fsadd = funcOfType ("__fsadd", floatType, floatType, 2, options.float_rent);
2268 __fssub = funcOfType ("__fssub", floatType, floatType, 2, options.float_rent);
2269 __fsmul = funcOfType ("__fsmul", floatType, floatType, 2, options.float_rent);
2270 __fsdiv = funcOfType ("__fsdiv", floatType, floatType, 2, options.float_rent);
2271 __fseq = funcOfType ("__fseq", CHARTYPE, floatType, 2, options.float_rent);
2272 __fsneq = funcOfType ("__fsneq", CHARTYPE, floatType, 2, options.float_rent);
2273 __fslt = funcOfType ("__fslt", CHARTYPE, floatType, 2, options.float_rent);
2274 __fslteq = funcOfType ("__fslteq", CHARTYPE, floatType, 2, options.float_rent);
2275 __fsgt = funcOfType ("__fsgt", CHARTYPE, floatType, 2, options.float_rent);
2276 __fsgteq = funcOfType ("__fsgteq", CHARTYPE, floatType, 2, options.float_rent);
2278 for (tofrom = 0; tofrom < 2; tofrom++)
2280 for (bwd = 0; bwd < 3; bwd++)
2282 for (su = 0; su < 2; su++)
2286 sprintf (buffer, "__fs2%s%s", ssu[su], sbwd[bwd]);
2287 __conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
2291 sprintf (buffer, "__%s%s2fs", ssu[su], sbwd[bwd]);
2292 __conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
2298 for (muldivmod = 0; muldivmod < 3; muldivmod++)
2300 for (bwd = 0; bwd < 3; bwd++)
2302 for (su = 0; su < 2; su++)
2304 sprintf (buffer, "_%s%s%s",
2305 smuldivmod[muldivmod],
2308 __muldiv[muldivmod][bwd][su] = funcOfType (buffer, __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
2309 SPEC_NONBANKED (__muldiv[muldivmod][bwd][su]->etype) = 1;
2310 if (bwd < port->muldiv.force_reg_param_below)
2311 _makeRegParam (__muldiv[muldivmod][bwd][su]);