* src/SDCCpeeph.c (replaceRule): support empty replacement peephole
[fw/sdcc] / src / SDCCsymt.c
index 4ceceaf007bd50c5a55f08ee18cb4d8d12a879cb..dcce5fcc763cb0fa810479f42b433a818eb23df6 100644 (file)
@@ -1595,7 +1595,8 @@ static sym_link *
 computeTypeOr (sym_link * etype1, sym_link * etype2, sym_link * reType)
 {
   /* sanity check */
-  assert (IS_CHAR (etype1) && IS_CHAR (etype2));
+  assert (   (IS_CHAR (etype1) || IS_BIT (etype1))
+          && (IS_CHAR (etype2) || IS_BIT (etype2)));
 
   if (SPEC_USIGN (etype1) == SPEC_USIGN (etype2))
     {
@@ -1660,7 +1661,7 @@ computeTypeOr (sym_link * etype1, sym_link * etype2, sym_link * reType)
 /*------------------------------------------------------------------*/
 sym_link *
 computeType (sym_link * type1, sym_link * type2,
-             RESULT_TYPE resultType, char op)
+             RESULT_TYPE resultType, int op)
 {
   sym_link *rType;
   sym_link *reType;
@@ -1732,6 +1733,7 @@ computeType (sym_link * type1, sym_link * type2,
        break;
       case RESULT_TYPE_INT:
       case RESULT_TYPE_NONE:
+      case RESULT_TYPE_OTHER:
        if (IS_BIT (reType))
          {
            SPEC_NOUN (reType) = V_CHAR;
@@ -1758,7 +1760,16 @@ computeType (sym_link * type1, sym_link * type2,
                SPEC_USIGN (reType) = 1;
                return rType;
              }
-           else
+           else if (op == '*')
+             {
+               SPEC_NOUN (reType) = V_INT;
+               SPEC_USIGN (reType) = 0;
+               return rType;
+             }
+           /* TODO: should be in SDCCast.c */
+           else if (   op == '/'
+                    && (   !SPEC_USIGN (etype1)
+                        || !SPEC_USIGN (etype2)))
              {
                SPEC_NOUN (reType) = V_INT;
                SPEC_USIGN (reType) = 0;
@@ -1904,7 +1915,12 @@ compareType (sym_link * dest, sym_link * src)
     {
       if (SPEC_USIGN (dest) == SPEC_USIGN (src) &&
          IS_INTEGRAL (dest) && IS_INTEGRAL (src) &&
-         getSize (dest) == getSize (src))
+         /* I would prefer
+         bitsForType (dest) == bitsForType (src))
+            instead of the next two lines, but the regression tests fail with
+            them; I guess it's a problem with replaceCheaperOp  */
+         getSize (dest) == getSize (src) &&
+         !(!IS_BIT (dest) && IS_BIT (src)))
        return 1;
       else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src))
        return -1;