* src/SDCCast.c (decorateType): fixed previouse immature commit, added optimisation
[fw/sdcc] / src / ds390 / gen.c
index 8301d4c4a39876fd8d756cc052b0e0c11b36f6a6..050020dae74b41eea82b429992c715fdc3c8fa69 100644 (file)
@@ -166,7 +166,7 @@ emitcode (char *inst, const char *fmt,...)
       tvsprintf (lb, sizeof(lb), fmt, ap);
     }
 
-  while (isspace (*lbp))
+  while (isspace ((unsigned char)*lbp))
     {
       lbp++;
     }
@@ -741,12 +741,8 @@ aopForRemat (symbol * sym)
               sym_link *from_type = operandType(IC_RIGHT(ic));
               aop->aopu.aop_immd.from_cast_remat = 1;
               ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
-              ptr_type = DCL_TYPE(from_type);
-              if (ptr_type == IPOINTER) {
-                // bug #481053
-                ptr_type = POINTER;
-              }
-              continue ;
+              ptr_type = pointerTypeToGPByte (DCL_TYPE(from_type), NULL, NULL);
+              continue;
       } else break;
 
       ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
@@ -1914,29 +1910,46 @@ genCpl (iCode * ic)
   int offset = 0;
   int size;
   symbol *tlbl;
+  sym_link *letype = getSpec (operandType (IC_LEFT (ic)));
 
-  D (emitcode (";", "genCpl "););
-
+  D(emitcode (";", "genCpl"));
 
   /* assign asmOps to operand & result */
   aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
   aopOp (IC_RESULT (ic), ic, TRUE, AOP_USESDPTR(IC_LEFT (ic)));
 
   /* special case if in bit space */
-  if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY) {
-    if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY) {
-      emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
-      emitcode ("cpl", "c");
-      emitcode ("mov", "%s,c", IC_RESULT (ic)->aop->aopu.aop_dir);
+  if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+    {
+      char *l;
+
+      if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY ||
+          (SPEC_USIGN (letype) && IS_CHAR (letype)))
+        {
+          /* promotion rules are responsible for this strange result:
+             bit -> int -> ~int -> bit
+             uchar -> int -> ~int -> bit
+          */
+          emitcode ("setb", "%s", IC_RESULT (ic)->aop->aopu.aop_dir);
+          goto release;
+        }
+      tlbl=newiTempLabel(NULL);
+      l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, FALSE, NULL);
+      if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC ||
+          AOP_TYPE (IC_LEFT (ic)) == AOP_REG ||
+          IS_AOP_PREG (IC_LEFT (ic)))
+        {
+          emitcode ("cjne", "%s,#0xFF,%05d$", l, tlbl->key + 100);
+        }
+      else
+        {
+          MOVA (l);
+          emitcode ("cjne", "a,#0xFF,%05d$", tlbl->key + 100);
+        }
+      emitcode ("", "%05d$:", tlbl->key+100);
+      outBitC (IC_RESULT(ic));
       goto release;
     }
-    tlbl=newiTempLabel(NULL);
-    emitcode ("cjne", "%s,#0x01,%05d$",
-              aopGet(AOP(IC_LEFT(ic)), 0, FALSE,FALSE,NULL), tlbl->key+100);
-    emitcode ("", "%05d$:", tlbl->key+100);
-    outBitC (IC_RESULT(ic));
-    goto release;
-  }
 
   size = AOP_SIZE (IC_RESULT (ic));
   _startLazyDPSEvaluation ();
@@ -1971,7 +1984,7 @@ genUminusFloat (operand * op, operand * result)
   size = AOP_SIZE (op) - 1;
 
   while (size--)
-  {
+    {
       aopPut (AOP (result),
               aopGet (AOP (op), offset, FALSE, FALSE, NULL),
               offset);
@@ -2638,7 +2651,7 @@ genCall (iCode * ic)
     if (!ic->regsSaved)
       saveRegisters (ic);
 
-  /* if send set is not empty the assign */
+  /* if send set is not empty then assign */
   /* We've saved all the registers we care about;
   * therefore, we may clobber any register not used
   * in the calling convention (i.e. anything not in
@@ -3989,7 +4002,7 @@ adjustArithmeticResult (iCode * ic)
     {
       char buff[5];
       SNPRINTF (buff, sizeof(buff),
-                "#%d", pointerCode (getSpec (operandType (IC_LEFT (ic)))));
+                "#%d", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
       aopPut (AOP (IC_RESULT (ic)), buff, GPTRSIZE - 1);
     }
 }
@@ -6394,7 +6407,7 @@ hasInc (operand *op, iCode *ic, int osize)
           return lic;
       }
       /* if the operand used or deffed */
-      if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) {
+      if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key) {
           return NULL;
       }
       /* if GOTO or IFX */
@@ -11707,7 +11720,7 @@ genCast (iCode * ic)
                     exit(1);
                 }
 
-                SNPRINTF(gpValStr, sizeof(gpValStr), "#0x%d", gpVal);
+                SNPRINTF(gpValStr, sizeof(gpValStr), "#0x%x", gpVal);
                 aopPut (AOP (result), gpValStr, GPTRSIZE - 1);
             }
           goto release;