+2008-08-31 Raphael Neider <rneider AT web.de>
+
+ * src/pic16/gen.c (genAssign): removed useless compiler output
+ * (genPointerGet,genPointerSet,genCast),
+ src/pic16/glue.c (pic16_printGPointerType):
+ also handle PPOINTERs just to avoid spurious asserts
+ * (pic16_printIvalType,pic16_printIvalBitFields):
+ generalized to arbitrary type/bitfield sizes, allows compilation of
+ regression test bug-1981238.c
+ * (pic16_printIvalChar): fix regression test structflexarray.c
+ * (pic16_printIvalArray): avoid SIGSEGV on uninitialized strings
+ in initialized structs and fix #1843745
+ * (pic16_printIvalStruct): always output initializers for all fields,
+ even those not explicitly given, fixes zeropad.c regression test
+ * (pic16_printIvalUnion): fix union initializers (bug1426356.c,
+ #2073635, #1567098, and #1485812)
+ * src/pic16/main.c (_pic16_keywords): remove unsupported 'pdata'
+
2008-08-31 Borut Razem <borut.razem AT siol.net>
* support/regression/tests/bug-895992.c,
enabled pic16 regression testing since the bugs
1511794: pic16: regression test bug-895992.c fails
1444425: onebyte.c regression tes fails on pic16
- are fiexed, probably by fixing
+ are fixed, probably by fixing
2048464: PIC16: fix genUminus - addresses not.c regression test
* src/SDCCsymt.c, src/SDCCglue.c,
support/regression/tests/bug-1981238.c:
case POINTER:
case FPOINTER:
case IPOINTER:
- genNearPointerGet (left,result,ic);
- break;
-
-#if 0
- /* MUST move them somewhere; handle [PF]POINTERs like POINTERS or like GPOINTERs?!? */
case PPOINTER:
- genPagedPointerGet(left,result,ic);
- break;
-
- case FPOINTER:
- genFarPointerGet (left,result,ic);
+ genNearPointerGet (left,result,ic);
break;
-#endif
case CPOINTER:
genConstPointerGet (left,result,ic);
case POINTER:
case FPOINTER:
case IPOINTER:
- genNearPointerSet (right,result,ic);
- break;
-
-#if 0
- /* MUST move them somewhere; handle [PF]POINTERs like POINTERS or like GPOINTERs?!? */
case PPOINTER:
- genPagedPointerSet (right,result,ic);
- break;
-
- case FPOINTER:
- genFarPointerSet (right,result,ic);
+ genNearPointerSet (right,result,ic);
break;
-#endif
case GPOINTER:
genGenPointerSet (right,result,ic);
&& !IS_ITEMP(right)) {
DEBUGpic16_emitcode("; ", "%s:%d symbol in code space, take special care\n", __FUNCTION__, __LINE__);
- fprintf(stderr, "%s:%d symbol %s = [ %s ] is in code space\n", __FILE__, __LINE__, OP_SYMBOL(result)->name, OP_SYMBOL(right)->name);
+ //fprintf(stderr, "%s:%d symbol %s = [ %s ] is in code space\n", __FILE__, __LINE__, OP_SYMBOL(result)->name, OP_SYMBOL(right)->name);
// set up table pointer
if(pic16_isLitOp(right)) {
/* pointer to generic pointer */
if (IS_GENPTR(ctype)) {
- char *l = zero;
if (IS_PTR(type))
p_type = DCL_TYPE(type);
}
/* the last byte depending on type */
switch (p_type) {
- case IPOINTER:
case POINTER:
case FPOINTER:
+ case IPOINTER:
+ case PPOINTER:
pic16_movLit2f(pic16_popGet(AOP(result), GPTRSIZE-1), GPTR_TAG_DATA);
break;
pic16_emitpcode(POC_MOVFF, pic16_popGet2(AOP(right), AOP(result), GPTRSIZE-1));
break;
- case PPOINTER:
- pic16_emitcode(";BUG!? ","%d",__LINE__);
- l = "#0x03";
- break;
-
case GPOINTER:
if (GPTRSIZE > AOP_SIZE(right)) {
// assume __data pointer... THIS MIGHT BE WRONG!
pic16_emitDS (buf, ptype, p);
break;
- case POINTER: /* __data space */
+ case POINTER: /* fall through */
+ case FPOINTER: /* fall through */
+ case IPOINTER: /* fall through */
+ case PPOINTER: /* __data space */
sprintf (buf, "0x%02x", GPTR_TAG_DATA);
pic16_emitDS (buf, ptype, p);
break;
- /*
- * FPOINTER and IPOINTER are not used in pic16 port
- case FPOINTER:
- case IPOINTER:
- */
default:
debugf ("itype = %d\n", itype );
assert (0);
pic16_printIvalType (symbol *sym, sym_link * type, initList * ilist, char ptype, void *p)
{
value *val;
+ int i;
// fprintf(stderr, "%s for symbol %s\n",__FUNCTION__, sym->rname);
val = valCastLiteral(type, floatFromVal(val));
}
- switch (getSize (type)) {
- case 1:
- pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
- break;
-
- case 2:
- pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
- pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
- break;
- case 3:
- pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
- pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
- pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
- case 4:
- pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
- pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
- pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
- pic16_emitDB(pic16aopLiteral(val, 3), ptype, p);
- break;
- }
+ for (i = 0; i < getSize (type); i++) {
+ pic16_emitDB(pic16aopLiteral(val, i), ptype, p);
+ } // for
}
/*--------------------------------------------------------------------*/
/* length of initializer string (might contain \0, so do not use strlen) */
ilen = DCL_ELEM(val->type);
+#if 0
+ /* This causes structflexarray.c to fail. */
if(!DCL_ELEM (type))
DCL_ELEM (type) = ilen;
+#endif
/* len is 0 if declartion equals initializer,
* >0 if declaration greater than initializer
if(len >= 0) {
/* emit initializer */
- for(remain=0; remain<ilen; remain++)
+ for(remain=0; remain<ilen; remain++) {
pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
-
- /* fill array with 0x00 */
- while(len--) {
- pic16_emitDB(0x00, ptype, p);
- }
+ } // for
+
+ /* fill array with 0x00 */
+ while(len--) {
+ pic16_emitDB(0x00, ptype, p);
+ } // while
+ } else if (!DCL_ELEM (type)) {
+ // flexible arrays: char str[] = "something"; */
+ for(remain=0; remain<ilen; remain++) {
+ pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
+ } // for
} else {
werror (W_EXCESS_INITIALIZERS, "array of chars", sym->name, sym->lineDef);
-
- for(remain=0; remain<DCL_ELEM (type); remain++)
+ for(remain=0; remain<DCL_ELEM (type); remain++) {
pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
- }
+ } // for
+ } // if
// if((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0) {
/* take care of the special case */
/* array of characters can be init */
/* by a string */
- if (IS_CHAR (type->next)) {
+ if (IS_CHAR (type->next) && ilist) {
if (!IS_LITERAL(list2val(ilist)->etype)) {
werror (W_INIT_WRONG);
return;
return;
}
- iloop = ilist->init.deep;
+ iloop = (ilist ? ilist->init.deep : NULL);
lcnt = DCL_ELEM (type);
for (;;)
}
}
+#if 0
+ /* This causes bug #1843745. */
/* if we have not been given a size */
if (!DCL_ELEM (type))
DCL_ELEM (type) = size;
+#endif
return;
}
symbol *lsym = *sym;
initList *lilist = *ilist ;
unsigned long ival = 0;
+ unsigned long i;
int size =0;
do {
- unsigned long i;
val = list2val(lilist);
if (size) {
if (SPEC_BLEN(lsym->etype) > 8) {
lsym = lsym->next;
lilist = lilist->next;
} while (1);
- switch (size) {
- case 1:
- pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
- break;
- case 2:
- pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
- pic16_emitDB(BYTE_IN_LONG(ival, 1), ptype, p);
- break;
-
- case 4: /* EEP: why is this db and not dw? */
- pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
- pic16_emitDB(BYTE_IN_LONG(ival, 1), ptype, p);
- pic16_emitDB(BYTE_IN_LONG(ival, 2), ptype, p);
- pic16_emitDB(BYTE_IN_LONG(ival, 3), ptype, p);
- break;
- default:
- /* VR - only 1,2,4 size long can be handled???? Why? */
- fprintf(stderr, "%s:%d: unhandled case. Contact author.\n", __FILE__, __LINE__);
- assert(0);
- }
+ for (i = 0; i < size; i++) {
+ pic16_emitDB(BYTE_IN_LONG(ival, i), ptype, p);
+ } // for
+
*sym = lsym;
*ilist = lilist;
}
iloop = ilist->init.deep;
}
- for (; (sflds && iloop); sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
+ for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
// fprintf(stderr, "%s:%d sflds: %p\tiloop = %p\n", __FILE__, __LINE__, sflds, iloop);
if (IS_BITFIELD(sflds->type)) {
pic16_printIvalBitFields(&sflds, &iloop, ptype, p);
{
//symbol *sflds;
initList *iloop = NULL;
- int i, size;
-
+ int size;
+ symbol *sflds = NULL;
#if DEBUG_PRINTIVAL
fprintf(stderr, "%s\n",__FUNCTION__);
#endif
- iloop = ilist;
- i = 0;
- while (iloop)
- {
- i++;
- iloop = iloop->next;
- } // while
+ assert (type);
- size = -1;
- if (type) size = SPEC_STRUCT(type)->size;
+ sflds = SPEC_STRUCT (type)->fields;
- if (i == 1 && size >= 0 && size <= sizeof(long))
- {
- unsigned long val = ulFromVal (list2val(ilist));
- while (size--)
- {
- pic16_emitDB(val, ptype, p);
- val >>= 8;
- } // while
- return;
- } // if
+ if (ilist) {
+ if (ilist->type != INIT_DEEP) {
+ werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
+ return;
+ }
+
+ iloop = ilist->init.deep;
+ }
- fprintf( stderr, "INCOMPLETE SUPPORT FOR INITIALIZED union---FALLING BACK TO struct\n" );
- fprintf( stderr, "This is a bug. Please file a bug-report with your source attached.\n" );
- pic16_printIvalStruct( sym, type, ilist, ptype, p );
+ size = SPEC_STRUCT(type)->size;
+ sflds = SPEC_STRUCT(type)->fields;
+ pic16_printIval (sym, sflds->type, iloop, ptype, p);
+
+ /* if the first field is not the longest, fill with 0s */
+ while (size > getSize (sflds->type)) {
+ pic16_emitDB(0, ptype, p);
+ size--;
+ } // while
}
static int