OP_SYMBOL and OP_VALUE check their parameters are the proper type
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 4 Mar 2003 21:47:10 +0000 (21:47 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 4 Mar 2003 21:47:10 +0000 (21:47 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2333 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCcse.c
src/SDCCicode.c
src/SDCCicode.h
src/SDCCmacro.c
src/ds390/gen.c
src/ds390/ralloc.c
src/mcs51/ralloc.c
src/z80/ralloc.c

index 2854a5bf956afe04e4ee431ea4836b4af29f7016..4b6eadcc50c357866b0fb47df78552f6063a9e04 100644 (file)
@@ -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 */
index 62f2ceadfde566e87d1fb8cbff4a5bf56e26a99f..466905ff32794f1db95be924de48c993ad99c6d6 100644 (file)
@@ -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.
+}
index 1c77db9203ad08604dcdeea4fd3773771b818cca..13f97ad57dbda584a74c2768a3aa514bf7b3b4ab 100644 (file)
@@ -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
index 9691c0bdce6d5f5f1d879feabddd69f6fc0a3d06..2502b04ebffea1ffa1d0391b9e02b223baac1e0d 100644 (file)
@@ -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;
         }
index 88ae8de7587b30c574eb79604d73ae2869a8b4f1..132fe8ee6182474bba0f1197cbd57cd3819e664c 100644 (file)
@@ -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)) {
index 2c3d52c31f24f81a0859afedf8c8885161eb5ce3..7826763ee539bbac6028652ab7e4a3a4918cf5a3 100644 (file)
@@ -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) {
index fedf008f7e476bdddefc78f33d1a14c78ce040be..4cd832aadcbf1932c03ba1f2fdf045fb2620b068 100644 (file)
@@ -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)) &&
index d3fd4a6f887eb8d41bb0679aeeee0bc4d1769122..32b7281daf6bdcd814701254adc983a0fc1aa5ac 100644 (file)
@@ -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 &&