From: kvigor Date: Tue, 4 Mar 2003 21:47:10 +0000 (+0000) Subject: OP_SYMBOL and OP_VALUE check their parameters are the proper type X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a77899caba78f1dd210c84a175ff372cf552567d;p=fw%2Fsdcc OP_SYMBOL and OP_VALUE check their parameters are the proper type git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2333 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 2854a5bf..4b6eadcc 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -937,9 +937,13 @@ updateSpillLocation (iCode * ic, int induction) !IS_VOLATILE (setype) && !IN_FARSPACE (SPEC_OCLS (setype)) && !OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic)))) - + { + wassert(IS_SYMOP(IC_RESULT (ic))); + wassert(IS_SYMOP(IC_RIGHT (ic))); SPIL_LOC (IC_RIGHT (ic)) = IC_RESULT (ic)->operand.symOperand; + } + } #if 0 /* this needs furthur investigation can save a lot of code */ diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 62f2cead..466905ff 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -819,6 +819,8 @@ isParameterToCall (value * args, operand * op) { value *tval = args; + wassert (IS_SYMOP(op)); + while (tval) { if (tval->sym && @@ -841,7 +843,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)) @@ -2244,6 +2246,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)); @@ -3770,3 +3774,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. +} diff --git a/src/SDCCicode.h b/src/SDCCicode.h index 1c77db92..13f97ad5 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -67,14 +67,6 @@ OPTYPE; #define IS_OP_GLOBAL(op) (IS_SYMOP(op) && op->isGlobal) #define IS_OP_POINTER(op) (IS_SYMOP(op) && op->isPtr) #define IS_OP_PARM(op) (IS_SYMOP(op) && op->isParm) -#define OP_SYMBOL(op) op->operand.symOperand -#define OP_SYM_TYPE(op) op->operand.symOperand->type -#define OP_SYM_ETYPE(op) op->operand.symOperand->etype -#define OP_VALUE(op) op->operand.valOperand -#define SPIL_LOC(op) op->operand.symOperand->usl.spillLoc -#define OP_LIVEFROM(op) op->operand.symOperand->liveFrom -#define OP_LIVETO(op) op->operand.symOperand->liveTo -#define OP_REQV(op) op->operand.symOperand->reqv #define OP_ISLIVE_FCALL(op) (IS_ITEMP(op) && OP_SYMBOL(op)->isLiveFcall) #define SYM_SPIL_LOC(sym) sym->usl.spillLoc @@ -104,6 +96,22 @@ typedef struct operand } operand; +extern operand *validateOpType(operand *op, + const char *macro, + const char *args, + OPTYPE type, + const char *file, + unsigned line); + +#define OP_SYMBOL(op) validateOpType(op, "OP_SYMBOL", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand +#define OP_VALUE(op) validateOpType(op, "OP_VALUE", #op, VALUE, __FILE__, __LINE__)->operand.valOperand +#define OP_SYM_TYPE(op) validateOpType(op, "OP_SYM_TYPE", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->type +#define OP_SYM_ETYPE(op) validateOpType(op, "OP_SYM_ETYPE", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->etype +#define SPIL_LOC(op) validateOpType(op, "SPIL_LOC", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->usl.spillLoc +#define OP_LIVEFROM(op) validateOpType(op, "OP_LIVEFROM", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->liveFrom +#define OP_LIVETO(op) validateOpType(op, "OP_LIVETO", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->liveTo +#define OP_REQV(op) validateOpType(op, "OP_REQV", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->reqv + /* definition for intermediate code */ #define IC_RESULT(x) (x)->ulrrcnd.lrr.result #define IC_LEFT(x) (x)->ulrrcnd.lrr.left diff --git a/src/SDCCmacro.c b/src/SDCCmacro.c index 9691c0bd..2502b04e 100644 --- a/src/SDCCmacro.c +++ b/src/SDCCmacro.c @@ -74,12 +74,14 @@ _evalMacros(char *apinto, hTab *pvals, const char *pfrom, size_t alen) fprintf (stderr, "Cant find macro \"%s\"\n", name); wassertl (0, "Invalid macro name"); } - - /* Replace */ - strncpy(pinto, pval, plen); - pinto += strlen(pval); - plen -= plen > strlen(pval) ? strlen(pval) : plen; - fdidsomething = TRUE; + else + { + /* Replace */ + strncpy(pinto, pval, plen); + pinto += strlen(pval); + plen -= plen > strlen(pval) ? strlen(pval) : plen; + fdidsomething = TRUE; + } pfrom = pend+1; } diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 88ae8de7..132fe8ee 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -109,22 +109,9 @@ static void saveRBank (int, iCode *, bool); (IC_RESULT(x) && IC_RESULT(x)->aop && \ IC_RESULT(x)->aop->type == AOP_STK ) -/* #define MOVA(x) if (strcmp(x,"a") && strcmp(x,"acc")) emitcode("mov","a,%s",x); */ -#define MOVA(x) { \ - char *_mova_tmp = strdup(x); \ - if (strcmp(_mova_tmp,"a") && strcmp(_mova_tmp,"acc")) \ - { \ - emitcode("mov","a,%s",_mova_tmp); \ - } \ - free(_mova_tmp); \ - } -#define MOVB(x) { char *_movb_tmp = strdup(x); \ - if (strcmp(_movb_tmp,"b")) \ - { \ - emitcode("mov","b,%s",_movb_tmp); \ - } \ - free(_movb_tmp); \ - } +#define MOVA(x) _movA(x) +#define MOVB(x) _movB(x) + #define CLRC emitcode("clr","c") #define SETC emitcode("setb","c") @@ -210,6 +197,30 @@ emitcode (char *inst, char *fmt,...) va_end (ap); } +// +// Move the passed value into A unless it is already there. +// +static void +_movA(const char *s) +{ + if (strcmp(s,"a") && strcmp(s,"acc")) + { + emitcode("mov","a,%s",s); + } +} + +// +// Move the passed value into B unless it is already there. +// +static void +_movB(const char *s) +{ + if (strcmp(s,"b")) + { + emitcode("mov","b,%s",s); + } +} + /*-----------------------------------------------------------------*/ /* getFreePtr - returns r0 or r1 whichever is free or can be pushed */ /*-----------------------------------------------------------------*/ @@ -9403,9 +9414,10 @@ genFarPointerGet (operand * left, _endLazyDPSEvaluation (); } pi->generated = 1; - } else if ((OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) && + } else if ((AOP_IS_STR(left) || AOP_INDPTRn(left)) && AOP_SIZE(result) > 1 && - (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) { + IS_SYMOP(left) && + (OP_SYMBOL(left)->liveTo > ic->seq || ic->depth)) { size = AOP_SIZE (result) - 1; if (AOP_INDPTRn(left)) { diff --git a/src/ds390/ralloc.c b/src/ds390/ralloc.c index 2c3d52c3..7826763e 100644 --- a/src/ds390/ralloc.c +++ b/src/ds390/ralloc.c @@ -1761,7 +1761,8 @@ regTypeNum () !IS_BITVAR (sym->etype)) { /* and that pointer is remat in data space */ - if (OP_SYMBOL (IC_LEFT (ic))->remat && + if (IS_SYMOP (IC_LEFT (ic)) && + OP_SYMBOL (IC_LEFT (ic))->remat && !IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) && DCL_TYPE (aggrToPtr (operandType(IC_LEFT(ic)), FALSE)) == POINTER) { @@ -2143,6 +2144,8 @@ packRegsForSupport (iCode * ic, eBBlock * ebp) sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key); } + wassert(IS_SYMOP(IC_LEFT (ic))); + wassert(IS_SYMOP(IC_RIGHT (dic))); IC_LEFT (ic)->operand.symOperand = IC_RIGHT (dic)->operand.symOperand; OP_SYMBOL(IC_LEFT(ic))->liveTo = ic->seq; @@ -2180,6 +2183,8 @@ right: sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key); } + wassert(IS_SYMOP(IC_RIGHT (ic))); + wassert(IS_SYMOP(IC_RIGHT (dic))); IC_RIGHT (ic)->operand.symOperand = IC_RIGHT (dic)->operand.symOperand; IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key; @@ -2764,20 +2769,22 @@ packRegisters (eBBlock * ebp) } /* mark the pointer usages */ - if (POINTER_SET (ic)) + if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic))) OP_SYMBOL (IC_RESULT (ic))->uptr = 1; - if (POINTER_GET (ic)) + if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))) OP_SYMBOL (IC_LEFT (ic))->uptr = 1; if (ic->op == RETURN && IS_SYMOP (IC_LEFT(ic))) OP_SYMBOL (IC_LEFT (ic))->uptr = 1; if (ic->op == RECEIVE && ic->argreg == 1 && + IS_SYMOP (IC_RESULT (ic)) && getSize (operandType(IC_RESULT(ic))) <= 3) OP_SYMBOL (IC_RESULT(ic))->uptr = 1; if (ic->op == SEND && ic->argreg == 1 && + IS_SYMOP(IC_LEFT(ic)) && getSize (aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) <= 3) OP_SYMBOL (IC_LEFT(ic))->uptr = 1; @@ -2846,6 +2853,7 @@ packRegisters (eBBlock * ebp) one and right is not in far space */ if (POINTER_SET (ic) && !isOperandInFarSpace (IC_RIGHT (ic)) && + IS_SYMOP (IC_RESULT (ic)) && !OP_SYMBOL (IC_RESULT (ic))->remat && !IS_OP_RUONLY (IC_RIGHT (ic)) && getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1) { @@ -2856,6 +2864,7 @@ packRegisters (eBBlock * ebp) /* if pointer get */ if (POINTER_GET (ic) && !isOperandInFarSpace (IC_RESULT (ic)) && + IS_SYMOP (IC_LEFT (ic)) && !OP_SYMBOL (IC_LEFT (ic))->remat && !IS_OP_RUONLY (IC_RESULT (ic)) && getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) { diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index fedf008f..4cd832aa 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -1606,7 +1606,8 @@ regTypeNum (eBBlock *ebbs) /* and that pointer is remat in data space */ - if (OP_SYMBOL (IC_LEFT (ic))->remat && + if (IS_SYMOP (IC_LEFT (ic)) && + OP_SYMBOL (IC_LEFT (ic))->remat && !IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) && DCL_TYPE (aggrToPtr (operandType(IC_LEFT(ic)), FALSE)) == POINTER) { @@ -2621,7 +2622,8 @@ packRegisters (eBBlock ** ebpp, int blockno) if (POINTER_SET (ic)) OP_SYMBOL (IC_RESULT (ic))->uptr = 1; - if (POINTER_GET (ic)) + if (POINTER_GET (ic) && + IS_SYMOP(IC_LEFT (ic))) OP_SYMBOL (IC_LEFT (ic))->uptr = 1; if (!SKIP_IC2 (ic)) @@ -2686,6 +2688,7 @@ packRegisters (eBBlock ** ebpp, int blockno) /* if pointer get */ if (POINTER_GET (ic) && + IS_SYMOP (IC_LEFT (ic)) && !isOperandInFarSpace (IC_RESULT (ic)) && !OP_SYMBOL (IC_LEFT (ic))->remat && !IS_OP_RUONLY (IC_RESULT (ic)) && diff --git a/src/z80/ralloc.c b/src/z80/ralloc.c index d3fd4a6f..32b7281d 100644 --- a/src/z80/ralloc.c +++ b/src/z80/ralloc.c @@ -2880,6 +2880,7 @@ packRegisters (eBBlock * ebp) /* if pointer get */ if (!DISABLE_PACK_ONE_USE && POINTER_GET (ic) && + IS_SYMOP (IC_LEFT (ic)) && /* MLH: dont have far space !isOperandInFarSpace(IC_RESULT(ic))&& */ !OP_SYMBOL (IC_LEFT (ic))->remat &&