src/SSDCCmain.c (setIncludePath): added port->target to SDCC_INCLUDE_NAME
[fw/sdcc] / src / SDCCicode.c
index c423c505196c0e5e1888cb2c2f7a59845cff81fd..a0289d047b80ce72111014f0767f68e019af42d7 100644 (file)
@@ -233,7 +233,8 @@ printOperand (operand * op, FILE * file)
 
     case SYMBOL:
 #define REGA 1
-#if REGA
+//#if REGA     /* { */
+    if(REGA && !getenv("PRINT_SHORT_OPERANDS")) {
       fprintf (file, "%s [k%d lr%d:%d so:%d]{ ia%d a2p%d re%d rm%d nos%d ru%d dp%d}",          /*{ar%d rm%d ru%d p%d a%d u%d i%d au%d k%d ks%d}"  , */
               (OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name),
               op->key,
@@ -276,28 +277,26 @@ printOperand (operand * op, FILE * file)
              fprintf (file, "]");
            }
        }
-#else
-
+//#else                /* } else { */
+    } else {
+      /* (getenv("PRINT_SHORT_OPERANDS") != NULL) */
       fprintf (file, "%s ", (OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name));
 
-#if 0
-
-      fprintf (file, "[lr%d:%d so:%d]",
+      if(getenv("PRINT_SHORT_OPERANDS")[0] < '1')
+        {
+          fprintf (file, "[lr%d:%d so:%d]",
               OP_LIVEFROM (op), OP_LIVETO (op),
-              OP_SYMBOL (op)->stack
-       );
-#endif
-
-#if 1
-      {
-       fprintf (file, "{");
-       printTypeChain (operandType (op), file);
-       if (SPIL_LOC (op) && IS_ITEMP (op))
-         fprintf (file, "}{ sir@ %s", SPIL_LOC (op)->rname);
-       fprintf (file, "}");
+              OP_SYMBOL (op)->stack);
+        }
 
-      }
-#endif
+      if(getenv("PRINT_SHORT_OPERANDS")[0] < '2')
+        {
+          fprintf (file, "{");
+          printTypeChain (operandType (op), file);
+          if (SPIL_LOC (op) && IS_ITEMP (op))
+              fprintf (file, "}{ sir@ %s", SPIL_LOC (op)->rname);
+          fprintf (file, "}");
+        }
 
       /* if assigned to registers */
       if (OP_SYMBOL (op)->nRegs)
@@ -323,8 +322,8 @@ printOperand (operand * op, FILE * file)
              fprintf (file, "]");
            }
        }
-
-#endif
+//#endif               /* } */
+    }
       break;
 
     case TYPE:
@@ -700,7 +699,7 @@ newiTempLabel (char *s)
 
   if (s)
     {
-       itmplbl = newSymbol (s, 1);
+      itmplbl = newSymbol (s, 1);
     }
   else
     {
@@ -1787,7 +1786,7 @@ getArraySizePtr (operand * op)
   if(IS_PTR(ltype))
     {
       int size = getSize(ltype);
-      return(IS_GENPTR(ltype)?(size-1):size);
+      return((IS_GENPTR(ltype) && GPTRSIZE > FPTRSIZE) ? (size-1) : size);
     }
 
   if(IS_ARRAY(ltype))
@@ -1805,7 +1804,10 @@ getArraySizePtr (operand * op)
        case FUNCTION:
          return (FPTRSIZE);
        case GPOINTER:
-         return (GPTRSIZE-1);
+          if (GPTRSIZE > FPTRSIZE)
+           return (GPTRSIZE-1);
+          else
+           return (FPTRSIZE);
 
        default:
          return (FPTRSIZE);
@@ -2001,7 +2003,12 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
        // if not a pointer to a function
        if (!(IS_CODEPTR(type) && IS_FUNC(type->next) && IS_FUNC(optype))) {
          if (implicit) { // if not to generic, they have to match
-           if ((!IS_GENPTR(type) && (DCL_TYPE(optype) != DCL_TYPE(type)))) {
+           if (!IS_GENPTR(type) &&
+                !((DCL_TYPE(optype) == DCL_TYPE(type)) ||
+                  ((DCL_TYPE(optype) == POINTER) && (DCL_TYPE(type) == IPOINTER))
+                 )
+               )
+            {
              werror(E_INCOMPAT_PTYPES);
              errors++;
            }
@@ -3375,6 +3382,8 @@ geniCodeCall (operand * left, ast * parms,int lvl)
 static void 
 geniCodeReceive (value * args)
 {
+  unsigned char paramByteCounter = 0;
+
   /* for all arguments that are passed in registers */
   while (args)
     {
@@ -3415,6 +3424,17 @@ geniCodeReceive (value * args)
              first = 0;
          }
          IC_RESULT (ic) = opr;
+         
+         /* misuse of parmBytes (normally used for functions) 
+          * to save estimated stack position of this argument.
+          * Normally this should be zero for RECEIVE iCodes.
+          * No idea if this causes side effects on other ports. - dw
+          */
+         ic->parmBytes = paramByteCounter;
+         
+         /* what stack position do we have? */
+         paramByteCounter += getSize (sym->type);
+
          ADDTOCHAIN (ic);
        }
 
@@ -3682,23 +3702,6 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree)
         }
     }
 
-  /* If cond is volatile, it might change after the boundary  */
-  /* conditions are tested to an out of bounds value, causing */
-  /* a jump to a location outside of the jump table. To avoid */
-  /* this possibility, use a non-volatile copy of it instead. */
-  if (IS_OP_VOLATILE (cond))
-    {
-      operand * newcond;
-      iCode * ic;
-      
-      newcond = newiTempOperand (operandType (cond), TRUE);
-      newcond->isvolatile = 0;
-      ic = newiCode ('=', NULL, cond);
-      IC_RESULT (ic) = newcond;
-      ADDTOCHAIN (ic);
-      cond = newcond;
-    }
-
   /* first we rule out the boundary conditions */
   /* if only optimization says so */
   if (needRangeCheck)
@@ -3768,6 +3771,22 @@ geniCodeSwitch (ast * tree,int lvl)
         }
       goto defaultOrBreak;
     }
+  
+  /* If cond is volatile, it might change while we are trying to */
+  /* find the matching case. To avoid this possibility, make a   */
+  /* non-volatile copy to use instead. */
+  if (IS_OP_VOLATILE (cond))
+    {
+      operand * newcond;
+      iCode * ic;
+      
+      newcond = newiTempOperand (operandType (cond), TRUE);
+      newcond->isvolatile = 0;
+      ic = newiCode ('=', NULL, cond);
+      IC_RESULT (ic) = newcond;
+      ADDTOCHAIN (ic);
+      cond = newcond;
+    }
 
   /* if we can make this a jump table */
   if (geniCodeJumpTable (cond, caseVals, tree))