{
int size, offset;
size = getDataSize(result);
- if(size){
+ if(size)
+ {
aopPut(AOP(result),"a",0);
size--;
offset = 1;
static void outBitC(operand *result)
{
/* if the result is bit */
- if (AOP_TYPE(result) == AOP_CRY)
+ if (AOP_TYPE(result) == AOP_CRY)
+ {
aopPut(AOP(result),"c",0);
- else {
+ }
+ else
+ {
emitcode("clr","a");
emitcode("rlc","a");
outAcc(result);
}
}
+#if 0
#define AOP_OP_3(ic) \
aopOp (IC_LEFT(ic),ic,FALSE, FALSE); \
aopOp (IC_RIGHT(ic),ic,FALSE, TRUE); \
fprintf(stderr, \
"Ack: three operands in far space! (%s:%d %s:%d)\n", __FILE__, __LINE__, ic->filename, ic->lineno); \
}
+#else
+#define AOP_OP_3(ic) \
+ aopOp (IC_RIGHT(ic),ic,FALSE, FALSE); \
+ aopOp (IC_LEFT(ic),ic,FALSE, (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR)); \
+ aopOp (IC_RESULT(ic),ic,TRUE, (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) || \
+ (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR)); \
+ if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR2 && \
+ AOP_TYPE(IC_RESULT(ic)) == AOP_DPTR2) \
+ { \
+ /* werror(E_INTERNAL_ERROR,__FILE__,__LINE__, */ \
+ fprintf(stderr, \
+ "Ack: three operands in far space! (%s:%d %s:%d)\n", __FILE__, __LINE__, ic->filename, ic->lineno); \
+ }
+
+#define AOP_OP_3_NOFATAL(ic, rc) \
+ aopOp (IC_RIGHT(ic),ic,FALSE, FALSE); \
+ aopOp (IC_LEFT(ic),ic,FALSE, (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR)); \
+ aopOp (IC_RESULT(ic),ic,TRUE, (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) || \
+ (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR)); \
+ if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR2 && \
+ AOP_TYPE(IC_RESULT(ic)) == AOP_DPTR2) \
+ { \
+ rc = TRUE; \
+ freeAsmop(IC_RESULT(ic), NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE)); \
+ } \
+ else \
+ { \
+ rc = FALSE; \
+ }
+
+#define AOP_OP_2(ic) \
+ aopOp (IC_RIGHT(ic),ic,FALSE, FALSE); \
+ aopOp (IC_LEFT(ic),ic,FALSE, (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR));
+
+#endif
+
#define AOP_SET_LOCALS(ic) \
left = IC_LEFT(ic); \
/* special cases :- */
-#ifdef LAZY_DPS_OPT
+#if 0
aopOp (IC_RIGHT(ic),ic,FALSE, FALSE);
aopOp (IC_LEFT(ic),ic,FALSE,
(AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR));
-#else
- aopOp (IC_LEFT(ic),ic,FALSE, TRUE);
- aopOp (IC_RIGHT(ic),ic,FALSE, FALSE);
-#endif
if ((AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR2) &&
(AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR))
{
aopOp (IC_RESULT(ic),ic,TRUE,
((AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR)
|| (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR)));
+ }
+#else
+ AOP_OP_3_NOFATAL(ic, pushResult);
+#endif
+ if (!pushResult)
+ {
/* if literal, literal on the right or
if left requires ACC or right is already
in ACC */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
- (AOP_NEEDSACC(IC_LEFT(ic))) ||
- AOP_TYPE(IC_RIGHT(ic)) == AOP_ACC ){
+ if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT)
+ || ((AOP_NEEDSACC(IC_LEFT(ic))) && !(AOP_NEEDSACC(IC_RIGHT(ic))))
+ || AOP_TYPE(IC_RIGHT(ic)) == AOP_ACC )
+ {
operand *t = IC_RIGHT(ic);
IC_RIGHT(ic) = IC_LEFT(ic);
IC_LEFT(ic) = t;
+ emitcode(";", "Swapped plus args.");
}
/* if both left & right are in bit
/* if I can do an increment instead
of add then GOOD for ME */
if (genPlusIncr (ic) == TRUE)
+ {
+ emitcode(";", "did genPlusIncr");
goto release;
+ }
}
size = getDataSize(pushResult ? IC_LEFT(ic) : IC_RESULT(ic));
/* genCmp :- greater or less than comparison */
/*-----------------------------------------------------------------*/
static void genCmp (operand *left,operand *right,
- operand *result, iCode *ifx, int sign)
+ iCode *ic, iCode *ifx, int sign)
{
- int size, offset = 0 ;
- unsigned long lit = 0L;
- bool swappedOps = FALSE;
+ int size, offset = 0 ;
+ unsigned long lit = 0L;
+ operand *result;
D(emitcode(";", "genCmp"););
-#if 0
- /* If left if lit and right isn't, swap 'em. */
- if (AOP_TYPE(left) == AOP_LIT &&
- AOP_TYPE(right) != AOP_LIT)
- {
- operand *tmp = left;
- left = right;
- right = tmp;
- D(emitcode(";", "kevin literal hack"););
- swappedOps = !swappedOps;
- }
-
- if (AOP_NEEDSACC(right))
- {
- if (AOP_NEEDSACC(left))
- {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "both CMP operands need ACC!");
- exit(1);
- }
- else
- {
- operand *tmp = left;
- left = right;
- right = tmp;
- D(emitcode(";", "kevin ACC hack"););
- swappedOps = !swappedOps;
- }
- }
-#endif
+ result = IC_RESULT(ic);
/* if left & right are bit variables */
if (AOP_TYPE(left) == AOP_CRY &&
lbl->key+100);
emitcode("","%05d$:",lbl->key+100);
} else {
- if(AOP_TYPE(right) == AOP_LIT){
+ if (AOP_TYPE(right) == AOP_LIT)
+ {
lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
/* optimize if(x < 0) or if(x >= 0) */
- if(lit == 0L){
- if(!sign){
+ if(lit == 0L)
+ {
+ if(!sign)
+ {
CLRC;
}
- else{
+ else
+ {
MOVA(aopGet(AOP(left),AOP_SIZE(left)-1,FALSE,FALSE,TRUE));
- if(!(AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) && ifx){
+
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+
+ aopOp(result,ic,FALSE, FALSE);
+
+ if(!(AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) && ifx)
+ {
+ freeAsmop(result,NULL,ic,TRUE);
genIfxJump (ifx,"acc.7");
return;
}
- else
+ else
+ {
emitcode("rlc","a");
+ }
+ goto release_freedLR;
}
goto release;
}
}
release:
- if (swappedOps)
- {
- D(emitcode(";","kevHack: flip carry."););
- emitcode("cpl", "c");
- }
+/* Don't need the left & right operands any more; do need the result. */
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+
+ aopOp(result,ic,FALSE, FALSE);
+
+release_freedLR:
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
+ if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result))
+ {
outBitC(result);
- } else {
+ }
+ else
+ {
/* if the result is used in the next
ifx conditional branch then generate
code a little differently */
if (ifx )
+ {
genIfxJump (ifx,"c");
+ }
else
+ {
outBitC(result);
+ }
/* leave the result in acc */
}
+ freeAsmop(result,NULL,ic,TRUE);
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void genCmpGt (iCode *ic, iCode *ifx)
{
- operand *left, *right, *result;
+ operand *left, *right;
sym_link *letype , *retype;
int sign ;
left = IC_LEFT(ic);
right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
letype = getSpec(operandType(left));
retype =getSpec(operandType(right));
sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
- /* assign the amsops */
- AOP_OP_3(ic);
-#if 0
- aopOp (left,ic,FALSE, TRUE);
- aopOp (right,ic,FALSE, FALSE);
- aopOp (result,ic,TRUE, FALSE);
-#endif
- genCmp(right, left, result, ifx, sign);
+ /* assign the left & right amsops */
+ AOP_OP_2(ic);
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ genCmp(right, left, ic, ifx, sign);
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void genCmpLt (iCode *ic, iCode *ifx)
{
- operand *left, *right, *result;
+ operand *left, *right;
sym_link *letype , *retype;
int sign ;
left = IC_LEFT(ic);
right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
letype = getSpec(operandType(left));
retype =getSpec(operandType(right));
sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
- /* assign the amsops */
- AOP_OP_3(ic);
-#if 0
- aopOp (left,ic,FALSE, FALSE);
- aopOp (right,ic,FALSE, TRUE);
- aopOp (result,ic,TRUE, FALSE);
-#endif
-
- genCmp(left, right, result, ifx, sign);
+ /* assign the left & right amsops */
+ AOP_OP_2(ic);
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ genCmp(left, right, ic, ifx, sign);
}
/*-----------------------------------------------------------------*/