* sim/ucsim/configure.in, sim/ucsim/configure, sim/ucsim/ddconfig_in.h:
[fw/sdcc] / src / SDCCast.c
index 84bbdd8f67d8b0cffb202b0fd7a3383da8b9f725..f1847f2ffb7d8bd8d34c4d2b4adb0d356318b5da 100644 (file)
@@ -3646,8 +3646,13 @@ decorateType (ast * tree, RESULT_TYPE resultType)
         }
 
       /* if left is another '!' */
-      if (tree->left->opval.op == '!')
+      if (IS_AST_NOT_OPER (tree->left))
         {
+          if ((resultType == RESULT_TYPE_IFX) || (resultType == RESULT_TYPE_BIT))
+            {
+              /* remove double '!!X' by 'X' */
+              return tree->left->left;
+            }
           /* remove double '!!X' by 'X ? 1 : 0' */
           tree->opval.op = '?';
           tree->left  = tree->left->left;
@@ -4132,7 +4137,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
           IS_LITERAL(RTYPE(tree))  &&
           ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0)
         {
-          if (resultType == RESULT_TYPE_IFX)
+          if ((resultType == RESULT_TYPE_IFX) || (resultType == RESULT_TYPE_BIT))
             {
               /* the parent is an ifx: */
               /* if (unsigned value) */
@@ -4363,6 +4368,35 @@ decorateType (ast * tree, RESULT_TYPE resultType)
     case '?':
       /* the type is value of the colon operator (on the right) */
       assert (IS_COLON_OP (tree->right));
+
+      if (IS_AST_LIT_VALUE (tree->right->left) && IS_AST_LIT_VALUE (tree->right->right))
+        {
+          double valTrue = AST_LIT_VALUE (tree->right->left);
+          double valFalse = AST_LIT_VALUE (tree->right->right);
+
+          if ((valTrue == 1) && (valFalse == 0) &&
+              ((resultType == RESULT_TYPE_IFX) || (resultType == RESULT_TYPE_BIT)))
+            {
+              /* assign cond to result */
+              return decorateType (tree->left, resultTypeProp);
+            }
+          else if ((valTrue == 0) && (valFalse == 1))
+            {
+              /* assign !cond to result */
+              tree->opval.op = '!';
+              tree->decorated = 0;
+              tree->right = NULL;
+              return decorateType (tree, resultTypeProp);
+            }
+        }
+
+      /* if they are equal then replace the tree */
+      if (!astHasVolatile (tree->right) &&
+          isAstEqual (tree->right->left, tree->right->right))
+        {
+          return decorateType (tree->right->left, resultTypeProp);
+        }
+
       /* if already known then replace the tree : optimizer will do it
          but faster to do it here */
       if (IS_LITERAL (LTYPE (tree)))
@@ -6117,6 +6151,32 @@ inlineFindParm (ast * parms, int index)
   return inlineFindParmRecurse (parms, &index);
 }
 
+/*-----------------------------------------------------------------*/
+/* inlineFindMaxBlockno - find maximum block number in an ast tree */
+/*-----------------------------------------------------------------*/
+static int
+inlineFindMaxBlockno (ast * tree, int maxBlockno)
+{
+  int tempBlockno;
+
+  if (!tree)
+    return maxBlockno;
+
+  tempBlockno = inlineFindMaxBlockno (tree->left, maxBlockno);
+  if (tempBlockno > maxBlockno)
+    maxBlockno = tempBlockno;
+
+  tempBlockno = inlineFindMaxBlockno (tree->right, maxBlockno);
+  if (tempBlockno > maxBlockno)
+    maxBlockno = tempBlockno;
+
+  if (tree->block > maxBlockno)
+    maxBlockno = tree->block;
+  return maxBlockno;
+}
+
+
+
 
 /*-----------------------------------------------------------------*/
 /* expandInlineFuncs - replace calls to inline functions with the  */
@@ -6295,6 +6355,7 @@ createFunction (symbol * name, ast * body)
   int stack = 0;
   sym_link *fetype;
   iCode *piCode = NULL;
+  int savedBlockno;
 
   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
     fprintf (stderr, "SDCCast.c:createFunction(%s)\n", name->name);
@@ -6351,7 +6412,10 @@ createFunction (symbol * name, ast * body)
     reentrant++;
 
   inlineState.count = 0;
+  savedBlockno = currBlockno;
+  currBlockno = inlineFindMaxBlockno (body, 0);
   expandInlineFuncs (body, NULL);
+  currBlockno = savedBlockno;
 
   if (FUNC_ISINLINE (name->type))
     name->funcTree = copyAst (body);