fixed the first parameter push of --int-long-reent
[fw/sdcc] / src / SDCCsymt.c
index a537c7053469c6f4346ba39769e5b85fd94fd75c..9349511d9f89ec36c717e8c112ad906a43ae8c82 100644 (file)
@@ -197,7 +197,7 @@ findSymWithLevel (bucket ** stab, symbol * sym)
          if (bp->level && bp->level == sym->level && bp->block == sym->block)
            return (bp->sym);
          /* if levels don't match then we are okay */
-         if (bp->level && bp->level != sym->level)
+         if (bp->level && bp->level != sym->level && bp->block <= sym->block)
            return (bp->sym);
          /* if this is a global variable then we are ok too */
          if (bp->level == 0)
@@ -434,9 +434,12 @@ mergeSpec (sym_link * dest, sym_link * src)
   if (SPEC_NOUN (dest) != SPEC_NOUN (src) && !SPEC_NOUN (dest))
     SPEC_NOUN (dest) = SPEC_NOUN (src);
 
-  if (!SPEC_SCLS (dest))       /* if destination has no storage class */
+  /* if destination has no storage class */
+  if (!SPEC_SCLS (dest) || 
+      ((SPEC_SCLS(dest) == S_CONSTANT || SPEC_SCLS(dest) == S_REGISTER) && 
+       SPEC_SCLS (src)))
     SPEC_SCLS (dest) = SPEC_SCLS (src);
-
+  /* special case for const */
   /* copy all the specifications  */
   SPEC_LONG (dest) |= SPEC_LONG (src);
   SPEC_SHORT (dest) |= SPEC_SHORT (src);
