* fixed GCC 4.4.0 mingw compilation:
[fw/sdcc] / src / SDCCglue.c
index 374288498b38375c57fce62185a1f477f7e710ce..f753441a01b4b846a60e6821771ccac47b8c472d 100644 (file)
@@ -370,6 +370,8 @@ initPointer (initList * ilist, sym_link *toType)
         DCL_TYPE (val->type) = CPOINTER;
         DCL_PTR_CONST (val->type) = port->mem.code_ro;
       }
+      else if (SPEC_SCLS (expr->left->etype) == S_PDATA)
+        DCL_TYPE (val->type) = PPOINTER;
       else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
         DCL_TYPE (val->type) = FPOINTER;
       else if (SPEC_SCLS (expr->left->etype) == S_XSTACK)
@@ -429,6 +431,8 @@ initPointer (initList * ilist, sym_link *toType)
       DCL_TYPE (val->type) = CPOINTER;
       DCL_PTR_CONST (val->type) = port->mem.code_ro;
     }
+    else if (SPEC_SCLS (expr->right->etype) == S_PDATA)
+      DCL_TYPE (val->type) = PPOINTER;
     else if (SPEC_SCLS (expr->right->etype) == S_XDATA)
       DCL_TYPE (val->type) = FPOINTER;
     else if (SPEC_SCLS (expr->right->etype) == S_XSTACK)
@@ -646,68 +650,66 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, struct dbuf_s * o
 /*-----------------------------------------------------------------*/
 /* printIvalBitFields - generate initializer for bitfields         */
 /*-----------------------------------------------------------------*/
-void printIvalBitFields(symbol **sym, initList **ilist, struct dbuf_s * oBuf)
+static void
+printIvalBitFields (symbol **sym, initList **ilist, struct dbuf_s * oBuf)
 {
-  value *val ;
   symbol *lsym = *sym;
-  initList *lilist = *ilist ;
+  initList *lilist = *ilist;
   unsigned long ival = 0;
   int size = 0;
 
-  do
+  while (lsym)
     {
-      unsigned long i;
-      val = list2val (lilist);
-      if (size)
+
+      if (0 == SPEC_BLEN (lsym->etype))
         {
-          if (SPEC_BLEN (lsym->etype) > 8)
-            {
-              size += ((SPEC_BLEN (lsym->etype) / 8) +
-                       (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
-            }
+          /* bit-field structure member with a width of 0 */
+          lsym = lsym->next;
+          break;
         }
-      else
+      else if (!SPEC_BUNNAMED (lsym->etype))
         {
-          size = ((SPEC_BLEN (lsym->etype) / 8) +
-                  (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
-        }
+          /* not an unnamed bit-field structure member */
+          value *val = list2val (lilist);
+          int bit_length = SPEC_BLEN (lsym->etype);
 
-      /* check if the literal value is within bounds */
-      if (val &&
-        checkConstantRange (lsym->etype, val->etype, '=', FALSE) == CCR_OVL &&
-        !options.lessPedantic)
-        {
-          werror (W_LIT_OVERFLOW);
-        }
+          if (size)
+            {
+              if (bit_length > 8)
+                size += (bit_length + 7) / 8;
+            }
+          else
+            size = (bit_length + 7) / 8;
 
-      i = ulFromVal (val);
-      i &= (1 << SPEC_BLEN (lsym->etype)) - 1;
-      i <<= SPEC_BSTR (lsym->etype);
-      ival |= i;
-      if (!(lsym->next &&
-        (IS_BITFIELD (lsym->next->type)) &&
-        (SPEC_BSTR (lsym->next->etype))))
-        break;
+          /* check if the literal value is within bounds */
+          if (val &&
+            checkConstantRange (lsym->etype, val->etype, '=', FALSE) == CCR_OVL &&
+            !options.lessPedantic)
+            {
+              werror (W_LIT_OVERFLOW);
+            }
+
+          ival |= (ulFromVal (val) & ((1ul << bit_length) - 1ul)) << SPEC_BSTR (lsym->etype);
+          lilist = lilist ? lilist->next : NULL;
+        }
       lsym = lsym->next;
-      lilist = lilist ? lilist->next : NULL;
     }
-  while (1);
 
   switch (size)
-  {
-  case 1:
-    dbuf_tprintf (oBuf, "\t!db !constbyte\n", ival);
-    break;
+    {
+    case 1:
+      dbuf_tprintf (oBuf, "\t!db !constbyte\n", ival);
+      break;
 
-  case 2:
-    dbuf_tprintf (oBuf, "\t!dw !constword\n", ival);
-    break;
+    case 2:
+      dbuf_tprintf (oBuf, "\t!dw !constword\n", ival);
+      break;
 
-  case 4:
-    dbuf_tprintf (oBuf, "\t!dw  !constword,!constword\n",
-      (ival >> 16) & 0xffff, (ival & 0xffff));
-    break;
-  }
+    case 4:
+      dbuf_tprintf (oBuf, "\t!dw  !constword,!constword\n",
+        (ival >> 16) & 0xffff, (ival & 0xffff));
+      break;
+    }
   *sym = lsym;
   *ilist = lilist;
 }
@@ -715,7 +717,7 @@ void printIvalBitFields(symbol **sym, initList **ilist, struct dbuf_s * oBuf)
 /*-----------------------------------------------------------------*/
 /* printIvalStruct - generates initial value for structures        */
 /*-----------------------------------------------------------------*/
-void
+static void
 printIvalStruct (symbol * sym, sym_link * type,
                  initList * ilist, struct dbuf_s * oBuf)
 {
@@ -724,31 +726,39 @@ printIvalStruct (symbol * sym, sym_link * type,
 
   sflds = SPEC_STRUCT (type)->fields;
 
-  if (ilist) {
-    if (ilist->type != INIT_DEEP) {
-      werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
-      return;
-    }
+  if (ilist)
+    {
+      if (ilist->type != INIT_DEEP)
+        {
+          werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
+          return;
+        }
 
-    iloop = ilist->init.deep;
-  }
+      iloop = ilist->init.deep;
+    }
 
-  if (SPEC_STRUCT (type)->type == UNION) {
-    printIval (sym, sflds->type, iloop, oBuf, TRUE);
-    iloop = iloop ? iloop->next : NULL;
-  } else {
-    for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
-      if (IS_BITFIELD(sflds->type)) {
-        printIvalBitFields(&sflds, &iloop, oBuf);
-      } else {
-        printIval (sym, sflds->type, iloop, oBuf, TRUE);
-      }
+  if (SPEC_STRUCT (type)->type == UNION)
+    {
+      printIval (sym, sflds->type, iloop, oBuf, 1);
+      iloop = iloop ? iloop->next : NULL;
     }
-  }
-  if (iloop) {
+  else
+    {
+      while (sflds)
+        {
+          if (IS_BITFIELD (sflds->type))
+            printIvalBitFields(&sflds, &iloop, oBuf);
+          else
+            {
+              printIval (sym, sflds->type, iloop, oBuf, 1);
+              sflds = sflds->next;
+              iloop = iloop ? iloop->next : NULL;
+            }
+        }
+    }
+
+  if (iloop)
     werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "struct", sym->name);
-  }
-  return;
 }
 
 /*-----------------------------------------------------------------*/