return NULL;
}
+/*-----------------------------------------------------------------*/
+/* hasInc - operand is incremented before any other use */
+/*-----------------------------------------------------------------*/
+static iCode *
+hasInc (operand *op, iCode *ic)
+{
+ sym_link *type = operandType(op);
+ sym_link *retype = getSpec (type);
+ iCode *lic = ic->next;
+ int isize ;
+
+ /* this could from a cast, e.g.: "(char xdata *) 0x7654;" */
+ if (!IS_SYMOP(op)) return NULL;
+
+ if (IS_BITVAR(retype)||!IS_PTR(type)) return NULL;
+ isize = getSize(type->next);
+ while (lic) {
+ /* if operand of the form op = op + <sizeof *op> */
+ if (lic->op == '+' && isOperandEqual(IC_LEFT(lic),op) &&
+ isOperandEqual(IC_RESULT(lic),op) &&
+ isOperandLiteral(IC_RIGHT(lic)) &&
+ operandLitValue(IC_RIGHT(lic)) == isize) {
+ return lic;
+ }
+ /* if the operand used or deffed */
+ if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) {
+ return NULL;
+ }
+ lic = lic->next;
+ }
+ return NULL;
+}
+
/*-----------------------------------------------------------------*/
/* genAndOp - for && operation */
/*-----------------------------------------------------------------*/
static void
genNearPointerGet (operand * left,
operand * result,
- iCode * ic)
+ iCode * ic,
+ iCode *pi)
{
asmop *aop = NULL;
regs *preg = NULL;
aopPut (AOP (result), buffer, offset);
}
offset++;
- if (size)
+ if (size || pi)
emitcode ("inc", "%s", rname);
}
}
if (aop)
{
/* we had to allocate for this iCode */
+ if (pi) { /* post increment present */
+ aopPut(AOP ( left ),rname,0);
+ }
freeAsmop (NULL, aop, ic, TRUE);
}
else
if (AOP_SIZE (result) > 1 &&
!OP_SYMBOL (left)->remat &&
(OP_SYMBOL (left)->liveTo > ic->seq ||
- ic->depth))
+ ic->depth) &&
+ !pi)
{
int size = AOP_SIZE (result) - 1;
while (size--)
/* done */
freeAsmop (result, NULL, ic, TRUE);
-
+ if (pi) pi->generated = 1;
}
/*-----------------------------------------------------------------*/
static void
genPagedPointerGet (operand * left,
operand * result,
- iCode * ic)
+ iCode * ic,
+ iCode * pi)
{
asmop *aop = NULL;
regs *preg = NULL;
offset++;
- if (size)
+ if (size || pi)
emitcode ("inc", "%s", rname);
}
}
if (aop)
{
/* we had to allocate for this iCode */
+ if (pi) aopPut ( AOP (left), rname, 0);
freeAsmop (NULL, aop, ic, TRUE);
}
else
if (AOP_SIZE (result) > 1 &&
!OP_SYMBOL (left)->remat &&
(OP_SYMBOL (left)->liveTo > ic->seq ||
- ic->depth))
+ ic->depth) &&
+ !pi)
{
int size = AOP_SIZE (result) - 1;
while (size--)
/* done */
freeAsmop (result, NULL, ic, TRUE);
-
-
+ if (pi) pi->generated = 1;
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void
genFarPointerGet (operand * left,
- operand * result, iCode * ic)
+ operand * result, iCode * ic, iCode *pi)
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
_flushLazyDPS ();
emitcode ("movx", "a,@dptr");
- if (size)
+ if (size || pi)
emitcode ("inc", "dptr");
aopPut (AOP (result), "a", offset++);
}
_endLazyDPSEvaluation ();
}
+ if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) {
+ aopPut ( AOP (left), "dpl", 0);
+ aopPut ( AOP (left), "dph", 1);
+ if (options.model == MODEL_FLAT24)
+ aopPut ( AOP (left), "dpx", 2);
+ pi->generated = 1;
+ }
freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
static void
emitcodePointerGet (operand * left,
- operand * result, iCode * ic)
+ operand * result, iCode * ic, iCode *pi)
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
}
}
/* so dptr know contains the address */
- freeAsmop (left, NULL, ic, TRUE);
aopOp (result, ic, FALSE, TRUE);
/* if bit then unpack */
emitcode ("clr", "a");
emitcode ("movc", "a,@a+dptr");
- if (size)
+ if (size || pi)
emitcode ("inc", "dptr");
aopPut (AOP (result), "a", offset++);
}
_endLazyDPSEvaluation ();
}
+ if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) {
+ aopPut ( AOP (left), "dpl", 0);
+ aopPut ( AOP (left), "dph", 1);
+ if (options.model == MODEL_FLAT24)
+ aopPut ( AOP (left), "dpx", 2);
+ pi->generated = 1;
+ }
+ freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
static void
genGenPointerGet (operand * left,
- operand * result, iCode * ic)
+ operand * result, iCode * ic, iCode * pi)
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
}
}
/* so dptr know contains the address */
- freeAsmop (left, NULL, ic, TRUE);
aopOp (result, ic, FALSE, TRUE);
/* if bit then unpack */
{
emitcode ("lcall", "__gptrget");
aopPut (AOP (result), "a", offset++);
- if (size)
+ if (size || pi)
emitcode ("inc", "dptr");
}
}
+ if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) {
+ aopPut ( AOP (left), "dpl", 0);
+ aopPut ( AOP (left), "dph", 1);
+ if (options.model == MODEL_FLAT24) {
+ aopPut ( AOP (left), "dpx", 2);
+ aopPut ( AOP (left), "b", 3);
+ } else aopPut ( AOP (left), "b", 2);
+ pi->generated = 1;
+ }
+ freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
static void
-genPointerGet (iCode * ic)
+genPointerGet (iCode * ic, iCode *pi)
{
operand *left, *result;
sym_link *type, *etype;
case POINTER:
case IPOINTER:
- genNearPointerGet (left, result, ic);
+ genNearPointerGet (left, result, ic, pi);
break;
case PPOINTER:
- genPagedPointerGet (left, result, ic);
+ genPagedPointerGet (left, result, ic, pi);
break;
case FPOINTER:
- genFarPointerGet (left, result, ic);
+ genFarPointerGet (left, result, ic, pi);
break;
case CPOINTER:
- emitcodePointerGet (left, result, ic);
+ emitcodePointerGet (left, result, ic, pi);
break;
case GPOINTER:
- genGenPointerGet (left, result, ic);
+ genGenPointerGet (left, result, ic, pi);
break;
}
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
static void
-genPointerSet (iCode * ic)
+genPointerSet (iCode * ic, iCode *pi)
{
operand *right, *result;
sym_link *type, *etype;
break;
case GET_VALUE_AT_ADDRESS:
- genPointerGet (ic);
+ genPointerGet (ic,hasInc(IC_LEFT(ic),ic));
break;
case '=':
if (POINTER_SET (ic))
- genPointerSet (ic);
+ genPointerSet (ic,hasInc(IC_RESULT(ic),ic));
else
genAssign (ic);
break;