* src/SDCCmain.c (linkEdit): do not test for PIC16 target since, PIC16
[fw/sdcc] / src / SDCCsymt.c
index 0c0c00cc0f9d6c2c1642378cfbc798df56e63814..40e1fed661ed02d3e1d3172c0342813453db5a8c 100644 (file)
@@ -1280,12 +1280,24 @@ compStructSize (int su, structdef * sdef)
                     bitOffset += loop->bitVar;
                 } 
                 else {
-                    /* does not fit; need to realign first */
-                    sum++;
-                    loop->offset = (su == UNION ? sum = 0 : sum);
-                    bitOffset = 0;
-                    SPEC_BSTR (loop->etype) = bitOffset;
-                    bitOffset += loop->bitVar;
+                                       if( TARGET_IS_PIC16 && getenv("PIC16_PACKED_BITFIELDS") ) {
+                                               /* if PIC16 && enviroment variable is set, then
+                                                * tightly pack bitfields, this means that when a
+                                                * bitfield goes beyond byte alignment, do not
+                                                * automatically start allocatint from next byte,
+                                                * but also use the available bits first */
+                                               fprintf(stderr, ": packing bitfields in structures\n");
+                                               SPEC_BSTR (loop->etype) = bitOffset;
+                                               bitOffset += loop->bitVar;
+                                               loop->offset = (su == UNION ? sum = 0 : sum);
+                                       } else {
+                                               /* does not fit; need to realign first */
+                           sum++;
+                       loop->offset = (su == UNION ? sum = 0 : sum);
+                           bitOffset = 0;
+                       SPEC_BSTR (loop->etype) = bitOffset;
+                           bitOffset += loop->bitVar;
+                       }
                 }
                 while (bitOffset>8) {
                     bitOffset -= 8;