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 -------------------------------------------------------------------------*/
27 value *aggregateToPointer (value *val);
28 void printTypeChainRaw (sym_link * start, FILE * of);
30 void printFromToType(sym_link *from, sym_link *to) {
31 fprintf (stderr, "from type '");
32 printTypeChain (from, stderr);
33 fprintf (stderr, "'\nto type '");
34 printTypeChain (to, stderr);
35 fprintf (stderr, "'\n");
39 char *nounName(sym_link *sl) {
40 switch (SPEC_NOUN(sl))
43 if (SPEC_LONG(sl)) return "long";
44 if (sl->select.s._short) return "short";
47 case V_FLOAT: return "float";
48 case V_CHAR: return "char";
49 case V_VOID: return "void";
50 case V_STRUCT: return "struct";
51 case V_LABEL: return "label";
52 case V_BITFIELD: return "bitfield";
53 case V_BIT: return "bit";
54 case V_SBIT: return "sbit";
55 case V_DOUBLE: return "double";
60 bucket *SymbolTab[256]; /* the symbol table */
61 bucket *StructTab[256]; /* the structure table */
62 bucket *TypedefTab[256]; /* the typedef table */
63 bucket *LabelTab[256]; /* the Label table */
64 bucket *enumTab[256]; /* enumerated table */
66 /*------------------------------------------------------------------*/
67 /* initSymt () - initialises symbol table related stuff */
68 /*------------------------------------------------------------------*/
74 for (i = 0; i < 256; i++)
75 SymbolTab[i] = StructTab[i] = (void *) NULL;
79 /*-----------------------------------------------------------------*/
80 /* newBucket - allocates & returns a new bucket */
81 /*-----------------------------------------------------------------*/
87 bp = Safe_alloc ( sizeof (bucket));
92 /*-----------------------------------------------------------------*/
93 /* hashKey - computes the hashkey given a symbol name */
94 /*-----------------------------------------------------------------*/
96 hashKey (const char *s)
98 unsigned long key = 0;
105 /*-----------------------------------------------------------------*/
106 /* addSym - adds a symbol to the hash Table */
107 /*-----------------------------------------------------------------*/
109 addSym (bucket ** stab,
116 int i; /* index into the hash Table */
117 bucket *bp; /* temp bucket * */
120 symbol *csym = (symbol *)sym;
122 if (getenv("DEBUG_SANITY")) {
123 fprintf (stderr, "addSym: %s ", sname);
125 /* make sure the type is complete and sane */
126 checkTypeSanity(csym->etype, csym->name);
129 /* prevent overflow of the (r)name buffers */
130 if (strlen(sname)>SDCC_SYMNAME_MAX) {
131 werror (W_SYMBOL_NAME_TOO_LONG, SDCC_SYMNAME_MAX);
132 sname[SDCC_SYMNAME_MAX]='\0';
135 /* the symbols are always added at the head of the list */
137 /* get a free entry */
138 bp = Safe_alloc ( sizeof (bucket));
140 bp->sym = sym; /* update the symbol pointer */
141 bp->level = level; /* update the nest level */
143 strncpyz (bp->name, sname, sizeof(bp->name)); /* copy the name into place */
145 /* if this is the first entry */
148 bp->prev = bp->next = (void *) NULL; /* point to nothing */
151 /* not first entry then add @ head of list */
161 /*-----------------------------------------------------------------*/
162 /* deleteSym - deletes a symbol from the hash Table entry */
163 /*-----------------------------------------------------------------*/
165 deleteSym (bucket ** stab, void *sym, char *sname)
173 /* find the symbol */
176 if (bp->sym == sym) /* found it then break out */
177 break; /* of the loop */
181 if (!bp) /* did not find it */
183 /* if this is the first one in the chain */
187 if (stab[i]) /* if chain ! empty */
188 stab[i]->prev = (void *) NULL;
190 /* middle || end of chain */
193 if (bp->next) /* if not end of chain */
194 bp->next->prev = bp->prev;
196 bp->prev->next = bp->next;
201 /*-----------------------------------------------------------------*/
202 /* findSym - finds a symbol in a table */
203 /*-----------------------------------------------------------------*/
205 findSym (bucket ** stab, void *sym, const char *sname)
209 bp = stab[hashKey (sname)];
212 if (bp->sym == sym || strcmp (bp->name, sname) == 0)
217 return (bp ? bp->sym : (void *) NULL);
220 /*-----------------------------------------------------------------*/
221 /* findSymWithLevel - finds a symbol with a name & level */
222 /*-----------------------------------------------------------------*/
224 findSymWithLevel (bucket ** stab, symbol * sym)
228 bp = stab[hashKey (sym->name)];
231 ** do the search from the head of the list since the
232 ** elements are added at the head it is ensured that
233 ** we will find the deeper definitions before we find
234 ** the global ones. we need to check for symbols with
235 ** level <= to the level given, if levels match then block
236 ** numbers need to match as well
240 if (strcmp (bp->name, sym->name) == 0 && bp->level <= sym->level)
242 /* if this is parameter then nothing else need to be checked */
243 if (((symbol *) (bp->sym))->_isparm)
245 /* if levels match then block numbers should also match */
246 if (bp->level && bp->level == sym->level && bp->block == sym->block)
248 /* if levels don't match then we are okay */
249 if (bp->level && bp->level != sym->level && bp->block <= sym->block)
251 /* if this is a global variable then we are ok too */
259 return (void *) NULL;
262 /*-----------------------------------------------------------------*/
263 /* findSymWithBlock - finds a symbol with name in with a block */
264 /*-----------------------------------------------------------------*/
266 findSymWithBlock (bucket ** stab, symbol * sym, int block)
270 bp = stab[hashKey (sym->name)];
273 if (strcmp (bp->name, sym->name) == 0 &&
279 return (bp ? bp->sym : (void *) NULL);
282 /*------------------------------------------------------------------*/
283 /* newSymbol () - returns a new pointer to a symbol */
284 /*------------------------------------------------------------------*/
286 newSymbol (char *name, int scope)
290 sym = Safe_alloc ( sizeof (symbol));
292 strncpyz (sym->name, name, sizeof(sym->name)); /* copy the name */
293 sym->level = scope; /* set the level */
294 sym->block = currBlockno;
295 sym->lineDef = mylineno; /* set the line number */
299 /*------------------------------------------------------------------*/
300 /* newLink - creates a new link (declarator,specifier) */
301 /*------------------------------------------------------------------*/
303 newLink (SYM_LINK_CLASS select)
307 p = Safe_alloc ( sizeof (sym_link));
313 /*------------------------------------------------------------------*/
314 /* newStruct - creats a new structdef from the free list */
315 /*------------------------------------------------------------------*/
317 newStruct (char *tag)
321 s = Safe_alloc ( sizeof (structdef));
323 strncpyz (s->tag, tag, sizeof(s->tag)); /* copy the tag */
327 /*------------------------------------------------------------------*/
328 /* sclsFromPtr - Return the storage class a pointer points into. */
329 /* S_FIXED is returned for generic pointers or other */
330 /* unexpected cases */
331 /*------------------------------------------------------------------*/
333 sclsFromPtr(sym_link *ptr)
335 switch (DCL_TYPE (ptr))
358 /*------------------------------------------------------------------*/
359 /* pointerTypes - do the computation for the pointer types */
360 /*------------------------------------------------------------------*/
362 pointerTypes (sym_link * ptr, sym_link * type)
367 /* find the first pointer type */
368 while (ptr && !IS_PTR (ptr))
371 /* could not find it */
372 if (!ptr || IS_SPEC (ptr))
375 if (IS_PTR(ptr) && DCL_TYPE(ptr)!=UPOINTER) {
376 pointerTypes (ptr->next, type);
380 /* change the pointer type depending on the
381 storage class of the type */
384 switch (SPEC_SCLS (type))
387 DCL_TYPE (ptr) = FPOINTER;
390 DCL_TYPE (ptr) = IPOINTER;
393 DCL_TYPE (ptr) = PPOINTER;
396 DCL_TYPE (ptr) = POINTER;
399 DCL_TYPE (ptr) = CPOINTER;
402 DCL_TYPE (ptr) = EEPPOINTER;
405 DCL_TYPE (ptr) = port->unqualified_pointer;
408 /* the storage class of type ends here */
409 SPEC_SCLS (type) = 0;
412 /* now change all the remaining unknown pointers
413 to generic pointers */
416 if (!IS_SPEC (ptr) && DCL_TYPE (ptr) == UPOINTER)
417 DCL_TYPE (ptr) = port->unqualified_pointer;
421 /* same for the type although it is highly unlikely that
422 type will have a pointer */
425 if (!IS_SPEC (type) && DCL_TYPE (type) == UPOINTER)
426 DCL_TYPE (type) = port->unqualified_pointer;
431 /*------------------------------------------------------------------*/
432 /* addDecl - adds a declarator @ the end of a chain */
433 /*------------------------------------------------------------------*/
435 addDecl (symbol * sym, int type, sym_link * p)
441 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
442 fprintf (stderr, "SDCCsymt.c:addDecl(%s,%d,%p)\n", sym->name, type, p);
444 /* if we are passed a link then set head & tail */
453 head = tail = newLink (DECLARATOR);
454 DCL_TYPE (head) = type;
457 /* if this is the first entry */
465 if (IS_SPEC (sym->etype) && IS_SPEC (head) && head == tail)
467 sym->etype = mergeSpec (sym->etype, head, sym->name);
471 if (IS_SPEC (sym->etype) && !IS_SPEC (head) && head == tail)
474 while (t->next != sym->etype)
477 tail->next = sym->etype;
481 sym->etype->next = head;
487 /* if the type is an unknown pointer and has
488 a tspec then take the storage class const & volatile
489 attribute from the tspec & make it those of this
493 //DCL_TYPE (p) == UPOINTER &&
496 if (!IS_SPEC (sym->etype))
498 sym->etype = sym->etype->next = newLink (SPECIFIER);
500 SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p));
501 DCL_TSPEC (p) = NULL;
504 // if there is a function in this type chain
505 if (p && funcInChain(sym->type)) {
506 processFuncArgs (sym);
512 /*------------------------------------------------------------------
513 checkTypeSanity: prevent the user from doing e.g.:
515 ------------------------------------------------------------------*/
516 void checkTypeSanity(sym_link *etype, char *name) {
520 if (getenv("DEBUG_SANITY")) {
521 fprintf (stderr, "sanity check skipped for %s (etype==0)\n", name);
526 if (!IS_SPEC(etype)) {
527 if (getenv("DEBUG_SANITY")) {
528 fprintf (stderr, "sanity check skipped for %s (!IS_SPEC)\n", name);
533 noun=nounName(etype);
535 if (getenv("DEBUG_SANITY")) {
536 fprintf (stderr, "checking sanity for %s %p\n", name, etype);
539 if ((SPEC_NOUN(etype)==V_CHAR ||
540 SPEC_NOUN(etype)==V_FLOAT ||
541 SPEC_NOUN(etype)==V_DOUBLE ||
542 SPEC_NOUN(etype)==V_VOID) &&
543 (etype->select.s._short || SPEC_LONG(etype))) {
544 // long or short for char float double or void
545 werror (E_LONG_OR_SHORT_INVALID, noun, name);
547 if ((SPEC_NOUN(etype)==V_FLOAT ||
548 SPEC_NOUN(etype)==V_DOUBLE ||
549 SPEC_NOUN(etype)==V_VOID) &&
550 (etype->select.s._signed || SPEC_USIGN(etype))) {
551 // signed or unsigned for float double or void
552 werror (E_SIGNED_OR_UNSIGNED_INVALID, noun, name);
555 // special case for "short"
556 if (etype->select.s._short) {
557 SPEC_NOUN(etype) = options.shortis8bits ? V_CHAR : V_INT;
558 etype->select.s._short = 0;
562 "const a;" or "data b;" or "signed s" or "long l"
564 if (!SPEC_NOUN(etype)) {
565 SPEC_NOUN(etype)=V_INT;
568 if (etype->select.s._signed && SPEC_USIGN(etype)) {
569 // signed AND unsigned
570 werror (E_SIGNED_AND_UNSIGNED_INVALID, noun, name);
572 if (etype->select.s._short && SPEC_LONG(etype)) {
574 werror (E_LONG_AND_SHORT_INVALID, noun, name);
579 /*------------------------------------------------------------------*/
580 /* mergeSpec - merges two specifiers and returns the new one */
581 /*------------------------------------------------------------------*/
583 mergeSpec (sym_link * dest, sym_link * src, char *name)
585 if (!IS_SPEC(dest) || !IS_SPEC(src)) {
587 werror (E_INTERNAL_ERROR, __FILE__, __LINE__, "cannot merge declarator");
590 werror (E_SYNTAX_ERROR, yytext);
591 // the show must go on
596 if (SPEC_NOUN(src)) {
597 if (!SPEC_NOUN(dest)) {
598 SPEC_NOUN(dest)=SPEC_NOUN(src);
600 /* we shouldn't redeclare the type */
601 if (getenv("DEBUG_SANITY")) {
602 fprintf (stderr, "mergeSpec: ");
604 werror(E_TWO_OR_MORE_DATA_TYPES, name);
608 if (SPEC_SCLS(src)) {
609 /* if destination has no storage class */
610 if (!SPEC_SCLS (dest) || SPEC_SCLS(dest)==S_REGISTER) {
611 SPEC_SCLS (dest) = SPEC_SCLS (src);
613 if (getenv("DEBUG_SANITY")) {
614 fprintf (stderr, "mergeSpec: ");
616 werror(E_TWO_OR_MORE_STORAGE_CLASSES, name);
620 /* copy all the specifications */
622 // we really should do:
624 if (SPEC_what(src)) {
625 if (SPEC_what(dest)) {
626 werror(W_DUPLICATE_SPEC, "what");
628 SPEC_what(dst)|=SPEC_what(src);
631 // but there are more important thing right now
633 SPEC_LONG (dest) |= SPEC_LONG (src);
634 dest->select.s._short|=src->select.s._short;
635 SPEC_USIGN (dest) |= SPEC_USIGN (src);
636 dest->select.s._signed|=src->select.s._signed;
637 SPEC_STAT (dest) |= SPEC_STAT (src);
638 SPEC_EXTR (dest) |= SPEC_EXTR (src);
639 SPEC_CONST(dest) |= SPEC_CONST (src);
640 SPEC_ABSA (dest) |= SPEC_ABSA (src);
641 SPEC_VOLATILE (dest) |= SPEC_VOLATILE (src);
642 SPEC_ADDR (dest) |= SPEC_ADDR (src);
643 SPEC_OCLS (dest) = SPEC_OCLS (src);
644 SPEC_BLEN (dest) |= SPEC_BLEN (src);
645 SPEC_BSTR (dest) |= SPEC_BSTR (src);
646 SPEC_TYPEDEF (dest) |= SPEC_TYPEDEF (src);
647 SPEC_ENUM (dest) |= SPEC_ENUM (src);
648 if (SPEC_ARGREG(src) && !SPEC_ARGREG(dest))
649 SPEC_ARGREG(dest) = SPEC_ARGREG(src);
651 if (IS_STRUCT (dest) && SPEC_STRUCT (dest) == NULL)
652 SPEC_STRUCT (dest) = SPEC_STRUCT (src);
654 /* these are the only function attributes that will be set
655 in a specifier while parsing */
656 FUNC_NONBANKED(dest) |= FUNC_NONBANKED(src);
657 FUNC_BANKED(dest) |= FUNC_BANKED(src);
658 FUNC_ISCRITICAL(dest) |= FUNC_ISCRITICAL(src);
659 FUNC_ISREENT(dest) |= FUNC_ISREENT(src);
660 FUNC_ISNAKED(dest) |= FUNC_ISNAKED(src);
661 FUNC_ISISR(dest) |= FUNC_ISISR(src);
662 FUNC_ISJAVANATIVE(dest) |= FUNC_ISJAVANATIVE(src);
663 FUNC_ISBUILTIN(dest) |= FUNC_ISBUILTIN(src);
664 FUNC_ISOVERLAY(dest) |= FUNC_ISOVERLAY(src);
665 FUNC_INTNO(dest) |= FUNC_INTNO(src);
666 FUNC_REGBANK(dest) |= FUNC_REGBANK(src);
671 /*------------------------------------------------------------------*/
672 /* genSymName - generates and returns a name used for anonymous vars */
673 /*------------------------------------------------------------------*/
675 genSymName (int level)
677 static int gCount = 0;
678 static char gname[SDCC_NAME_MAX + 1];
680 SNPRINTF (gname, sizeof(gname), "__%04d%04d", level, gCount++);
684 /*------------------------------------------------------------------*/
685 /* getSpec - returns the specifier part from a declaration chain */
686 /*------------------------------------------------------------------*/
688 getSpec (sym_link * p)
693 while (p && !(IS_SPEC (p)))
699 /*------------------------------------------------------------------*/
700 /* newCharLink() - creates an char type */
701 /*------------------------------------------------------------------*/
707 p = newLink (SPECIFIER);
708 SPEC_NOUN (p) = V_CHAR;
713 /*------------------------------------------------------------------*/
714 /* newFloatLink - a new Float type */
715 /*------------------------------------------------------------------*/
721 p = newLink (SPECIFIER);
722 SPEC_NOUN (p) = V_FLOAT;
727 /*------------------------------------------------------------------*/
728 /* newLongLink() - new long type */
729 /*------------------------------------------------------------------*/
735 p = newLink (SPECIFIER);
736 SPEC_NOUN (p) = V_INT;
742 /*------------------------------------------------------------------*/
743 /* newIntLink() - creates an int type */
744 /*------------------------------------------------------------------*/
750 p = newLink (SPECIFIER);
751 SPEC_NOUN (p) = V_INT;
756 /*------------------------------------------------------------------*/
757 /* getSize - returns size of a type chain in bits */
758 /*------------------------------------------------------------------*/
760 getSize (sym_link * p)
762 /* if nothing return 0 */
766 { /* if this is the specifier then */
767 switch (SPEC_NOUN (p))
768 { /* depending on the specifier type */
770 return (IS_LONG (p) ? LONGSIZE : INTSIZE);
778 return SPEC_STRUCT (p)->size;
785 return ((SPEC_BLEN (p) / 8) + (SPEC_BLEN (p) % 8 ? 1 : 0));
791 /* this is a specifier */
792 switch (DCL_TYPE (p))
796 return DCL_ELEM (p) * getSize (p->next);
798 // werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
799 // "can not tell the size of an array[]");
819 /*------------------------------------------------------------------*/
820 /* bitsForType - returns # of bits required to store this type */
821 /*------------------------------------------------------------------*/
823 bitsForType (sym_link * p)
825 /* if nothing return 0 */
830 { /* if this is the specifier then */
832 switch (SPEC_NOUN (p))
833 { /* depending on the specifier type */
835 return (IS_LONG (p) ? LONGSIZE * 8 : INTSIZE * 8);
837 return FLOATSIZE * 8;
843 return SPEC_STRUCT (p)->size * 8;
850 return SPEC_BLEN (p);
856 /* this is a specifier */
857 switch (DCL_TYPE (p))
860 return DCL_ELEM (p) * getSize (p->next) * 8;
864 return (PTRSIZE * 8);
869 return (FPTRSIZE * 8);
871 return (GPTRSIZE * 8);
878 /*------------------------------------------------------------------*/
879 /* copySymbolChain - copies a symbol chain */
880 /*------------------------------------------------------------------*/
882 copySymbolChain (symbol * src)
889 dest = copySymbol (src);
890 dest->next = copySymbolChain (src->next);
894 /*------------------------------------------------------------------*/
895 /* copySymbol - makes a copy of a symbol */
896 /*------------------------------------------------------------------*/
898 copySymbol (symbol * src)
905 dest = newSymbol (src->name, src->level);
906 memcpy (dest, src, sizeof (symbol));
907 dest->level = src->level;
908 dest->block = src->block;
909 dest->ival = copyIlist (src->ival);
910 dest->type = copyLinkChain (src->type);
911 dest->etype = getSpec (dest->type);
913 dest->key = src->key;
914 dest->allocreq = src->allocreq;
918 /*------------------------------------------------------------------*/
919 /* reverseSyms - reverses the links for a symbol chain */
920 /*------------------------------------------------------------------*/
922 reverseSyms (symbol * sym)
924 symbol *prev, *curr, *next;
939 sym->next = (void *) NULL;
943 /*------------------------------------------------------------------*/
944 /* reverseLink - reverses the links for a type chain */
945 /*------------------------------------------------------------------*/
947 reverseLink (sym_link * type)
949 sym_link *prev, *curr, *next;
964 type->next = (void *) NULL;
968 /*------------------------------------------------------------------*/
969 /* addSymChain - adds a symbol chain to the symboltable */
970 /*------------------------------------------------------------------*/
972 addSymChain (symbol * symHead)
974 symbol *sym = symHead;
978 for (; sym != NULL; sym = sym->next)
981 checkTypeSanity(sym->etype, sym->name);
983 if (!sym->level && !(IS_SPEC(sym->etype) && IS_TYPEDEF(sym->etype)))
986 /* if already exists in the symbol table then check if
987 one of them is an extern definition if yes then
988 then check if the type match, if the types match then
989 delete the current entry and add the new entry */
990 if ((csym = findSymWithLevel (SymbolTab, sym)) &&
991 csym->level == sym->level) {
993 /* If the previous definition was for an array with incomplete */
994 /* type, and the new definition has completed the type, update */
995 /* the original type to match */
996 if (IS_DECL(csym->type) && DCL_TYPE(csym->type)==ARRAY
997 && IS_DECL(sym->type) && DCL_TYPE(sym->type)==ARRAY)
999 if (!DCL_ELEM(csym->type) && DCL_ELEM(sym->type))
1000 DCL_ELEM(csym->type) = DCL_ELEM(sym->type);
1004 if (csym->ival && sym->ival)
1006 if (compareTypeExact (csym->type, sym->type, sym->level) != 1)
1010 /* one definition extern ? */
1011 if (IS_EXTERN (csym->etype) || IS_EXTERN (sym->etype))
1012 werror (E_EXTERN_MISMATCH, sym->name);
1014 werror (E_DUPLICATE, sym->name);
1015 printFromToType (csym->type, sym->type);
1019 if (csym->ival && !sym->ival)
1020 sym->ival = csym->ival;
1022 /* delete current entry */
1023 deleteSym (SymbolTab, csym, csym->name);
1024 deleteFromSeg(csym);
1028 addSym (SymbolTab, sym, sym->name, sym->level, sym->block, 1);
1033 /*------------------------------------------------------------------*/
1034 /* funcInChain - DCL Type 'FUNCTION' found in type chain */
1035 /*------------------------------------------------------------------*/
1037 funcInChain (sym_link * lnk)
1048 /*------------------------------------------------------------------*/
1049 /* structElemType - returns the type info of a struct member */
1050 /*------------------------------------------------------------------*/
1052 structElemType (sym_link * stype, value * id)
1054 symbol *fields = (SPEC_STRUCT (stype) ? SPEC_STRUCT (stype)->fields : NULL);
1055 sym_link *type, *etype;
1056 sym_link *petype = getSpec (stype);
1060 /* look for the id */
1063 if (strcmp (fields->rname, id->name) == 0)
1065 type = copyLinkChain (fields->type);
1066 etype = getSpec (type);
1067 SPEC_SCLS (etype) = (SPEC_SCLS (petype) == S_REGISTER ?
1068 SPEC_SCLS (etype) : SPEC_SCLS (petype));
1070 SPEC_CONST (type) |= SPEC_CONST (stype);
1072 DCL_PTR_CONST (type) |= SPEC_CONST (stype);
1075 fields = fields->next;
1079 werror (E_NOT_MEMBER, id->name);
1081 // the show must go on
1082 return newIntLink();
1085 /*------------------------------------------------------------------*/
1086 /* getStructElement - returns element of a tructure definition */
1087 /*------------------------------------------------------------------*/
1089 getStructElement (structdef * sdef, symbol * sym)
1093 for (field = sdef->fields; field; field = field->next)
1094 if (strcmp (field->name, sym->name) == 0)
1097 werror (E_NOT_MEMBER, sym->name);
1099 return sdef->fields;
1102 /*------------------------------------------------------------------*/
1103 /* compStructSize - computes the size of a structure */
1104 /*------------------------------------------------------------------*/
1106 compStructSize (int su, structdef * sdef)
1108 int sum = 0, usum = 0;
1112 /* for the identifiers */
1113 loop = sdef->fields;
1116 /* create the internal name for this variable */
1117 SNPRINTF (loop->rname, sizeof(loop->rname), "_%s", loop->name);
1122 SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
1124 /* if this is a bit field */
1127 /* change it to a unsigned bit */
1128 SPEC_NOUN (loop->etype) = V_BITFIELD;
1129 SPEC_USIGN (loop->etype) = 1;
1130 SPEC_BLEN (loop->etype) = loop->bitVar;
1132 if (loop->bitVar == BITVAR_PAD) {
1133 /* A zero length bitfield forces padding */
1134 SPEC_BSTR (loop->etype) = bitOffset;
1135 SPEC_BLEN (loop->etype) = 0;
1140 if (bitOffset == 8) {
1144 /* check if this fit into the remaining */
1145 /* bits of this byte else align it to the */
1146 /* next byte boundary */
1147 if (loop->bitVar <= (8 - bitOffset)) {
1148 /* fits into current byte */
1150 SPEC_BSTR (loop->etype) = bitOffset;
1151 bitOffset += loop->bitVar;
1153 else if (!bitOffset) {
1154 /* does not fit, but is already byte aligned */
1156 SPEC_BSTR (loop->etype) = bitOffset;
1157 bitOffset += loop->bitVar;
1160 /* does not fit; need to realign first */
1162 loop->offset = (su == UNION ? sum = 0 : sum);
1164 SPEC_BSTR (loop->etype) = bitOffset;
1165 bitOffset += loop->bitVar;
1167 while (bitOffset>8) {
1174 /* This is a non-bit field. Make sure we are */
1175 /* byte aligned first */
1178 loop->offset = (su == UNION ? sum = 0 : sum);
1182 checkDecl (loop, 1);
1183 sum += getSize (loop->type);
1188 /* if union then size = sizeof larget field */
1190 /* For UNION, round up after each field */
1191 sum += ((bitOffset+7)/8);
1192 usum = max (usum, sum);
1197 /* For STRUCT, round up after all fields processed */
1199 sum += ((bitOffset+7)/8);
1201 return (su == UNION ? usum : sum);
1204 /*------------------------------------------------------------------*/
1205 /* checkSClass - check the storage class specification */
1206 /*------------------------------------------------------------------*/
1208 checkSClass (symbol * sym, int isProto)
1212 if (getenv("DEBUG_SANITY")) {
1213 fprintf (stderr, "checkSClass: %s \n", sym->name);
1216 /* type is literal can happen for enums change
1218 if (SPEC_SCLS (sym->etype) == S_LITERAL && !SPEC_ENUM (sym->etype))
1219 SPEC_SCLS (sym->etype) = S_AUTO;
1221 /* if sfr or sbit then must also be volatile */
1222 if (SPEC_SCLS (sym->etype) == S_SBIT ||
1223 SPEC_SCLS (sym->etype) == S_SFR)
1225 SPEC_VOLATILE (sym->etype) = 1;
1228 /* if absolute address given then it mark it as
1229 volatile -- except in the PIC port */
1231 #if !OPT_DISABLE_PIC || !OPT_DISABLE_PIC16
1232 /* The PIC port uses a different peep hole optimizer based on "pCode" */
1233 if (!TARGET_IS_PIC && !TARGET_IS_PIC16)
1236 if (IS_ABSOLUTE (sym->etype))
1237 SPEC_VOLATILE (sym->etype) = 1;
1239 /* If code memory is read only, then pointers to code memory */
1240 /* implicitly point to constants -- make this explicit */
1242 while (t && t->next) {
1243 if (IS_CODEPTR(t) && port->mem.code_ro) {
1244 if (IS_SPEC(t->next)) {
1245 SPEC_CONST (t->next) = 1;
1247 DCL_PTR_CONST (t->next) = 1;
1253 /* global variables declared const put into code */
1254 /* if no other storage class specified */
1255 if (sym->level == 0 &&
1256 SPEC_SCLS(sym->etype) == S_FIXED &&
1257 !IS_FUNC(sym->type)) {
1258 /* find the first non-array link */
1262 if (IS_CONSTANT (t)) {
1263 SPEC_SCLS (sym->etype) = S_CODE;
1267 /* global variable in code space is a constant */
1268 if (sym->level == 0 &&
1269 SPEC_SCLS (sym->etype) == S_CODE &&
1270 port->mem.code_ro) {
1271 /* find the first non-array link */
1278 DCL_PTR_CONST (t) = 1;
1282 /* if bit variable then no storage class can be */
1283 /* specified since bit is already a storage */
1284 if (IS_BITVAR (sym->etype) &&
1285 (SPEC_SCLS (sym->etype) != S_FIXED &&
1286 SPEC_SCLS (sym->etype) != S_SBIT &&
1287 SPEC_SCLS (sym->etype) != S_BIT)
1290 werror (E_BITVAR_STORAGE, sym->name);
1291 SPEC_SCLS (sym->etype) = S_FIXED;
1294 /* extern variables cannot be initialized */
1295 if (IS_EXTERN (sym->etype) && sym->ival)
1297 werror (E_EXTERN_INIT, sym->name);
1301 /* if this is an automatic symbol */
1302 if (sym->level && (options.stackAuto || reentrant)) {
1303 if ((SPEC_SCLS (sym->etype) == S_AUTO ||
1304 SPEC_SCLS (sym->etype) == S_FIXED ||
1305 SPEC_SCLS (sym->etype) == S_REGISTER ||
1306 SPEC_SCLS (sym->etype) == S_STACK ||
1307 SPEC_SCLS (sym->etype) == S_XSTACK)) {
1308 SPEC_SCLS (sym->etype) = S_AUTO;
1310 /* storage class may only be specified for statics */
1311 if (!IS_STATIC(sym->etype)) {
1312 werror (E_AUTO_ASSUMED, sym->name);
1317 /* automatic symbols cannot be given */
1318 /* an absolute address ignore it */
1320 SPEC_ABSA (sym->etype) &&
1321 (options.stackAuto || reentrant))
1323 werror (E_AUTO_ABSA, sym->name);
1324 SPEC_ABSA (sym->etype) = 0;
1327 /* arrays & pointers cannot be defined for bits */
1328 /* SBITS or SFRs or BIT */
1329 if ((IS_ARRAY (sym->type) || IS_PTR (sym->type)) &&
1330 (SPEC_NOUN (sym->etype) == V_BIT ||
1331 SPEC_NOUN (sym->etype) == V_SBIT ||
1332 SPEC_NOUN (sym->etype) == V_BITFIELD ||
1333 SPEC_SCLS (sym->etype) == S_SFR))
1334 werror (E_BIT_ARRAY, sym->name);
1336 /* if this is a bit|sbit then set length & start */
1337 if (SPEC_NOUN (sym->etype) == V_BIT ||
1338 SPEC_NOUN (sym->etype) == V_SBIT)
1340 SPEC_BLEN (sym->etype) = 1;
1341 SPEC_BSTR (sym->etype) = 0;
1345 /* variables declared in CODE space must have */
1346 /* initializers if not an extern */
1347 if (SPEC_SCLS (sym->etype) == S_CODE &&
1348 sym->ival == NULL &&
1350 port->mem.code_ro &&
1351 !IS_EXTERN (sym->etype) &&
1352 !funcInChain (sym->type))
1353 werror (E_CODE_NO_INIT, sym->name);
1356 /* if parameter or local variable then change */
1357 /* the storage class to reflect where the var will go */
1358 if (sym->level && SPEC_SCLS (sym->etype) == S_FIXED &&
1359 !IS_STATIC(sym->etype))
1361 if (options.stackAuto || (currFunc && IFFUNC_ISREENT (currFunc->type)))
1363 SPEC_SCLS (sym->etype) = (options.useXstack ?
1364 S_XSTACK : S_STACK);
1368 /* hack-o-matic! I see no reason why the useXstack option should ever
1369 * control this allcoation, but the code was originally that way, and
1370 * changing it for non-390 ports breaks the compiler badly.
1372 bool useXdata = (TARGET_IS_DS390 || TARGET_IS_DS400) ?
1373 1 : options.useXstack;
1374 SPEC_SCLS (sym->etype) = (useXdata ?
1380 /*------------------------------------------------------------------*/
1381 /* changePointer - change pointer to functions */
1382 /*------------------------------------------------------------------*/
1384 changePointer (symbol * sym)
1388 /* go thru the chain of declarations */
1389 /* if we find a pointer to a function */
1390 /* unconditionally change it to a ptr */
1392 for (p = sym->type; p; p = p->next)
1394 if (!IS_SPEC (p) && DCL_TYPE (p) == UPOINTER)
1395 DCL_TYPE (p) = port->unqualified_pointer;
1396 if (IS_PTR (p) && IS_FUNC (p->next))
1397 DCL_TYPE (p) = CPOINTER;
1401 /*------------------------------------------------------------------*/
1402 /* checkDecl - does semantic validation of a declaration */
1403 /*------------------------------------------------------------------*/
1405 checkDecl (symbol * sym, int isProto)
1408 checkSClass (sym, isProto); /* check the storage class */
1409 changePointer (sym); /* change pointers if required */
1411 /* if this is an array without any dimension
1412 then update the dimension from the initial value */
1413 if (IS_ARRAY (sym->type) && !DCL_ELEM (sym->type))
1414 DCL_ELEM (sym->type) = getNelements (sym->type, sym->ival);
1419 /*------------------------------------------------------------------*/
1420 /* copyLinkChain - makes a copy of the link chain & rets ptr 2 head */
1421 /*------------------------------------------------------------------*/
1423 copyLinkChain (sym_link * p)
1425 sym_link *head, *curr, *loop;
1428 head = loop = (curr ? newLink (p->class) : (void *) NULL);
1431 memcpy (loop, curr, sizeof (sym_link)); /* copy it */
1432 loop->next = (curr->next ? newLink (curr->next->class) : (void *) NULL);
1441 /*------------------------------------------------------------------*/
1442 /* cleanUpBlock - cleansup the symbol table specified for all the */
1443 /* symbols in the given block */
1444 /*------------------------------------------------------------------*/
1446 cleanUpBlock (bucket ** table, int block)
1451 /* go thru the entire table */
1452 for (i = 0; i < 256; i++)
1454 for (chain = table[i]; chain; chain = chain->next)
1456 if (chain->block >= block)
1458 deleteSym (table, chain->sym, chain->name);
1464 /*------------------------------------------------------------------*/
1465 /* cleanUpLevel - cleansup the symbol table specified for all the */
1466 /* symbols in the given level */
1467 /*------------------------------------------------------------------*/
1469 cleanUpLevel (bucket ** table, int level)
1474 /* go thru the entire table */
1475 for (i = 0; i < 256; i++)
1477 for (chain = table[i]; chain; chain = chain->next)
1479 if (chain->level >= level)
1481 deleteSym (table, chain->sym, chain->name);
1487 /*------------------------------------------------------------------*/
1488 /* computeType - computes the resultant type from two types */
1489 /*------------------------------------------------------------------*/
1491 computeType (sym_link * type1, sym_link * type2)
1495 sym_link *etype1 = getSpec (type1);
1496 sym_link *etype2 = getSpec (type2);
1498 /* if one of them is a float then result is a float */
1499 /* here we assume that the types passed are okay */
1500 /* and can be cast to one another */
1501 /* which ever is greater in size */
1502 if (IS_FLOAT (etype1) || IS_FLOAT (etype2))
1503 rType = newFloatLink ();
1505 /* if only one of them is a bit variable
1506 then the other one prevails */
1507 if (IS_BITVAR (etype1) && !IS_BITVAR (etype2))
1508 rType = copyLinkChain (type2);
1509 else if (IS_BITVAR (etype2) && !IS_BITVAR (etype1))
1510 rType = copyLinkChain (type1);
1512 /* if one of them is a pointer or array then that
1514 if (IS_PTR (type1) || IS_ARRAY (type1))
1515 rType = copyLinkChain (type1);
1516 else if (IS_PTR (type2) || IS_ARRAY (type2))
1517 rType = copyLinkChain (type2);
1518 else if (getSize (type1) > getSize (type2))
1519 rType = copyLinkChain (type1);
1521 rType = copyLinkChain (type2);
1523 reType = getSpec (rType);
1525 if (SPEC_NOUN (reType) == V_CHAR)
1526 SPEC_NOUN (reType) = V_INT;
1529 /* if either of them unsigned but not val then make this unsigned */
1530 if ((SPEC_USIGN (etype1) || SPEC_USIGN (etype2)) &&
1532 SPEC_USIGN (reType) = 1;
1534 SPEC_USIGN (reType) = 0;
1536 /* if result is a literal then make not so */
1537 if (IS_LITERAL (reType))
1538 SPEC_SCLS (reType) = S_REGISTER;
1543 /*--------------------------------------------------------------------*/
1544 /* compareType - will do type check return 1 if match, -1 if castable */
1545 /*--------------------------------------------------------------------*/
1547 compareType (sym_link * dest, sym_link * src)
1558 /* if dest is a declarator then */
1563 if (DCL_TYPE (src) == DCL_TYPE (dest)) {
1565 //checkFunction(src,dest);
1567 return compareType (dest->next, src->next);
1569 if (IS_PTR (dest) && IS_GENPTR (src) && IS_VOID(src->next)) {
1572 if (IS_PTR (src) && IS_GENPTR (dest))
1574 if (IS_PTR (dest) && IS_ARRAY (src)) {
1575 value *val=aggregateToPointer (valFromType(src));
1576 int res=compareType (dest, val->type);
1577 Safe_free(val->type);
1581 if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
1582 return compareType (dest->next, src);
1585 else if (IS_PTR (dest) && IS_INTEGRAL (src))
1591 /* if one is a specifier and the other is not */
1592 if ((IS_SPEC (src) && !IS_SPEC (dest)) ||
1593 (IS_SPEC (dest) && !IS_SPEC (src)))
1596 /* if one of them is a void then ok */
1597 if (SPEC_NOUN (dest) == V_VOID &&
1598 SPEC_NOUN (src) != V_VOID)
1601 if (SPEC_NOUN (dest) != V_VOID &&
1602 SPEC_NOUN (src) == V_VOID)
1605 /* if they are both bitfields then if the lengths
1606 and starts don't match */
1607 if (IS_BITFIELD (dest) && IS_BITFIELD (src) &&
1608 (SPEC_BLEN (dest) != SPEC_BLEN (src) ||
1609 SPEC_BSTR (dest) != SPEC_BSTR (src)))
1612 /* it is a specifier */
1613 if (SPEC_NOUN (dest) != SPEC_NOUN (src))
1615 if (SPEC_USIGN (dest) == SPEC_USIGN (src) &&
1616 IS_INTEGRAL (dest) && IS_INTEGRAL (src) &&
1617 getSize (dest) == getSize (src))
1619 else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src))
1624 else if (IS_STRUCT (dest))
1626 if (SPEC_STRUCT (dest) != SPEC_STRUCT (src))
1631 if (SPEC_LONG (dest) != SPEC_LONG (src))
1634 if (SPEC_USIGN (dest) != SPEC_USIGN (src))
1640 /*--------------------------------------------------------------------*/
1641 /* compareTypeExact - will do type check return 1 if match exactly */
1642 /*--------------------------------------------------------------------*/
1644 compareTypeExact (sym_link * dest, sym_link * src, int level)
1646 STORAGE_CLASS srcScls, destScls;
1657 /* if dest is a declarator then */
1662 if (DCL_TYPE (src) == DCL_TYPE (dest)) {
1663 if ((DCL_TYPE (src) == ARRAY) && (DCL_ELEM (src) != DCL_ELEM (dest)))
1665 if (DCL_PTR_CONST (src) != DCL_PTR_CONST (dest))
1667 if (DCL_PTR_VOLATILE (src) != DCL_PTR_VOLATILE (dest))
1671 value *exargs, *acargs, *checkValue;
1673 /* verify function return type */
1674 if (!compareTypeExact (dest->next, src->next, -1))
1676 if (FUNC_ISISR (dest) != FUNC_ISISR (src))
1678 if (FUNC_REGBANK (dest) != FUNC_REGBANK (src))
1680 if (IFFUNC_ISNAKED (dest) != IFFUNC_ISNAKED (src))
1683 if (IFFUNC_ISREENT (dest) != IFFUNC_ISREENT (src) && argCnt>1)
1687 /* compare expected args with actual args */
1688 exargs = FUNC_ARGS(dest);
1689 acargs = FUNC_ARGS(src);
1691 /* for all the expected args do */
1692 for (; exargs && acargs; exargs = exargs->next, acargs = acargs->next)
1694 //checkTypeSanity(acargs->etype, acargs->name);
1696 if (IS_AGGREGATE (acargs->type))
1698 checkValue = copyValue (acargs);
1699 aggregateToPointer (checkValue);
1702 checkValue = acargs;
1705 if (!compareTypeExact (exargs->type, checkValue->type, -1))
1710 /* if one them ended we have a problem */
1711 if ((exargs && !acargs && !IS_VOID (exargs->type)) ||
1712 (!exargs && acargs && !IS_VOID (acargs->type)))
1716 return compareTypeExact (dest->next, src->next, level);
1723 /* if one is a specifier and the other is not */
1724 if ((IS_SPEC (src) && !IS_SPEC (dest)) ||
1725 (IS_SPEC (dest) && !IS_SPEC (src)))
1728 /* if one of them is a void then ok */
1729 if (SPEC_NOUN (dest) != SPEC_NOUN (src))
1732 /* if they are both bitfields then if the lengths
1733 and starts don't match */
1734 if (IS_BITFIELD (dest) && IS_BITFIELD (src) &&
1735 (SPEC_BLEN (dest) != SPEC_BLEN (src) ||
1736 SPEC_BSTR (dest) != SPEC_BSTR (src)))
1739 if (IS_INTEGRAL (dest))
1741 /* signedness must match */
1742 if (SPEC_USIGN (dest) != SPEC_USIGN (src))
1744 /* size must match */
1745 if (SPEC_LONG (dest) != SPEC_LONG (src))
1747 if (SPEC_SHORT (dest) != SPEC_SHORT (src))
1751 if (IS_STRUCT (dest))
1753 if (SPEC_STRUCT (dest) != SPEC_STRUCT (src))
1757 if (SPEC_CONST (dest) != SPEC_CONST (src))
1759 if (SPEC_VOLATILE (dest) != SPEC_VOLATILE (src))
1761 if (SPEC_STAT (dest) != SPEC_STAT (src))
1763 if (SPEC_ABSA (dest) != SPEC_ABSA (src))
1765 if (SPEC_ABSA (dest) && SPEC_ADDR (dest) != SPEC_ADDR (src))
1768 destScls = SPEC_SCLS (dest);
1769 srcScls = SPEC_SCLS (src);
1771 /* Compensate for const to const code change in checkSClass() */
1772 if (!level & port->mem.code_ro && SPEC_CONST (dest))
1774 if (srcScls == S_CODE && destScls == S_FIXED)
1776 if (destScls == S_CODE && srcScls == S_FIXED)
1780 /* compensate for allocGlobal() */
1781 if ((srcScls == S_FIXED || srcScls == S_AUTO)
1782 && port->mem.default_globl_map == xdata
1786 if (level>0 && !SPEC_STAT (dest))
1788 /* Compensate for hack-o-matic in checkSClass() */
1789 if (options.stackAuto || (currFunc && IFFUNC_ISREENT (currFunc->type)))
1791 if (destScls == S_FIXED)
1792 destScls = (options.useXstack ? S_XSTACK : S_STACK);
1793 if (srcScls == S_FIXED)
1794 srcScls = (options.useXstack ? S_XSTACK : S_STACK);
1796 else if (TARGET_IS_DS390 || TARGET_IS_DS400 || options.useXstack)
1798 if (destScls == S_FIXED)
1800 if (srcScls == S_FIXED)
1805 if (srcScls != destScls)
1808 printf ("level = %d\n", level);
1809 printf ("SPEC_SCLS (src) = %d, SPEC_SCLS (dest) = %d\n",
1810 SPEC_SCLS (src), SPEC_SCLS (dest));
1811 printf ("srcScls = %d, destScls = %d\n",srcScls, destScls);
1819 /*------------------------------------------------------------------*/
1820 /* inCalleeSaveList - return 1 if found in callee save list */
1821 /*------------------------------------------------------------------*/
1823 calleeCmp(void *p1, void *p2)
1825 return (strcmp((char *)p1, (char *)(p2)) == 0);
1829 inCalleeSaveList(char *s)
1831 if (options.all_callee_saves)
1833 return isinSetWith(options.calleeSavesSet, s, calleeCmp);
1836 /*-----------------------------------------------------------------*/
1837 /* aggregateToPointer: change an agggregate type function */
1838 /* argument to a pointer to that type. */
1839 /*-----------------------------------------------------------------*/
1841 aggregateToPointer (value * val)
1843 if (IS_AGGREGATE (val->type))
1845 /* if this is a structure */
1846 /* then we need to add a new link */
1847 if (IS_STRUCT (val->type))
1849 /* first lets add DECLARATOR type */
1850 sym_link *p = val->type;
1852 werror (W_STRUCT_AS_ARG, val->name);
1853 val->type = newLink (DECLARATOR);
1854 val->type->next = p;
1857 /* change to a pointer depending on the */
1858 /* storage class specified */
1859 switch (SPEC_SCLS (val->etype))
1862 DCL_TYPE (val->type) = IPOINTER;
1865 DCL_TYPE (val->type) = PPOINTER;
1868 if (SPEC_OCLS(val->etype)) {
1869 DCL_TYPE(val->type)=PTR_TYPE(SPEC_OCLS(val->etype));
1871 // this happens for (external) function parameters
1872 DCL_TYPE (val->type) = port->unqualified_pointer;
1878 DCL_TYPE (val->type) = POINTER;
1881 DCL_TYPE (val->type) = CPOINTER;
1884 DCL_TYPE (val->type) = FPOINTER;
1887 DCL_TYPE (val->type) = EEPPOINTER;
1890 DCL_TYPE (val->type) = port->unqualified_pointer;
1893 /* is there is a symbol associated then */
1894 /* change the type of the symbol as well */
1897 val->sym->type = copyLinkChain (val->type);
1898 val->sym->etype = getSpec (val->sym->type);
1903 /*------------------------------------------------------------------*/
1904 /* checkFunction - does all kinds of check on a function */
1905 /*------------------------------------------------------------------*/
1907 checkFunction (symbol * sym, symbol *csym)
1909 value *exargs, *acargs;
1913 if (getenv("DEBUG_SANITY")) {
1914 fprintf (stderr, "checkFunction: %s ", sym->name);
1917 if (!IS_DECL(sym->type) || DCL_TYPE(sym->type)!=FUNCTION)
1919 werror(E_SYNTAX_ERROR, sym->name);
1923 /* make sure the type is complete and sane */
1924 checkTypeSanity(((symbol *)sym)->etype, ((symbol *)sym)->name);
1926 /* if not type then some kind of error */
1930 /* if the function has no type then make it return int */
1931 if (!sym->type->next)
1932 sym->type->next = sym->etype = newIntLink ();
1934 /* function cannot return aggregate */
1935 if (IS_AGGREGATE (sym->type->next))
1937 werror (E_FUNC_AGGR, sym->name);
1941 /* function cannot return bit */
1942 if (IS_BITVAR (sym->type->next))
1944 werror (E_FUNC_BIT, sym->name);
1948 /* check if this function is defined as calleeSaves
1949 then mark it as such */
1950 FUNC_CALLEESAVES(sym->type) = inCalleeSaveList (sym->name);
1952 /* if interrupt service routine */
1953 /* then it cannot have arguments */
1954 if (IFFUNC_ARGS(sym->type) && FUNC_ISISR (sym->type))
1956 if (!IS_VOID(FUNC_ARGS(sym->type)->type)) {
1957 werror (E_INT_ARGS, sym->name);
1958 FUNC_ARGS(sym->type)=NULL;
1962 for (argCnt=1, acargs = FUNC_ARGS(sym->type);
1964 acargs=acargs->next, argCnt++) {
1966 // this can happen for reentrant functions
1967 werror(E_PARAM_NAME_OMITTED, sym->name, argCnt);
1968 // the show must go on: synthesize a name and symbol
1969 SNPRINTF (acargs->name, sizeof(acargs->name), "_%s_PARM_%d", sym->name, argCnt);
1970 acargs->sym = newSymbol (acargs->name, 1);
1971 SPEC_OCLS (acargs->etype) = istack;
1972 acargs->sym->type = copyLinkChain (acargs->type);
1973 acargs->sym->etype = getSpec (acargs->sym->type);
1974 acargs->sym->_isparm = 1;
1975 strncpyz (acargs->sym->rname, acargs->name, sizeof(acargs->sym->rname));
1976 } else if (strcmp(acargs->sym->name, acargs->sym->rname)==0) {
1978 werror(E_PARAM_NAME_OMITTED, sym->name, argCnt);
1983 if (!csym && !(csym = findSym (SymbolTab, sym, sym->name)))
1984 return 1; /* not defined nothing more to check */
1986 /* check if body already present */
1987 if (csym && IFFUNC_HASBODY(csym->type))
1989 werror (E_FUNC_BODY, sym->name);
1993 /* check the return value type */
1994 if (compareType (csym->type, sym->type) <= 0)
1996 werror (E_PREV_DEF_CONFLICT, csym->name, "type");
1997 printFromToType(csym->type, sym->type);
2001 if (FUNC_ISISR (csym->type) != FUNC_ISISR (sym->type))
2003 werror (E_PREV_DEF_CONFLICT, csym->name, "interrupt");
2006 if (FUNC_REGBANK (csym->type) != FUNC_REGBANK (sym->type))
2008 werror (E_PREV_DEF_CONFLICT, csym->name, "using");
2011 if (IFFUNC_ISNAKED (csym->type) != IFFUNC_ISNAKED (sym->type))
2013 werror (E_PREV_DEF_CONFLICT, csym->name, "_naked");
2016 /* Really, reentrant should match regardless of argCnt, but */
2017 /* this breaks some existing code (the fp lib functions). If */
2018 /* the first argument is always passed the same way, this */
2019 /* lax checking is ok (but may not be true for in future ports) */
2020 if (IFFUNC_ISREENT (csym->type) != IFFUNC_ISREENT (sym->type)
2023 //printf("argCnt = %d\n",argCnt);
2024 werror (E_PREV_DEF_CONFLICT, csym->name, "reentrant");
2027 /* compare expected args with actual args */
2028 exargs = FUNC_ARGS(csym->type);
2029 acargs = FUNC_ARGS(sym->type);
2031 /* for all the expected args do */
2034 exargs = exargs->next, acargs = acargs->next, argCnt++)
2036 if (getenv("DEBUG_SANITY")) {
2037 fprintf (stderr, "checkFunction: %s ", exargs->name);
2039 /* make sure the type is complete and sane */
2040 checkTypeSanity(exargs->etype, exargs->name);
2042 /* If the actual argument is an array, any prototype
2043 * will have modified it to a pointer. Duplicate that
2046 if (IS_AGGREGATE (acargs->type))
2048 checkValue = copyValue (acargs);
2049 aggregateToPointer (checkValue);
2053 checkValue = acargs;
2056 if (compareType (exargs->type, checkValue->type) <= 0)
2058 werror (E_ARG_TYPE, argCnt);
2059 printFromToType(exargs->type, checkValue->type);
2064 /* if one them ended we have a problem */
2065 if ((exargs && !acargs && !IS_VOID (exargs->type)) ||
2066 (!exargs && acargs && !IS_VOID (acargs->type)))
2067 werror (E_ARG_COUNT);
2069 /* replace with this defition */
2070 sym->cdef = csym->cdef;
2071 deleteSym (SymbolTab, csym, csym->name);
2072 deleteFromSeg(csym);
2073 addSym (SymbolTab, sym, sym->name, sym->level, sym->block, 1);
2074 if (IS_EXTERN (csym->etype) && !
2075 IS_EXTERN (sym->etype))
2077 addSet (&publics, sym);
2082 /*------------------------------------------------------------------*/
2083 /* cdbStructBlock - calls struct printing for a blcks */
2084 /*------------------------------------------------------------------*/
2085 void cdbStructBlock (int block)
2088 bucket **table = StructTab;
2091 /* go thru the entire table */
2092 for (i = 0; i < 256; i++)
2094 for (chain = table[i]; chain; chain = chain->next)
2096 if (chain->block >= block)
2099 debugFile->writeType((structdef *)chain->sym, chain->block, 0, NULL);
2105 /*-----------------------------------------------------------------*/
2106 /* processFuncArgs - does some processing with function args */
2107 /*-----------------------------------------------------------------*/
2109 processFuncArgs (symbol * func)
2113 sym_link *funcType=func->type;
2115 if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
2116 fprintf (stderr, "SDCCsymt.c:processFuncArgs(%s)\n", func->name);
2118 // if this is a pointer to a function
2119 if (IS_PTR(funcType)) {
2120 funcType=funcType->next;
2123 /* if this function has variable argument list */
2124 /* then make the function a reentrant one */
2125 if (IFFUNC_HASVARARGS(funcType) || (options.stackAuto && !func->cdef))
2126 FUNC_ISREENT(funcType)=1;
2128 /* check if this function is defined as calleeSaves
2129 then mark it as such */
2130 FUNC_CALLEESAVES(funcType) = inCalleeSaveList (func->name);
2132 /* loop thru all the arguments */
2133 val = FUNC_ARGS(funcType);
2135 /* if it is void then remove parameters */
2136 if (val && IS_VOID (val->type))
2138 FUNC_ARGS(funcType) = NULL;
2142 /* reset regparm for the port */
2143 (*port->reset_regparms) ();
2144 /* if any of the arguments is an aggregate */
2145 /* change it to pointer to the same type */
2149 /* mark it as a register parameter if
2150 the function does not have VA_ARG
2151 and as port dictates */
2152 if (!IFFUNC_HASVARARGS(funcType) &&
2153 (argreg = (*port->reg_parm) (val->type)))
2155 SPEC_REGPARM (val->etype) = 1;
2156 SPEC_ARGREG(val->etype) = argreg;
2157 } else if (IFFUNC_ISREENT(funcType)) {
2158 FUNC_HASSTACKPARM(funcType) = 1;
2161 if (IS_AGGREGATE (val->type))
2163 aggregateToPointer (val);
2170 /* if this is an internal generated function call */
2172 /* ignore --stack-auto for this one, we don't know how it is compiled */
2173 /* simply trust on --int-long-reent or --float-reent */
2174 if (IFFUNC_ISREENT(funcType)) {
2178 /* if this function is reentrant or */
2179 /* automatics r 2b stacked then nothing */
2180 if (IFFUNC_ISREENT (funcType) || options.stackAuto)
2184 val = FUNC_ARGS(funcType);
2189 /* if a symbolname is not given */
2190 /* synthesize a variable name */
2193 SNPRINTF (val->name, sizeof(val->name),
2194 "_%s_PARM_%d", func->name, pNum++);
2195 val->sym = newSymbol (val->name, 1);
2196 SPEC_OCLS (val->etype) = port->mem.default_local_map;
2197 val->sym->type = copyLinkChain (val->type);
2198 val->sym->etype = getSpec (val->sym->type);
2199 val->sym->_isparm = 1;
2200 strncpyz (val->sym->rname, val->name, sizeof(val->sym->rname));
2201 if (IS_SPEC(func->etype)) {
2202 SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
2203 SPEC_STAT (func->etype);
2205 addSymChain (val->sym);
2208 else /* symbol name given create synth name */
2211 SNPRINTF (val->name, sizeof(val->name), "_%s_PARM_%d", func->name, pNum++);
2212 strncpyz (val->sym->rname, val->name, sizeof(val->sym->rname));
2213 val->sym->_isparm = 1;
2214 SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
2215 (options.model != MODEL_SMALL ? xdata : data);
2216 if (IS_SPEC(func->etype)) {
2217 SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
2218 SPEC_STAT (func->etype);
2221 if (!isinSet(operKeyReset, val->sym)) {
2222 addSet (&operKeyReset, val->sym);
2223 applyToSet (operKeyReset, resetParmKey);
2229 /*-----------------------------------------------------------------*/
2230 /* isSymbolEqual - compares two symbols return 1 if they match */
2231 /*-----------------------------------------------------------------*/
2233 isSymbolEqual (symbol * dest, symbol * src)
2235 /* if pointers match then equal */
2239 /* if one of them is null then don't match */
2243 /* if both of them have rname match on rname */
2244 if (dest->rname[0] && src->rname[0])
2245 return (!strcmp (dest->rname, src->rname));
2247 /* otherwise match on name */
2248 return (!strcmp (dest->name, src->name));
2251 void PT(sym_link *type)
2253 printTypeChain(type,0);
2255 /*-----------------------------------------------------------------*/
2256 /* printTypeChain - prints the type chain in human readable form */
2257 /*-----------------------------------------------------------------*/
2259 printTypeChain (sym_link * start, FILE * of)
2263 sym_link * type, * search;
2273 fprintf (of, "void");
2277 /* Print the chain as it is written in the source: */
2278 /* start with the last entry. */
2279 /* However, the storage class at the end of the */
2280 /* chain reall applies to the first in the chain! */
2282 for (type = start; type && type->next; type = type->next)
2285 scls=SPEC_SCLS(type);
2293 case S_DATA: fprintf (of, "data-"); break;
2294 case S_XDATA: fprintf (of, "xdata-"); break;
2295 case S_SFR: fprintf (of, "sfr-"); break;
2296 case S_SBIT: fprintf (of, "sbit-"); break;
2297 case S_CODE: fprintf (of, "code-"); break;
2298 case S_IDATA: fprintf (of, "idata-"); break;
2299 case S_PDATA: fprintf (of, "pdata-"); break;
2300 case S_LITERAL: fprintf (of, "literal-"); break;
2301 case S_STACK: fprintf (of, "stack-"); break;
2302 case S_XSTACK: fprintf (of, "xstack-"); break;
2303 case S_BIT: fprintf (of, "bit-"); break;
2304 case S_EEPROM: fprintf (of, "eeprom-"); break;
2311 if (!IS_FUNC(type)) {
2312 if (DCL_PTR_VOLATILE (type)) {
2313 fprintf (of, "volatile-");
2315 if (DCL_PTR_CONST (type)) {
2316 fprintf (of, "const-");
2319 switch (DCL_TYPE (type))
2322 fprintf (of, "function %s %s",
2323 (IFFUNC_ISBUILTIN(type) ? "__builtin__" : " "),
2324 (IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " "));
2326 for (args = FUNC_ARGS(type);
2329 printTypeChain(args->type, of);
2336 fprintf (of, "generic* ");
2339 fprintf (of, "code* ");
2342 fprintf (of, "xdata* ");
2345 fprintf (of, "eeprom* ");
2348 fprintf (of, "near* ");
2351 fprintf (of, "idata* ");
2354 fprintf (of, "pdata* ");
2357 fprintf (of, "unknown* ");
2360 if (DCL_ELEM(type)) {
2361 fprintf (of, "[%d] ", DCL_ELEM(type));
2363 fprintf (of, "[] ");
2370 if (SPEC_VOLATILE (type))
2371 fprintf (of, "volatile-");
2372 if (SPEC_CONST (type))
2373 fprintf (of, "const-");
2374 if (SPEC_USIGN (type))
2375 fprintf (of, "unsigned-");
2376 switch (SPEC_NOUN (type))
2380 fprintf (of, "long-");
2381 fprintf (of, "int");
2385 fprintf (of, "char");
2389 fprintf (of, "void");
2393 fprintf (of, "float");
2397 fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
2401 fprintf (of, "sbit");
2405 fprintf (of, "bit");
2409 fprintf (of, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
2413 fprintf (of, "double");
2417 fprintf (of, "unknown type");
2421 /* search entry in list before "type" */
2422 for (search = start; search && search->next != type;)
2423 search = search->next;
2432 /*--------------------------------------------------------------------*/
2433 /* printTypeChainRaw - prints the type chain in human readable form */
2434 /* in the raw data structure ordering */
2435 /*--------------------------------------------------------------------*/
2437 printTypeChainRaw (sym_link * start, FILE * of)
2450 fprintf (of, "void");
2460 if (!IS_FUNC(type)) {
2461 if (DCL_PTR_VOLATILE (type)) {
2462 fprintf (of, "volatile-");
2464 if (DCL_PTR_CONST (type)) {
2465 fprintf (of, "const-");
2468 switch (DCL_TYPE (type))
2471 fprintf (of, "function %s %s",
2472 (IFFUNC_ISBUILTIN(type) ? "__builtin__" : " "),
2473 (IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " "));
2475 for (args = FUNC_ARGS(type);
2478 printTypeChain(args->type, of);
2485 fprintf (of, "generic* ");
2488 fprintf (of, "code* ");
2491 fprintf (of, "xdata* ");
2494 fprintf (of, "eeprom* ");
2497 fprintf (of, "near* ");
2500 fprintf (of, "idata* ");
2503 fprintf (of, "pdata* ");
2506 fprintf (of, "unknown* ");
2509 if (DCL_ELEM(type)) {
2510 fprintf (of, "[%d] ", DCL_ELEM(type));
2512 fprintf (of, "[] ");
2516 if (DCL_TSPEC(type))
2519 printTypeChainRaw(DCL_TSPEC(type), of);
2523 else if (IS_SPEC (type))
2525 switch (SPEC_SCLS (type))
2527 case S_DATA: fprintf (of, "data-"); break;
2528 case S_XDATA: fprintf (of, "xdata-"); break;
2529 case S_SFR: fprintf (of, "sfr-"); break;
2530 case S_SBIT: fprintf (of, "sbit-"); break;
2531 case S_CODE: fprintf (of, "code-"); break;
2532 case S_IDATA: fprintf (of, "idata-"); break;
2533 case S_PDATA: fprintf (of, "pdata-"); break;
2534 case S_LITERAL: fprintf (of, "literal-"); break;
2535 case S_STACK: fprintf (of, "stack-"); break;
2536 case S_XSTACK: fprintf (of, "xstack-"); break;
2537 case S_BIT: fprintf (of, "bit-"); break;
2538 case S_EEPROM: fprintf (of, "eeprom-"); break;
2541 if (SPEC_VOLATILE (type))
2542 fprintf (of, "volatile-");
2543 if (SPEC_CONST (type))
2544 fprintf (of, "const-");
2545 if (SPEC_USIGN (type))
2546 fprintf (of, "unsigned-");
2547 switch (SPEC_NOUN (type))
2551 fprintf (of, "long-");
2552 fprintf (of, "int");
2556 fprintf (of, "char");
2560 fprintf (of, "void");
2564 fprintf (of, "float");
2568 fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
2572 fprintf (of, "sbit");
2576 fprintf (of, "bit");
2580 fprintf (of, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
2584 fprintf (of, "double");
2588 fprintf (of, "unknown type");
2593 fprintf (of, "NOT_SPEC_OR_DECL");
2603 /*-----------------------------------------------------------------*/
2604 /* powof2 - returns power of two for the number if number is pow 2 */
2605 /*-----------------------------------------------------------------*/
2607 powof2 (unsigned long num)
2620 if (n1s > 1 || nshifts == 0)
2636 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
2637 symbol *__muldiv[3][3][2];
2638 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
2639 sym_link *__multypes[3][2];
2640 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
2641 symbol *__conv[2][3][2];
2642 /* Dims: shift left/shift right, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
2643 symbol *__rlrr[2][3][2];
2645 sym_link *floatType;
2648 _mangleFunctionName(char *in)
2650 if (port->getMangledFunctionName)
2652 return port->getMangledFunctionName(in);
2660 /*-----------------------------------------------------------------*/
2661 /* typeFromStr - create a typechain from an encoded string */
2662 /* basic types - 'c' - char */
2668 /* '*' - pointer - default (GPOINTER) */
2669 /* modifiers - 'u' - unsigned */
2670 /* pointer modifiers - 'g' - generic */
2674 /* 'F' - function */
2675 /* examples : "ig*" - generic int * */
2676 /* "cx*" - char xdata * */
2677 /* "ui" - unsigned int */
2678 /*-----------------------------------------------------------------*/
2679 sym_link *typeFromStr (char *s)
2681 sym_link *r = newLink(DECLARATOR);
2693 r->class = SPECIFIER;
2694 SPEC_NOUN(r) = V_CHAR;
2698 r->class = SPECIFIER;
2699 SPEC_NOUN(r) = V_INT;
2702 r->class = SPECIFIER;
2703 SPEC_NOUN(r) = V_INT;
2707 r->class = SPECIFIER;
2708 SPEC_NOUN(r) = V_FLOAT;
2711 r->class = SPECIFIER;
2712 SPEC_NOUN(r) = V_VOID;
2715 DCL_TYPE(r) = port->unqualified_pointer;
2722 assert(*(s+1)=='*');
2723 nr = newLink(DECLARATOR);
2728 DCL_TYPE(r) = GPOINTER;
2731 DCL_TYPE(r) = FPOINTER;
2734 DCL_TYPE(r) = CPOINTER;
2737 DCL_TYPE(r) = POINTER;
2740 DCL_TYPE(r) = FUNCTION;
2741 nr = newLink(DECLARATOR);
2744 DCL_TYPE(r) = CPOINTER;
2750 werror(E_INTERNAL_ERROR, __FILE__, __LINE__,
2751 "typeFromStr: unknown type");
2754 if (IS_SPEC(r) && usign) {
2763 /*-----------------------------------------------------------------*/
2764 /* initCSupport - create functions for C support routines */
2765 /*-----------------------------------------------------------------*/
2769 const char *smuldivmod[] =
2773 const char *sbwd[] =
2775 "char", "int", "long"
2781 const char *srlrr[] =
2786 int bwd, su, muldivmod, tofrom, rlrr;
2788 if (getenv("SDCC_NO_C_SUPPORT")) {
2789 /* for debugging only */
2793 floatType = newFloatLink ();
2795 for (bwd = 0; bwd < 3; bwd++)
2812 __multypes[bwd][0] = l;
2813 __multypes[bwd][1] = copyLinkChain (l);
2814 SPEC_USIGN (__multypes[bwd][1]) = 1;
2817 __fsadd = funcOfType ("__fsadd", floatType, floatType, 2, options.float_rent);
2818 __fssub = funcOfType ("__fssub", floatType, floatType, 2, options.float_rent);
2819 __fsmul = funcOfType ("__fsmul", floatType, floatType, 2, options.float_rent);
2820 __fsdiv = funcOfType ("__fsdiv", floatType, floatType, 2, options.float_rent);
2821 __fseq = funcOfType ("__fseq", CHARTYPE, floatType, 2, options.float_rent);
2822 __fsneq = funcOfType ("__fsneq", CHARTYPE, floatType, 2, options.float_rent);
2823 __fslt = funcOfType ("__fslt", CHARTYPE, floatType, 2, options.float_rent);
2824 __fslteq = funcOfType ("__fslteq", CHARTYPE, floatType, 2, options.float_rent);
2825 __fsgt = funcOfType ("__fsgt", CHARTYPE, floatType, 2, options.float_rent);
2826 __fsgteq = funcOfType ("__fsgteq", CHARTYPE, floatType, 2, options.float_rent);
2828 for (tofrom = 0; tofrom < 2; tofrom++)
2830 for (bwd = 0; bwd < 3; bwd++)
2832 for (su = 0; su < 2; su++)
2836 SNPRINTF (buffer, sizeof(buffer), "__fs2%s%s", ssu[su], sbwd[bwd]);
2837 __conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
2841 SNPRINTF (buffer, sizeof(buffer), "__%s%s2fs", ssu[su], sbwd[bwd]);
2842 __conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
2849 for (muldivmod = 0; muldivmod < 3; muldivmod++)
2851 for (bwd = 0; bwd < 3; bwd++)
2853 for (su = 0; su < 2; su++)
2855 SNPRINTF (buffer, sizeof(buffer),
2857 smuldivmod[muldivmod],
2860 __muldiv[muldivmod][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
2861 FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1;
2866 muluint() and mulsint() resp. mululong() and mulslong() return the same result.
2867 Therefore they've been merged into mulint() and mullong().
2870 for (bwd = 0; bwd < 3; bwd++)
2872 for (su = 0; su < 2; su++)
2874 for (muldivmod = 1; muldivmod < 3; muldivmod++)
2877 SNPRINTF (buffer, sizeof(buffer),
2879 smuldivmod[muldivmod],
2882 __muldiv[muldivmod][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
2883 FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1;
2891 for (su = 0; su < 2; su++)
2893 /* muluchar and mulschar are still separate functions, because e.g. the z80
2894 port is sign/zero-extending to int before calling mulint() */
2895 SNPRINTF (buffer, sizeof(buffer),
2897 smuldivmod[muldivmod],
2900 __muldiv[muldivmod][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
2901 FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1;
2905 /* word and doubleword */
2906 for (bwd = 1; bwd < 3; bwd++)
2909 SNPRINTF (buffer, sizeof(buffer),
2911 smuldivmod[muldivmod],
2913 __muldiv[muldivmod][bwd][0] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
2914 FUNC_NONBANKED (__muldiv[muldivmod][bwd][0]->type) = 1;
2915 /* signed = unsigned */
2916 __muldiv[muldivmod][bwd][1] = __muldiv[muldivmod][bwd][0];
2919 for (rlrr = 0; rlrr < 2; rlrr++)
2921 for (bwd = 0; bwd < 3; bwd++)
2923 for (su = 0; su < 2; su++)
2925 SNPRINTF (buffer, sizeof(buffer),
2930 __rlrr[rlrr][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[0][0], 2, options.intlong_rent);
2931 FUNC_NONBANKED (__rlrr[rlrr][bwd][su]->type) = 1;
2937 /*-----------------------------------------------------------------*/
2938 /* initBuiltIns - create prototypes for builtin functions */
2939 /*-----------------------------------------------------------------*/
2945 if (!port->builtintable) return ;
2947 for (i = 0 ; port->builtintable[i].name ; i++) {
2948 sym = funcOfTypeVarg(port->builtintable[i].name,port->builtintable[i].rtype,
2949 port->builtintable[i].nParms,port->builtintable[i].parm_types);
2950 FUNC_ISBUILTIN(sym->type) = 1;
2951 FUNC_ISREENT(sym->type) = 0; /* can never be reentrant */
2955 sym_link *validateLink(sym_link *l,
2962 if (l && l->class==select)
2967 "Internal error: validateLink failed in %s(%s) @ %s:%u:"
2968 " expected %s, got %s\n",
2969 macro, args, file, line,
2970 DECLSPEC2TXT(select), l ? DECLSPEC2TXT(l->class) : "null-link");
2972 return l; // never reached, makes compiler happy.