else if (IS_FIXED16X16 (opetype))
dbuf_printf (dbuf, "%g {", doubleFromFixed16x16(SPEC_CVAL (opetype).v_fixed16x16));
else
- dbuf_printf (dbuf, "0x%x {", (unsigned) floatFromVal (op->operand.valOperand));
+ dbuf_printf (dbuf, "0x%x {", (unsigned int) ulFromVal (op->operand.valOperand));
dbuf_printTypeChain (operandType (op), dbuf);
dbuf_append_char (dbuf, '}');
break;
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);
}
}
}
ic = Safe_alloc ( sizeof (iCode));
ic->seqPoint = seqPoint;
- ic->lineno = lineno;
ic->filename = filename;
+ ic->lineno = lineno;
ic->block = block;
ic->level = scopeLevel;
ic->op = op;
{
iCode *nic = newiCode (ic->op, NULL, NULL);
- nic->lineno = ic->lineno;
nic->filename = ic->filename;
+ nic->lineno = ic->lineno;
nic->block = ic->block;
nic->level = ic->level;
nic->parmBytes = ic->parmBytes;
/* depending on type of operand */
switch (op->type)
{
-
case VALUE:
return op->operand.valOperand->type;
case TYPE:
return op->operand.typeOperand;
+
default:
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
" operand type not known ");
}
}
+/*-----------------------------------------------------------------*/
+/* operandSize - returns size of an operand in bytes */
+/*-----------------------------------------------------------------*/
+unsigned int
+operandSize (operand * op)
+{
+ sym_link *type;
+
+ /* if nothing return 0 */
+ if (!op)
+ return 0;
+
+ type = operandType (op);
+ if (op->aggr2ptr == 2)
+ type = type->next;
+ return getSize (type);
+}
+
/*-----------------------------------------------------------------*/
/* isParamterToCall - will return 1 if op is a parameter to args */
/*-----------------------------------------------------------------*/
/* signed and unsigned mul are the same, as long as the precision
of the result isn't bigger than the precision of the operands. */
retval = operandFromValue (valCastLiteral (type,
- (TYPE_TARGET_ULONG) operandLitValue (left) *
- (TYPE_TARGET_ULONG) operandLitValue (right)));
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) *
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue (right))));
else if (IS_UNSIGNED (type)) /* unsigned int */
{
/* unsigned int is handled here in order to detect overflow */
- TYPE_TARGET_ULONG ul = (TYPE_TARGET_UINT) operandLitValue (left) *
- (TYPE_TARGET_UINT) operandLitValue (right);
+ TYPE_TARGET_ULONG ul = (TYPE_TARGET_UINT) double2ul (operandLitValue (left)) *
+ (TYPE_TARGET_UINT) double2ul (operandLitValue (right));
retval = operandFromValue (valCastLiteral (type, (TYPE_TARGET_UINT) ul));
if (ul != (TYPE_TARGET_UINT) ul)
operandLitValue (right)));
break;
case '/':
- if ((TYPE_TARGET_ULONG) operandLitValue (right) == 0)
+ if (IS_UNSIGNED (type))
{
- werror (E_DIVIDE_BY_ZERO);
- retval = right;
-
+ if ((TYPE_TARGET_ULONG) double2ul (operandLitValue (right)) == 0)
+ {
+ werror (E_DIVIDE_BY_ZERO);
+ retval = right;
+ }
+ SPEC_USIGN (let) = 1;
+ SPEC_USIGN (ret) = 1;
+ retval = operandFromValue (valCastLiteral (type,
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) /
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue (right))));
}
else
{
- if (IS_UNSIGNED (type))
- {
- SPEC_USIGN (let) = 1;
- SPEC_USIGN (ret) = 1;
- retval = operandFromValue (valCastLiteral (type,
- (TYPE_TARGET_ULONG) operandLitValue (left) /
- (TYPE_TARGET_ULONG) operandLitValue (right)));
- }
- else
+ if (operandLitValue (right) == 0)
{
- retval = operandFromValue (valCastLiteral (type,
- operandLitValue (left) /
- operandLitValue (right)));
+ werror (E_DIVIDE_BY_ZERO);
+ retval = right;
}
+ retval = operandFromValue (valCastLiteral (type,
+ operandLitValue (left) /
+ operandLitValue (right)));
}
break;
case '%':
- if ((TYPE_TARGET_ULONG) operandLitValue (right) == 0)
+ if ((TYPE_TARGET_ULONG) double2ul (operandLitValue (right)) == 0)
{
werror (E_DIVIDE_BY_ZERO);
retval = right;
else
{
if (IS_UNSIGNED (type))
- retval = operandFromLit ((TYPE_TARGET_ULONG) operandLitValue (left) %
- (TYPE_TARGET_ULONG) operandLitValue (right));
+ retval = operandFromLit ((TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) %
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue (right)));
else
retval = operandFromLit ((TYPE_TARGET_LONG) operandLitValue (left) %
(TYPE_TARGET_LONG) operandLitValue (right));
/* The number of left shifts is always unsigned. Signed doesn't make
sense here. Shifting by a negative number is impossible. */
retval = operandFromValue (valCastLiteral (type,
- ((TYPE_TARGET_ULONG) operandLitValue (left) <<
- (TYPE_TARGET_ULONG) operandLitValue (right))));
+ ((TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) <<
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue (right)))));
break;
case RIGHT_OP:
/* The number of right shifts is always unsigned. Signed doesn't make
sense here. Shifting by a negative number is impossible. */
if (IS_UNSIGNED(let))
/* unsigned: logic shift right */
- retval = operandFromLit ((TYPE_TARGET_ULONG) operandLitValue (left) >>
- (TYPE_TARGET_ULONG) operandLitValue (right));
+ retval = operandFromLit ((TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) >>
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue (right)));
else
/* signed: arithmetic shift right */
- retval = operandFromLit ((TYPE_TARGET_LONG ) operandLitValue (left) >>
- (TYPE_TARGET_ULONG) operandLitValue (right));
+ retval = operandFromLit ((TYPE_TARGET_LONG) operandLitValue (left) >>
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue (right)));
break;
case EQ_OP:
if (IS_FLOAT (let) || IS_FLOAT (ret))
/* this op doesn't care about signedness */
TYPE_TARGET_ULONG l, r;
- l = (TYPE_TARGET_ULONG) operandLitValue (left);
- r = (TYPE_TARGET_ULONG) operandLitValue (right);
+ l = (TYPE_TARGET_ULONG) double2ul (operandLitValue (left));
+ r = (TYPE_TARGET_ULONG) double2ul (operandLitValue (right));
/* In order to correctly compare 'signed int' and 'unsigned int' it's
neccessary to strip them to 16 bit.
Literals are reduced to their cheapest type, therefore left and
break;
case BITWISEAND:
retval = operandFromValue (valCastLiteral (type,
- (TYPE_TARGET_ULONG)operandLitValue(left) &
- (TYPE_TARGET_ULONG)operandLitValue(right)));
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(left)) &
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(right))));
break;
case '|':
retval = operandFromValue (valCastLiteral (type,
- (TYPE_TARGET_ULONG)operandLitValue(left) |
- (TYPE_TARGET_ULONG)operandLitValue(right)));
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(left)) |
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(right))));
break;
case '^':
retval = operandFromValue (valCastLiteral (type,
- (TYPE_TARGET_ULONG)operandLitValue(left) ^
- (TYPE_TARGET_ULONG)operandLitValue(right)));
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(left)) ^
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(right))));
break;
case AND_OP:
retval = operandFromLit (operandLitValue (left) &&
break;
case RRC:
{
- TYPE_TARGET_ULONG i = (TYPE_TARGET_ULONG) operandLitValue (left);
+ TYPE_TARGET_ULONG i = (TYPE_TARGET_ULONG) double2ul (operandLitValue (left));
retval = operandFromLit ((i >> (getSize (operandType (left)) * 8 - 1)) |
(i << 1));
break;
case RLC:
{
- TYPE_TARGET_ULONG i = (TYPE_TARGET_ULONG) operandLitValue (left);
+ TYPE_TARGET_ULONG i = (TYPE_TARGET_ULONG) double2ul (operandLitValue (left));
retval = operandFromLit ((i << (getSize (operandType (left)) * 8 - 1)) |
(i >> 1));
}
break;
case GETABIT:
- retval = operandFromLit (((TYPE_TARGET_ULONG)operandLitValue(left) >>
- (TYPE_TARGET_ULONG)operandLitValue(right)) & 1);
+ retval = operandFromLit (((TYPE_TARGET_ULONG) double2ul (operandLitValue(left)) >>
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(right))) & 1);
break;
case GETBYTE:
- retval = operandFromLit (((TYPE_TARGET_ULONG)operandLitValue(left) >>
- (TYPE_TARGET_ULONG)operandLitValue(right)) & 0xFF);
+ retval = operandFromLit (((TYPE_TARGET_ULONG) double2ul (operandLitValue(left)) >>
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(right)) & 0xFF));
break;
case GETWORD:
- retval = operandFromLit (((TYPE_TARGET_ULONG)operandLitValue(left) >>
- (TYPE_TARGET_ULONG)operandLitValue(right)) & 0xFFFF);
+ retval = operandFromLit (((TYPE_TARGET_ULONG) double2ul (operandLitValue(left)) >>
+ (TYPE_TARGET_ULONG) double2ul (operandLitValue(right)) & 0xFFFF));
break;
case GETHBIT:
- retval = operandFromLit (((TYPE_TARGET_ULONG)operandLitValue(left) >>
+ retval = operandFromLit (((TYPE_TARGET_ULONG) double2ul (operandLitValue(left)) >>
((getSize (let) * 8) - 1)) & 1);
break;
case '~':
retval = operandFromValue (valCastLiteral (type,
- ~((TYPE_TARGET_ULONG)
- operandLitValue (left))));
+ ~((TYPE_TARGET_ULONG) double2ul (operandLitValue (left)))));
break;
case '!':
return IC_RESULT (ic);
}
+static DECLARATOR_TYPE
+getPtrType(sym_link *type)
+{
+ //for Z80 anything goes
+ if (TARGET_Z80_LIKE)
+ return POINTER;
+
+ //preserve original behaviour for PIC16
+ if (TARGET_IS_PIC16)
+ return POINTER;
+
+ //for HC08 only zeropage ptr is different
+ if (TARGET_IS_HC08)
+ {
+ if (IS_DATA_PTR (type))
+ return POINTER;
+ else
+ return FPOINTER;
+ }
+
+ if (IS_DATA_PTR (type) && TARGET_MCS51_LIKE)
+ return IPOINTER;
+ if (IS_PTR (type))
+ return DCL_TYPE (type);
+ else if (IS_FUNC (type))
+ return CPOINTER;
+ else if (IS_ARRAY (type))
+ return PTR_TYPE (SPEC_OCLS (getSpec (type)));
+ return UPOINTER;
+}
+
/*-----------------------------------------------------------------*/
/* geniCodeCast - changes the value from one type to another */
/*-----------------------------------------------------------------*/
/* if this is a literal then just change the type & return */
if (IS_LITERAL (opetype) && op->type == VALUE && !IS_PTR (type) && !IS_PTR (optype))
{
- return operandFromValue (valCastLiteral (type,
- operandLitValue (op)));
+ return operandFromValue (valCastLiteral (type, operandLitValue (op)));
}
/* if casting to/from pointers, do some checking */
/* 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. */
!IS_FIXED (type) &&
!IS_FIXED (optype) &&
((IS_SPEC (type) && IS_SPEC (optype)) ||
- (!IS_SPEC (type) && !IS_SPEC (optype))))
+ (IS_DECL (type) && IS_DECL (optype) && getPtrType (type) == getPtrType (optype))))
{
ic = newiCode ('=', NULL, op);
IC_RESULT (ic) = newiTempOperand (type, 0);
right->operand.valOperand));
if (IS_LITERAL(retype)) {
- p2 = powof2 ((TYPE_TARGET_ULONG) floatFromVal (right->operand.valOperand));
+ p2 = powof2 ((TYPE_TARGET_ULONG) ulFromVal (right->operand.valOperand));
}
resType = usualBinaryConversions (&left, &right, resultType, '*');
!IS_FLOAT (letype) &&
!IS_FIXED (letype) &&
IS_UNSIGNED(letype) &&
- ((p2 = powof2 ((TYPE_TARGET_ULONG)
- floatFromVal (right->operand.valOperand))) > 0)) {
+ ((p2 = powof2 ((TYPE_TARGET_ULONG) ulFromVal (right->operand.valOperand))) > 0)) {
ic = newiCode (RIGHT_OP, left, operandFromLit (p2)); /* right shift */
}
else
/*-----------------------------------------------------------------*/
-/* 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->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);
if (left->isaddr && IS_PTR (ltype) && IS_ITEMP (left) &&
compareType (ltype, rtype) <= 0)
{
- if (compareType (ltype->next, rtype) < 0)
+ if (left->aggr2ptr)
+ right = geniCodeCast (ltype, right, TRUE);
+ else if (compareType (ltype->next, rtype) < 0)
right = geniCodeCast (ltype->next, right, TRUE);
}
else if (compareType (ltype, rtype) < 0)
iCode *ic;
operand *func;
sym_link *fetype;
+ char *savefilename;
int savelineno;
/* reset the auto generation */
func = ast2iCode (tree->left,lvl+1);
fetype = getSpec (operandType (func));
+ savefilename = filename;
savelineno = lineno;
+ filename = OP_SYMBOL (func)->fileDef;
lineno = OP_SYMBOL (func)->lineDef;
/* create an entry label */
geniCodeLabel (entryLabel);
+ filename = savefilename;
lineno = savelineno;
/* create a proc icode */
ic = newiCode (FUNCTION, func, NULL);
- lineno=ic->lineno = OP_SYMBOL (func)->lineDef;
+ filename = ic->filename = OP_SYMBOL (func)->fileDef;
+ lineno = ic->lineno = OP_SYMBOL (func)->lineDef;
ic->tree = tree;
ADDTOCHAIN (ic);
/* If not all integer numbers are present the algorithm */
/* inserts jumps to the default label for the missing numbers */
/* and decides later whether it is worth it */
- min = (int) floatFromVal (vch = caseVals);
+ min = (int) ulFromVal (vch = caseVals);
while (vch->next)
{
cnt++;
vch = vch->next;
}
- max = (int) floatFromVal (vch);
+ max = (int) ulFromVal (vch);
/* Exit if the range is too large to handle with a jump table. */
if (1 + max - min > port->jumptableCost.maxCount)
/* Build the list of labels for the jump table. */
vch = caseVals;
- t = (int) floatFromVal (vch);
+ t = (int) ulFromVal (vch);
for (i=min; i<=max; i++)
{
if (vch && t==i)
addSet (&labels, newiTempLabel (buffer));
vch = vch->next;
if (vch)
- t = (int) floatFromVal (vch);
+ t = (int) ulFromVal (vch);
}
else
{
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);
}
{
int switchVal, caseVal;
- switchVal = (int) floatFromVal (cond->operand.valOperand);
+ switchVal = (int) ulFromVal (cond->operand.valOperand);
while (caseVals)
{
- caseVal = (int) floatFromVal (caseVals);
+ caseVal = (int) ulFromVal (caseVals);
if (caseVal == switchVal)
{
SNPRINTF (buffer, sizeof(buffer), "_case_%d_%d",
operand *compare = geniCodeLogic (cond,
operandFromValue (caseVals),
- EQ_OP);
+ EQ_OP, NULL);
SNPRINTF (buffer, sizeof(buffer), "_case_%d_%d",
tree->values.switchVals.swNum,
- (int) floatFromVal (caseVals));
+ (int) ulFromVal (caseVals));
trueLabel = newiTempLabel (buffer);
ic = newiCodeCondition (compare, trueLabel, NULL);
operand *op = NULL;
sym_link *type;
- if (!options.stackAuto)
+ if (!options.stackAuto && !TARGET_IS_HC08)
{
type = newLink(SPECIFIER);
SPEC_VOLATILE(type) = 1;
tree->opval.op);
*/
{
- operand *leftOp, *rightOp;
+ operand *leftOp, *rightOp;
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);