X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCglue.c;h=19c452ea17571170913290e4404f3bea74cee696;hb=3bd25d75bcad68055bb616dcc29dde8a2965965e;hp=4194fa1c79c0d41bb16ea086b9226961ff44bfdf;hpb=122a98623b6e7e3811469a36163421079652966a;p=fw%2Fsdcc diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 4194fa1c..19c452ea 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -37,7 +37,7 @@ symbol *interrupts[INTNO_MAX+1]; -void printIval (symbol *, sym_link *, initList *, struct dbuf_s *); +void printIval (symbol *, sym_link *, initList *, struct dbuf_s *, bool check); set *publics = NULL; /* public variables */ set *externs = NULL; /* Variables that are declared as extern */ @@ -47,57 +47,6 @@ symbol *mainf; int noInit = 0; /* no initialization */ -/*-----------------------------------------------------------------*/ -/* closePipes - closes all pipes created by the compiler */ -/*-----------------------------------------------------------------*/ -DEFSETFUNC (closePipes) -{ - FILE *pfile = item; - int ret; - - if (pfile) { - ret = pclose (pfile); - assert(ret != -1); - } - - return 0; -} - -/*-----------------------------------------------------------------*/ -/* closeTmpFiles - closes all tmp files created by the compiler */ -/* because of BRAIN DEAD MS/DOS & CYGNUS Libraries */ -/*-----------------------------------------------------------------*/ -DEFSETFUNC (closeTmpFiles) -{ - FILE *tfile = item; - int ret; - - if (tfile) { - ret = fclose (tfile); - assert(ret == 0); - } - - return 0; -} - -/*-----------------------------------------------------------------*/ -/* rmTmpFiles - unlinks all tmp files created by the compiler */ -/* because of BRAIN DEAD MS/DOS & CYGNUS Libraries */ -/*-----------------------------------------------------------------*/ -DEFSETFUNC (rmTmpFiles) -{ - char *name = item; - int ret; - - if (name) { - ret = remove (name); - assert(ret == 0); - Safe_free (name); - } - - return 0; -} - char * aopLiteralLong (value * val, int offset, int size) { @@ -276,7 +225,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) ++noAlloc; resolveIvalSym (sym->ival, sym->type); ++noInit; - printIval (sym, sym->type, sym->ival, &tmpBuf); + printIval (sym, sym->type, sym->ival, &tmpBuf, TRUE); --noInit; --noAlloc; dbuf_destroy(&tmpBuf); @@ -697,68 +646,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; } @@ -766,7 +713,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) { @@ -775,38 +722,46 @@ 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); - 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); - } + 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; } /*-----------------------------------------------------------------*/ /* printIvalChar - generates initital value for character array */ /*-----------------------------------------------------------------*/ int -printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s) +printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s, bool check) { value *val; unsigned int size = DCL_ELEM (type); @@ -828,6 +783,9 @@ printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * DCL_ELEM (type) = size; } + if (check && DCL_ELEM (val->type) > size) + werror (W_EXCESS_INITIALIZERS, "array of chars", sym->name, sym->lineDef); + printChar (oBuf, SPEC_CVAL (val->etype).v_char, size); return 1; @@ -845,7 +803,7 @@ printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * /*-----------------------------------------------------------------*/ void printIvalArray (symbol * sym, sym_link * type, initList * ilist, - struct dbuf_s * oBuf) + struct dbuf_s * oBuf, bool check) { value *val; initList *iloop; @@ -867,7 +825,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist, } if (printIvalChar (sym, type, (ilist->type == INIT_DEEP ? ilist->init.deep : ilist), - oBuf, SPEC_CVAL (sym->etype).v_char)) + oBuf, SPEC_CVAL (sym->etype).v_char, check)) return; } /* not the special case */ @@ -881,7 +839,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist, werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "array", sym->name); break; } - printIval (sym, type->next, iloop, oBuf); + printIval (sym, type->next, iloop, oBuf, TRUE); } } @@ -1182,7 +1140,7 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * o /* printIval - generates code for initial value */ /*-----------------------------------------------------------------*/ void -printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf) +printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, bool check) { sym_link *itype; @@ -1196,7 +1154,7 @@ printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf /* if this is an array */ if (IS_ARRAY (type)) { - printIvalArray (sym, type, ilist, oBuf); + printIvalArray (sym, type, ilist, oBuf, check); return; } @@ -1313,7 +1271,7 @@ emitStaticSeg (memmap * map, struct dbuf_s * oBuf) dbuf_printf (oBuf, "%s:\n", sym->rname); ++noAlloc; resolveIvalSym (sym->ival, sym->type); - printIval (sym, sym->type, sym->ival, oBuf); + printIval (sym, sym->type, sym->ival, oBuf, map != xinit); --noAlloc; /* if sym is a simple string and sym->ival is a string, WE don't need it anymore */