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 ;
+
+ 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(ic->uses,op->key) || ic->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;
else
rname = aopGet (AOP (left), 0, FALSE, FALSE);
- freeAsmop (left, NULL, ic, TRUE);
aopOp (result, ic, FALSE);
/* if bitfield then unpack the bits */
aopPut (AOP (result), buffer, offset);
}
offset++;
- if (size)
+ if (size || pi)
emitcode ("inc", "%s", rname);
}
}
/* now some housekeeping stuff */
- if (aop)
+ if (aop) /* we had to allocate for this iCode */
{
- /* we had to allocate for this iCode */
+ if (pi) { /* post increment present */
+ aopPut(AOP ( left ),rname,0);
+ }
freeAsmop (NULL, aop, ic, TRUE);
}
else
if size > 0 && this could be used again
we have to point it back to where it
belongs */
- if (AOP_SIZE (result) > 1 &&
- !OP_SYMBOL (left)->remat &&
- (OP_SYMBOL (left)->liveTo > ic->seq ||
- ic->depth))
+ if ((AOP_SIZE (result) > 1 &&
+ !OP_SYMBOL (left)->remat &&
+ (OP_SYMBOL (left)->liveTo > ic->seq ||
+ ic->depth)) &&
+ !pi)
{
int size = AOP_SIZE (result) - 1;
while (size--)
}
/* done */
+ freeAsmop (left, NULL, ic, TRUE);
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;
else
rname = aopGet (AOP (left), 0, FALSE, FALSE);
- freeAsmop (left, NULL, ic, TRUE);
aopOp (result, ic, FALSE);
/* if bitfield then unpack the bits */
offset++;
- if (size)
+ if (size || pi)
emitcode ("inc", "%s", rname);
}
}
/* now some housekeeping stuff */
- if (aop)
+ if (aop) /* we had to allocate for this iCode */
{
- /* we had to allocate for this iCode */
+ if (pi) aopPut ( AOP (left), rname, 0);
freeAsmop (NULL, aop, ic, TRUE);
}
else
if size > 0 && this could be used again
we have to point it back to where it
belongs */
- if (AOP_SIZE (result) > 1 &&
- !OP_SYMBOL (left)->remat &&
- (OP_SYMBOL (left)->liveTo > ic->seq ||
- ic->depth))
+ if ((AOP_SIZE (result) > 1 &&
+ !OP_SYMBOL (left)->remat &&
+ (OP_SYMBOL (left)->liveTo > ic->seq ||
+ ic->depth)) &&
+ !pi)
{
int size = AOP_SIZE (result) - 1;
while (size--)
}
/* done */
+ freeAsmop (left, NULL, ic, TRUE);
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));
}
}
/* so dptr know contains the address */
- freeAsmop (left, NULL, ic, TRUE);
aopOp (result, ic, FALSE);
/* if bit then unpack */
{
emitcode ("movx", "a,@dptr");
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);
+ pi->generated = 1;
+ }
+ freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
-/* emitcodePointerGet - gget value from code space */
+/* genCodePointerGet - gget value from code space */
/*-----------------------------------------------------------------*/
static void
-emitcodePointerGet (operand * left,
- operand * result, iCode * ic)
+genCodePointerGet (operand * left,
+ 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);
/* if bit then unpack */
emitcode ("clr", "a");
emitcode ("movc", "a,@a+dptr");
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);
+ 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);
/* 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);
+ 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;
{
/* we have to go by the storage class */
p_type = PTR_TYPE (SPEC_OCLS (etype));
-
-/* if (SPEC_OCLS(etype)->codesp ) { */
-/* p_type = CPOINTER ; */
-/* } */
-/* else */
-/* if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged) */
-/* p_type = FPOINTER ; */
-/* else */
-/* if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged) */
-/* p_type = PPOINTER; */
-/* else */
-/* if (SPEC_OCLS(etype) == idata ) */
-/* p_type = IPOINTER; */
-/* else */
-/* p_type = POINTER ; */
}
/* now that we have the pointer type we assign
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);
+ genCodePointerGet (left, result, ic, pi);
break;
case GPOINTER:
- genGenPointerGet (left, result, ic);
+ genGenPointerGet (left, result, ic, pi);
break;
}
static void
genNearPointerSet (operand * right,
operand * result,
- iCode * ic)
+ iCode * ic,
+ iCode * pi)
{
asmop *aop = NULL;
regs *preg = NULL;
else
rname = aopGet (AOP (result), 0, FALSE, FALSE);
- freeAsmop (result, NULL, ic, TRUE);
aopOp (right, ic, FALSE);
/* if bitfield then unpack the bits */
}
else
emitcode ("mov", "@%s,%s", rname, l);
- if (size)
+ if (size || pi)
emitcode ("inc", "%s", rname);
offset++;
}
}
/* now some housekeeping stuff */
- if (aop)
+ if (aop) /* we had to allocate for this iCode */
{
- /* we had to allocate for this iCode */
+ if (pi) aopPut (AOP (result),rname,0);
freeAsmop (NULL, aop, ic, TRUE);
}
else
if size > 0 && this could be used again
we have to point it back to where it
belongs */
- if (AOP_SIZE (right) > 1 &&
- !OP_SYMBOL (result)->remat &&
- (OP_SYMBOL (result)->liveTo > ic->seq ||
- ic->depth))
+ if ((AOP_SIZE (right) > 1 &&
+ !OP_SYMBOL (result)->remat &&
+ (OP_SYMBOL (result)->liveTo > ic->seq ||
+ ic->depth)) &&
+ !pi)
{
int size = AOP_SIZE (right) - 1;
while (size--)
}
/* done */
+ if (pi) pi->generated = 1;
+ freeAsmop (result, NULL, ic, TRUE);
freeAsmop (right, NULL, ic, TRUE);
-
-
}
/*-----------------------------------------------------------------*/
static void
genPagedPointerSet (operand * right,
operand * result,
- iCode * ic)
+ iCode * ic,
+ iCode * pi)
{
asmop *aop = NULL;
regs *preg = NULL;
else
rname = aopGet (AOP (result), 0, FALSE, FALSE);
- freeAsmop (result, NULL, ic, TRUE);
aopOp (right, ic, FALSE);
/* if bitfield then unpack the bits */
MOVA (l);
emitcode ("movx", "@%s,a", rname);
- if (size)
+ if (size || pi)
emitcode ("inc", "%s", rname);
offset++;
}
/* now some housekeeping stuff */
- if (aop)
+ if (aop) /* we had to allocate for this iCode */
{
- /* we had to allocate for this iCode */
+ if (pi) aopPut (AOP (result),rname,0);
freeAsmop (NULL, aop, ic, TRUE);
}
else
}
/* done */
+ if (pi) pi->generated = 1;
+ freeAsmop (result, NULL, ic, TRUE);
freeAsmop (right, NULL, ic, TRUE);
/*-----------------------------------------------------------------*/
static void
genFarPointerSet (operand * right,
- operand * result, iCode * ic)
+ operand * result, iCode * ic, iCode * pi)
{
int size, offset;
sym_link *retype = getSpec (operandType (right));
}
}
/* so dptr know contains the address */
- freeAsmop (result, NULL, ic, TRUE);
aopOp (right, ic, FALSE);
/* if bit then unpack */
char *l = aopGet (AOP (right), offset++, FALSE, FALSE);
MOVA (l);
emitcode ("movx", "@dptr,a");
- if (size)
+ if (size || pi)
emitcode ("inc", "dptr");
}
}
-
+ if (pi && AOP_TYPE (result) != AOP_STR && AOP_TYPE (result) != AOP_IMMD) {
+ aopPut (AOP(result),"dpl",0);
+ aopPut (AOP(result),"dph",1);
+ pi->generated=1;
+ }
+ freeAsmop (result, NULL, ic, TRUE);
freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
static void
genGenPointerSet (operand * right,
- operand * result, iCode * ic)
+ operand * result, iCode * ic, iCode * pi)
{
int size, offset;
sym_link *retype = getSpec (operandType (right));
}
}
/* so dptr know contains the address */
- freeAsmop (result, NULL, ic, TRUE);
aopOp (right, ic, FALSE);
/* if bit then unpack */
char *l = aopGet (AOP (right), offset++, FALSE, FALSE);
MOVA (l);
emitcode ("lcall", "__gptrput");
- if (size)
+ if (size || pi)
emitcode ("inc", "dptr");
}
}
+ if (pi && AOP_TYPE (result) != AOP_STR && AOP_TYPE (result) != AOP_IMMD) {
+ aopPut (AOP(result),"dpl",0);
+ aopPut (AOP(result),"dph",1);
+ pi->generated=1;
+ }
+ freeAsmop (result, NULL, ic, TRUE);
freeAsmop (right, NULL, ic, TRUE);
}
/* 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;
case POINTER:
case IPOINTER:
- genNearPointerSet (right, result, ic);
+ genNearPointerSet (right, result, ic, pi);
break;
case PPOINTER:
- genPagedPointerSet (right, result, ic);
+ genPagedPointerSet (right, result, ic, pi);
break;
case FPOINTER:
- genFarPointerSet (right, result, ic);
+ genFarPointerSet (right, result, ic, pi);
break;
case GPOINTER:
- genGenPointerSet (right, result, ic);
+ genGenPointerSet (right, result, ic, pi);
break;
}
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;