* config.dsp: added dependency on .version and configure_vc.awk
[fw/sdcc] / src / SDCCglue.c
index 7ec4ad69b2bec3eb8e4ecc1cb6684e0bb7fb5cb2..6f76b0fdc60609bd669816f91ac89f5fe5633552 100644 (file)
@@ -361,7 +361,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                    SPEC_ADDR (sym->etype));
         }
       else {
-        int size = getAllocSize (sym->type);
+        int size = getSize (sym->type) + sym->flexArrayLength;
         if (size==0) {
           werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE, sym->name);
         }
@@ -790,21 +790,29 @@ printIvalStruct (symbol * sym, sym_link * type,
 /* printIvalChar - generates initital value for character array    */
 /*-----------------------------------------------------------------*/
 int 
-printIvalChar (sym_link * type, initList * ilist, FILE * oFile, char *s)
+printIvalChar (symbol * sym, sym_link * type, initList * ilist, FILE * oFile, char *s)
 {
   value *val;
+  unsigned int size = DCL_ELEM (type);
 
   if (!s)
     {
-
       val = list2val (ilist);
       /* if the value is a character string  */
       if (IS_ARRAY (val->type) && IS_CHAR (val->etype))
         {
-          if (!DCL_ELEM (type))
-            DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
+          if (!size)
+            {
+              /* we have not been given a size, but now we know it */
+              size = strlen (SPEC_CVAL (val->etype).v_char) + 1;
+              /* but first check, if it's a flexible array */
+              if (sym && IS_STRUCT (sym->type))
+                sym->flexArrayLength = size;
+              else
+                DCL_ELEM (type) = size;
+            }
 
-          printChar (oFile, SPEC_CVAL (val->etype).v_char, DCL_ELEM (type));
+          printChar (oFile, SPEC_CVAL (val->etype).v_char, size);
 
           return 1;
         }
@@ -835,7 +843,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
         werrorfl (ilist->filename, ilist->lineno, E_CONST_EXPECTED);
         return;
       }
-      if (printIvalChar (type,
+      if (printIvalChar (sym, type,
                          (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
                          oFile, SPEC_CVAL (sym->etype).v_char))
         return;
@@ -864,8 +872,12 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
       }
     }
   } else {
-    // we have not been given a size, but we now know it
-    DCL_ELEM (type) = size;
+    /* we have not been given a size, but now we know it */
+    /* but first check, if it's a flexible array */
+    if (IS_STRUCT (sym->type))
+      sym->flexArrayLength = size * getSize (type->next);
+    else
+      DCL_ELEM (type) = size;
   }
 
   return;
@@ -1562,7 +1574,7 @@ spacesToUnderscores (char *dest, const char *src, size_t len)
 
   --len;
   for (p = dest, i = 0; *src != '\0' && i < len; ++src, ++i) {
-    *p++ = isspace(*src) ? '_' : *src;
+    *p++ = isspace((unsigned char)*src) ? '_' : *src;
   }
   *p = '\0';
 
@@ -1694,7 +1706,7 @@ glue (void)
     {
       /* copy the sbit segment */
       fprintf (asmFile, "%s", iComments2);
-      fprintf (asmFile, "; special function bits \n");
+      fprintf (asmFile, "; special function bits\n");
       fprintf (asmFile, "%s", iComments2);
       copyFile (asmFile, sfrbit->oFile);
   
@@ -1702,16 +1714,16 @@ glue (void)
       if(RegBankUsed[0]||RegBankUsed[1]||RegBankUsed[2]||RegBankUsed[3])
       {
          fprintf (asmFile, "%s", iComments2);
-         fprintf (asmFile, "; overlayable register banks \n");
+         fprintf (asmFile, "; overlayable register banks\n");
          fprintf (asmFile, "%s", iComments2);
          if(RegBankUsed[0])
-            fprintf (asmFile, "\t.area REG_BANK_0\t(REL,OVR,DATA)\n\t.ds 8\n");
+           fprintf (asmFile, "\t.area REG_BANK_0\t(REL,OVR,DATA)\n\t.ds 8\n");
          if(RegBankUsed[1]||options.parms_in_bank1)
-            fprintf (asmFile, "\t.area REG_BANK_1\t(REL,OVR,DATA)\n\t.ds 8\n");
+           fprintf (asmFile, "\t.area REG_BANK_1\t(REL,OVR,DATA)\n\t.ds 8\n");
          if(RegBankUsed[2])
-            fprintf (asmFile, "\t.area REG_BANK_2\t(REL,OVR,DATA)\n\t.ds 8\n");
+           fprintf (asmFile, "\t.area REG_BANK_2\t(REL,OVR,DATA)\n\t.ds 8\n");
          if(RegBankUsed[3])
-            fprintf (asmFile, "\t.area REG_BANK_3\t(REL,OVR,DATA)\n\t.ds 8\n");
+           fprintf (asmFile, "\t.area REG_BANK_3\t(REL,OVR,DATA)\n\t.ds 8\n");
       }
       if(BitBankUsed)
       {