{
case AND_OP:
case OR_OP:
+ case '!':
return resultType;
case '=':
case '?':
if (IS_LITERAL (RTYPE (tree)))
{
- int arrayIndex = (int) floatFromVal (valFromType (RETYPE (tree)));
+ int arrayIndex = (int) ulFromVal (valFromType (RETYPE (tree)));
int arraySize = DCL_ELEM (LTYPE (tree));
if (arraySize && arrayIndex >= arraySize)
{
/* rearrange the tree */
if (IS_LITERAL (RTYPE (tree))
/* avoid infinite loop */
- && (TYPE_TARGET_ULONG) floatFromVal (tree->right->opval.val) != 1)
+ && (TYPE_TARGET_ULONG) ulFromVal (tree->right->opval.val) != 1)
{
ast *parent;
ast *litTree = searchLitOp (tree, &parent, "/");
/* rearrange the tree */
if (IS_LITERAL (RTYPE (tree))
/* avoid infinite loop */
- && (TYPE_TARGET_ULONG) floatFromVal (tree->right->opval.val) != 0)
+ && (TYPE_TARGET_ULONG) ulFromVal (tree->right->opval.val) != 0)
{
ast *litTree, *litParent;
litTree = searchLitOp (tree, &litParent, "+-");
}
/* 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;
/* if only the right side is a literal & we are
shifting more than size of the left operand then zero */
if (IS_LITERAL (RTYPE (tree)) &&
- ((TYPE_TARGET_ULONG) floatFromVal (valFromType (RETYPE (tree)))) >=
+ ((TYPE_TARGET_ULONG) ulFromVal (valFromType (RETYPE (tree)))) >=
(getSize (TETYPE (tree)) * 8))
{
if (tree->opval.op==LEFT_OP ||
TTYPE (tree) = tree->opval.val->type;
tree->values.literalFromCast = 1;
} else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) &&
- ((int)floatFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ {
+ ((int) ulFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ {
sym_link *rest = LTYPE(tree)->next;
werrorfl (tree->filename, tree->lineno, W_LITERAL_GENERIC);
TTYPE(tree) = newLink(DECLARATOR);
if (tree->opval.op == '>' &&
SPEC_USIGN(LETYPE(tree)) &&
IS_LITERAL(RTYPE(tree)) &&
- ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0)
+ ((int) ulFromVal (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) */
if (IS_LITERAL(RTYPE(tree)) &&
floatFromVal (valFromType (RETYPE (tree))) == 0 &&
tree->opval.op == EQ_OP &&
- resultType == RESULT_TYPE_IFX)
+ (resultType == RESULT_TYPE_IFX || resultType == RESULT_TYPE_BIT))
{
tree->opval.op = '!';
tree->right = NULL;
if (IS_LITERAL (RTYPE (tree)) && IS_UNSIGNED (RTYPE (tree)) &&
/* the value range of a 'unsigned char' is 0...255;
if the actual value is < 128 it can be changed to signed */
- (int) floatFromVal (valFromType (RETYPE (tree))) < 128)
+ (int) ulFromVal (valFromType (RETYPE (tree))) < 128)
{
/* now we've got 2 'signed char'! */
SPEC_USIGN (RETYPE (tree)) = 0;
}
/* same test for the left operand: */
else if (IS_LITERAL (LTYPE (tree)) && IS_UNSIGNED (LTYPE (tree)) &&
- (int) floatFromVal (valFromType (LETYPE (tree))) < 128)
+ (int) ulFromVal (valFromType (LETYPE (tree))) < 128)
{
SPEC_USIGN (LETYPE (tree)) = 0;
}
}
LRVAL (tree) = RRVAL (tree) = 1;
- TTYPE (tree) = TETYPE (tree) = newBoolLink ();
+ TTYPE (tree) = TETYPE (tree) = (resultType == RESULT_TYPE_BIT) ? newBoolLink() :newCharLink();
/* condition transformations */
{
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)))
{
- if (((int) floatFromVal (valFromType (LETYPE (tree)))) != 0)
+ if (((int) ulFromVal (valFromType (LETYPE (tree)))) != 0)
return decorateType (tree->right->left, resultTypeProp);
else
return decorateType (tree->right->right, resultTypeProp);
{
/* also order the cases according to value */
value *pval = NULL;
- int cVal = (int) floatFromVal (caseVal->opval.val);
- while (val && (int) floatFromVal (val) < cVal)
+ int cVal = (int) ulFromVal (caseVal->opval.val);
+ while (val && (int) ulFromVal (val) < cVal)
{
pval = val;
val = val->next;
{
pval->next = caseVal->opval.val;
}
- else if ((int) floatFromVal (val) == cVal)
+ else if ((int) ulFromVal (val) == cVal)
{
werrorfl (caseVal->filename, caseVal->lineno, E_DUPLICATE_LABEL,
"case");
SNPRINTF(caseLbl, sizeof(caseLbl),
"_case_%d_%d",
swStat->values.switchVals.swNum,
- (int) floatFromVal (caseVal->opval.val));
+ (int) ulFromVal (caseVal->opval.val));
rexpr = createLabel (newSymbol (caseLbl, 0), stmnt);
rexpr->lineno = 0;
root->right->opval.val : NULL);
/* if left is a BITVAR in BITSPACE */
- /* and right is a LITERAL then opt- */
- /* imize else do nothing */
+ /* and right is a LITERAL then */
+ /* optimize else do nothing */
if (vleft && vright &&
IS_BITVAR (vleft->etype) &&
IN_BITSPACE (SPEC_OCLS (vleft->etype)) &&
{
/* if right side > 1 then comparison may never succeed */
- if ((litValue = (int) floatFromVal (vright)) > 1)
+ if ((litValue = (int) ulFromVal (vright)) > 1)
{
werror (W_BAD_COMPARE);
goto noOptimize;
sym->level = level;
sym->block = currBlockno;
+ sym->reqv = NULL;
+ SYM_SPIL_LOC (sym) = NULL;
+ sym->key = 0;
+
/* If the symbol is a label, we need to renumber it */
if (sym->islbl)
fixupInlineLabel (sym);
static void
inlineAddDecl (symbol * sym, ast * block, int addSymTab)
{
+ sym->reqv = NULL;
+ SYM_SPIL_LOC (sym) = NULL;
+ sym->key = 0;
if (block != NULL)
{
symbol **decl = &(block->values.sym);
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);
if (fatalError)
goto skipall;
- /* Do not generate code for inline functions unless extern also */
+ /* Do not generate code for inline functions unless extern also. */
+#if 0
if (FUNC_ISINLINE (name->type) && !IS_EXTERN (fetype))
goto skipall;
+#else
+ /* Temporary hack: always generate code for static inline functions. */
+ /* Ideally static inline functions should only be generated if needed. */
+ if (FUNC_ISINLINE (name->type) && !IS_EXTERN (fetype) && !IS_STATIC (fetype))
+ goto skipall;
+#endif
/* create the node & generate intermediate code */
GcurMemmap = code;
if (IS_LITERAL (tree->opval.val->etype)) {
fprintf(outfile,"CONSTANT (%p) value = ", tree);
if (SPEC_USIGN (tree->opval.val->etype))
- fprintf(outfile,"%u", (TYPE_TARGET_ULONG) floatFromVal(tree->opval.val));
+ fprintf(outfile,"%u", (TYPE_TARGET_ULONG) ulFromVal(tree->opval.val));
else
- fprintf(outfile,"%d", (TYPE_TARGET_LONG) floatFromVal(tree->opval.val));
- fprintf(outfile,", 0x%x, %f", (TYPE_TARGET_ULONG) floatFromVal(tree->opval.val),
+ fprintf(outfile,"%d", (TYPE_TARGET_LONG) ulFromVal(tree->opval.val));
+ fprintf(outfile,", 0x%x, %f", (TYPE_TARGET_ULONG) ulFromVal(tree->opval.val),
floatFromVal(tree->opval.val));
} else if (tree->opval.val->sym) {
/* if the undefined flag is set then give error message */
for (val = tree->values.switchVals.swVals; val ; val = val->next) {
INDENT(indent+2,outfile);
fprintf(outfile,"CASE 0x%x GOTO _case_%d_%d\n",
- (int) floatFromVal(val),
+ (int) ulFromVal(val),
tree->values.switchVals.swNum,
- (int) floatFromVal(val));
+ (int) ulFromVal(val));
}
ast_print(tree->right,outfile,indent);
}