}
/* 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;
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) */
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)))
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 */
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);
reentrant++;
inlineState.count = 0;
+ savedBlockno = currBlockno;
+ currBlockno = inlineFindMaxBlockno (body, 0);
expandInlineFuncs (body, NULL);
+ currBlockno = savedBlockno;
if (FUNC_ISINLINE (name->type))
name->funcTree = copyAst (body);