@@ -787,7 +790,7 @@ addSymChain (symbol * symHead)
 
   for (; sym != NULL; sym = sym->next)
     {
-
+      changePointer(sym);
       /* if already exists in the symbol table then check if
          the previous was an extern definition if yes then
          then check if the type match, if the types match then
@@ -904,81 +907,72 @@ getStructElement (structdef * sdef, symbol * sym)
 int 
 compStructSize (int su, structdef * sdef)
 {
-  int sum = 0, usum = 0;
-  int bitOffset = 0;
-  symbol *loop;
-
-  /* for the identifiers  */
-  loop = sdef->fields;
-  while (loop)
-    {
-
-      /* create the internal name for this variable */
-      sprintf (loop->rname, "_%s", loop->name);
-      loop->offset = (su == UNION ? sum = 0 : sum);
-      SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
-
-      /* if this is a bit field  */
-      if (loop->bitVar)
-       {
-
-         /* change it to a unsigned bit */
-         SPEC_NOUN (loop->etype) = V_BIT;
-         SPEC_USIGN (loop->etype) = 1;
-         /* check if this fit into the remaining   */
-         /* bits of this byte else align it to the */
-         /* next byte boundary                     */
-         if ((SPEC_BLEN (loop->etype) = loop->bitVar) <= (8 - bitOffset))
-           {
-             SPEC_BSTR (loop->etype) = bitOffset;
-             if ((bitOffset += (loop->bitVar % 8)) == 8)
-               sum++;
+    int sum = 0, usum = 0;
+    int bitOffset = 0;
+    symbol *loop;
+
+    /* for the identifiers  */
+    loop = sdef->fields;
+    while (loop) {
+
+       /* create the internal name for this variable */
+       sprintf (loop->rname, "_%s", loop->name);
+       loop->offset = (su == UNION ? sum = 0 : sum);
+       SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
+
+       /* if this is a bit field  */
+       if (loop->bitVar) {
+
+           /* change it to a unsigned bit */
+           SPEC_NOUN (loop->etype) = V_BIT;
+           SPEC_USIGN (loop->etype) = 1;
+           /* check if this fit into the remaining   */
+           /* bits of this byte else align it to the */
+           /* next byte boundary                     */
+           if ((SPEC_BLEN (loop->etype) = loop->bitVar) <= (8 - bitOffset)) {
+               SPEC_BSTR (loop->etype) = bitOffset;
+               if ((bitOffset += (loop->bitVar % 8)) == 8)
+                   sum++;
            }
-         else
-           /* does not fit */
-           {
-             bitOffset = 0;
-             SPEC_BSTR (loop->etype) = bitOffset;
-             sum += (loop->bitVar / 8);
-             bitOffset += (loop->bitVar % 8);
+           else /* does not fit */ {
+               bitOffset = 0;
+               SPEC_BSTR (loop->etype) = bitOffset;
+               sum += (loop->bitVar / 8);
+               bitOffset += (loop->bitVar % 8);
            }
-         /* if this is the last field then pad */
-         if (!loop->next && bitOffset && bitOffset != 8)
-           {
-             bitOffset = 0;
-             sum++;
+           /* if this is the last field then pad */
+           if (!loop->next && bitOffset && bitOffset != 8) {
+               bitOffset = 0;
+               sum++;
            }
        }
-      else
-       {
-         checkDecl (loop);
-         sum += getSize (loop->type);
+       else {
+           checkDecl (loop);
+           sum += getSize (loop->type);
        }
 
-      /* if function then do the arguments for it */
-      if (funcInChain (loop->type))
-       {
-         processFuncArgs (loop, 1);
+       /* if function then do the arguments for it */
+       if (funcInChain (loop->type)) {
+           processFuncArgs (loop, 1);
        }
 
-      loop = loop->next;
+       loop = loop->next;
 
-      /* if this is not a bitfield but the */
-      /* previous one was and did not take */
-      /* the whole byte then pad the rest  */
-      if ((loop && !loop->bitVar) && bitOffset)
-       {
-         bitOffset = 0;
-         sum++;
+       /* if this is not a bitfield but the */
+       /* previous one was and did not take */
+       /* the whole byte then pad the rest  */
+       if ((loop && !loop->bitVar) && bitOffset) {
+           bitOffset = 0;
+           sum++;
        }
 
-      /* if union then size = sizeof larget field */
-      if (su == UNION)
-       usum = max (usum, sum);
+       /* if union then size = sizeof larget field */
+       if (su == UNION)
+           usum = max (usum, sum);
 
     }
 
-  return (su == UNION ? usum : sum);
+    return (su == UNION ? usum : sum);
 }
 
 /*------------------------------------------------------------------*/
@@ -1117,7 +1111,7 @@ checkSClass (symbol * sym)
           * control this allcoation, but the code was originally that way, and
           * changing it for non-390 ports breaks the compiler badly.
           */
-         bool useXdata = IS_DS390_PORT ? options.model : options.useXstack;
+         bool useXdata = TARGET_IS_DS390 ? 1 : options.useXstack;
          SPEC_SCLS (sym->etype) = (useXdata ?
                                    S_XDATA : S_FIXED);
        }
@@ -1427,7 +1421,7 @@ aggregateArgToPointer (value * val)
          DCL_TYPE (val->type) = PPOINTER;
          break;
        case S_FIXED:
-         if (IS_DS390_PORT)
+         if (TARGET_IS_DS390)
            {
              /* The AUTO and REGISTER classes should probably
               * also become generic pointers, but I haven't yet
@@ -1600,7 +1594,6 @@ processFuncArgs (symbol * func, int ignoreName)
   value *val;
   int pNum = 1;
 
-
   /* if this function has variable argument list */
   /* then make the function a reentrant one    */
   if (func->hasVargs)
@@ -1630,8 +1623,6 @@ processFuncArgs (symbol * func, int ignoreName)
          and as port dictates
          not inhibited by command line option or #pragma */
       if (!func->hasVargs &&
-         !options.noregparms &&
-         !IS_RENT (func->etype) &&
          (*port->reg_parm) (val->type))
        {
          SPEC_REGPARM (val->etype) = 1;
@@ -1645,10 +1636,19 @@ processFuncArgs (symbol * func, int ignoreName)
       pNum++;
     }
 
-  /* if this function is reentrant or */
-  /* automatics r 2b stacked then nothing */
-  if (IS_RENT (func->etype) || options.stackAuto)
-    return;
+  /* if this is an internal generated function call */
+  if (func->cdef) {
+    /* ignore --stack-auto for this one, we don't know how it is compiled */
+    /* simply trust on --int-long-reent or --float-reent */
+    if (IS_RENT(func->etype)) {
+      return;
+    }
+  } else {
+    /* if this function is reentrant or */
+    /* automatics r 2b stacked then nothing */
+    if (IS_RENT (func->etype) || options.stackAuto)
+      return;
+  }
 
   val = func->args;
   pNum = 1;
@@ -1709,6 +1709,10 @@ isSymbolEqual (symbol * dest, symbol * src)
   return (!strcmp (dest->name, src->name));
 }
 
+void PT(sym_link *type)
+{
+       printTypeChain(type,0);
+}
 /*-----------------------------------------------------------------*/
 /* printTypeChain - prints the type chain in human readable form   */
 /*-----------------------------------------------------------------*/
@@ -1727,6 +1731,9 @@ printTypeChain (sym_link * type, FILE * of)
     {
       if (IS_DECL (type))
        {
+         if (DCL_PTR_VOLATILE(type)) {
+           fprintf (of, "volatile ");
+         }
          switch (DCL_TYPE (type))
            {
            case FUNCTION:
@@ -1773,7 +1780,6 @@ printTypeChain (sym_link * type, FILE * of)
              if (DCL_PTR_CONST (type))
                fprintf (of, "const ");
              break;
-
            case ARRAY:
              fprintf (of, "array of ");
              break;
@@ -1785,6 +1791,8 @@ printTypeChain (sym_link * type, FILE * of)
            fprintf (of, "volatile ");
          if (SPEC_USIGN (type))
            fprintf (of, "unsigned ");
+         if (SPEC_CONST (type))
+           fprintf (of, "const ");
 
          switch (SPEC_NOUN (type))
            {
@@ -2088,7 +2096,6 @@ _makeRegParam (symbol * sym)
   while (val)
     {
       SPEC_REGPARM (val->etype) = 1;
-      sym->argStack -= getSize (val->type);
       val = val->next;
     }
 }