split PIC port gen.c pcodepeep.c into smaller files. Added structure support.
[fw/sdcc] / src / SDCCsymt.c
index 2f1ba81a62160417e838af9daa66748cfddec5c8..b9f90da1bba29f4343d985d1615d8ae21d19e29f 100644 (file)
@@ -435,7 +435,9 @@ mergeSpec (sym_link * dest, sym_link * src)
     SPEC_NOUN (dest) = SPEC_NOUN (src);
 
   /* if destination has no storage class */
-  if (!SPEC_SCLS (dest) || (SPEC_SCLS(dest) == S_CONSTANT && SPEC_SCLS (src)))
+  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  */
@@ -788,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
@@ -905,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);
 }
 
 /*------------------------------------------------------------------*/
@@ -1062,7 +1055,6 @@ checkSClass (symbol * sym)
        SPEC_SCLS (sym->etype) != S_XSTACK &&
        SPEC_SCLS (sym->etype) != S_CONSTANT))
     {
-
       werror (E_AUTO_ASSUMED, sym->name);
       SPEC_SCLS (sym->etype) = S_AUTO;
     }
@@ -1118,7 +1110,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);
        }
@@ -1428,7 +1420,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
@@ -1601,7 +1593,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)
@@ -1628,11 +1619,8 @@ processFuncArgs (symbol * func, int ignoreName)
     {
       /* mark it as a register parameter if
          the function does not have VA_ARG
-         and as port dictates
-         not inhibited by command line option or #pragma */
+         and as port dictates */
       if (!func->hasVargs &&
-         !options.noregparms &&
-         !IS_RENT (func->etype) &&
          (*port->reg_parm) (val->type))
        {
          SPEC_REGPARM (val->etype) = 1;
@@ -1646,10 +1634,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;
@@ -1732,6 +1729,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:
@@ -1778,7 +1778,6 @@ printTypeChain (sym_link * type, FILE * of)
              if (DCL_PTR_CONST (type))
                fprintf (of, "const ");
              break;
-
            case ARRAY:
              fprintf (of, "array of ");
              break;
@@ -2095,7 +2094,6 @@ _makeRegParam (symbol * sym)
   while (val)
     {
       SPEC_REGPARM (val->etype) = 1;
-      sym->argStack -= getSize (val->type);
       val = val->next;
     }
 }