dbuf_append_char (dbuf, '\t');
dbuf_printf (dbuf, "%s\t", s);
dbuf_printOperand (IC_JTCOND (ic), dbuf);
- dbuf_append_char (dbuf, '\n');
for (sym = setFirstItem (IC_JTLABELS (ic)); sym;
sym = setNextItem (IC_JTLABELS (ic)))
- dbuf_printf (dbuf, "\t\t\t%s\n", sym->name);
+ dbuf_printf (dbuf, "; %s", sym->name);
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picGeneric)
dbuf_printf (dbuf, " == 0 goto %s($%d)\n", IC_FALSE (ic)->name, IC_FALSE (ic)->key);
else
{
- dbuf_printf (dbuf, " != 0 goto %s($%d)\n", IC_TRUE (ic)->name, IC_TRUE (ic)->key);
+ dbuf_printf (dbuf, " != 0 goto %s($%d)", IC_TRUE (ic)->name, IC_TRUE (ic)->key);
if (IC_FALSE (ic))
- dbuf_printf (dbuf, "\tzzgoto %s\n", IC_FALSE (ic)->name);
+ dbuf_printf (dbuf, "; zzgoto %s\n", IC_FALSE (ic)->name);
+ dbuf_append_char (dbuf, '\n');
}
}
dbuf_init(&dbuf, 1024);
icTab->iCodePrint (&dbuf, loop, icTab->printName);
dbuf_write_and_destroy (&dbuf, of);
+ ////
+ fflush(of);
}
}
}
/* This seems very dangerous to me, since there are several */
/* optimizations (for example, gcse) that don't notice the */
- /* cast hidden in this assignement and may simplify an */
+ /* cast hidden in this assignment and may simplify an */
/* iCode to use the original (uncasted) operand. */
/* Unfortunately, other things break when this cast is */
/* made explicit. Need to fix this someday. */
/*-----------------------------------------------------------------*/
-/* geniCodeBitwise - gen int code for bitWise operators */
+/* geniCodeBitwise - gen int code for bitWise operators */
/*-----------------------------------------------------------------*/
operand *
geniCodeBitwise (operand * left, operand * right,
/* geniCodeLogic- logic code */
/*-----------------------------------------------------------------*/
static operand *
-geniCodeLogic (operand * left, operand * right, int op)
+geniCodeLogic (operand * left, operand * right, int op, ast *tree)
{
iCode *ic;
- sym_link *ctype;
+ sym_link *ctype, *ttype;
sym_link *rtype = operandType (right);
sym_link *ltype = operandType (left);
ctype = usualBinaryConversions (&left, &right, RESULT_TYPE_BIT, 0);
ic = newiCode (op, left, right);
- IC_RESULT (ic) = newiTempOperand (newCharLink (), 1);
+ /* store 0 or 1 in result */
+ ttype = (tree && IS_BIT (tree->ftype)) ? newBoolLink() : newCharLink();
+ IC_RESULT (ic) = newiTempOperand (ttype, 1);
/* if comparing float
and not a '==' || '!=' || '&&' || '||' (these
ADDTOCHAIN (ic);
/* store 0 or 1 in result */
- type = (SPEC_NOUN(tree->ftype) == V_BIT) ? newBoolLink() : newCharLink();
+ type = (IS_BIT (tree->ftype)) ? newBoolLink() : newCharLink();
result = newiTempOperand (type, 1);
geniCodeLabel (falseLabel);
iCode *ic;
symbol *falseLabel = newiTempLabel (NULL);
symbol *exitLabel = newiTempLabel (NULL);
- operand *cond = ast2iCode (tree->left,lvl+1);
- operand *true, *false, *result;
+ ast *astTrue = tree->right->left;
+ ast *astFalse = tree->right->right;
+ operand *cond = ast2iCode (tree->left, lvl+1);
+ operand *result = newiTempOperand (tree->right->ftype, 0);
+ operand *opTrue, *opFalse;
- ic = newiCodeCondition (geniCodeRValue (cond, FALSE),
- NULL, falseLabel);
+ ic = newiCodeCondition (geniCodeRValue (cond, FALSE), NULL, falseLabel);
ADDTOCHAIN (ic);
- true = ast2iCode (tree->right->left,lvl+1);
+ opTrue = ast2iCode (astTrue, lvl+1);
- /* move the value to a new Operand */
- result = newiTempOperand (tree->right->ftype, 0);
- geniCodeAssign (result, geniCodeRValue (true, FALSE), 0, 0);
+ /* move the value to the new operand */
+ geniCodeAssign (result, geniCodeRValue (opTrue, FALSE), 0, 0);
/* generate an unconditional goto */
geniCodeGoto (exitLabel);
/* now for the right side */
geniCodeLabel (falseLabel);
- false = ast2iCode (tree->right->right,lvl+1);
- geniCodeAssign (result, geniCodeRValue (false, FALSE), 0, 0);
+ opFalse = ast2iCode (astFalse, lvl+1);
+ geniCodeAssign (result, geniCodeRValue (opFalse, FALSE), 0, 0);
/* create the exit label */
geniCodeLabel (exitLabel);
ic->supportRtn = 1;
ic->nosupdate = nosupdate;
- return left;
+ /* left could be a pointer assignment,
+ return the properly casted right instead */
+ return right;
}
/*-----------------------------------------------------------------*/
the condition is unsigned & minimum value is zero */
if (!(min == 0 && IS_UNSIGNED (cetype)))
{
- boundary = geniCodeLogic (cond, operandFromLit (min), '<');
+ boundary = geniCodeLogic (cond, operandFromLit (min), '<', NULL);
ic = newiCodeCondition (boundary, falseLabel, NULL);
ADDTOCHAIN (ic);
}
/* now for upper bounds */
- boundary = geniCodeLogic (cond, operandFromLit (max), '>');
+ boundary = geniCodeLogic (cond, operandFromLit (max), '>', NULL);
ic = newiCodeCondition (boundary, falseLabel, NULL);
ADDTOCHAIN (ic);
}
operand *compare = geniCodeLogic (cond,
operandFromValue (caseVals),
- EQ_OP);
+ EQ_OP, NULL);
SNPRINTF (buffer, sizeof(buffer), "_case_%d_%d",
tree->values.switchVals.swNum,
case GETHBIT:
{
operand *op = geniCodeUnary (geniCodeRValue (left, FALSE), tree->opval.op);
- setOperandType (op, UCHARTYPE);
+ if (!IS_BIT (operandType (op)))
+ setOperandType (op, UCHARTYPE);
return op;
}
case GETABIT:
+ {
+ operand *op = geniCodeBinary (geniCodeRValue (left, FALSE),
+ geniCodeRValue (right, FALSE),
+ tree->opval.op);
+ if (!IS_BIT (operandType (op)))
+ setOperandType (op, UCHARTYPE);
+ return op;
+ }
case GETBYTE:
+ {
+ operand *op = geniCodeBinary (geniCodeRValue (left, FALSE),
+ geniCodeRValue (right, FALSE),
+ tree->opval.op);
+ setOperandType (op, UCHARTYPE);
+ return op;
+ }
case GETWORD:
{
operand *op = geniCodeBinary (geniCodeRValue (left, FALSE),
geniCodeRValue (right, FALSE),
tree->opval.op);
- setOperandType (op, (tree->opval.op == GETWORD) ? UINTTYPE : UCHARTYPE);
+ setOperandType (op, UINTTYPE);
return op;
}
case AND_OP:
case NE_OP:
/* different compilers (even different gccs) evaluate
the two calls in a different order. to get the same
- result on all machines we've to specify a clear sequence.
+ result on all machines we have to specify a clear sequence.
return geniCodeLogic (geniCodeRValue (left, FALSE),
geniCodeRValue (right, FALSE),
tree->opval.op);
leftOp = geniCodeRValue (left , FALSE);
rightOp = geniCodeRValue (right, FALSE);
- return geniCodeLogic (leftOp, rightOp, tree->opval.op);
+ return geniCodeLogic (leftOp, rightOp, tree->opval.op, tree);
}
case '?':
return geniCodeConditional (tree,lvl);
else
right = geniCodeRValue (right, FALSE);
- geniCodeAssign (left, right, 0, 1);
- return right;
+ return geniCodeAssign (left, right, 0, 1);
}
case MUL_ASSIGN:
return