X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCicode.c;h=9c37fe0a2d5f22cdc4197ffc06ea11eb134f0c4f;hb=017f41af54f2c9aeb55f31e237eb58762b6ea2ff;hp=4ab359dc000872995b73e548e0cec1ef05681ae6;hpb=9b6292c6f1828886ea5bacb609e63403823e3c06;p=fw%2Fsdcc diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 4ab359dc..9c37fe0a 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -115,26 +115,6 @@ iCodeTable codeTable[] = {ARRAYINIT, "arrayInit", picGenericOne, NULL}, }; -// this makes it more easy to catch bugs -struct bitVect *OP_DEFS(struct operand *op) { - assert (IS_SYMOP(op)); - return OP_SYMBOL(op)->defs; -} -struct bitVect *OP_DEFS_SET(struct operand *op, struct bitVect *bv) { - assert (IS_SYMOP(op)); - OP_SYMBOL(op)->defs=bv; - return bv; -} -struct bitVect *OP_USES(struct operand *op) { - assert (IS_SYMOP(op)); - return OP_SYMBOL(op)->uses; -} -struct bitVect *OP_USES_SET(struct operand *op, struct bitVect *bv) { - assert (IS_SYMOP(op)); - OP_SYMBOL(op)->uses=bv; - return bv; -} - /*-----------------------------------------------------------------*/ /* checkConstantRange: check a constant against the type */ /*-----------------------------------------------------------------*/ @@ -200,7 +180,7 @@ void checkConstantRange(sym_link *ltype, value *val, char *msg, #if 0 // temporary disabled, leaving the warning as a reminder if (warnings) { - sprintf (message, "for %s %s in %s", + SNPRINTF (message, sizeof(message), "for %s %s in %s", SPEC_USIGN(ltype) ? "unsigned" : "signed", nounName(ltype), msg); werror (W_CONST_RANGE, message); @@ -520,7 +500,7 @@ printiCChain (iCode * icChain, FILE * of) { if ((icTab = getTableEntry (loop->op))) { - fprintf (of, "%s(%d:%d:%d:%d:%d)\t", + fprintf (of, "%s(l%d:s%d:k%d:d%d:s%d)\t", loop->filename, loop->lineno, loop->seq, loop->key, loop->depth, loop->supportRtn); @@ -597,7 +577,7 @@ newiCodeLabelGoto (int op, symbol * label) ic = newiCode (op, NULL, NULL); ic->op = op; - ic->argLabel.label = label; + ic->label = label; IC_LEFT (ic) = NULL; IC_RIGHT (ic) = NULL; IC_RESULT (ic) = NULL; @@ -613,11 +593,16 @@ newiTemp (char *s) symbol *itmp; if (s) - sprintf (buffer, "%s", s); + { + SNPRINTF (buffer, sizeof(buffer), "%s", s); + } else - sprintf (buffer, "iTemp%d", iTempNum++); + { + SNPRINTF (buffer, sizeof(buffer), "iTemp%d", iTempNum++); + } + itmp = newSymbol (buffer, 1); - strcpy (itmp->rname, itmp->name); + strncpyz (itmp->rname, itmp->name, SDCC_NAME_MAX); itmp->isitmp = 1; return itmp; @@ -636,10 +621,12 @@ newiTempLabel (char *s) return itmplbl; if (s) - itmplbl = newSymbol (s, 1); + { + itmplbl = newSymbol (s, 1); + } else { - sprintf (buffer, "iTempLbl%d", iTempLblNum++); + SNPRINTF (buffer, sizeof(buffer), "iTempLbl%d", iTempLblNum++); itmplbl = newSymbol (buffer, 1); } @@ -658,7 +645,7 @@ newiTempPreheaderLabel () { symbol *itmplbl; - sprintf (buffer, "preHeaderLbl%d", iTempLblNum++); + SNPRINTF (buffer, sizeof(buffer), "preHeaderLbl%d", iTempLblNum++); itmplbl = newSymbol (buffer, 1); itmplbl->isitmp = 1; @@ -812,6 +799,8 @@ isParameterToCall (value * args, operand * op) { value *tval = args; + wassert (IS_SYMOP(op)); + while (tval) { if (tval->sym && @@ -834,7 +823,7 @@ isOperandGlobal (operand * op) if (IS_ITEMP (op)) return 0; - if (op->type == SYMBOL && + if (IS_SYMOP(op) && (op->operand.symOperand->level == 0 || IS_STATIC (op->operand.symOperand->etype) || IS_EXTERN (op->operand.symOperand->etype)) @@ -2237,6 +2226,8 @@ geniCodeStruct (operand * left, operand * right, bool islval) symbol *element = getStructElement (SPEC_STRUCT (etype), right->operand.symOperand); + wassert(IS_SYMOP(right)); + /* add the offset */ ic = newiCode ('+', left, operandFromLit (element->offset)); @@ -2888,7 +2879,7 @@ geniCodeParms (ast * parms, value *argVals, int *stack, /* assign */ operand *top = operandFromSymbol (argVals->sym); /* clear useDef and other bitVectors */ - OP_USES_SET ((top), OP_DEFS_SET ((top), OP_SYMBOL(top)->clashes = NULL)); + OP_USES(top)=OP_DEFS(top)=OP_SYMBOL(top)->clashes = NULL; geniCodeAssign (top, pval, 1); } else @@ -3148,7 +3139,8 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) /* all integer numbers between the maximum & minimum must */ /* be present , the maximum value should not exceed 255 */ min = max = (int) floatFromVal (vch = caseVals); - sprintf (buffer, "_case_%d_%d", + SNPRINTF (buffer, sizeof(buffer), + "_case_%d_%d", tree->values.switchVals.swNum, min); addSet (&labels, newiTempLabel (buffer)); @@ -3161,7 +3153,8 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) { if (((t = (int) floatFromVal (vch)) - max) != 1) return 0; - sprintf (buffer, "_case_%d_%d", + SNPRINTF (buffer, sizeof(buffer), + "_case_%d_%d", tree->values.switchVals.swNum, t); addSet (&labels, newiTempLabel (buffer)); @@ -3177,9 +3170,14 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) return 0; if (tree->values.switchVals.swDefault) - sprintf (buffer, "_default_%d", tree->values.switchVals.swNum); + { + SNPRINTF (buffer, sizeof(buffer), "_default_%d", tree->values.switchVals.swNum); + } else - sprintf (buffer, "_swBrk_%d", tree->values.switchVals.swNum); + { + SNPRINTF (buffer, sizeof(buffer), "_swBrk_%d", tree->values.switchVals.swNum); + } + falseLabel = newiTempLabel (buffer); @@ -3242,7 +3240,7 @@ geniCodeSwitch (ast * tree,int lvl) operandFromValue (caseVals), EQ_OP); - sprintf (buffer, "_case_%d_%d", + SNPRINTF (buffer, sizeof(buffer), "_case_%d_%d", tree->values.switchVals.swNum, (int) floatFromVal (caseVals)); trueLabel = newiTempLabel (buffer); @@ -3256,9 +3254,13 @@ geniCodeSwitch (ast * tree,int lvl) /* if default is present then goto break else break */ if (tree->values.switchVals.swDefault) - sprintf (buffer, "_default_%d", tree->values.switchVals.swNum); + { + SNPRINTF (buffer, sizeof(buffer), "_default_%d", tree->values.switchVals.swNum); + } else - sprintf (buffer, "_swBrk_%d", tree->values.switchVals.swNum); + { + SNPRINTF (buffer, sizeof(buffer), "_swBrk_%d", tree->values.switchVals.swNum); + } falseLabel = newiTempLabel (buffer); geniCodeGoto (falseLabel); @@ -3752,3 +3754,35 @@ iCodeFromAst (ast * tree) ast2iCode (tree,0); return reverseiCChain (); } + +static const char *opTypeToStr(OPTYPE op) +{ + switch(op) + { + case SYMBOL: return "symbol"; + case VALUE: return "value"; + case TYPE: return "type"; + } + return "undefined type"; +} + + +operand *validateOpType(operand *op, + const char *macro, + const char *args, + OPTYPE type, + const char *file, + unsigned line) +{ + if (op && op->type == type) + { + return op; + } + fprintf(stderr, + "Internal error: validateOpType failed in %s(%s) @ %s:%u:" + " expected %s, got %s\n", + macro, args, file, line, + opTypeToStr(type), op ? opTypeToStr(op->type) : "null op"); + exit(-1); + return op; // never reached, makes compiler happy. +}