93ef1d86ea2c255b9ad37c67131380c517d5df7d
[fw/sdcc] / src / SDCCsymt.c
1 /*-------------------------------------------------------------------------
2   SDCCsymt.c - Code file for Symbols table related structures and MACRO's.
3         Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1998)
4
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
8    later version.
9
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.
14
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.
18
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 -------------------------------------------------------------------------*/
23
24 #include "common.h"
25 #include "newalloc.h"
26
27 /* noun strings */
28 char *nounName(sym_link *sl) {
29   switch (SPEC_NOUN(sl)) 
30     {
31     case V_INT: {
32       if (SPEC_LONG(sl)) return "long";
33       if (SPEC_SHORT(sl)) return "short";
34       return "int";
35     }
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";
44     }
45   return "unknown";
46 };
47
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  */
53
54 /*------------------------------------------------------------------*/
55 /* initSymt () - initialises symbol table related stuff             */
56 /*------------------------------------------------------------------*/
57 void 
58 initSymt ()
59 {
60   int i = 0;
61
62   for (i = 0; i < 256; i++)
63     SymbolTab[i] = StructTab[i] = (void *) NULL;
64
65
66 }
67 /*-----------------------------------------------------------------*/
68 /* newBucket - allocates & returns a new bucket        */
69 /*-----------------------------------------------------------------*/
70 bucket *
71 newBucket ()
72 {
73   bucket *bp;
74
75   bp = Safe_calloc (1, sizeof (bucket));
76
77   return bp;
78 }
79
80 /*-----------------------------------------------------------------*/
81 /* hashKey - computes the hashkey given a symbol name              */
82 /*-----------------------------------------------------------------*/
83 int 
84 hashKey (const char *s)
85 {
86   unsigned long key = 0;
87
88   while (*s)
89     key += *s++;
90   return key % 256;
91 }
92
93 /*-----------------------------------------------------------------*/
94 /* addSym - adds a symbol to the hash Table                        */
95 /*-----------------------------------------------------------------*/
96 void 
97 addSym (bucket ** stab,
98         void *sym,
99         char *sname,
100         int level,
101         int block)
102 {
103   int i;                        /* index into the hash Table */
104   bucket *bp;                   /* temp bucket    *         */
105
106   checkTypeSanity(((symbol *)sym)->etype, sname);
107
108   /* the symbols are always added at the head of the list  */
109   i = hashKey (sname);
110   /* get a free entry */
111   bp = Safe_calloc (1, sizeof (bucket));
112
113   bp->sym = sym;                /* update the symbol pointer  */
114   bp->level = level;            /* update the nest level      */
115   bp->block = block;
116   strcpy (bp->name, sname);     /* copy the name into place */
117
118   /* if this is the first entry */
119   if (stab[i] == NULL)
120     {
121       bp->prev = bp->next = (void *) NULL;      /* point to nothing */
122       stab[i] = bp;
123     }
124   /* not first entry then add @ head of list */
125   else
126     {
127       bp->prev = NULL;
128       stab[i]->prev = bp;
129       bp->next = stab[i];
130       stab[i] = bp;
131     }
132 }
133
134 /*-----------------------------------------------------------------*/
135 /* deleteSym - deletes a symbol from the hash Table  entry     */
136 /*-----------------------------------------------------------------*/
137 void 
138 deleteSym (bucket ** stab, void *sym, char *sname)
139 {
140   int i = 0;
141   bucket *bp;
142
143   i = hashKey (sname);
144
145   bp = stab[i];
146   /* find the symbol */
147   while (bp)
148     {
149       if (bp->sym == sym)       /* found it then break out */
150         break;                  /* of the loop       */
151       bp = bp->next;
152     }
153
154   if (!bp)                      /* did not find it */
155     return;
156   /* if this is the first one in the chain */
157   if (!bp->prev)
158     {
159       stab[i] = bp->next;
160       if (stab[i])              /* if chain ! empty */
161         stab[i]->prev = (void *) NULL;
162     }
163   /* middle || end of chain */
164   else
165     {
166       if (bp->next)             /* if not end of chain */
167         bp->next->prev = bp->prev;
168
169       bp->prev->next = bp->next;
170     }
171
172 }
173
174 /*-----------------------------------------------------------------*/
175 /* findSym - finds a symbol in a table           */
176 /*-----------------------------------------------------------------*/
177 void *
178 findSym (bucket ** stab, void *sym, const char *sname)
179 {
180   bucket *bp;
181
182   bp = stab[hashKey (sname)];
183   while (bp)
184     {
185       if (bp->sym == sym || strcmp (bp->name, sname) == 0)
186         break;
187       bp = bp->next;
188     }
189
190   return (bp ? bp->sym : (void *) NULL);
191 }
192
193 /*-----------------------------------------------------------------*/
194 /* findSymWithLevel - finds a symbol with a name & level           */
195 /*-----------------------------------------------------------------*/
196 void *
197 findSymWithLevel (bucket ** stab, symbol * sym)
198 {
199   bucket *bp;
200
201   bp = stab[hashKey (sym->name)];
202
203   /**
204    **  do the search from the head of the list since the
205    **  elements are added at the head it is ensured that
206    ** we will find the deeper definitions before we find
207    ** the global ones. we need to check for symbols with
208    ** level <= to the level given, if levels match then block
209    ** numbers need to match as well
210    **/
211   while (bp)
212     {
213
214       if (strcmp (bp->name, sym->name) == 0 && bp->level <= sym->level)
215         {
216           /* if this is parameter then nothing else need to be checked */
217           if (((symbol *) (bp->sym))->_isparm)
218             return (bp->sym);
219           /* if levels match then block numbers hsould also match */
220           if (bp->level && bp->level == sym->level && bp->block == sym->block)
221             return (bp->sym);
222           /* if levels don't match then we are okay */
223           if (bp->level && bp->level != sym->level && bp->block <= sym->block)
224             return (bp->sym);
225           /* if this is a global variable then we are ok too */
226           if (bp->level == 0)
227             return (bp->sym);
228         }
229
230       bp = bp->next;
231     }
232
233   return (void *) NULL;
234 }
235
236 /*-----------------------------------------------------------------*/
237 /* findSymWithBlock - finds a symbol with name in with a block     */
238 /*-----------------------------------------------------------------*/
239 void *
240 findSymWithBlock (bucket ** stab, symbol * sym, int block)
241 {
242   bucket *bp;
243
244   bp = stab[hashKey (sym->name)];
245   while (bp)
246     {
247       if (strcmp (bp->name, sym->name) == 0 &&
248           bp->block <= block)
249         break;
250       bp = bp->next;
251     }
252
253   return (bp ? bp->sym : (void *) NULL);
254 }
255
256 /*------------------------------------------------------------------*/
257 /* newSymbol () - returns a new pointer to a symbol                 */
258 /*------------------------------------------------------------------*/
259 symbol *
260 newSymbol (char *name, int scope)
261 {
262   symbol *sym;
263
264   sym = Safe_calloc (1, sizeof (symbol));
265
266   strcpy (sym->name, name);     /* copy the name    */
267   sym->level = scope;           /* set the level    */
268   sym->block = currBlockno;
269   sym->lineDef = yylineno;      /* set the line number */
270   return sym;
271 }
272
273 /*------------------------------------------------------------------*/
274 /* newLink - creates a new link (declarator,specifier)              */
275 /*------------------------------------------------------------------*/
276 sym_link *
277 newLink ()
278 {
279   sym_link *p;
280
281   p = Safe_calloc (1, sizeof (sym_link));
282
283   return p;
284 }
285
286 /*------------------------------------------------------------------*/
287 /* newStruct - creats a new structdef from the free list            */
288 /*------------------------------------------------------------------*/
289 structdef *
290 newStruct (char *tag)
291 {
292   structdef *s;
293
294   s = Safe_calloc (1, sizeof (structdef));
295
296   strcpy (s->tag, tag);         /* copy the tag            */
297   return s;
298 }
299
300 /*------------------------------------------------------------------*/
301 /* pointerTypes - do the computation for the pointer types          */
302 /*------------------------------------------------------------------*/
303 void 
304 pointerTypes (sym_link * ptr, sym_link * type)
305 {
306   if (IS_SPEC (ptr))
307     return;
308
309   /* find the first pointer type */
310   while (ptr && !IS_PTR (ptr))
311     ptr = ptr->next;
312
313   /* could not find it */
314   if (!ptr || IS_SPEC (ptr) ||
315       DCL_TYPE (ptr) != UPOINTER)
316     return;
317
318   /* change the pointer type depending on the
319      storage class of the type */
320   if (IS_SPEC (type))
321     {
322       DCL_PTR_CONST (ptr) = SPEC_CONST (type);
323       DCL_PTR_VOLATILE (ptr) = SPEC_VOLATILE (type);
324       switch (SPEC_SCLS (type))
325         {
326         case S_XDATA:
327           DCL_TYPE (ptr) = FPOINTER;
328           break;
329         case S_IDATA:
330           DCL_TYPE (ptr) = IPOINTER;
331           break;
332         case S_PDATA:
333           DCL_TYPE (ptr) = PPOINTER;
334           break;
335         case S_DATA:
336           DCL_TYPE (ptr) = POINTER;
337           break;
338         case S_CODE:
339           DCL_PTR_CONST (ptr) = port->mem.code_ro;
340           DCL_TYPE (ptr) = CPOINTER;
341           break;
342         case S_EEPROM:
343           DCL_TYPE (ptr) = EEPPOINTER;
344           break;
345         default:
346           DCL_TYPE (ptr) = GPOINTER;
347           break;
348         }
349       /* the storage class of type ends here */
350       SPEC_SCLS (type) =
351         SPEC_CONST (type) =
352         SPEC_VOLATILE (type) = 0;
353     }
354
355   /* now change all the remaining unknown pointers
356      to generic pointers */
357   while (ptr)
358     {
359       if (!IS_SPEC (ptr) && DCL_TYPE (ptr) == UPOINTER)
360         DCL_TYPE (ptr) = GPOINTER;
361       ptr = ptr->next;
362     }
363
364   /* same for the type although it is highly unlikely that
365      type will have a pointer */
366   while (type)
367     {
368       if (!IS_SPEC (type) && DCL_TYPE (type) == UPOINTER)
369         DCL_TYPE (type) = GPOINTER;
370       type = type->next;
371     }
372
373 }
374
375 /*------------------------------------------------------------------*/
376 /* addDecl - adds a declarator @ the end of a chain                 */
377 /*------------------------------------------------------------------*/
378 void 
379 addDecl (symbol * sym, int type, sym_link * p)
380 {
381   sym_link *head;
382   sym_link *tail;
383   sym_link *t;
384
385   /* if we are passed a link then set head & tail */
386   if (p)
387     {
388       tail = head = p;
389       while (tail->next)
390         tail = tail->next;
391     }
392   else
393     {
394       head = tail = newLink ();
395       DCL_TYPE (head) = type;
396     }
397
398   /* if this is the first entry   */
399   if (!sym->type)
400     {
401       sym->type = head;
402       sym->etype = tail;
403     }
404   else
405     {
406       if (IS_SPEC (sym->etype) && IS_SPEC (head) && head == tail)
407         {
408           sym->etype = mergeSpec (sym->etype, head);
409         }
410       else
411         {
412           if (IS_SPEC (sym->etype) && !IS_SPEC (head) && head == tail)
413             {
414               t = sym->type;
415               while (t->next != sym->etype)
416                 t = t->next;
417               t->next = head;
418               tail->next = sym->etype;
419             }
420           else
421             {
422               sym->etype->next = head;
423               sym->etype = tail;
424             }
425         }
426     }
427
428   /* if the type is a unknown pointer and has
429      a tspec then take the storage class const & volatile
430      attribute from the tspec & make it those of this
431      symbol */
432   if (p &&
433       !IS_SPEC (p) &&
434       DCL_TYPE (p) == UPOINTER &&
435       DCL_TSPEC (p))
436     {
437       if (!IS_SPEC (sym->etype))
438         {
439           sym->etype = sym->etype->next = newLink ();
440           sym->etype->class = SPECIFIER;
441         }
442       SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p));
443       SPEC_CONST (sym->etype) = SPEC_CONST (DCL_TSPEC (p));
444       SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p));
445       DCL_TSPEC (p) = NULL;
446     }
447   return;
448 }
449
450 /*------------------------------------------------------------------
451   checkTypeSanity: prevent the user from doing e.g.:
452   unsigned float uf;
453   ------------------------------------------------------------------*/
454 void checkTypeSanity(sym_link *dest, char *name) {
455   char *noun;
456
457   if (!dest) {
458     //printf ("sanity check skipped for %s\n", name);
459     return;
460   }
461
462   noun=nounName(dest);
463
464   //printf ("checking sanity for %s\n", name);
465
466   if ((SPEC_NOUN(dest)==V_CHAR || 
467        SPEC_NOUN(dest)==V_FLOAT || 
468        SPEC_NOUN(dest)==V_DOUBLE || 
469        SPEC_NOUN(dest)==V_VOID) &&
470       (SPEC_SHORT(dest) || SPEC_LONG(dest))) {
471     // long or short for char float double or void
472     werror (E_LONG_OR_SHORT_INVALID, noun, name);
473   }
474   if ((SPEC_NOUN(dest)==V_FLOAT || 
475        SPEC_NOUN(dest)==V_DOUBLE || 
476        SPEC_NOUN(dest)==V_VOID) && 
477       (SPEC_SIGNED(dest) || SPEC_USIGN(dest))) {
478     // signed or unsigned for float double or void
479     werror (E_SIGNED_OR_UNSIGNED_INVALID, noun, name);
480   }
481   if (SPEC_SIGNED(dest) && SPEC_USIGN(dest)) {
482     // signed AND unsigned 
483     werror (E_SIGNED_AND_UNSIGNED_INVALID, noun, name);
484   }
485   if (SPEC_SHORT(dest) && SPEC_LONG(dest)) {
486     // short AND long
487     werror (E_LONG_AND_SHORT_INVALID, noun, name);
488   }
489
490 }
491
492 /*------------------------------------------------------------------*/
493 /* mergeSpec - merges two specifiers and returns the new one        */
494 /*------------------------------------------------------------------*/
495 sym_link *
496 mergeSpec (sym_link * dest, sym_link * src)
497 {
498
499   /* we shouldn't redeclare the type */
500   if ((SPEC_NOUN (dest) && SPEC_NOUN (src)) && 
501       (SPEC_NOUN(dest) != SPEC_NOUN(src))) {
502     werror(E_TWO_OR_MORE_DATA_TYPES, yylval.yychar);
503   }
504
505   /* if noun different then src overrides */
506   if (SPEC_NOUN (dest) != SPEC_NOUN (src) && !SPEC_NOUN (dest))
507     SPEC_NOUN (dest) = SPEC_NOUN (src);
508
509   /* if destination has no storage class */
510   if (!SPEC_SCLS (dest) || 
511       ((SPEC_SCLS(dest) == S_CONSTANT || SPEC_SCLS(dest) == S_REGISTER) && 
512        SPEC_SCLS (src)))
513     SPEC_SCLS (dest) = SPEC_SCLS (src);
514   /* special case for const */
515   /* copy all the specifications  */
516   SPEC_LONG (dest) |= SPEC_LONG (src);
517   SPEC_SHORT (dest) |= SPEC_SHORT (src);
518   SPEC_USIGN (dest) |= SPEC_USIGN (src);
519   SPEC_SIGNED (dest) |= SPEC_SIGNED (src);
520   SPEC_STAT (dest) |= SPEC_STAT (src);
521   SPEC_EXTR (dest) |= SPEC_EXTR (src);
522   SPEC_ABSA (dest) |= SPEC_ABSA (src);
523   SPEC_RENT (dest) |= SPEC_RENT (src);
524   SPEC_INTN (dest) |= SPEC_INTN (src);
525   SPEC_BANK (dest) |= SPEC_BANK (src);
526   SPEC_VOLATILE (dest) |= SPEC_VOLATILE (src);
527   SPEC_CRTCL (dest) |= SPEC_CRTCL (src);
528   SPEC_ADDR (dest) |= SPEC_ADDR (src);
529   SPEC_OCLS (dest) = SPEC_OCLS (src);
530   SPEC_BLEN (dest) |= SPEC_BLEN (src);
531   SPEC_BSTR (dest) |= SPEC_BSTR (src);
532   SPEC_TYPEDEF (dest) |= SPEC_TYPEDEF (src);
533   SPEC_NONBANKED (dest) |= SPEC_NONBANKED (src);
534   SPEC_NAKED (dest) |= SPEC_NAKED (src);
535
536   if (IS_STRUCT (dest) && SPEC_STRUCT (dest) == NULL)
537     SPEC_STRUCT (dest) = SPEC_STRUCT (src);
538
539   return dest;
540 }
541
542 /*------------------------------------------------------------------*/
543 /* cloneSpec - copies the entire spec and returns a new spec        */
544 /*------------------------------------------------------------------*/
545 sym_link *
546 cloneSpec (sym_link * src)
547 {
548   sym_link *spec;
549
550   /* go thru chain till we find the specifier */
551   while (src && src->class != SPECIFIER)
552     src = src->next;
553
554   spec = newLink ();
555   memcpy (spec, src, sizeof (sym_link));
556   return spec;
557 }
558
559 /*------------------------------------------------------------------*/
560 /* genSymName - generates and returns a name used for anonymous vars */
561 /*------------------------------------------------------------------*/
562 char *
563 genSymName (int level)
564 {
565   static int gCount = 0;
566   static char gname[SDCC_NAME_MAX + 1];
567
568   sprintf (gname, "__%04d%04d", level, gCount++);
569   return gname;
570 }
571
572 /*------------------------------------------------------------------*/
573 /* getSpec - returns the specifier part from a declaration chain    */
574 /*------------------------------------------------------------------*/
575 sym_link *
576 getSpec (sym_link * p)
577 {
578   sym_link *loop;
579
580   loop = p;
581   while (p && !(IS_SPEC (p)))
582     p = p->next;
583
584   return p;
585 }
586
587 /*------------------------------------------------------------------*/
588 /* newCharLink() - creates an char type                             */
589 /*------------------------------------------------------------------*/
590 sym_link *
591 newCharLink ()
592 {
593   sym_link *p;
594
595   p = newLink ();
596   p->class = SPECIFIER;
597   SPEC_NOUN (p) = V_CHAR;
598
599   return p;
600 }
601
602 /*------------------------------------------------------------------*/
603 /* newFloatLink - a new Float type                                  */
604 /*------------------------------------------------------------------*/
605 sym_link *
606 newFloatLink ()
607 {
608   sym_link *p;
609
610   p = newLink ();
611   p->class = SPECIFIER;
612   SPEC_NOUN (p) = V_FLOAT;
613
614   return p;
615 }
616
617 /*------------------------------------------------------------------*/
618 /* newLongLink() - new long type                                    */
619 /*------------------------------------------------------------------*/
620 sym_link *
621 newLongLink ()
622 {
623   sym_link *p;
624
625   p = newLink ();
626   p->class = SPECIFIER;
627   SPEC_NOUN (p) = V_INT;
628   SPEC_LONG (p) = 1;
629
630   return p;
631 }
632
633 /*------------------------------------------------------------------*/
634 /* newIntLink() - creates an int type                               */
635 /*------------------------------------------------------------------*/
636 sym_link *
637 newIntLink ()
638 {
639   sym_link *p;
640
641   p = newLink ();
642   p->class = SPECIFIER;
643   SPEC_NOUN (p) = V_INT;
644
645   return p;
646 }
647
648 /*------------------------------------------------------------------*/
649 /* getSize - returns size of a type chain in bits                   */
650 /*------------------------------------------------------------------*/
651 unsigned int 
652 getSize (sym_link * p)
653 {
654   /* if nothing return 0 */
655   if (!p)
656     return 0;
657   if (IS_SPEC (p))
658     {                           /* if this is the specifier then */
659       switch (SPEC_NOUN (p))
660         {                       /* depending on the specifier type */
661         case V_INT:
662           return (IS_LONG (p) ? LONGSIZE : (IS_SHORT (p) ? SHORTSIZE : INTSIZE));
663         case V_FLOAT:
664           return FLOATSIZE;
665         case V_CHAR:
666           return CHARSIZE;
667         case V_VOID:
668           return 0;
669         case V_STRUCT:
670           return SPEC_STRUCT (p)->size;
671         case V_LABEL:
672           return 0;
673         case V_SBIT:
674           return BITSIZE;
675         case V_BIT:
676           return ((SPEC_BLEN (p) / 8) + (SPEC_BLEN (p) % 8 ? 1 : 0));
677         default:
678           return 0;
679         }
680     }
681
682   /* this is a specifier  */
683   switch (DCL_TYPE (p))
684     {
685     case FUNCTION:
686       return 2;
687     case ARRAY:
688       return DCL_ELEM (p) * getSize (p->next);
689     case IPOINTER:
690     case PPOINTER:
691     case POINTER:
692       return (PTRSIZE);
693     case EEPPOINTER:
694     case FPOINTER:
695     case CPOINTER:
696       return (FPTRSIZE);
697     case GPOINTER:
698       return (GPTRSIZE);
699
700     default:
701       return 0;
702     }
703 }
704
705 /*------------------------------------------------------------------*/
706 /* bitsForType - returns # of bits required to store this type      */
707 /*------------------------------------------------------------------*/
708 unsigned int 
709 bitsForType (sym_link * p)
710 {
711   /* if nothing return 0 */
712   if (!p)
713     return 0;
714
715   if (IS_SPEC (p))
716     {                           /* if this is the specifier then */
717
718       switch (SPEC_NOUN (p))
719         {                       /* depending on the specifier type */
720         case V_INT:
721           return (IS_LONG (p) ? LONGSIZE * 8 : (IS_SHORT (p) ? SHORTSIZE * 8 : INTSIZE * 8));
722         case V_FLOAT:
723           return FLOATSIZE * 8;
724         case V_CHAR:
725           return CHARSIZE * 8;
726         case V_VOID:
727           return 0;
728         case V_STRUCT:
729           return SPEC_STRUCT (p)->size * 8;
730         case V_LABEL:
731           return 0;
732         case V_SBIT:
733           return 1;
734         case V_BIT:
735           return SPEC_BLEN (p);
736         default:
737           return 0;
738         }
739     }
740
741   /* this is a specifier  */
742   switch (DCL_TYPE (p))
743     {
744     case FUNCTION:
745       return 2;
746     case ARRAY:
747       return DCL_ELEM (p) * getSize (p->next) * 8;
748     case IPOINTER:
749     case PPOINTER:
750     case POINTER:
751       return (PTRSIZE * 8);
752     case EEPPOINTER:
753     case FPOINTER:
754     case CPOINTER:
755       return (FPTRSIZE * 8);
756     case GPOINTER:
757       return (GPTRSIZE * 8);
758
759     default:
760       return 0;
761     }
762 }
763
764 /*------------------------------------------------------------------*/
765 /* copySymbolChain - copies a symbol chain                          */
766 /*------------------------------------------------------------------*/
767 symbol *
768 copySymbolChain (symbol * src)
769 {
770   symbol *dest;
771
772   if (!src)
773     return NULL;
774
775   dest = copySymbol (src);
776   dest->next = copySymbolChain (src->next);
777   return dest;
778 }
779
780 /*------------------------------------------------------------------*/
781 /* copySymbol - makes a copy of a symbol                            */
782 /*------------------------------------------------------------------*/
783 symbol *
784 copySymbol (symbol * src)
785 {
786   symbol *dest;
787
788   if (!src)
789     return NULL;
790
791   dest = newSymbol (src->name, src->level);
792   memcpy (dest, src, sizeof (symbol));
793   dest->level = src->level;
794   dest->block = src->block;
795   dest->ival = copyIlist (src->ival);
796   dest->type = copyLinkChain (src->type);
797   dest->etype = getSpec (dest->type);
798   dest->next = NULL;
799   dest->args = copyValueChain (src->args);
800   dest->key = src->key;
801   dest->calleeSave = src->calleeSave;
802   dest->allocreq = src->allocreq;
803   return dest;
804 }
805
806 /*------------------------------------------------------------------*/
807 /* reverseSyms - reverses the links for a symbol chain      */
808 /*------------------------------------------------------------------*/
809 symbol *
810 reverseSyms (symbol * sym)
811 {
812   symbol *prev, *curr, *next;
813
814   if (!sym)
815     return NULL;
816
817   prev = sym;
818   curr = sym->next;
819
820   while (curr)
821     {
822       next = curr->next;
823       curr->next = prev;
824       prev = curr;
825       curr = next;
826     }
827   sym->next = (void *) NULL;
828   return prev;
829 }
830
831 /*------------------------------------------------------------------*/
832 /* reverseLink - reverses the links for a type chain        */
833 /*------------------------------------------------------------------*/
834 sym_link *
835 reverseLink (sym_link * type)
836 {
837   sym_link *prev, *curr, *next;
838
839   if (!type)
840     return NULL;
841
842   prev = type;
843   curr = type->next;
844
845   while (curr)
846     {
847       next = curr->next;
848       curr->next = prev;
849       prev = curr;
850       curr = next;
851     }
852   type->next = (void *) NULL;
853   return prev;
854 }
855
856 /*------------------------------------------------------------------*/
857 /* addSymChain - adds a symbol chain to the symboltable             */
858 /*------------------------------------------------------------------*/
859 void 
860 addSymChain (symbol * symHead)
861 {
862   symbol *sym = symHead;
863   symbol *csym = NULL;
864
865
866   for (; sym != NULL; sym = sym->next)
867     {
868       changePointer(sym);
869
870       /* if already exists in the symbol table then check if
871          the previous was an extern definition if yes then
872          then check if the type match, if the types match then
873          delete the current entry and add the new entry      */
874       if ((csym = findSymWithLevel (SymbolTab, sym)) &&
875           csym->level == sym->level)
876         {
877
878           /* previous definition extern ? */
879           if (1 || IS_EXTERN (csym->etype))
880             {
881               /* do types match ? */
882               if (checkType (csym->type, sym->type) != 1)
883                 /* no then error */
884                 werror (E_DUPLICATE, csym->name);
885
886               /* delete current entry */
887               deleteSym (SymbolTab, csym, csym->name);
888               /* add new entry */
889               addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
890             }
891           else                  /* not extern */
892             werror (E_DUPLICATE, sym->name);
893           continue;
894         }
895
896       /* check if previously defined */
897       if (csym && csym->level == sym->level)
898         {
899           /* if the previous one was declared as extern */
900           /* then check the type with the current one         */
901           if (IS_EXTERN (csym->etype))
902             {
903               if (checkType (csym->type, sym->type) <= 0)
904                 werror (W_EXTERN_MISMATCH, csym->name);
905             }
906         }
907       addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
908     }
909 }
910
911
912 /*------------------------------------------------------------------*/
913 /* funcInChain - DCL Type 'FUNCTION' found in type chain            */
914 /*------------------------------------------------------------------*/
915 int 
916 funcInChain (sym_link * lnk)
917 {
918   while (lnk)
919     {
920       if (IS_FUNC (lnk))
921         return 1;
922       lnk = lnk->next;
923     }
924   return 0;
925 }
926
927 /*------------------------------------------------------------------*/
928 /* structElemType - returns the type info of a sturct member        */
929 /*------------------------------------------------------------------*/
930 sym_link *
931 structElemType (sym_link * stype, value * id, value ** argsp)
932 {
933   symbol *fields = (SPEC_STRUCT (stype) ? SPEC_STRUCT (stype)->fields : NULL);
934   sym_link *type, *etype;
935   sym_link *petype = getSpec (stype);
936
937   if (!fields || !id)
938     return NULL;
939
940   /* look for the id */
941   while (fields)
942     {
943       if (strcmp (fields->rname, id->name) == 0)
944         {
945           if (argsp)
946             {
947               *argsp = fields->args;
948             }
949           type = copyLinkChain (fields->type);
950           etype = getSpec (type);
951           SPEC_SCLS (etype) = (SPEC_SCLS (petype) == S_REGISTER ?
952                                SPEC_SCLS (etype) : SPEC_SCLS (petype));
953           return type;
954         }
955       fields = fields->next;
956     }
957   werror (E_NOT_MEMBER, id->name);
958
959   return NULL;
960 }
961
962 /*------------------------------------------------------------------*/
963 /* getStructElement - returns element of a tructure definition      */
964 /*------------------------------------------------------------------*/
965 symbol *
966 getStructElement (structdef * sdef, symbol * sym)
967 {
968   symbol *field;
969
970   for (field = sdef->fields; field; field = field->next)
971     if (strcmp (field->name, sym->name) == 0)
972       return field;
973
974   werror (E_NOT_MEMBER, sym->name);
975
976   return sdef->fields;
977 }
978
979 /*------------------------------------------------------------------*/
980 /* compStructSize - computes the size of a structure                */
981 /*------------------------------------------------------------------*/
982 int 
983 compStructSize (int su, structdef * sdef)
984 {
985     int sum = 0, usum = 0;
986     int bitOffset = 0;
987     symbol *loop;
988
989     /* for the identifiers  */
990     loop = sdef->fields;
991     while (loop) {
992
993         /* create the internal name for this variable */
994         sprintf (loop->rname, "_%s", loop->name);
995         loop->offset = (su == UNION ? sum = 0 : sum);
996         SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
997
998         /* if this is a bit field  */
999         if (loop->bitVar) {
1000
1001             /* change it to a unsigned bit */
1002             SPEC_NOUN (loop->etype) = V_BIT;
1003             SPEC_USIGN (loop->etype) = 1;
1004             /* check if this fit into the remaining   */
1005             /* bits of this byte else align it to the */
1006             /* next byte boundary                     */
1007             if ((SPEC_BLEN (loop->etype) = loop->bitVar) <= (8 - bitOffset)) {
1008                 SPEC_BSTR (loop->etype) = bitOffset;
1009                 if ((bitOffset += (loop->bitVar % 8)) == 8)
1010                     sum++;
1011             }
1012             else /* does not fit */ {
1013                 bitOffset = 0;
1014                 SPEC_BSTR (loop->etype) = bitOffset;
1015                 sum += (loop->bitVar / 8);
1016                 bitOffset += (loop->bitVar % 8);
1017             }
1018             /* if this is the last field then pad */
1019             if (!loop->next && bitOffset && bitOffset != 8) {
1020                 bitOffset = 0;
1021                 sum++;
1022             }
1023         }
1024         else {
1025             checkDecl (loop);
1026             sum += getSize (loop->type);
1027         }
1028
1029         /* if function then do the arguments for it */
1030         if (funcInChain (loop->type)) {
1031             processFuncArgs (loop, 1);
1032         }
1033
1034         loop = loop->next;
1035
1036         /* if this is not a bitfield but the */
1037         /* previous one was and did not take */
1038         /* the whole byte then pad the rest  */
1039         if ((loop && !loop->bitVar) && bitOffset) {
1040             bitOffset = 0;
1041             sum++;
1042         }
1043
1044         /* if union then size = sizeof larget field */
1045         if (su == UNION)
1046             usum = max (usum, sum);
1047
1048     }
1049
1050     return (su == UNION ? usum : sum);
1051 }
1052
1053 /*------------------------------------------------------------------*/
1054 /* checkSClass - check the storage class specification              */
1055 /*------------------------------------------------------------------*/
1056 static void 
1057 checkSClass (symbol * sym)
1058 {
1059   /* type is literal can happen foe enums change
1060      to auto */
1061   if (SPEC_SCLS (sym->etype) == S_LITERAL && !SPEC_ENUM (sym->etype))
1062     SPEC_SCLS (sym->etype) = S_AUTO;
1063
1064   /* if sfr or sbit then must also be */
1065   /* volatile the initial value will be xlated */
1066   /* to an absolute address */
1067   if (SPEC_SCLS (sym->etype) == S_SBIT ||
1068       SPEC_SCLS (sym->etype) == S_SFR)
1069     {
1070       SPEC_VOLATILE (sym->etype) = 1;
1071       /* if initial value given */
1072       if (sym->ival)
1073         {
1074           SPEC_ABSA (sym->etype) = 1;
1075           SPEC_ADDR (sym->etype) =
1076             (int) list2int (sym->ival);
1077           sym->ival = NULL;
1078         }
1079     }
1080
1081   /* if absolute address given then it mark it as
1082      volatile */
1083   if (IS_ABSOLUTE (sym->etype))
1084     SPEC_VOLATILE (sym->etype) = 1;
1085
1086   /* global variables declared const put into code */
1087   if (sym->level == 0 &&
1088       SPEC_SCLS (sym->etype) == S_CONSTANT)
1089     {
1090       SPEC_SCLS (sym->etype) = S_CODE;
1091       SPEC_CONST (sym->etype) = 1;
1092     }
1093
1094   /* global variable in code space is a constant */
1095   if (sym->level == 0 &&
1096       SPEC_SCLS (sym->etype) == S_CODE &&
1097       port->mem.code_ro)
1098     SPEC_CONST (sym->etype) = 1;
1099
1100
1101   /* if bit variable then no storage class can be */
1102   /* specified since bit is already a storage */
1103   if (IS_BITVAR (sym->etype) &&
1104       (SPEC_SCLS (sym->etype) != S_FIXED &&
1105        SPEC_SCLS (sym->etype) != S_SBIT &&
1106        SPEC_SCLS (sym->etype) != S_BIT)
1107     )
1108     {
1109       werror (E_BITVAR_STORAGE, sym->name);
1110       SPEC_SCLS (sym->etype) = S_FIXED;
1111     }
1112
1113   /* extern variables cannot be initialized */
1114   if (IS_EXTERN (sym->etype) && sym->ival)
1115     {
1116       werror (E_EXTERN_INIT, sym->name);
1117       sym->ival = NULL;
1118     }
1119
1120   /* if this is an automatic symbol then */
1121   /* storage class will be ignored and   */
1122   /* symbol will be allocated on stack/  */
1123   /* data depending on flag             */
1124   if (sym->level &&
1125       (options.stackAuto || reentrant) &&
1126       (SPEC_SCLS (sym->etype) != S_AUTO &&
1127        SPEC_SCLS (sym->etype) != S_FIXED &&
1128        SPEC_SCLS (sym->etype) != S_REGISTER &&
1129        SPEC_SCLS (sym->etype) != S_STACK &&
1130        SPEC_SCLS (sym->etype) != S_XSTACK &&
1131        SPEC_SCLS (sym->etype) != S_CONSTANT))
1132     {
1133       werror (E_AUTO_ASSUMED, sym->name);
1134       SPEC_SCLS (sym->etype) = S_AUTO;
1135     }
1136
1137   /* automatic symbols cannot be given   */
1138   /* an absolute address ignore it      */
1139   if (sym->level &&
1140       SPEC_ABSA (sym->etype) &&
1141       (options.stackAuto || reentrant))
1142     {
1143       werror (E_AUTO_ABSA, sym->name);
1144       SPEC_ABSA (sym->etype) = 0;
1145     }
1146
1147   /* arrays & pointers cannot be defined for bits   */
1148   /* SBITS or SFRs or BIT                           */
1149   if ((IS_ARRAY (sym->type) || IS_PTR (sym->type)) &&
1150       (SPEC_NOUN (sym->etype) == V_BIT ||
1151        SPEC_NOUN (sym->etype) == V_SBIT ||
1152        SPEC_SCLS (sym->etype) == S_SFR))
1153     werror (E_BIT_ARRAY, sym->name);
1154
1155   /* if this is a bit|sbit then set length & start  */
1156   if (SPEC_NOUN (sym->etype) == V_BIT ||
1157       SPEC_NOUN (sym->etype) == V_SBIT)
1158     {
1159       SPEC_BLEN (sym->etype) = 1;
1160       SPEC_BSTR (sym->etype) = 0;
1161     }
1162
1163   /* variables declared in CODE space must have */
1164   /* initializers if not an extern */
1165   if (SPEC_SCLS (sym->etype) == S_CODE &&
1166       sym->ival == NULL &&
1167       !sym->level &&
1168       port->mem.code_ro &&
1169       !IS_EXTERN (sym->etype) &&
1170       !funcInChain (sym->type))
1171     werror (E_CODE_NO_INIT, sym->name);
1172
1173   /* if parameter or local variable then change */
1174   /* the storage class to reflect where the var will go */
1175   if (sym->level && SPEC_SCLS (sym->etype) == S_FIXED &&
1176       !IS_STATIC(sym->etype))
1177     {
1178       if (options.stackAuto || (currFunc && IS_RENT (currFunc->etype)))
1179         {
1180           SPEC_SCLS (sym->etype) = (options.useXstack ?
1181                                     S_XSTACK : S_STACK);
1182         }
1183       else
1184         {
1185           /* hack-o-matic! I see no reason why the useXstack option should ever
1186            * control this allcoation, but the code was originally that way, and
1187            * changing it for non-390 ports breaks the compiler badly.
1188            */
1189           bool useXdata = TARGET_IS_DS390 ? 1 : options.useXstack;
1190           SPEC_SCLS (sym->etype) = (useXdata ?
1191                                     S_XDATA : S_FIXED);
1192         }
1193     }
1194 }
1195
1196 /*------------------------------------------------------------------*/
1197 /* changePointer - change pointer to functions                      */
1198 /*------------------------------------------------------------------*/
1199 void 
1200 changePointer (symbol * sym)
1201 {
1202   sym_link *p;
1203
1204   /* go thru the chain of declarations   */
1205   /* if we find a pointer to a function  */
1206   /* unconditionally change it to a ptr  */
1207   /* to code area                        */
1208   for (p = sym->type; p; p = p->next)
1209     {
1210       if (!IS_SPEC (p) && DCL_TYPE (p) == UPOINTER)
1211         DCL_TYPE (p) = GPOINTER;
1212       if (IS_PTR (p) && IS_FUNC (p->next))
1213         DCL_TYPE (p) = CPOINTER;
1214     }
1215 }
1216
1217 /*------------------------------------------------------------------*/
1218 /* checkDecl - does semantic validation of a declaration                   */
1219 /*------------------------------------------------------------------*/
1220 int 
1221 checkDecl (symbol * sym)
1222 {
1223
1224   checkSClass (sym);            /* check the storage class      */
1225   changePointer (sym);          /* change pointers if required */
1226
1227   /* if this is an array without any dimension
1228      then update the dimension from the initial value */
1229   if (IS_ARRAY (sym->type) && !DCL_ELEM (sym->type))
1230     DCL_ELEM (sym->type) = getNelements (sym->type, sym->ival);
1231
1232   return 0;
1233 }
1234
1235 /*------------------------------------------------------------------*/
1236 /* copyLinkChain - makes a copy of the link chain & rets ptr 2 head */
1237 /*------------------------------------------------------------------*/
1238 sym_link *
1239 copyLinkChain (sym_link * p)
1240 {
1241   sym_link *head, *curr, *loop;
1242
1243   curr = p;
1244   head = loop = (curr ? newLink () : (void *) NULL);
1245   while (curr)
1246     {
1247       memcpy (loop, curr, sizeof (sym_link));   /* copy it */
1248       loop->next = (curr->next ? newLink () : (void *) NULL);
1249       loop = loop->next;
1250       curr = curr->next;
1251     }
1252
1253   return head;
1254 }
1255
1256
1257 /*------------------------------------------------------------------*/
1258 /* cleanUpBlock - cleansup the symbol table specified for all the   */
1259 /*                symbols in the given block                        */
1260 /*------------------------------------------------------------------*/
1261 void 
1262 cleanUpBlock (bucket ** table, int block)
1263 {
1264   int i;
1265   bucket *chain;
1266
1267   /* go thru the entire  table  */
1268   for (i = 0; i < 256; i++)
1269     {
1270       for (chain = table[i]; chain; chain = chain->next)
1271         {
1272           if (chain->block >= block)
1273             {
1274               deleteSym (table, chain->sym, chain->name);
1275             }
1276         }
1277     }
1278 }
1279
1280 /*------------------------------------------------------------------*/
1281 /* cleanUpLevel - cleansup the symbol table specified for all the   */
1282 /*                symbols in the given level                        */
1283 /*------------------------------------------------------------------*/
1284 void 
1285 cleanUpLevel (bucket ** table, int level)
1286 {
1287   int i;
1288   bucket *chain;
1289
1290   /* go thru the entire  table  */
1291   for (i = 0; i < 256; i++)
1292     {
1293       for (chain = table[i]; chain; chain = chain->next)
1294         {
1295           if (chain->level >= level)
1296             {
1297               deleteSym (table, chain->sym, chain->name);
1298             }
1299         }
1300     }
1301 }
1302
1303 /*------------------------------------------------------------------*/
1304 /* computeType - computes the resultant type from two types         */
1305 /*------------------------------------------------------------------*/
1306 sym_link *
1307 computeType (sym_link * type1, sym_link * type2)
1308 {
1309   sym_link *rType;
1310   sym_link *reType;
1311   sym_link *etype1 = getSpec (type1);
1312   sym_link *etype2 = getSpec (type2);
1313
1314   /* if one of them is a float then result is a float */
1315   /* here we assume that the types passed are okay */
1316   /* and can be cast to one another                */
1317   /* which ever is greater in size */
1318   if (IS_FLOAT (etype1) || IS_FLOAT (etype2))
1319     rType = newFloatLink ();
1320   else
1321     /* if only one of them is a bit variable
1322        then the other one prevails */
1323   if (IS_BITVAR (etype1) && !IS_BITVAR (etype2))
1324     rType = copyLinkChain (type2);
1325   else if (IS_BITVAR (etype2) && !IS_BITVAR (etype1))
1326     rType = copyLinkChain (type1);
1327   else
1328     /* if one of them is a pointer then that
1329        prevails */
1330   if (IS_PTR (type1))
1331     rType = copyLinkChain (type1);
1332   else if (IS_PTR (type2))
1333     rType = copyLinkChain (type2);
1334   else if (getSize (type1) > getSize (type2))
1335     rType = copyLinkChain (type1);
1336   else
1337     rType = copyLinkChain (type2);
1338
1339   reType = getSpec (rType);
1340
1341   /* if either of them unsigned then make this unsigned */
1342   if ((SPEC_USIGN (etype1) || SPEC_USIGN (etype2)) && !IS_FLOAT (reType))
1343     SPEC_USIGN (reType) = 1;
1344
1345   /* if result is a literal then make not so */
1346   if (IS_LITERAL (reType))
1347     SPEC_SCLS (reType) = S_REGISTER;
1348
1349   return rType;
1350 }
1351
1352 /*------------------------------------------------------------------*/
1353 /* checkType - will do type check return 1 if match                 */
1354 /*------------------------------------------------------------------*/
1355 int 
1356 checkType (sym_link * dest, sym_link * src)
1357 {
1358   if (!dest && !src)
1359     return 1;
1360
1361   if (dest && !src)
1362     return 0;
1363
1364   if (src && !dest)
1365     return 0;
1366
1367   /* if dest is a declarator then */
1368   if (IS_DECL (dest))
1369     {
1370       if (IS_DECL (src))
1371         {
1372           if (DCL_TYPE (src) == DCL_TYPE (dest))
1373             return checkType (dest->next, src->next);
1374           else if (IS_PTR (src) && IS_PTR (dest))
1375             return -1;
1376           else if (IS_PTR (dest) && IS_ARRAY (src))
1377             return -1;
1378           else if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
1379             return -1 * checkType (dest->next, src);
1380           else
1381             return 0;
1382         }
1383       else if (IS_PTR (dest) && IS_INTEGRAL (src))
1384         return -1;
1385       else
1386         return 0;
1387     }
1388
1389   /* if one is a specifier and the other is not */
1390   if ((IS_SPEC (src) && !IS_SPEC (dest)) ||
1391       (IS_SPEC (dest) && !IS_SPEC (src)))
1392     return 0;
1393
1394   /* if one of them is a void then ok */
1395   if (SPEC_NOUN (dest) == V_VOID &&
1396       SPEC_NOUN (src) != V_VOID)
1397     return -1;
1398
1399   if (SPEC_NOUN (dest) != V_VOID &&
1400       SPEC_NOUN (src) == V_VOID)
1401     return -1;
1402
1403   /* char === to short */
1404   if (SPEC_NOUN (dest) == V_CHAR &&
1405       SPEC_NOUN (src) == V_INT &&
1406       SPEC_SHORT (src))
1407     return (SPEC_USIGN (src) == SPEC_USIGN (dest) ? 1 : -2);
1408
1409   if (SPEC_NOUN (src) == V_CHAR &&
1410       SPEC_NOUN (dest) == V_INT &&
1411       SPEC_SHORT (dest))
1412     return (SPEC_USIGN (src) == SPEC_USIGN (dest) ? 1 : -2);
1413
1414   /* if they are both bitfields then if the lengths
1415      and starts don't match */
1416   if (IS_BITFIELD (dest) && IS_BITFIELD (src) &&
1417       (SPEC_BLEN (dest) != SPEC_BLEN (src) ||
1418        SPEC_BSTR (dest) != SPEC_BSTR (src)))
1419     return -1;
1420
1421   /* it is a specifier */
1422   if (SPEC_NOUN (dest) != SPEC_NOUN (src))
1423     {
1424       if (SPEC_USIGN (dest) == SPEC_USIGN (src) &&
1425           IS_INTEGRAL (dest) && IS_INTEGRAL (src) &&
1426           getSize (dest) == getSize (src))
1427         return 1;
1428       else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src))
1429         return -1;
1430       else
1431         return 0;
1432     }
1433   else if (IS_STRUCT (dest))
1434     {
1435       if (SPEC_STRUCT (dest) != SPEC_STRUCT (src))
1436         return 0;
1437       else
1438         return 1;
1439     }
1440   if (SPEC_LONG (dest) != SPEC_LONG (src))
1441     return -1;
1442
1443   if (SPEC_SHORT (dest) != SPEC_SHORT (src))
1444     return -1;
1445
1446   if (SPEC_USIGN (dest) != SPEC_USIGN (src))
1447     return -2;
1448
1449   return 1;
1450 }
1451
1452 /*------------------------------------------------------------------*/
1453 /* inCalleeSaveList - return 1 if found in calle save list          */
1454 /*------------------------------------------------------------------*/
1455 bool 
1456 inCalleeSaveList (char *s)
1457 {
1458   int i;
1459
1460   for (i = 0; options.calleeSaves[i]; i++)
1461     if (strcmp (options.calleeSaves[i], s) == 0)
1462       return 1;
1463
1464   return 0;
1465 }
1466
1467 /*-----------------------------------------------------------------*/
1468 /* aggregateArgToPointer:  change an agggregate type function      */
1469 /*         argument to a pointer to that type.     */
1470 /*-----------------------------------------------------------------*/
1471 void 
1472 aggregateArgToPointer (value * val)
1473 {
1474   if (IS_AGGREGATE (val->type))
1475     {
1476       /* if this is a structure */
1477       /* then we need to add a new link */
1478       if (IS_STRUCT (val->type))
1479         {
1480           /* first lets add DECLARATOR type */
1481           sym_link *p = val->type;
1482
1483           werror (W_STRUCT_AS_ARG, val->name);
1484           val->type = newLink ();
1485           val->type->next = p;
1486         }
1487
1488       /* change to a pointer depending on the */
1489       /* storage class specified        */
1490       switch (SPEC_SCLS (val->etype))
1491         {
1492         case S_IDATA:
1493           DCL_TYPE (val->type) = IPOINTER;
1494           break;
1495         case S_PDATA:
1496           DCL_TYPE (val->type) = PPOINTER;
1497           break;
1498         case S_FIXED:
1499           if (TARGET_IS_DS390)
1500             {
1501               /* The AUTO and REGISTER classes should probably
1502                * also become generic pointers, but I haven't yet
1503                * devised a test case for that.
1504                */
1505               DCL_TYPE (val->type) = GPOINTER;
1506               break;
1507             }
1508           /* fall through! */
1509         case S_AUTO:
1510         case S_DATA:
1511         case S_REGISTER:
1512           DCL_TYPE (val->type) = POINTER;
1513           break;
1514         case S_CODE:
1515           DCL_TYPE (val->type) = CPOINTER;
1516           break;
1517         case S_XDATA:
1518           DCL_TYPE (val->type) = FPOINTER;
1519           break;
1520         case S_EEPROM:
1521           DCL_TYPE (val->type) = EEPPOINTER;
1522           break;
1523         default:
1524           DCL_TYPE (val->type) = GPOINTER;
1525         }
1526
1527       /* is there is a symbol associated then */
1528       /* change the type of the symbol as well */
1529       if (val->sym)
1530         {
1531           val->sym->type = copyLinkChain (val->type);
1532           val->sym->etype = getSpec (val->sym->type);
1533         }
1534     }
1535 }
1536 /*------------------------------------------------------------------*/
1537 /* checkFunction - does all kinds of check on a function            */
1538 /*------------------------------------------------------------------*/
1539 int 
1540 checkFunction (symbol * sym)
1541 {
1542   symbol *csym;
1543   value *exargs, *acargs;
1544   int argCnt = 0;
1545
1546   /* if not type then some kind of error */
1547   if (!sym->type)
1548     return 0;
1549
1550   /* if the function has no type then make it return int */
1551   if (!sym->type->next)
1552     sym->type->next = sym->etype = newIntLink ();
1553
1554   /* function cannot return aggregate */
1555   if (IS_AGGREGATE (sym->type->next))
1556     {
1557       werror (E_FUNC_AGGR, sym->name);
1558       return 0;
1559     }
1560
1561   /* function cannot return bit */
1562   if (IS_BITVAR (sym->type->next))
1563     {
1564       werror (E_FUNC_BIT, sym->name);
1565       return 0;
1566     }
1567
1568   /* check if this function is defined as calleeSaves
1569      then mark it as such */
1570   sym->calleeSave = inCalleeSaveList (sym->name);
1571
1572   /* if interrupt service routine  */
1573   /* then it cannot have arguments */
1574   if (sym->args && IS_ISR (sym->etype) && !IS_VOID (sym->args->type))
1575     {
1576       werror (E_INT_ARGS, sym->name);
1577       sym->args = NULL;
1578     }
1579
1580   if (!(csym = findSym (SymbolTab, sym, sym->name)))
1581     return 1;                   /* not defined nothing more to check  */
1582
1583   /* check if body already present */
1584   if (csym && csym->fbody)
1585     {
1586       werror (E_FUNC_BODY, sym->name);
1587       return 0;
1588     }
1589
1590   /* check the return value type   */
1591   if (checkType (csym->type, sym->type) <= 0)
1592     {
1593       werror (E_PREV_DEF_CONFLICT, csym->name, "type");
1594       werror (E_CONTINUE, "previous definition type ");
1595       printTypeChain (csym->type, stderr);
1596       fprintf (stderr, "\n");
1597       werror (E_CONTINUE, "current definition type ");
1598       printTypeChain (sym->type, stderr);
1599       fprintf (stderr, "\n");
1600       return 0;
1601     }
1602
1603   if (SPEC_INTRTN (csym->etype) != SPEC_INTRTN (sym->etype))
1604     {
1605       werror (E_PREV_DEF_CONFLICT, csym->name, "interrupt");
1606       return 0;
1607     }
1608
1609   if (SPEC_BANK (csym->etype) != SPEC_BANK (sym->etype))
1610     {
1611       werror (E_PREV_DEF_CONFLICT, csym->name, "using");
1612       return 0;
1613     }
1614
1615   /* compare expected agrs with actual args */
1616   exargs = csym->args;
1617   acargs = sym->args;
1618
1619   /* for all the expected args do */
1620   for (argCnt = 1;
1621        exargs && acargs;
1622        exargs = exargs->next, acargs = acargs->next, argCnt++)
1623     {
1624       value *checkValue;
1625       /* If the actual argument is an array, any prototype
1626        * will have modified it to a pointer. Duplicate that
1627        * change here.
1628        */
1629       if (IS_AGGREGATE (acargs->type))
1630         {
1631           checkValue = copyValue (acargs);
1632           aggregateArgToPointer (checkValue);
1633         }
1634       else
1635         {
1636           checkValue = acargs;
1637         }
1638
1639       if (checkType (exargs->type, checkValue->type) <= 0)
1640         {
1641           werror (E_ARG_TYPE, argCnt);
1642           return 0;
1643         }
1644     }
1645
1646   /* if one them ended we have a problem */
1647   if ((exargs && !acargs && !IS_VOID (exargs->type)) ||
1648       (!exargs && acargs && !IS_VOID (acargs->type)))
1649     werror (E_ARG_COUNT);
1650
1651   /* replace with this defition */
1652   sym->cdef = csym->cdef;
1653   deleteSym (SymbolTab, csym, csym->name);
1654   addSym (SymbolTab, sym, sym->name, sym->level, sym->block);
1655   if (IS_EXTERN (csym->etype) && !
1656       IS_EXTERN (sym->etype))
1657     {
1658       addSet (&publics, sym);
1659     }
1660   return 1;
1661 }
1662
1663 /*-----------------------------------------------------------------*/
1664 /* processFuncArgs - does some processing with function args       */
1665 /*-----------------------------------------------------------------*/
1666 void 
1667 processFuncArgs (symbol * func, int ignoreName)
1668 {
1669   value *val;
1670   int pNum = 1;
1671
1672   /* if this function has variable argument list */
1673   /* then make the function a reentrant one    */
1674   if (func->hasVargs)
1675     SPEC_RENT (func->etype) = 1;
1676
1677   /* check if this function is defined as calleeSaves
1678      then mark it as such */
1679   func->calleeSave = inCalleeSaveList (func->name);
1680
1681   val = func->args;             /* loop thru all the arguments   */
1682
1683   /* if it is void then remove parameters */
1684   if (val && IS_VOID (val->type))
1685     {
1686       func->args = NULL;
1687       return;
1688     }
1689
1690   /* reset regparm for the port */
1691   (*port->reset_regparms) ();
1692   /* if any of the arguments is an aggregate */
1693   /* change it to pointer to the same type */
1694   while (val)
1695     {
1696       /* mark it as a register parameter if
1697          the function does not have VA_ARG
1698          and as port dictates */
1699       if (!func->hasVargs &&
1700           (*port->reg_parm) (val->type))
1701         {
1702           SPEC_REGPARM (val->etype) = 1;
1703         }
1704
1705       if (IS_AGGREGATE (val->type))
1706         {
1707           aggregateArgToPointer (val);
1708         }
1709       val = val->next;
1710       pNum++;
1711     }
1712
1713   /* if this is an internal generated function call */
1714   if (func->cdef) {
1715     /* ignore --stack-auto for this one, we don't know how it is compiled */
1716     /* simply trust on --int-long-reent or --float-reent */
1717     if (IS_RENT(func->etype)) {
1718       return;
1719     }
1720   } else {
1721     /* if this function is reentrant or */
1722     /* automatics r 2b stacked then nothing */
1723     if (IS_RENT (func->etype) || options.stackAuto)
1724       return;
1725   }
1726
1727   val = func->args;
1728   pNum = 1;
1729   while (val)
1730     {
1731
1732       /* if a symbolname is not given  */
1733       /* synthesize a variable name */
1734       if (!val->sym)
1735         {
1736
1737           sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
1738           val->sym = newSymbol (val->name, 1);
1739           SPEC_OCLS (val->etype) = port->mem.default_local_map;
1740           val->sym->type = copyLinkChain (val->type);
1741           val->sym->etype = getSpec (val->sym->type);
1742           val->sym->_isparm = 1;
1743           strcpy (val->sym->rname, val->name);
1744           SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
1745             SPEC_STAT (func->etype);
1746           addSymChain (val->sym);
1747
1748         }
1749       else                      /* symbol name given create synth name */
1750         {
1751
1752           sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
1753           strcpy (val->sym->rname, val->name);
1754           val->sym->_isparm = 1;
1755           SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
1756             (options.model != MODEL_SMALL ? xdata : data);
1757           SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
1758             SPEC_STAT (func->etype);
1759         }
1760       val = val->next;
1761     }
1762 }
1763
1764 /*-----------------------------------------------------------------*/
1765 /* isSymbolEqual - compares two symbols return 1 if they match     */
1766 /*-----------------------------------------------------------------*/
1767 int 
1768 isSymbolEqual (symbol * dest, symbol * src)
1769 {
1770   /* if pointers match then equal */
1771   if (dest == src)
1772     return 1;
1773
1774   /* if one of them is null then don't match */
1775   if (!dest || !src)
1776     return 0;
1777
1778   /* if both of them have rname match on rname */
1779   if (dest->rname[0] && src->rname[0])
1780     return (!strcmp (dest->rname, src->rname));
1781
1782   /* otherwise match on name */
1783   return (!strcmp (dest->name, src->name));
1784 }
1785
1786 void PT(sym_link *type)
1787 {
1788         printTypeChain(type,0);
1789 }
1790 /*-----------------------------------------------------------------*/
1791 /* printTypeChain - prints the type chain in human readable form   */
1792 /*-----------------------------------------------------------------*/
1793 void 
1794 printTypeChain (sym_link * type, FILE * of)
1795 {
1796   int nlr = 0;
1797
1798   if (!of)
1799     {
1800       of = stdout;
1801       nlr = 1;
1802     }
1803
1804   while (type)
1805     {
1806       if (IS_DECL (type))
1807         {
1808           if (DCL_PTR_VOLATILE(type)) {
1809             fprintf (of, "volatile ");
1810           }
1811           switch (DCL_TYPE (type))
1812             {
1813             case FUNCTION:
1814               fprintf (of, "function ");
1815               break;
1816             case GPOINTER:
1817               fprintf (of, "_generic * ");
1818               if (DCL_PTR_CONST (type))
1819                 fprintf (of, "const ");
1820               break;
1821             case CPOINTER:
1822               fprintf (of, "_code * ");
1823               if (DCL_PTR_CONST (type))
1824                 fprintf (of, "const ");
1825               break;
1826             case FPOINTER:
1827               fprintf (of, "_far * ");
1828               if (DCL_PTR_CONST (type))
1829                 fprintf (of, "const ");
1830               break;
1831             case EEPPOINTER:
1832               fprintf (of, "_eeprom * ");
1833               if (DCL_PTR_CONST (type))
1834                 fprintf (of, "const ");
1835               break;
1836
1837             case POINTER:
1838               fprintf (of, "_near * ");
1839               if (DCL_PTR_CONST (type))
1840                 fprintf (of, "const ");
1841               break;
1842             case IPOINTER:
1843               fprintf (of, "_idata *");
1844               if (DCL_PTR_CONST (type))
1845                 fprintf (of, "const ");
1846               break;
1847             case PPOINTER:
1848               fprintf (of, "_pdata *");
1849               if (DCL_PTR_CONST (type))
1850                 fprintf (of, "const ");
1851               break;
1852             case UPOINTER:
1853               fprintf (of, " _unkown *");
1854               if (DCL_PTR_CONST (type))
1855                 fprintf (of, "const ");
1856               break;
1857             case ARRAY:
1858               fprintf (of, "array of ");
1859               break;
1860             }
1861         }
1862       else
1863         {
1864           if (SPEC_VOLATILE (type))
1865             fprintf (of, "volatile ");
1866           if (SPEC_USIGN (type))
1867             fprintf (of, "unsigned ");
1868           if (SPEC_CONST (type))
1869             fprintf (of, "const ");
1870
1871           switch (SPEC_NOUN (type))
1872             {
1873             case V_INT:
1874               if (IS_LONG (type))
1875                 fprintf (of, "long ");
1876               if (IS_SHORT (type))
1877                 fprintf (of, "short ");
1878               fprintf (of, "int ");
1879               break;
1880
1881             case V_CHAR:
1882               fprintf (of, "char ");
1883               break;
1884
1885             case V_VOID:
1886               fprintf (of, "void ");
1887               break;
1888
1889             case V_FLOAT:
1890               fprintf (of, "float ");
1891               break;
1892
1893             case V_STRUCT:
1894               fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
1895               break;
1896
1897             case V_SBIT:
1898               fprintf (of, "sbit ");
1899               break;
1900
1901             case V_BIT:
1902               fprintf (of, "bit {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
1903               break;
1904
1905             case V_DOUBLE:
1906               fprintf (of, "double ");
1907               break;
1908
1909             default:
1910               fprintf (of, "unknown type ");
1911               break;
1912             }
1913         }
1914       type = type->next;
1915     }
1916   if (nlr)
1917     fprintf (of, "\n");
1918 }
1919
1920 /*-----------------------------------------------------------------*/
1921 /* cdbTypeInfo - print the type information for debugger           */
1922 /*-----------------------------------------------------------------*/
1923 void 
1924 cdbTypeInfo (sym_link * type, FILE * of)
1925 {
1926   fprintf (of, "{%d}", getSize (type));
1927   while (type)
1928     {
1929       if (IS_DECL (type))
1930         {
1931           switch (DCL_TYPE (type))
1932             {
1933             case FUNCTION:
1934               fprintf (of, "DF,");
1935               break;
1936             case GPOINTER:
1937               fprintf (of, "DG,");
1938               break;
1939             case CPOINTER:
1940               fprintf (of, "DC,");
1941               break;
1942             case FPOINTER:
1943               fprintf (of, "DX,");
1944               break;
1945             case POINTER:
1946               fprintf (of, "DD,");
1947               break;
1948             case IPOINTER:
1949               fprintf (of, "DI,");
1950               break;
1951             case PPOINTER:
1952               fprintf (of, "DP,");
1953               break;
1954             case EEPPOINTER:
1955               fprintf (of, "DA,");
1956               break;
1957             case ARRAY:
1958               fprintf (of, "DA%d,", DCL_ELEM (type));
1959               break;
1960             default:
1961               break;
1962             }
1963         }
1964       else
1965         {
1966           switch (SPEC_NOUN (type))
1967             {
1968             case V_INT:
1969               if (IS_LONG (type))
1970                 fprintf (of, "SL");
1971               else if (IS_SHORT (type))
1972                 fprintf (of, "SS");
1973               else
1974                 fprintf (of, "SI");
1975               break;
1976
1977             case V_CHAR:
1978               fprintf (of, "SC");
1979               break;
1980
1981             case V_VOID:
1982               fprintf (of, "SV");
1983               break;
1984
1985             case V_FLOAT:
1986               fprintf (of, "SF");
1987               break;
1988
1989             case V_STRUCT:
1990               fprintf (of, "ST%s", SPEC_STRUCT (type)->tag);
1991               break;
1992
1993             case V_SBIT:
1994               fprintf (of, "SX");
1995               break;
1996
1997             case V_BIT:
1998               fprintf (of, "SB%d$%d", SPEC_BSTR (type), SPEC_BLEN (type));
1999               break;
2000
2001             default:
2002               break;
2003             }
2004           fputs (":", of);
2005           if (SPEC_USIGN (type))
2006             fputs ("U", of);
2007           else
2008             fputs ("S", of);
2009         }
2010       type = type->next;
2011     }
2012 }
2013 /*-----------------------------------------------------------------*/
2014 /* cdbSymbol - prints a symbol & its type information for debugger */
2015 /*-----------------------------------------------------------------*/
2016 void 
2017 cdbSymbol (symbol * sym, FILE * of, int isStructSym, int isFunc)
2018 {
2019   memmap *map;
2020
2021   if (!sym)
2022     return;
2023   if (!of)
2024     of = stdout;
2025
2026   if (isFunc)
2027     fprintf (of, "F:");
2028   else
2029     fprintf (of, "S:");         /* symbol record */
2030   /* if this is not a structure symbol then
2031      we need to figure out the scope information */
2032   if (!isStructSym)
2033     {
2034       if (!sym->level)
2035         {
2036           /* global */
2037           if (IS_STATIC (sym->etype))
2038             fprintf (of, "F%s$", moduleName);   /* scope is file */
2039           else
2040             fprintf (of, "G$"); /* scope is global */
2041         }
2042       else
2043         /* symbol is local */
2044         fprintf (of, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
2045     }
2046   else
2047     fprintf (of, "S$");         /* scope is structure */
2048
2049   /* print the name, & mangled name */
2050   fprintf (of, "%s$%d$%d(", sym->name,
2051            sym->level, sym->block);
2052
2053   cdbTypeInfo (sym->type, of);
2054   fprintf (of, "),");
2055
2056   /* print the address space */
2057   map = SPEC_OCLS (sym->etype);
2058   fprintf (of, "%c,%d,%d",
2059            (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
2060
2061   /* if assigned to registers then output register names */
2062   /* if this is a function then print
2063      if is it an interrupt routine & interrupt number
2064      and the register bank it is using */
2065   if (isFunc)
2066     fprintf (of, ",%d,%d,%d", SPEC_INTRTN (sym->etype),
2067              SPEC_INTN (sym->etype), SPEC_BANK (sym->etype));
2068   /* alternate location to find this symbol @ : eg registers
2069      or spillication */
2070
2071   if (!isStructSym)
2072     fprintf (of, "\n");
2073 }
2074
2075 /*-----------------------------------------------------------------*/
2076 /* cdbStruct - print a structure for debugger                      */
2077 /*-----------------------------------------------------------------*/
2078 void 
2079 cdbStruct (structdef * sdef, int block, FILE * of,
2080            int inStruct, char *tag)
2081 {
2082   symbol *sym;
2083
2084   fprintf (of, "T:");
2085   /* if block # then must have function scope */
2086   fprintf (of, "F%s$", moduleName);
2087   fprintf (of, "%s[", (tag ? tag : sdef->tag));
2088   for (sym = sdef->fields; sym; sym = sym->next)
2089     {
2090       fprintf (of, "({%d}", sym->offset);
2091       cdbSymbol (sym, of, TRUE, FALSE);
2092       fprintf (of, ")");
2093     }
2094   fprintf (of, "]");
2095   if (!inStruct)
2096     fprintf (of, "\n");
2097 }
2098
2099 /*------------------------------------------------------------------*/
2100 /* cdbStructBlock - calls struct printing for a blcks               */
2101 /*------------------------------------------------------------------*/
2102 void 
2103 cdbStructBlock (int block, FILE * of)
2104 {
2105   int i;
2106   bucket **table = StructTab;
2107   bucket *chain;
2108   wassert (of);
2109
2110   /* go thru the entire  table  */
2111   for (i = 0; i < 256; i++)
2112     {
2113       for (chain = table[i]; chain; chain = chain->next)
2114         {
2115           if (chain->block >= block)
2116             {
2117               cdbStruct ((structdef *) chain->sym, chain->block, of, 0, NULL);
2118             }
2119         }
2120     }
2121 }
2122
2123 /*-----------------------------------------------------------------*/
2124 /* powof2 - returns power of two for the number if number is pow 2 */
2125 /*-----------------------------------------------------------------*/
2126 int 
2127 powof2 (unsigned long num)
2128 {
2129   int nshifts = 0;
2130   int n1s = 0;
2131
2132   while (num)
2133     {
2134       if (num & 1)
2135         n1s++;
2136       num >>= 1;
2137       nshifts++;
2138     }
2139
2140   if (n1s > 1 || nshifts == 0)
2141     return 0;
2142   return nshifts - 1;
2143 }
2144
2145 symbol *__fsadd;
2146 symbol *__fssub;
2147 symbol *__fsmul;
2148 symbol *__fsdiv;
2149 symbol *__fseq;
2150 symbol *__fsneq;
2151 symbol *__fslt;
2152 symbol *__fslteq;
2153 symbol *__fsgt;
2154 symbol *__fsgteq;
2155
2156 /* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
2157 symbol *__muldiv[3][3][2];
2158 /* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */
2159 sym_link *__multypes[3][2];
2160 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
2161 symbol *__conv[2][3][2];
2162
2163 sym_link *floatType;
2164
2165 static void 
2166 _makeRegParam (symbol * sym)
2167 {
2168   value *val;
2169
2170   val = sym->args;              /* loop thru all the arguments   */
2171
2172   /* reset regparm for the port */
2173   (*port->reset_regparms) ();
2174   while (val)
2175     {
2176       SPEC_REGPARM (val->etype) = 1;
2177       val = val->next;
2178     }
2179 }
2180
2181 /*-----------------------------------------------------------------*/
2182 /* initCSupport - create functions for C support routines          */
2183 /*-----------------------------------------------------------------*/
2184 void 
2185 initCSupport ()
2186 {
2187   const char *smuldivmod[] =
2188   {
2189     "mul", "div", "mod"
2190   };
2191   const char *sbwd[] =
2192   {
2193     "char", "int", "long"
2194   };
2195   const char *ssu[] =
2196   {
2197     "s", "u"
2198   };
2199
2200   int bwd, su, muldivmod, tofrom;
2201
2202   floatType = newFloatLink ();
2203
2204   for (bwd = 0; bwd < 3; bwd++)
2205     {
2206       sym_link *l;
2207       switch (bwd)
2208         {
2209         case 0:
2210           l = newCharLink ();
2211           break;
2212         case 1:
2213           l = newIntLink ();
2214           break;
2215         case 2:
2216           l = newLongLink ();
2217           break;
2218         default:
2219           assert (0);
2220         }
2221       __multypes[bwd][0] = l;
2222       __multypes[bwd][1] = copyLinkChain (l);
2223       SPEC_USIGN (__multypes[bwd][1]) = 1;
2224     }
2225
2226   __fsadd = funcOfType ("__fsadd", floatType, floatType, 2, options.float_rent);
2227   __fssub = funcOfType ("__fssub", floatType, floatType, 2, options.float_rent);
2228   __fsmul = funcOfType ("__fsmul", floatType, floatType, 2, options.float_rent);
2229   __fsdiv = funcOfType ("__fsdiv", floatType, floatType, 2, options.float_rent);
2230   __fseq = funcOfType ("__fseq", CHARTYPE, floatType, 2, options.float_rent);
2231   __fsneq = funcOfType ("__fsneq", CHARTYPE, floatType, 2, options.float_rent);
2232   __fslt = funcOfType ("__fslt", CHARTYPE, floatType, 2, options.float_rent);
2233   __fslteq = funcOfType ("__fslteq", CHARTYPE, floatType, 2, options.float_rent);
2234   __fsgt = funcOfType ("__fsgt", CHARTYPE, floatType, 2, options.float_rent);
2235   __fsgteq = funcOfType ("__fsgteq", CHARTYPE, floatType, 2, options.float_rent);
2236
2237   for (tofrom = 0; tofrom < 2; tofrom++)
2238     {
2239       for (bwd = 0; bwd < 3; bwd++)
2240         {
2241           for (su = 0; su < 2; su++)
2242             {
2243               if (tofrom)
2244                 {
2245                   sprintf (buffer, "__fs2%s%s", ssu[su], sbwd[bwd]);
2246                   __conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
2247                 }
2248               else
2249                 {
2250                   sprintf (buffer, "__%s%s2fs", ssu[su], sbwd[bwd]);
2251                   __conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
2252                 }
2253             }
2254         }
2255     }
2256
2257   for (muldivmod = 0; muldivmod < 3; muldivmod++)
2258     {
2259       for (bwd = 0; bwd < 3; bwd++)
2260         {
2261           for (su = 0; su < 2; su++)
2262             {
2263               sprintf (buffer, "_%s%s%s",
2264                        smuldivmod[muldivmod],
2265                        ssu[su],
2266                        sbwd[bwd]);
2267               __muldiv[muldivmod][bwd][su] = funcOfType (buffer, __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
2268               SPEC_NONBANKED (__muldiv[muldivmod][bwd][su]->etype) = 1;
2269               if (bwd < port->muldiv.force_reg_param_below)
2270                 _makeRegParam (__muldiv[muldivmod][bwd][su]);
2271             }
2272         }
2273     }
2274 }