}
+/*-----------------------------------------------------------------*/
+/* leftRightUseAcc - returns size of accumulator use by operands */
+/*-----------------------------------------------------------------*/
+static int
+leftRightUseAcc(iCode *ic)
+{
+ operand *op;
+ int size;
+ int accuseSize = 0;
+ int accuse = 0;
+
+ if (!ic)
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "null iCode pointer");
+ return 0;
+ }
+
+ if (ic->op == IFX)
+ {
+ op = IC_COND (ic);
+ if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+ {
+ accuse = 1;
+ size = getSize (OP_SYMBOL (op)->type);
+ if (size>accuseSize)
+ accuseSize = size;
+ }
+ }
+ else if (ic->op == JUMPTABLE)
+ {
+ op = IC_JTCOND (ic);
+ if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+ {
+ accuse = 1;
+ size = getSize (OP_SYMBOL (op)->type);
+ if (size>accuseSize)
+ accuseSize = size;
+ }
+ }
+ else
+ {
+ op = IC_LEFT (ic);
+ if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+ {
+ accuse = 1;
+ size = getSize (OP_SYMBOL (op)->type);
+ if (size>accuseSize)
+ accuseSize = size;
+ }
+ op = IC_RIGHT (ic);
+ if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+ {
+ accuse = 1;
+ size = getSize (OP_SYMBOL (op)->type);
+ if (size>accuseSize)
+ accuseSize = size;
+ }
+ }
+
+ if (accuseSize)
+ return accuseSize;
+ else
+ return accuse;
+}
+
/*-----------------------------------------------------------------*/
/* aopForSym - for a true symbol */
/*-----------------------------------------------------------------*/
{
asmop *aop;
memmap *space = SPEC_OCLS (sym->etype);
+ int accuse = leftRightUseAcc (ic);
/* if already has one */
if (sym->aop)
if (sym->onStack)
{
- if (_G.accInUse)
+ if (_G.accInUse || accuse)
emitcode ("push", "acc");
- if (_G.bInUse)
+ if (_G.bInUse || (accuse>1))
emitcode ("push", "b");
emitcode ("mov", "a,_bp");
emitcode ("mov", "%s,a",
aop->aopu.aop_ptr->name);
- if (_G.bInUse)
+ if (_G.bInUse || (accuse>1))
emitcode ("pop", "b");
- if (_G.accInUse)
+ if (_G.accInUse || accuse)
emitcode ("pop", "acc");
}
else
if (stack_val < 0 && stack_val > -5) { /* between -5 & -1 */
if (useDP2) {
if (options.model == MODEL_FLAT24)
- emitcode ("mov", "dpx1,#!constbyte", (options.stack_loc >> 16) & 0xff);
- TR_DPTR("#2");
+ {
+ emitcode ("mov", "dpx1,#!constbyte",
+ (options.stack_loc >> 16) & 0xff);
+ }
emitcode ("mov", "dph1,_bpx+1");
+
emitcode ("mov", "dpl1,_bpx");
emitcode ("mov","dps,#1");
} else {
if (options.model == MODEL_FLAT24)
- emitcode ("mov", "dpx,#!constbyte", (options.stack_loc >> 16) & 0xff);
+ {
+ emitcode ("mov", "dpx,#!constbyte",
+ (options.stack_loc >> 16) & 0xff);
+ }
emitcode ("mov", "dph,_bpx+1");
emitcode ("mov", "dpl,_bpx");
}
emitcode("mov","dps,#0");
}
} else {
- if (_G.accInUse)
+ if (_G.accInUse || accuse)
emitcode ("push", "acc");
- if (_G.bInUse)
+ if (_G.bInUse || (accuse>1))
emitcode ("push", "b");
emitcode ("mov", "a,_bpx");
emitcode ("subb","a,#!constbyte",(stack_val >> 8) & 0xff);
if (useDP2) {
if (options.model == MODEL_FLAT24)
- emitcode ("mov", "dpx1,#!constbyte", (options.stack_loc >> 16) & 0xff);
- TR_DPTR("#2");
+ {
+ emitcode ("mov", "dpx1,#!constbyte",
+ (options.stack_loc >> 16) & 0xff);
+ }
emitcode ("mov", "dph1,a");
emitcode ("mov", "dpl1,b");
} else {
if (options.model == MODEL_FLAT24)
- emitcode ("mov", "dpx,#!constbyte", (options.stack_loc >> 16) & 0xff);
+ {
+ emitcode ("mov", "dpx,#!constbyte",
+ (options.stack_loc >> 16) & 0xff);
+ }
emitcode ("mov", "dph,a");
emitcode ("mov", "dpl,b");
}
- if (_G.bInUse)
+ if (_G.bInUse || (accuse>1))
emitcode ("pop", "b");
- if (_G.accInUse)
+ if (_G.accInUse || accuse)
emitcode ("pop", "acc");
}
sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
}
/* special case for a function */
- if (IS_FUNC (sym->type))
+ if (IS_FUNC (sym->type) && !(sym->isitmp))
{
sym->aop = aop = newAsmop (AOP_IMMD);
- aop->aopu.aop_immd.aop_immd1 = Safe_strdup(sym->rname);
+ aop->aopu.aop_immd.aop_immd1 = Safe_strdup(sym->rname);
aop->size = FPTRSIZE;
return aop;
}
-
+
/* only remaining is far space */
/* in which case DPTR gets the address */
sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
aop->aopu.dptr = sym->dptr;
return ;
}
- /* else spill location */
- if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) {
- /* force a new aop if sizes differ */
- sym->usl.spillLoc->aop = NULL;
- }
- sym->aop = op->aop = aop =
- aopForSym (ic, sym->usl.spillLoc, result, useDP2);
+
+ if (sym->usl.spillLoc)
+ {
+ if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
+ {
+ /* force a new aop if sizes differ */
+ sym->usl.spillLoc->aop = NULL;
+ }
+ sym->aop = op->aop = aop =
+ aopForSym (ic, sym->usl.spillLoc, result, useDP2);
+ aop->size = getSize (sym->type);
+ return;
+ }
+
+ /* else must be a dummy iTemp */
+ sym->aop = op->aop = aop = newAsmop (AOP_DUMMY);
aop->size = getSize (sym->type);
return;
}
/* depending on type */
switch (aop->type)
{
+ case AOP_DUMMY:
+ return zero;
case AOP_R0:
case AOP_R1:
/* depending on where it is ofcourse */
switch (aop->type)
{
+ case AOP_DUMMY:
+ MOVA (s); /* read s in case it was volatile */
+ break;
+
case AOP_DIR:
if (offset)
{
emitcode("nop", "; workaround for DS80C390 div bug."); \
}
-/*-----------------------------------------------------------------*/
-/* genNotFloat - generates not for float operations */
-/*-----------------------------------------------------------------*/
-static void
-genNotFloat (operand * op, operand * res)
-{
- int size, offset;
- symbol *tlbl;
-
- D (emitcode (";", "genNotFloat "););
-
- /* we will put 127 in the first byte of
- the result */
- aopPut (AOP (res), "#127", 0);
- size = AOP_SIZE (op) - 1;
- offset = 1;
-
- _startLazyDPSEvaluation ();
- MOVA(aopGet(op->aop, offset++, FALSE, FALSE, NULL));
-
- while (size--)
- {
- emitcode ("orl", "a,%s",
- aopGet (op->aop,
- offset++, FALSE, FALSE,
- DP2_RESULT_REG));
- }
- _endLazyDPSEvaluation ();
-
- tlbl = newiTempLabel (NULL);
- aopPut (res->aop, one, 1);
- emitcode ("jz", "!tlabel", (tlbl->key + 100));
- aopPut (res->aop, zero, 1);
- emitcode ("", "!tlabeldef", (tlbl->key + 100));
-
- size = res->aop->size - 2;
- offset = 2;
- /* put zeros in the rest */
- while (size--)
- aopPut (res->aop, zero, offset++);
-}
/*-----------------------------------------------------------------*/
/* opIsGptr: returns non-zero if the passed operand is */
genNot (iCode * ic)
{
symbol *tlbl;
- sym_link *optype = operandType (IC_LEFT (ic));
D (emitcode (";", "genNot "););
goto release;
}
- /* if type float then do float */
- if (IS_FLOAT (optype))
- {
- genNotFloat (IC_LEFT (ic), IC_RESULT (ic));
- goto release;
- }
-
toBoolean (IC_LEFT (ic));
tlbl = newiTempLabel (NULL);
/* if the registers have been saved already then
do nothing */
- if (ic->regsSaved || IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT(ic)))) return ;
+ if (ic->regsSaved
+ || (IS_SYMOP(IC_LEFT(ic)) && IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT(ic))) && !TARGET_IS_DS400) )
+ return ;
/* special case if DPTR alive across a function call then must save it
even though callee saves */
- if (IFFUNC_CALLEESAVES(OP_SYMBOL (IC_LEFT (ic))->type)) {
+ if (IS_SYMOP(IC_LEFT(ic)) &&
+ IFFUNC_CALLEESAVES(OP_SYMBOL (IC_LEFT (ic))->type)) {
int i;
rsave = newBitVect(ic->rMask->size);
for (i = DPL_IDX ; i <= B_IDX ; i++ ) {
}
}
+static void
+adjustEsp(const char *reg)
+{
+ emitcode ("anl","%s,#3", reg);
+ if (TARGET_IS_DS400)
+ {
+ emitcode ("orl","%s,#!constbyte",
+ reg,
+ (options.stack_loc >> 8) & 0xff);
+ }
+}
+
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
the same register bank then we need to save the
destination registers on the stack */
dtype = operandType (IC_LEFT (ic));
- if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) &&
+ if (currFunc && dtype && (!IFFUNC_ISNAKED(dtype) || TARGET_IS_DS400) &&
(FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) &&
IFFUNC_ISISR (currFunc->type))
{
emitcode ("subb","a,#!constbyte",ic->parmBytes & 0xff);
emitcode ("mov","sp,a");
emitcode ("mov","a,esp");
- emitcode ("anl","a,#3");
+ adjustEsp("a");
emitcode ("subb","a,#!constbyte",(ic->parmBytes >> 8) & 0xff);
emitcode ("mov","esp,a");
UNPROTECT_SP;
the same register bank then we need to save the
destination registers on the stack */
dtype = operandType (IC_LEFT (ic));
- if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) &&
+ if (currFunc && dtype && (!IFFUNC_ISNAKED(dtype) || TARGET_IS_DS400) &&
IFFUNC_ISISR (currFunc->type) &&
(FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype))) {
saveRBank (FUNC_REGBANK (dtype), ic, TRUE);
emitcode ("subb","a,#!constbyte",ic->parmBytes & 0xff);
emitcode ("mov","sp,a");
emitcode ("mov","a,esp");
- emitcode ("anl","a,#3");
+ adjustEsp("a");
emitcode ("subb","a,#!constbyte",(ic->parmBytes >> 8) & 0xff);
emitcode ("mov","esp,a");
UNPROTECT_SP;
/*-----------------------------------------------------------------*/
/* inExcludeList - return 1 if the string is in exclude Reg list */
/*-----------------------------------------------------------------*/
+static int
+regsCmp(void *p1, void *p2)
+{
+ return (STRCASECMP((char *)p1, (char *)(p2)) == 0);
+}
+
static bool
inExcludeList (char *s)
{
- int i = 0;
+ const char *p = setFirstItem(options.excludeRegsSet);
- if (options.excludeRegs[i] &&
- STRCASECMP (options.excludeRegs[i], "none") == 0)
+ if (p == NULL || STRCASECMP(p, "none") == 0)
return FALSE;
- for (i = 0; options.excludeRegs[i]; i++)
- {
- if (options.excludeRegs[i] &&
- STRCASECMP (s, options.excludeRegs[i]) == 0)
- return TRUE;
- }
- return FALSE;
+
+ return isinSetWith(options.excludeRegsSet, s, regsCmp);
}
/*-----------------------------------------------------------------*/
if (options.stack_probe)
emitcode ("lcall","__stack_probe");
- /* if critical function then turn interrupts off */
- if (IFFUNC_ISCRITICAL (ftype))
- emitcode ("clr", "ea");
/* here we need to generate the equates for the
register bank if required */
emitcode ("push","_bpx+1");
emitcode ("mov","_bpx,%s",spname);
emitcode ("mov","_bpx+1,esp");
- emitcode ("anl","_bpx+1,#3");
+ adjustEsp("_bpx+1");
} else {
if (options.useXstack) {
emitcode ("mov", "r0,%s", spname);
emitcode ("add","a,#!constbyte", ((short) sym->stack & 0xff));
emitcode ("mov","sp,a");
emitcode ("mov","a,esp");
- emitcode ("anl","a,#3");
+ adjustEsp("a");
emitcode ("addc","a,#!constbyte", (((short) sym->stack) >> 8) & 0xff);
emitcode ("mov","esp,a");
UNPROTECT_SP;
emitcode ("add", "a,#!constbyte", ((char) sym->xstack & 0xff));
emitcode ("mov", "_spx,a");
}
+
+ /* if critical function then turn interrupts off */
+ if (IFFUNC_ISCRITICAL (ftype))
+ {
+ emitcode ("mov", "c,ea");
+ emitcode ("push", "psw"); /* save old ea via c in psw */
+ emitcode ("clr", "ea");
+ }
}
return;
}
+ if (IFFUNC_ISCRITICAL (sym->type))
+ {
+ emitcode ("pop", "psw"); /* restore ea via c in psw */
+ emitcode ("mov", "ea,c");
+ }
+
if ((IFFUNC_ISREENT (sym->type) || options.stackAuto) &&
(sym->stack || FUNC_HASSTACKPARM(sym->type))) {
if (!inExcludeList ("acc"))
emitcode ("pop", "acc");
- if (IFFUNC_ISCRITICAL (sym->type))
- emitcode ("setb", "ea");
-
/* if debug then send end of function */
if (options.debug && currFunc) {
_G.debugLine = 1;
}
else
{
- if (IFFUNC_ISCRITICAL (sym->type))
- emitcode ("setb", "ea");
-
if (IFFUNC_CALLEESAVES(sym->type))
{
int i;
// AOP_IS_DPTRn(IC_LEFT(ic)) ? "true" : "false",
// AOP_IS_DPTRn(IC_RIGHT(ic)) ? "true" : "false",
// AOP_IS_DPTRn(IC_RESULT(ic)) ? "true" : "false");
-// );
-
+// );
- // Right uses DPTR unless left or result is an AOP_STR.
- aopOp (IC_RIGHT(ic),ic,FALSE, AOP_IS_STR(IC_LEFT(ic)) || AOP_IS_STR(IC_RESULT(ic)));
+ // Right uses DPTR unless left or result is an AOP_STR; however,
+ // if right is an AOP_STR, it must use DPTR regardless.
+ if ((AOP_IS_STR(IC_LEFT(ic)) || AOP_IS_STR(IC_RESULT(ic)))
+ && !AOP_IS_STR(IC_RIGHT(ic)))
+ {
+ useDp2 = TRUE;
+ }
+ else
+ {
+ useDp2 = FALSE;
+ }
+
+ aopOp (IC_RIGHT(ic),ic,FALSE, useDp2);
// if the right used DPTR, left MUST use DPTR2.
// if the right used DPTR2, left MUST use DPTR.
if ( AOP_IS_STR(IC_LEFT(ic)) &&
isOperandLiteral(IC_RIGHT(ic)) && OP_SYMBOL(IC_RESULT(ic))->ruonly) {
aopOp (IC_RIGHT (ic), ic, TRUE, FALSE);
- size = floatFromVal (AOP (IC_RIGHT(ic))->aopu.aop_lit);
+ size = (int)floatFromVal (AOP (IC_RIGHT(ic))->aopu.aop_lit);
if (size <= 9) {
while (size--) emitcode ("inc","dptr");
} else {
/* if literal */
if (AOP_TYPE(right)==AOP_LIT) {
- signed char val=floatFromVal (AOP (right)->aopu.aop_lit);
+ signed char val=(signed char)floatFromVal (AOP (right)->aopu.aop_lit);
/* AND literal negative */
if ((int) val < 0) {
emitcode ("cpl", "F0"); // complement sign flag
if (!umult) {
emitcode("clr","F0");
if (AOP_TYPE(right) == AOP_LIT) {
- int val=floatFromVal (AOP (right)->aopu.aop_lit);
+ int val=(int)floatFromVal (AOP (right)->aopu.aop_lit);
if (val < 0) {
emitcode("setb","F0");
val = -val;
/* load up MB with right */
if (!umult) {
if (AOP_TYPE(right) == AOP_LIT) {
- int val=floatFromVal (AOP (right)->aopu.aop_lit);
+ int val=(int)floatFromVal (AOP (right)->aopu.aop_lit);
if (val < 0) {
lbl = newiTempLabel(NULL);
emitcode ("jbc","F0,!tlabel",lbl->key+100);
/* load up MB with right */
if (!umult) {
if (AOP_TYPE(right) == AOP_LIT) {
- int val=floatFromVal (AOP (right)->aopu.aop_lit);
+ int val=(int)floatFromVal (AOP (right)->aopu.aop_lit);
if (val < 0) {
val = -val;
}
AOP_TYPE (right) == AOP_CRY)
{
emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
- emitcode ("anl", "c,/%s", AOP (left)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
}
else
{
}
#endif
-#if 0
-//REMOVE ME!!!
/*-----------------------------------------------------------------*/
/* shiftLLeftOrResult - shift left one byte from left, or to result */
/*-----------------------------------------------------------------*/
/* back to result */
aopPut (AOP (result), "a", offr);
}
-#endif
#if 0
//REMOVE ME!!!
}
#endif
-#if 0
-//REMOVE ME!!!
/*-----------------------------------------------------------------*/
/* shiftRLong - shift right one long from left to result */
/* offl = LSB or MSB16 */
werror(E_INTERNAL_ERROR, __FILE__, __LINE__);
}
- MOVA (aopGet (AOP (left), MSB32, FALSE, NULL));
+ MOVA (aopGet (AOP (left), MSB32, FALSE, FALSE, NULL));
if (offl==MSB16) {
// shift is > 8
emitcode ("rlc", "a");
emitcode ("subb", "a,acc");
emitcode ("xch", "a,%s",
- aopGet(AOP(left), MSB32, FALSE, DP2_RESULT_REG));
+ aopGet(AOP(left), MSB32, FALSE, FALSE, DP2_RESULT_REG));
} else {
aopPut (AOP(result), zero, MSB32);
}
if (isSameRegs && offl==MSB16) {
emitcode ("xch",
- "a,%s",aopGet (AOP (left), MSB24, FALSE, DP2_RESULT_REG));
+ "a,%s",aopGet (AOP (left), MSB24, FALSE, FALSE, DP2_RESULT_REG));
} else {
aopPut (AOP (result), "a", MSB32);
- MOVA (aopGet (AOP (left), MSB24, FALSE, NULL));
+ MOVA (aopGet (AOP (left), MSB24, FALSE, FALSE, NULL));
}
emitcode ("rrc", "a");
if (isSameRegs && offl==1) {
emitcode ("xch", "a,%s",
- aopGet (AOP (left), MSB16, FALSE, DP2_RESULT_REG));
+ aopGet (AOP (left), MSB16, FALSE, FALSE, DP2_RESULT_REG));
} else {
aopPut (AOP (result), "a", MSB24);
- MOVA (aopGet (AOP (left), MSB16, FALSE, NULL));
+ MOVA (aopGet (AOP (left), MSB16, FALSE, FALSE, NULL));
}
emitcode ("rrc", "a");
aopPut (AOP (result), "a", MSB16 - offl);
if (offl == LSB)
{
- MOVA (aopGet (AOP (left), LSB, FALSE, NULL));
+ MOVA (aopGet (AOP (left), LSB, FALSE, FALSE, NULL));
emitcode ("rrc", "a");
aopPut (AOP (result), "a", LSB);
}
}
-#endif
-#if 0
-//REMOVE ME!!!
/*-----------------------------------------------------------------*/
/* genrshFour - shift four byte by a known amount != 0 */
/*-----------------------------------------------------------------*/
genrshFour (operand * result, operand * left,
int shCount, int sign)
{
- D (emitcode (";", "genrshFour");
- );
+ D (emitcode (";", "genrshFour"););
/* if shifting more that 3 bytes */
if (shCount >= 24)
{
shCount -= 24;
+ _startLazyDPSEvaluation();
if (shCount)
shiftR1Left2Result (left, MSB32, result, LSB, shCount, sign);
else
movLeft2Result (left, MSB32, result, LSB, sign);
addSign (result, MSB16, sign);
+ _endLazyDPSEvaluation();
}
else if (shCount >= 16)
{
shCount -= 16;
+ _startLazyDPSEvaluation();
if (shCount)
shiftR2Left2Result (left, MSB24, result, LSB, shCount, sign);
else
movLeft2Result (left, MSB32, result, MSB16, sign);
}
addSign (result, MSB24, sign);
+ _endLazyDPSEvaluation();
}
else if (shCount >= 8)
{
shCount -= 8;
+ _startLazyDPSEvaluation();
if (shCount == 1)
- shiftRLong (left, MSB16, result, sign);
+ {
+ shiftRLong (left, MSB16, result, sign);
+ }
else if (shCount == 0)
{
movLeft2Result (left, MSB16, result, LSB, 0);
shiftR1Left2Result (left, MSB32, result, MSB24, shCount, sign);
addSign (result, MSB32, sign);
}
+ _endLazyDPSEvaluation();
}
else
- { /* 1 <= shCount <= 7 */
+ {
+ /* 1 <= shCount <= 7 */
if (shCount <= 2)
{
shiftRLong (left, LSB, result, sign);
}
}
}
-#endif
#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
if ((shCount != 0)
&& (shCount < (size * 8))
&& (size != 1)
- && (size != 2))
+ && (size != 2)
+ && (size != 4))
{
D(emitcode (";", "genRightShiftLiteral wimping out"););
return FALSE;
case 2:
genrshTwo (result, left, shCount, sign);
break;
-#if 0
+#if 1
case 4:
genrshFour (result, left, shCount, sign);
break;
freeAsmop (result, NULL, ic, TRUE);
}
+
/*-----------------------------------------------------------------*/
-/* genUnpackBits - generates code for unpacking bits */
+/* emitPtrByteGet - emits code to get a byte into A through a */
+/* pointer register (R0, R1, or DPTR). The */
+/* original value of A can be preserved in B. */
/*-----------------------------------------------------------------*/
static void
-genUnpackBits (operand * result, char *rname, int ptype)
+emitPtrByteGet (char *rname, int p_type, bool preserveAinB)
{
- int shCnt;
- int rlen;
- sym_link *etype;
- int offset = 0;
-
- D (emitcode (";", "genUnpackBits "););
-
- etype = getSpec (operandType (result));
-
- /* read the first byte */
- switch (ptype)
+ switch (p_type)
{
-
- case POINTER:
case IPOINTER:
+ case POINTER:
+ if (preserveAinB)
+ emitcode ("mov", "b,a");
emitcode ("mov", "a,@%s", rname);
break;
case PPOINTER:
+ if (preserveAinB)
+ emitcode ("mov", "b,a");
emitcode ("movx", "a,@%s", rname);
break;
-
+
case FPOINTER:
+ if (preserveAinB)
+ emitcode ("mov", "b,a");
emitcode ("movx", "a,@dptr");
break;
case CPOINTER:
+ if (preserveAinB)
+ emitcode ("mov", "b,a");
emitcode ("clr", "a");
emitcode ("movc", "a,@a+dptr");
break;
case GPOINTER:
+ if (preserveAinB)
+ {
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ }
emitcode ("lcall", "__gptrget");
+ if (preserveAinB)
+ emitcode ("pop", "b");
break;
}
+}
- /* if we have bitdisplacement then it fits */
- /* into this byte completely or if length is */
- /* less than a byte */
- if (((shCnt = SPEC_BSTR (etype)) != 0) || (SPEC_BLEN (etype) <= 8))
+/*-----------------------------------------------------------------*/
+/* emitPtrByteSet - emits code to set a byte from src through a */
+/* pointer register (R0, R1, or DPTR). */
+/*-----------------------------------------------------------------*/
+static void
+emitPtrByteSet (char *rname, int p_type, char *src)
+{
+ switch (p_type)
{
+ case IPOINTER:
+ case POINTER:
+ if (*src=='@')
+ {
+ MOVA (src);
+ emitcode ("mov", "@%s,a", rname);
+ }
+ else
+ emitcode ("mov", "@%s,%s", rname, src);
+ break;
- /* shift right acc */
- AccRsh (shCnt);
+ case PPOINTER:
+ MOVA (src);
+ emitcode ("movx", "@%s,a", rname);
+ break;
+
+ case FPOINTER:
+ MOVA (src);
+ emitcode ("movx", "@dptr,a");
+ break;
- emitcode ("anl", "a,#!constbyte",
- ((unsigned char) -1) >> (8 - SPEC_BLEN (etype)));
- aopPut (AOP (result), "a", offset);
- return;
+ case GPOINTER:
+ MOVA (src);
+ emitcode ("lcall", "__gptrput");
+ break;
}
+}
- /* bit field did not fit in a byte */
- rlen = SPEC_BLEN (etype) - 8;
- aopPut (AOP (result), "a", offset++);
-
- while (1)
- {
-
- switch (ptype)
- {
- case POINTER:
- case IPOINTER:
- emitcode ("inc", "%s", rname);
- emitcode ("mov", "a,@%s", rname);
- break;
-
- case PPOINTER:
- emitcode ("inc", "%s", rname);
- emitcode ("movx", "a,@%s", rname);
- break;
-
- case FPOINTER:
- emitcode ("inc", "dptr");
- emitcode ("movx", "a,@dptr");
- break;
-
- case CPOINTER:
- emitcode ("clr", "a");
- emitcode ("inc", "dptr");
- emitcode ("movc", "a,@a+dptr");
- break;
+/*-----------------------------------------------------------------*/
+/* genUnpackBits - generates code for unpacking bits */
+/*-----------------------------------------------------------------*/
+static void
+genUnpackBits (operand * result, char *rname, int ptype)
+{
+ int offset = 0; /* result byte offset */
+ int rsize; /* result size */
+ int rlen = 0; /* remaining bitfield length */
+ sym_link *etype; /* bitfield type information */
+ int blen; /* bitfield length */
+ int bstr; /* bitfield starting bit within byte */
- case GPOINTER:
- emitcode ("inc", "dptr");
- emitcode ("lcall", "__gptrget");
- break;
- }
+ D(emitcode ("; genUnpackBits",""));
- rlen -= 8;
- /* if we are done */
- if (rlen < 8)
- break;
+ etype = getSpec (operandType (result));
+ rsize = getSize (operandType (result));
+ blen = SPEC_BLEN (etype);
+ bstr = SPEC_BSTR (etype);
+ /* If the bitfield length is less than a byte */
+ if (blen < 8)
+ {
+ emitPtrByteGet (rname, ptype, FALSE);
+ AccRsh (bstr);
+ emitcode ("anl", "a,#!constbyte", ((unsigned char) -1) >> (8 - blen));
aopPut (AOP (result), "a", offset++);
+ goto finish;
+ }
+ /* Bit field did not fit in a byte. Copy all
+ but the partial byte at the end. */
+ for (rlen=blen;rlen>=8;rlen-=8)
+ {
+ emitPtrByteGet (rname, ptype, FALSE);
+ aopPut (AOP (result), "a", offset++);
+ if (rlen>8)
+ emitcode ("inc", "%s", rname);
}
+ /* Handle the partial byte at the end */
if (rlen)
{
- emitcode ("anl", "a,#!constbyte", ((unsigned char) -1) >> (rlen));
- aopPut (AOP (result), "a", offset);
+ emitPtrByteGet (rname, ptype, FALSE);
+ emitcode ("anl", "a,#!constbyte", ((unsigned char) -1) >> (8-rlen));
+ aopPut (AOP (result), "a", offset++);
}
- return;
+finish:
+ if (offset < rsize)
+ {
+ rsize -= offset;
+ while (rsize--)
+ aopPut (AOP (result), zero, offset++);
+ }
}
operand * right,
char *rname, int p_type)
{
- int offset = 0;
- int rLen;
- int blen, bstr;
- char *l;
+ int offset = 0; /* source byte offset */
+ int rlen = 0; /* remaining bitfield length */
+ int blen; /* bitfield length */
+ int bstr; /* bitfield starting bit within byte */
+ int litval; /* source literal value (if AOP_LIT) */
+ unsigned char mask; /* bitmask within current byte */
+
+ D(emitcode ("; genPackBits",""));
blen = SPEC_BLEN (etype);
bstr = SPEC_BSTR (etype);
- MOVA (aopGet (AOP (right), offset++, FALSE, FALSE, NULL));
-
- /* if the bit lenth is less than or */
- /* it exactly fits a byte then */
- if (SPEC_BLEN (etype) <= 8)
- {
- /* shift left acc */
- AccLsh (SPEC_BSTR (etype));
-
- if (SPEC_BLEN (etype) < 8)
- { /* if smaller than a byte */
-
-
- switch (p_type)
- {
- case POINTER:
- emitcode ("mov", "b,a");
- emitcode ("mov", "a,@%s", rname);
- break;
-
- case FPOINTER:
- emitcode ("mov", "b,a");
- emitcode ("movx", "a,@dptr");
- break;
-
- case GPOINTER:
- emitcode ("push", "b");
- emitcode ("push", "acc");
- emitcode ("lcall", "__gptrget");
- emitcode ("pop", "b");
- break;
- }
-
- emitcode ("anl", "a,#!constbyte", (unsigned char)
- ((unsigned char) (0xFF << (blen + bstr)) |
- (unsigned char) (0xFF >> (8 - bstr))));
- emitcode ("orl", "a,b");
- if (p_type == GPOINTER)
- emitcode ("pop", "b");
- }
- }
-
- switch (p_type)
+ /* If the bitfield length is less than a byte */
+ if (blen < 8)
{
- case POINTER:
- emitcode ("mov", "@%s,a", rname);
- break;
+ mask = ((unsigned char) (0xFF << (blen + bstr)) |
+ (unsigned char) (0xFF >> (8 - bstr)));
- case FPOINTER:
- emitcode ("movx", "@dptr,a");
- break;
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ /* Case with a bitfield length <8 and literal source
+ */
+ litval = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ litval <<= bstr;
+ litval &= (~mask) & 0xff;
+ emitPtrByteGet (rname, p_type, FALSE);
+ if ((mask|litval)!=0xff)
+ emitcode ("anl","a,#!constbyte", mask);
+ if (litval)
+ emitcode ("orl","a,#!constbyte", litval);
+ }
+ else
+ {
+ if ((blen==1) && (p_type!=GPOINTER))
+ {
+ /* Case with a bitfield length == 1 and no generic pointer
+ */
+ if (AOP_TYPE (right) == AOP_CRY)
+ emitcode ("mov", "c,%s", AOP(right)->aopu.aop_dir);
+ else
+ {
+ MOVA (aopGet (AOP (right), 0, FALSE, FALSE, NULL));
+ emitcode ("rrc","a");
+ }
+ emitPtrByteGet (rname, p_type, FALSE);
+ emitcode ("mov","acc.%d,c",bstr);
+ }
+ else
+ {
+ /* Case with a bitfield length < 8 and arbitrary source
+ */
+ MOVA (aopGet (AOP (right), 0, FALSE, FALSE, NULL));
+ /* shift and mask source value */
+ AccLsh (bstr);
+ emitcode ("anl", "a,#!constbyte", (~mask) & 0xff);
+
+ /* transfer A to B and get next byte */
+ emitPtrByteGet (rname, p_type, TRUE);
+
+ emitcode ("anl", "a,#!constbyte", mask);
+ emitcode ("orl", "a,b");
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+ }
+ }
- case GPOINTER:
- emitcode ("lcall", "__gptrput");
- break;
+ emitPtrByteSet (rname, p_type, "a");
+ return;
}
- /* if we r done */
- if (SPEC_BLEN (etype) <= 8)
- return;
-
- emitcode ("inc", "%s", rname);
- rLen = SPEC_BLEN (etype);
-
- /* now generate for lengths greater than one byte */
- while (1)
+ /* Bit length is greater than 7 bits. In this case, copy */
+ /* all except the partial byte at the end */
+ for (rlen=blen;rlen>=8;rlen-=8)
{
-
- l = aopGet (AOP (right), offset++, FALSE, TRUE, NULL);
-
- rLen -= 8;
- if (rLen < 8)
- break;
-
- switch (p_type)
- {
- case POINTER:
- if (*l == '@')
- {
- MOVA (l);
- emitcode ("mov", "@%s,a", rname);
- }
- else
- emitcode ("mov", "@%s,%s", rname, l);
- break;
-
- case FPOINTER:
- MOVA (l);
- emitcode ("movx", "@dptr,a");
- break;
-
- case GPOINTER:
- MOVA (l);
- emitcode ("lcall", "__gptrput");
- break;
- }
- emitcode ("inc", "%s", rname);
+ emitPtrByteSet (rname, p_type,
+ aopGet (AOP (right), offset++, FALSE, TRUE, NULL) );
+ if (rlen>8)
+ emitcode ("inc", "%s", rname);
}
- MOVA (l);
-
- /* last last was not complete */
- if (rLen)
+ /* If there was a partial byte at the end */
+ if (rlen)
{
- /* save the byte & read byte */
- switch (p_type)
- {
- case POINTER:
- emitcode ("mov", "b,a");
- emitcode ("mov", "a,@%s", rname);
- break;
-
- case FPOINTER:
- emitcode ("mov", "b,a");
- emitcode ("movx", "a,@dptr");
- break;
-
- case GPOINTER:
- emitcode ("push", "b");
- emitcode ("push", "acc");
- emitcode ("lcall", "__gptrget");
- emitcode ("pop", "b");
- break;
- }
-
- emitcode ("anl", "a,#!constbyte", ((unsigned char) -1 << rLen));
- emitcode ("orl", "a,b");
+ mask = (((unsigned char) -1 << rlen) & 0xff);
+
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ /* Case with partial byte and literal source
+ */
+ litval = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ litval >>= (blen-rlen);
+ litval &= (~mask) & 0xff;
+ emitPtrByteGet (rname, p_type, FALSE);
+ if ((mask|litval)!=0xff)
+ emitcode ("anl","a,#!constbyte", mask);
+ if (litval)
+ emitcode ("orl","a,#!constbyte", litval);
+ }
+ else
+ {
+ /* Case with partial byte and arbitrary source
+ */
+ MOVA (aopGet (AOP (right), offset++, FALSE, FALSE, NULL));
+ emitcode ("anl", "a,#!constbyte", (~mask) & 0xff);
+
+ /* transfer A to B and get next byte */
+ emitPtrByteGet (rname, p_type, TRUE);
+
+ emitcode ("anl", "a,#!constbyte", mask);
+ emitcode ("orl", "a,b");
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+ }
+ emitPtrByteSet (rname, p_type, "a");
}
- if (p_type == GPOINTER)
- emitcode ("pop", "b");
-
- switch (p_type)
- {
-
- case POINTER:
- emitcode ("mov", "@%s,a", rname);
- break;
+}
- case FPOINTER:
- emitcode ("movx", "@dptr,a");
- break;
- case GPOINTER:
- emitcode ("lcall", "__gptrput");
- break;
- }
-}
/*-----------------------------------------------------------------*/
/* genDataPointerSet - remat pointer to data space */
/*-----------------------------------------------------------------*/
/* if 10 bit stack */
if (options.stack10bit) {
char buff[10];
+ int offset;
+
tsprintf(buff, sizeof(buff),
"#!constbyte",(options.stack_loc >> 16) & 0xff);
/* if it has an offset then we need to compute it */
((char) sym->stack )) & 0xff);
emitcode ("mov", "b,a");
emitcode ("mov", "a,_bpx+1");
- emitcode ("addc","a,#!constbyte", (((sym->stack < 0) ?
- ((short) (sym->stack - _G.nRegsSaved)) :
- ((short) sym->stack )) >> 8) & 0xff);
+
+ offset = (((sym->stack < 0) ?
+ ((short) (sym->stack - _G.nRegsSaved)) :
+ ((short) sym->stack )) >> 8) & 0xff;
+
+ emitcode ("addc","a,#!constbyte", offset);
+
aopPut (AOP (IC_RESULT (ic)), "b", 0);
aopPut (AOP (IC_RESULT (ic)), "a", 1);
aopPut (AOP (IC_RESULT (ic)), buff, 2);
}
+#if 0 // obsolete, and buggy for != xdata
/*-----------------------------------------------------------------*/
/* genArrayInit - generates code for address of */
/*-----------------------------------------------------------------*/
freeAsmop (IC_LEFT(ic), NULL, ic, TRUE);
}
+#endif
/*-----------------------------------------------------------------*/
/* genFarFarAssign - assignment when both are in far space */
return;
aopOp (right, ic, FALSE, FALSE);
- aopOp (result, ic, FALSE, AOP_USESDPTR(right));
+ aopOp (result, ic, FALSE, (AOP_TYPE(right) == AOP_DPTR));
/* if the result is a bit */
- // if (AOP_TYPE (result) == AOP_CRY) /* works only for true symbols */
- if (IS_BITVAR(OP_SYMBOL(result)->type))
+ if (IS_BITVAR (OP_SYMBOL (result)->type)
+ && !IS_BITFIELD (OP_SYMBOL (result)->type) )
{
/* if the right size is a literal then
we know what the value is */
/* also, if the source is a bit, we don't need to sign extend, because
* it can't possibly have set the sign bit.
*/
- if (SPEC_USIGN (rtype) || !IS_SPEC (rtype) || AOP_TYPE (right) == AOP_CRY)
+ if (!IS_SPEC (rtype) || SPEC_USIGN (rtype) || AOP_TYPE (right) == AOP_CRY)
{
while (size--)
{
}
}
+/*-----------------------------------------------------------------*/
+/* genDummyRead - generate code for dummy read of volatiles */
+/*-----------------------------------------------------------------*/
+static void
+genDummyRead (iCode * ic)
+{
+ operand *right;
+ int size, offset;
+
+ D(emitcode("; genDummyRead",""));
+
+ right = IC_RIGHT (ic);
+
+ aopOp (right, ic, FALSE, FALSE);
+
+ /* if the result is a bit */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ goto release;
+ }
+
+ /* bit variables done */
+ /* general case */
+ size = AOP_SIZE (right);
+ offset = 0;
+ while (size--)
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+ offset++;
+ }
+
+release:
+ freeAsmop (right, NULL, ic, TRUE);
+}
+
/*-----------------------------------------------------------------*/
/* genBuiltIn - calls the appropriate function to generating code */
/* for a built in function */
}
#if 1
/* print the allocation information */
- if (allocInfo)
+ if (allocInfo && currFunc)
printAllocInfo (currFunc, codeOutFile);
#endif
/* if debug information required */
if (options.debug && currFunc)
{
- cdbSymbol (currFunc, cdbFile, FALSE, TRUE);
+ debugFile->writeFunction(currFunc);
_G.debugLine = 1;
if (IS_STATIC (currFunc->etype))
emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
else addSet (&_G.sendSet, ic);
break;
+ case DUMMY_READ_VOLATILE:
+ genDummyRead (ic);
+ break;
+
+#if 0 // obsolete, and buggy for != xdata
case ARRAYINIT:
genArrayInit(ic);
break;
+#endif
default:
ic = ic;