/*-------------------------------------------------------------------------
- SDCCgen51.c - source file for code generation for 8051
+ gen.c - source file for code generation for 8051
Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
and - Jean-Louis VERN.jlvern@writeme.com (1999)
#include "SDCCpeeph.h"
#include "ralloc.h"
#include "gen.h"
+#include "dbuf_string.h"
char *aopLiteral (value * val, int offset);
char *aopLiteralLong (value * val, int offset, int size);
static unsigned short rbank = -1;
+#define REG_WITH_INDEX mcs51_regWithIdx
+
#define AOP(op) op->aop
#define AOP_TYPE(op) AOP(op)->type
#define AOP_SIZE(op) AOP(op)->size
#define IS_AOP_PREG(x) (AOP(x) && (AOP_TYPE(x) == AOP_R1 || \
- AOP_TYPE(x) == AOP_R0))
+ AOP_TYPE(x) == AOP_R0))
#define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY || \
- AOP_TYPE(x) == AOP_DPTR || \
- AOP(x)->paged))
+ AOP_TYPE(x) == AOP_DPTR || \
+ AOP(x)->paged))
#define AOP_INPREG(x) (x && (x->type == AOP_REG && \
- (x->aopu.aop_reg[0] == mcs51_regWithIdx(R0_IDX) || \
- x->aopu.aop_reg[0] == mcs51_regWithIdx(R1_IDX) )))
+ (x->aopu.aop_reg[0] == REG_WITH_INDEX(R0_IDX) || \
+ x->aopu.aop_reg[0] == REG_WITH_INDEX(R1_IDX) )))
#define SYM_BP(sym) (SPEC_OCLS (sym->etype)->paged ? "_bpx" : "_bp")
"b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7"
};
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
static void saveRBank (int, iCode *, bool);
#define RESULTONSTACK(x) \
IC_RESULT(x)->aop->type == AOP_STK )
#define MOVA(x) mova(x) /* use function to avoid multiple eval */
+#define MOVB(x) movb(x)
+
#define CLRC emitcode("clr","c")
#define SETC emitcode("setb","c")
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
static void
-emitcode (char *inst, const char *fmt,...)
+emitcode (const char *inst, const char *fmt,...)
{
va_list ap;
- char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ struct dbuf_s dbuf;
+ const char *lbp, *lb;
+
+ dbuf_init (&dbuf, INITIAL_INLINEASM);
va_start (ap, fmt);
if (inst && *inst)
{
+ dbuf_append_str (&dbuf, inst);
+
if (fmt && *fmt)
{
- SNPRINTF (lb, sizeof(lb), "%s\t", inst);
- }
- else
- {
- SNPRINTF (lb, sizeof(lb), "%s", inst);
+ dbuf_append_char (&dbuf, '\t');
+ dbuf_tvprintf (&dbuf, fmt, ap);
}
-
- tvsprintf (lb + strlen(lb), sizeof(lb) - strlen(lb), fmt, ap);
}
else
{
- tvsprintf (lb, sizeof(lb), fmt, ap);
+ dbuf_tvprintf (&dbuf, fmt, ap);
}
+ lbp = lb = dbuf_c_str(&dbuf);
+
while (isspace ((unsigned char)*lbp))
{
lbp++;
lineCurr->ic = _G.current_iCode;
lineCurr->isComment = (*lbp==';');
va_end (ap);
+
+ dbuf_destroy(&dbuf);
+}
+
+static void
+emitLabel (symbol *tlbl)
+{
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ lineCurr->isLabel = 1;
}
/*-----------------------------------------------------------------*/
emitcode("mov", "a,%s", x);
}
+/*-----------------------------------------------------------------*/
+/* movb - moves specified value into register b */
+/*-----------------------------------------------------------------*/
+static void
+movb (const char *x)
+{
+ /* do some early peephole optimization */
+ if (!strncmp(x, "b", 2))
+ return;
+
+ emitcode("mov","b,%s", x);
+}
+
/*-----------------------------------------------------------------*/
/* movc - moves specified value into the carry */
/*-----------------------------------------------------------------*/
static void
movc (const char *s)
{
- if (s == zero)
+ if (!strcmp (s, zero))
CLRC;
- else if (s == one)
+ else if (!strcmp (s, one))
SETC;
else if (strcmp (s, "c"))
{/* it's not in carry already */
static bool
pushReg (int index, bool bits_pushed)
{
- regs * reg = mcs51_regWithIdx (index);
+ regs * reg = REG_WITH_INDEX (index);
if (reg->type == REG_BIT)
{
if (!bits_pushed)
static bool
popReg (int index, bool bits_popped)
{
- regs * reg = mcs51_regWithIdx (index);
+ regs * reg = REG_WITH_INDEX (index);
if (reg->type == REG_BIT)
{
if (!bits_popped)
ic->rUsed = bitVectSetBit (ic->rUsed, R0_IDX);
(*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx (R0_IDX);
+ return (*aopp)->aopu.aop_ptr = REG_WITH_INDEX (R0_IDX);
}
/* if no usage of r1 then return it */
ic->rUsed = bitVectSetBit (ic->rUsed, R1_IDX);
(*aopp)->type = AOP_R1;
- return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx (R1_IDX);
+ return (*aopp)->aopu.aop_ptr = REG_WITH_INDEX (R1_IDX);
}
/* now we know they both have usage */
/* push it if not already pushed */
if (ic->op == IPUSH)
{
- emitcode ("mov", "b,%s",
- mcs51_regWithIdx (R0_IDX)->dname);
+ MOVB (REG_WITH_INDEX (R0_IDX)->dname);
R0INB++;
}
else if (!_G.r0Pushed)
{
emitcode ("push", "%s",
- mcs51_regWithIdx (R0_IDX)->dname);
+ REG_WITH_INDEX (R0_IDX)->dname);
_G.r0Pushed++;
}
ic->rUsed = bitVectSetBit (ic->rUsed, R0_IDX);
(*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx (R0_IDX);
+ return (*aopp)->aopu.aop_ptr = REG_WITH_INDEX (R0_IDX);
}
/* if r1 not used then */
/* push it if not already pushed */
if (ic->op == IPUSH)
{
- emitcode ("mov", "b,%s",
- mcs51_regWithIdx (R1_IDX)->dname);
+ MOVB (REG_WITH_INDEX (R1_IDX)->dname);
R1INB++;
}
else if (!_G.r1Pushed)
{
emitcode ("push", "%s",
- mcs51_regWithIdx (R1_IDX)->dname);
+ REG_WITH_INDEX (R1_IDX)->dname);
_G.r1Pushed++;
}
ic->rUsed = bitVectSetBit (ic->rUsed, R1_IDX);
(*aopp)->type = AOP_R1;
- return mcs51_regWithIdx (R1_IDX);
+ return REG_WITH_INDEX (R1_IDX);
}
+
endOfWorld:
/* I said end of world, but not quite end of world yet */
- if (result) {
- /* we can push it on the stack */
- (*aopp)->type = AOP_STK;
- return NULL;
- } else {
- /* in the case that result AND left AND right needs a pointer reg
- we can safely use the result's */
- if (bitVectBitValue (mcs51_rUmaskForOp(IC_RESULT(ic)), R0_IDX)) {
+ /* if this is a result then we can push it on the stack */
+ if (result)
+ {
+ (*aopp)->type = AOP_STK;
+ return NULL;
+ }
+ /* in the case that result AND left AND right needs a pointer reg
+ we can safely use the result's */
+ if (bitVectBitValue (mcs51_rUmaskForOp(IC_RESULT(ic)), R0_IDX))
+ {
(*aopp)->type = AOP_R0;
- return mcs51_regWithIdx (R0_IDX);
+ return REG_WITH_INDEX (R0_IDX);
}
- if (bitVectBitValue (mcs51_rUmaskForOp(IC_RESULT(ic)), R1_IDX)) {
+ if (bitVectBitValue (mcs51_rUmaskForOp(IC_RESULT(ic)), R1_IDX))
+ {
(*aopp)->type = AOP_R1;
- return mcs51_regWithIdx (R1_IDX);
+ return REG_WITH_INDEX (R1_IDX);
}
- }
/* now this is REALLY the end of the world */
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
for (i=0; i<freeRegs->size; i++)
{
if (bitVectBitValue(freeRegs,i))
- tempRegs[offset++] = mcs51_regWithIdx(i);
+ tempRegs[offset++] = REG_WITH_INDEX(i);
if (offset>=size)
{
freeBitVect(freeRegs);
{
if (sym->onStack)
{
- char offset = ((sym->stack < 0) ?
- ((char) (sym->stack - _G.nRegsSaved)) :
- ((char) sym->stack)) & 0xff;
+ signed char offset = ((sym->stack < 0) ?
+ ((signed char) (sym->stack - _G.nRegsSaved)) :
+ ((signed char) sym->stack)) & 0xff;
if ((abs(offset) <= 3) ||
(accuse && (abs(offset) <= 7)))
if (accuse)
emitcode ("push", "acc");
emitcode ("mov", "a,%s", SYM_BP (sym));
- emitcode ("add", "a,#0x%02x", offset);
+ emitcode ("add", "a,#0x%02x", offset & 0xff);
emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name);
if (accuse)
emitcode ("pop", "acc");
/* set immd2 field if required */
if (aop->aopu.aop_immd.from_cast_remat)
{
- sprintf(buffer,"#0x%02x",ptr_type);
+ SNPRINTF (buffer, sizeof(buffer), "#0x%02x", ptr_type);
aop->aopu.aop_immd.aop_immd2 = Safe_strdup(buffer);
}
}
/*-----------------------------------------------------------------*/
-/* sameReg - two asmops have the same register at given offsets */
+/* sameByte - two asmops have the same address at given offsets */
/*-----------------------------------------------------------------*/
static bool
-sameReg (asmop * aop1, int off1, asmop * aop2, int off2)
+sameByte (asmop * aop1, int off1, asmop * aop2, int off2)
{
+ if (aop1 == aop2 && off1 == off2)
+ return TRUE;
+
if (aop1->type != AOP_REG && aop1->type != AOP_CRY)
return FALSE;
/* rematerialize it NOW */
if (sym->remat)
{
- sym->aop = op->aop = aop =
- aopForRemat (sym);
+ sym->aop = op->aop = aop = aopForRemat (sym);
aop->size = getSize (sym->type);
return;
}
emitcode ("mov", "r1,b");
R1INB--;
}
- if (_G.r1Pushed)
+ else if (_G.r1Pushed)
{
if (pop)
{
emitcode ("pop", "ar1");
_G.r1Pushed--;
}
-
if (_G.r0Pushed)
{
emitcode ("pop", "ar0");
SNPRINTF (buffer, sizeof(buffer), "@%s", aop->aopu.aop_ptr->name);
return Safe_strdup(buffer);
-
case AOP_DPTR:
if (aop->code && aop->coff==0 && offset>=1) {
emitcode ("mov", "a,#0x%02x", offset);
else
{
SNPRINTF (buffer, sizeof(buffer),
- "#%s", aop->aopu.aop_immd.aop_immd1);
+ "#%s",
+ aop->aopu.aop_immd.aop_immd1);
}
return Safe_strdup(buffer);
{
SNPRINTF (buffer, sizeof(buffer),
"(%s + %d)",
- aop->aopu.aop_dir,
- offset);
+ aop->aopu.aop_dir,
+ offset);
}
else
{
SNPRINTF (buffer, sizeof(buffer),
- "%s", aop->aopu.aop_dir);
+ "%s",
+ aop->aopu.aop_dir);
}
return Safe_strdup(buffer);
}
else if (offset)
{
- SNPRINTF (buffer, sizeof(buffer),
- "(%s + %d)",
- aop->aopu.aop_dir, offset);
+ SNPRINTF (buffer, sizeof(buffer),
+ "(%s + %d)",
+ aop->aopu.aop_dir, offset);
}
else
{
- SNPRINTF (buffer, sizeof(buffer),
- "%s", aop->aopu.aop_dir);
+ SNPRINTF (buffer, sizeof(buffer),
+ "%s",
+ aop->aopu.aop_dir);
}
if (strcmp (buffer, s) || bvolatile)
{
- emitcode ("mov", "%s,%s", buffer, s);
+ emitcode ("mov", "%s,%s", buffer, s);
}
if (!strcmp (buffer, "acc"))
{
case AOP_STK:
if (strcmp (s, "a") == 0)
- emitcode ("push", "acc");
- else
- if (*s=='@') {
+ {
+ emitcode ("push", "acc");
+ }
+ else if (*s=='@')
+ {
MOVA(s);
emitcode ("push", "acc");
- } else {
+ }
+ else if (strcmp (s, "r0") == 0 ||
+ strcmp (s, "r1") == 0 ||
+ strcmp (s, "r2") == 0 ||
+ strcmp (s, "r3") == 0 ||
+ strcmp (s, "r4") == 0 ||
+ strcmp (s, "r5") == 0 ||
+ strcmp (s, "r6") == 0 ||
+ strcmp (s, "r7") == 0)
+ {
+ char buffer[10];
+ SNPRINTF (buffer, sizeof(buffer), "a%s", s);
+ emitcode ("push", buffer);
+ }
+ else
+ {
emitcode ("push", s);
}
{
while (size--)
{
- emitcode ("orl", "a,%s", aopGet (oper, offset++, FALSE, FALSE));
+ emitcode ("orl", "a,%s",
+ aopGet (oper, offset++, FALSE, FALSE));
}
}
}
+/*-------------------------------------------------------------------*/
+/* xch_a_aopGet - for exchanging acc with value of the aop */
+/*-------------------------------------------------------------------*/
+static char *
+xch_a_aopGet (operand * oper, int offset, bool bit16, bool dname)
+{
+ char * l;
+
+ if (aopGetUsesAcc (oper, offset))
+ {
+ emitcode("mov", "b,a");
+ MOVA (aopGet (oper, offset, bit16, dname));
+ emitcode("xch", "a,b");
+ aopPut (oper, "a", offset);
+ emitcode("xch", "a,b");
+ l = "b";
+ }
+ else
+ {
+ l = aopGet (oper, offset, bit16, dname);
+ emitcode("xch", "a,%s", l);
+ }
+ return l;
+}
+
+
/*-----------------------------------------------------------------*/
/* genNot - generate code for ! operation */
/*-----------------------------------------------------------------*/
/* set C, if a == 0 */
tlbl = newiTempLabel (NULL);
emitcode ("cjne", "a,#0x01,%05d$", tlbl->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
outBitC (IC_RESULT (ic));
release:
MOVA (l);
emitcode ("cjne", "a,#0xFF,%05d$", tlbl->key + 100);
}
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
outBitC (IC_RESULT(ic));
goto release;
}
if (ic->regsSaved)
return;
if (IS_SYMOP(IC_LEFT(ic)) &&
- (IFFUNC_CALLEESAVES(OP_SYMBOL(IC_LEFT(ic))->type) ||
- IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT (ic)))))
+ (IFFUNC_CALLEESAVES (OP_SYMBOL (IC_LEFT (ic))->type) ||
+ IFFUNC_ISNAKED (OP_SYM_TYPE (IC_LEFT (ic)))))
return;
/* save the registers in use at this time but skip the
if (count == 1)
{
- regs * reg = mcs51_regWithIdx (bitVectFirstBit (rsave));
+ regs * reg = REG_WITH_INDEX (bitVectFirstBit (rsave));
if (reg->type == REG_BIT)
{
emitcode ("mov", "a,%s", reg->base);
{
if (bitVectBitValue (rsave, R0_IDX))
{
- emitcode ("push", "%s", mcs51_regWithIdx (R0_IDX)->dname);
+ emitcode ("push", "%s", REG_WITH_INDEX (R0_IDX)->dname);
}
emitcode ("mov", "r0,%s", spname);
MOVA ("r0");
{
if (bitVectBitValue (rsave, i))
{
- regs * reg = mcs51_regWithIdx (i);
+ regs * reg = REG_WITH_INDEX (i);
if (i == R0_IDX)
{
emitcode ("pop", "acc");
}
if (bitVectBitValue (rsave, R0_IDX))
{
- emitcode ("pop", "%s", mcs51_regWithIdx (R0_IDX)->dname);
+ emitcode ("pop", "%s", REG_WITH_INDEX (R0_IDX)->dname);
}
}
}
if (count == 1)
{
- regs * reg = mcs51_regWithIdx (bitVectFirstBit (rsave));
+ regs * reg = REG_WITH_INDEX (bitVectFirstBit (rsave));
emitcode ("mov", "r0,%s", spname);
emitcode ("dec", "r0");
emitcode ("movx", "a,@r0");
{
if (bitVectBitValue (rsave, i))
{
- regs * reg = mcs51_regWithIdx (i);
+ regs * reg = REG_WITH_INDEX (i);
emitcode ("dec", "r0");
emitcode ("movx", "a,@r0");
if (i == R0_IDX)
if (options.useXstack)
{
if (!ic)
- {
+ {
/* Assume r0 is available for use. */
- r = mcs51_regWithIdx (R0_IDX);;
- }
+ r = REG_WITH_INDEX (R0_IDX);;
+ }
else
- {
+ {
aop = newAsmop (0);
r = getFreePtr (ic, &aop, FALSE);
- }
+ }
// allocate space first
emitcode ("mov", "%s,%s", r->name, spname);
MOVA (r->name);
if (!ic)
{
/* Assume r0 is available for use. */
- r = mcs51_regWithIdx (R0_IDX);;
+ r = REG_WITH_INDEX (R0_IDX);;
}
else
{
{
char *l = aopGet (IC_LEFT (sic), offset, FALSE, FALSE);
if (strcmp (l, fReturn[offset]))
+ {
emitcode ("mov", "%s,%s", fReturn[offset], l);
+ }
offset++;
}
}
/* make the call */
emitcode ("ret", "");
- emitcode ("", "%05d$:", (rlbl->key + 100));
+ emitLabel (rlbl);
}
}
if (swapBanks)
else
for (i = 0; i < ic->parmBytes; i++)
emitcode ("dec", "%s", spname);
-
}
// /* if register bank was saved then unsave them */
return 0;
}
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
/*-----------------------------------------------------------------*/
/* inExcludeList - return 1 if the string is in exclude Reg list */
/*-----------------------------------------------------------------*/
emitcode (";", "-----------------------------------------");
emitcode ("", "%s:", sym->rname);
+ lineCurr->isLabel = 1;
ftype = operandType (IC_LEFT (ic));
_G.currentFunc = sym;
}
}
-
if (fReentrant)
{
if (options.useXstack)
/* if it's a callee-saves function we need a saved register */
if (calleesaves_saved_register >= 0)
{
- emitcode ("mov", "%s,a", mcs51_regWithIdx (calleesaves_saved_register)->dname);
+ emitcode ("mov", "%s,a", REG_WITH_INDEX (calleesaves_saved_register)->dname);
emitcode ("mov", "a,sp");
emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
emitcode ("mov", "sp,a");
- emitcode ("mov", "a,%s", mcs51_regWithIdx (calleesaves_saved_register)->dname);
+ emitcode ("mov", "a,%s", REG_WITH_INDEX (calleesaves_saved_register)->dname);
}
else
/* do it the hard way */
if (i > 3 && accIsFree)
{
emitcode ("mov", "a,_spx");
- emitcode ("add", "a,#0x%02x", i);
+ emitcode ("add", "a,#0x%02x", i & 0xff);
emitcode ("mov", "_spx,a");
}
else if (i > 5)
{
emitcode ("push", "acc");
emitcode ("mov", "a,_spx");
- emitcode ("add", "a,#0x%02x", i);
+ emitcode ("add", "a,#0x%02x", i & 0xff);
emitcode ("mov", "_spx,a");
emitcode ("pop", "acc");
}
emitcode ("setb", "c");
emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
emitcode ("clr", "c");
- emitcode ("", "%05d$:", (tlbl->key + 100));
+ emitLabel (tlbl);
emitcode ("push", "psw"); /* save old ea via c in psw */
}
}
}
else if (sym->stack || FUNC_HASSTACKPARM(sym->type))
{
- emitcode ("mov", "sp,_bp");
+ if (sym->stack)
+ emitcode ("mov", "sp,_bp");
emitcode ("pop", "_bp");
}
}
{
if (bitVectBitValue (sym->regsUsed, i) ||
(mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
- emitcode ("pop", "%s", mcs51_regWithIdx (i)->dname);
+ emitcode ("pop", "%s", REG_WITH_INDEX (i)->dname);
}
}
else if (mcs51_ptrRegReq)
{
- emitcode ("pop", "%s", mcs51_regWithIdx (R1_IDX)->dname);
- emitcode ("pop", "%s", mcs51_regWithIdx (R0_IDX)->dname);
+ emitcode ("pop", "%s", REG_WITH_INDEX (R1_IDX)->dname);
+ emitcode ("pop", "%s", REG_WITH_INDEX (R0_IDX)->dname);
}
}
for (idx = 0; idx < regsUnneeded->size; idx++)
if (bitVectBitValue (regsUnneeded, idx))
- emitcode ("", ";\teliminated unneeded push/pop %s", mcs51_regWithIdx (idx)->dname);
+ emitcode (";", "eliminated unneeded push/pop %s", REG_WITH_INDEX (idx)->dname);
freeBitVect (regsUnneeded);
freeBitVect (regsUsed);
if (IS_BIT(_G.currentFunc->etype))
{
- movc (aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
- size = 0;
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ else
+ movc (aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
}
-
- while (size--)
+ else
{
- char *l;
- if (AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR)
+ while (size--)
{
- /* #NOCHANGE */
- l = aopGet (IC_LEFT (ic), offset++,
- FALSE, TRUE);
- emitcode ("push", "%s", l);
- pushed++;
+ char *l;
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR)
+ {
+ /* #NOCHANGE */
+ l = aopGet (IC_LEFT (ic), offset++,
+ FALSE, TRUE);
+ emitcode ("push", "%s", l);
+ pushed++;
+ }
+ else
+ {
+ l = aopGet (IC_LEFT (ic), offset,
+ FALSE, FALSE);
+ if (strcmp (fReturn[offset], l))
+ emitcode ("mov", "%s,%s", fReturn[offset++], l);
+ }
}
- else
+
+ while (pushed)
{
- l = aopGet (IC_LEFT (ic), offset,
- FALSE, FALSE);
- if (strcmp (fReturn[offset], l))
- emitcode ("mov", "%s,%s", fReturn[offset++], l);
+ pushed--;
+ if (strcmp (fReturn[pushed], "a"))
+ emitcode ("pop", fReturn[pushed]);
+ else
+ emitcode ("pop", "acc");
}
}
-
- while (pushed)
- {
- pushed--;
- if (strcmp (fReturn[pushed], "a"))
- emitcode ("pop", fReturn[pushed]);
- else
- emitcode ("pop", "acc");
- }
freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
jumpret:
if (IC_LABEL (ic) == entryLabel)
return;
- emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100));
+ emitLabel (IC_LABEL (ic));
}
/*-----------------------------------------------------------------*/
icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
- D(emitcode ("; genPlusIncr",""));
+ D(emitcode (";","genPlusIncr"));
/* if increment >=16 bits in register or direct space */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ) &&
+ if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG ||
+ AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ||
+ (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) &&
sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
!isOperandVolatile (IC_RESULT (ic), FALSE) &&
(size > 1) &&
&& (labelRange = findLabelBackwards (ic, IC_LABEL (ic->next)->key)) != 0
&& labelRange <= 10)
{
- emitcode (";", "tail increment optimized");
+ D (emitcode (";", "tail increment optimized (range %d)", labelRange));
tlbl = IC_LABEL (ic->next);
emitTlbl = 0;
}
if (emitTlbl)
{
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
return TRUE;
}
same */
if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
{
-
if (icount > 3)
{
MOVA (aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
}
else
{
-
while (icount--)
- emitcode ("inc", "%s", aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
+ {
+ emitcode ("inc", "%s", aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
+ }
}
return TRUE;
}
+ if (icount == 1)
+ {
+ MOVA (aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
+ emitcode ("inc", "a");
+ aopPut (IC_RESULT (ic), "a", 0);
+ return TRUE;
+ }
+
return FALSE;
}
{
emitcode ("jz", "%05d$", tlbl->key + 100);
emitcode ("mov", "a,%s", one);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
outAcc (result);
}
}
static void
genPlusBits (iCode * ic)
{
- D(emitcode ("; genPlusBits",""));
+ D (emitcode (";", "genPlusBits"));
if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
{
emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
emitcode ("jnb", "%s,%05d$", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
emitcode ("cpl", "c");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
outBitC (IC_RESULT (ic));
}
else
emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
emitcode ("rlc", "a");
emitcode ("mov", "c,%s", AOP (IC_RIGHT (ic))->aopu.aop_dir);
- emitcode ("addc", "a,#0x00");
+ emitcode ("addc", "a,%s", zero);
outAcc (IC_RESULT (ic));
}
}
!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
{
char buffer[5];
- sprintf (buffer, "#%d", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+ SNPRINTF (buffer, sizeof(buffer),
+ "#%d", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
}
}
operand *leftOp, *rightOp;
operand * op;
- /* special cases :- */
+ D (emitcode (";", "genPlus"));
- D(emitcode ("; genPlus",""));
+ /* special cases :- */
aopOp (IC_LEFT (ic), ic, FALSE);
aopOp (IC_RIGHT (ic), ic, FALSE);
while (size--)
{
MOVA (aopGet (IC_RIGHT (ic), offset, FALSE, FALSE));
- emitcode ("addc", "a,#00");
+ emitcode ("addc", "a,%s", zero);
aopPut (IC_RESULT (ic), "a", offset++);
}
}
if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
return FALSE;
- D(emitcode ("; genMinusDec",""));
+ D (emitcode (";", "genMinusDec"));
/* if decrement >=16 bits in register or direct space */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR) &&
+ if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG ||
+ AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ||
+ (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) &&
sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
(size > 1) &&
(icount == 1))
&& (labelRange = findLabelBackwards (ic, IC_LABEL (ic->next)->key)) != 0
&& labelRange <= 10)
{
- emitcode (";", "tail decrement optimized");
+ D (emitcode (";", "tail decrement optimized (range %d)", labelRange));
tlbl = IC_LABEL (ic->next);
emitTlbl = 0;
}
}
if (emitTlbl)
{
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
return TRUE;
}
}
while (icount--)
- emitcode ("dec", "%s", l);
+ {
+ emitcode ("dec", "%s", l);
+ }
if (AOP_NEEDSACC (IC_RESULT (ic)))
aopPut (IC_RESULT (ic), "a", 0);
return TRUE;
}
+ if (icount == 1)
+ {
+ MOVA (aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
+ emitcode ("dec", "a");
+ aopPut (IC_RESULT (ic), "a", 0);
+ return TRUE;
+ }
+
return FALSE;
}
emitcode ("rlc", "a");
emitcode ("subb", "a,acc");
while (size--)
- aopPut (result, "a", offset++);
+ {
+ aopPut (result, "a", offset++);
+ }
}
else
- while (size--)
- aopPut (result, zero, offset++);
+ {
+ while (size--)
+ {
+ aopPut (result, zero, offset++);
+ }
+ }
}
}
{
symbol *lbl = newiTempLabel (NULL);
- D(emitcode ("; genMinusBits",""));
+ D (emitcode (";", "genMinusBits"));
if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
{
emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
emitcode ("jnb", "%s,%05d$", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
emitcode ("cpl", "c");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
outBitC (IC_RESULT (ic));
}
else
emitcode ("subb", "a,acc");
emitcode ("jnb", "%s,%05d$", AOP (IC_LEFT (ic))->aopu.aop_dir, (lbl->key + 100));
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
aopPut (IC_RESULT (ic), "a", 0);
addSign (IC_RESULT (ic), MSB16, SPEC_USIGN (getSpec (operandType (IC_RESULT (ic)))));
}
{
int size, offset = 0;
- D(emitcode ("; genMinus",""));
+ D (emitcode (";", "genMinus"));
aopOp (IC_LEFT (ic), ic, FALSE);
aopOp (IC_RIGHT (ic), ic, FALSE);
{
if (useCarry || ((lit >> (offset * 8)) & 0x0FFL))
{
- MOVA (aopGet (IC_LEFT (ic), offset, FALSE, FALSE));
+ MOVA (aopGet (IC_LEFT (ic), offset, FALSE, FALSE));
if (!offset && !size && lit== (unsigned long) -1)
{
emitcode ("dec", "a");
/* reverse subtraction with 2's complement */
if (offset == 0)
emitcode( "setb", "c");
- else
+ else
emitcode( "cpl", "c");
wassertl(!aopGetUsesAcc(leftOp, offset), "accumulator clash");
MOVA (aopGet(rightOp, offset, FALSE, TRUE));
operand * right,
operand * result)
{
- D(emitcode ("; genMultbits",""));
+ D (emitcode (";", "genMultbits"));
emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
bool runtimeSign, compiletimeSign;
bool lUnsigned, rUnsigned, pushedB;
- D(emitcode ("; genMultOneByte",""));
+ D (emitcode (";", "genMultOneByte"));
if (size < 1 || size > 2)
{
emitcode ("cpl", "F0"); /* complement sign flag */
emitcode ("cpl", "a"); /* 2's complement */
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
emitcode ("mov", "b,a");
}
}
emitcode ("cpl", "F0"); /* complement sign flag */
emitcode ("cpl", "a"); /* 2's complement */
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
}
}
emitcode ("addc", "a,#0");
emitcode ("xch", "a,b");
}
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
}
aopPut (result, "a", 0);
if (size == 2)
operand *right = IC_RIGHT (ic);
operand *result = IC_RESULT (ic);
- D(emitcode ("; genMult",""));
+ D (emitcode (";", "genMult"));
/* assign the asmops */
aopOp (left, ic, FALSE);
emitcode ("cpl", "F0"); /* complement sign flag */
emitcode ("cpl", "a"); /* 2's complement */
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
emitcode ("mov", "b,a");
}
}
emitcode ("cpl", "F0"); /* complement sign flag */
emitcode ("cpl", "a"); /* 2's complement */
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
}
}
emitcode ("jnb", "F0,%05d$", (lbl->key + 100));
emitcode ("cpl", "a"); /* lsb 2's complement */
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
accuse = aopPut (result, "a", 0);
if (size > 0)
operand *right = IC_RIGHT (ic);
operand *result = IC_RESULT (ic);
- D(emitcode ("; genDiv",""));
+ D (emitcode (";", "genDiv"));
/* assign the amsops */
aopOp (left, ic, FALSE);
char *l;
bool pushedB;
- D(emitcode ("; genModbits",""));
+ D (emitcode (";", "genModbits"));
pushedB = pushB ();
symbol *lbl;
int size, offset;
- D(emitcode ("; genModOneByte",""));
+ D (emitcode (";", "genModOneByte"));
size = AOP_SIZE (result) - 1;
offset = 1;
lbl2 = newiTempLabel (NULL);
emitcode ("sjmp", "%05d$", (lbl2->key + 100));
}
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
aopPut (result, "a", 0);
while (size--)
aopPut (result, zero, offset++);
if (lbl2)
{
- emitcode ("", "%05d$:", (lbl2->key + 100));
+ emitLabel (lbl2);
}
return;
emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
emitcode ("cpl", "a"); /* 2's complement */
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
emitcode ("mov", "b,a");
}
}
emitcode ("setb", "F0"); /* set sign flag */
emitcode ("cpl", "a"); /* 2's complement */
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
}
}
emitcode ("jnb", "F0,%05d$", (lbl->key + 100));
emitcode ("cpl", "a"); /* 2's complement */
emitcode ("inc", "a");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
aopPut (result, "a", 0);
if (size > 0)
operand *right = IC_RIGHT (ic);
operand *result = IC_RESULT (ic);
- D(emitcode ("; genMod",""));
+ D (emitcode (";", "genMod"));
/* assign the asmops */
aopOp (left, ic, FALSE);
symbol *tlbl = newiTempLabel (NULL);
char *inst;
- D(emitcode ("; genIfxJump",""));
+ D (emitcode (";", "genIfxJump"));
/* if true label then we jump if condition
supplied is true */
freeForBranchAsmop (right);
freeForBranchAsmop (left);
emitcode ("ljmp", "%05d$", jlbl->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
/* mark the icode as generated */
ic->generated = 1;
unsigned long lit = 0L;
bool rightInB;
- D(emitcode ("; genCmp",""));
+ D (emitcode (";", "genCmp"));
/* if left & right are bit variables */
if (AOP_TYPE (left) == AOP_CRY &&
aopGet (left, offset, FALSE, FALSE),
aopGet (right, offset, FALSE, FALSE),
lbl->key + 100);
- emitcode ("", "%05d$:", lbl->key + 100);
+ emitLabel (lbl);
}
else
{
return;
}
else
- emitcode ("rlc", "a");
+ {
+ emitcode ("rlc", "a");
+ }
+ }
+ goto release;
+ }
+ else
+ {//nonzero literal
+ int bytelit = ((lit >> (offset * 8)) & 0x0FFL);
+ while (size && (bytelit == 0))
+ {
+ offset++;
+ bytelit = ((lit >> (offset * 8)) & 0x0FFL);
+ size--;
+ }
+ CLRC;
+ while (size--)
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE));
+ if (sign && size == 0)
+ {
+ emitcode ("xrl", "a,#0x80");
+ emitcode ("subb", "a,#0x%02x",
+ 0x80 ^ (unsigned int) ((lit >> (offset * 8)) & 0x0FFL));
+ }
+ else
+ {
+ emitcode ("subb", "a,%s", aopGet (right, offset, FALSE, FALSE));
+ }
+ offset++;
}
goto release;
}
if (sign && size == 0)
{
emitcode ("xrl", "a,#0x80");
- if (AOP_TYPE (right) == AOP_LIT)
- {
- unsigned long lit = (unsigned long)
- floatFromVal (AOP (right)->aopu.aop_lit);
- emitcode ("subb", "a,#0x%02x",
- 0x80 ^ (unsigned int) ((lit >> (offset * 8)) & 0x0FFL));
- }
- else
+ if (!rightInB)
{
- if (!rightInB)
- {
- pushedB = pushB ();
- rightInB++;
- emitcode ("mov", "b,%s", aopGet (right, offset, FALSE, FALSE));
- }
- emitcode ("xrl", "b,#0x80");
- emitcode ("subb", "a,b");
+ pushedB = pushB ();
+ rightInB++;
+ MOVB (aopGet (right, offset, FALSE, FALSE));
}
+ emitcode ("xrl", "b,#0x80");
+ emitcode ("subb", "a,b");
}
else
{
ifx conditional branch then generate
code a little differently */
if (ifx)
- genIfxJump (ifx, "c", NULL, NULL, result);
+ {
+ genIfxJump (ifx, "c", NULL, NULL, result);
+ }
else
- outBitC (result);
+ {
+ outBitC (result);
+ }
/* leave the result in acc */
}
}
sym_link *letype, *retype;
int sign;
- D(emitcode ("; genCmpGt",""));
+ D (emitcode (";", "genCmpGt"));
left = IC_LEFT (ic);
right = IC_RIGHT (ic);
sym_link *letype, *retype;
int sign;
- D(emitcode ("; genCmpLt",""));
+ D (emitcode (";", "genCmpLt"));
left = IC_LEFT (ic);
right = IC_RIGHT (ic);
int offset = 0;
unsigned long lit = 0L;
+ D (emitcode (";", "gencjneshort"));
+
/* if the left side is a literal or
if the right is in a pointer register and left
is not */
/* right is a pointer reg need both a & b */
while (size--)
{
- char *l;
//if B in use: push B; mov B,left; mov A,right; clrc; subb A,B; pop B; jnz
wassertl(!BINUSE, "B was in use");
- l = aopGet (left, offset, FALSE, FALSE);
- if (strcmp (l, "b"))
- emitcode ("mov", "b,%s", l);
+ MOVB (aopGet (left, offset, FALSE, FALSE));
MOVA (aopGet (right, offset, FALSE, FALSE));
emitcode ("cjne", "a,b,%05d$", lbl->key + 100);
offset++;
{
symbol *tlbl = newiTempLabel (NULL);
+ D (emitcode (";", "gencjne"));
+
gencjneshort (left, right, lbl);
emitcode ("mov", "a,%s", one);
emitcode ("sjmp", "%05d$", tlbl->key + 100);
- emitcode ("", "%05d$:", lbl->key + 100);
+ emitLabel (lbl);
emitcode ("clr", "a");
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
/*-----------------------------------------------------------------*/
bool swappedLR = FALSE;
operand *left, *right, *result;
- D(emitcode ("; genCmpEq",""));
+ D (emitcode (";", "genCmpEq"));
aopOp ((left = IC_LEFT (ic)), ic, FALSE);
aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
emitcode ("jb", "%s,%05d$", AOP (right)->aopu.aop_dir, (lbl->key + 100));
emitcode ("cpl", "c");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
}
/* if true label then we jump if condition
supplied is true */
freeForBranchAsmop (left);
emitcode ("ljmp", "%05d$", IC_FALSE (ifx)->key + 100);
}
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
else
{
freeForBranchAsmop (right);
freeForBranchAsmop (left);
emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
else
{
symbol *lbl = newiTempLabel (NULL);
emitcode ("sjmp", "%05d$", lbl->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
freeForBranchAsmop (result);
freeForBranchAsmop (right);
freeForBranchAsmop (left);
emitcode ("ljmp", "%05d$", IC_FALSE (ifx)->key + 100);
- emitcode ("", "%05d$:", lbl->key + 100);
+ emitLabel (lbl);
}
}
/* mark the icode as generated */
emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
emitcode ("jb", "%s,%05d$", AOP (right)->aopu.aop_dir, (lbl->key + 100));
emitcode ("cpl", "c");
- emitcode ("", "%05d$:", (lbl->key + 100));
+ emitLabel (lbl);
}
/* c = 1 if egal */
if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
/* hasInc - operand is incremented before any other use */
/*-----------------------------------------------------------------*/
static iCode *
-hasInc (operand *op, iCode *ic,int osize)
+hasInc (operand *op, iCode *ic, int osize)
{
sym_link *type = operandType(op);
sym_link *retype = getSpec (type);
operand *left, *right, *result;
symbol *tlbl;
- D(emitcode ("; genAndOp",""));
+ D (emitcode (";", "genAndOp"));
/* note here that && operations that are in an
if statement are taken away by backPatchLabels
toBoolean (left);
emitcode ("jz", "%05d$", tlbl->key + 100);
toBoolean (right);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
outBitAcc (result);
}
operand *left, *right, *result;
symbol *tlbl;
- D(emitcode ("; genOrOp",""));
+ D (emitcode (";", "genOrOp"));
/* note here that || operations that are in an
if statement are taken away by backPatchLabels
toBoolean (left);
emitcode ("jnz", "%05d$", tlbl->key + 100);
toBoolean (right);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
outBitAcc (result);
}
{
symbol *nlbl = newiTempLabel (NULL);
emitcode ("sjmp", "%05d$", nlbl->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
freeForBranchAsmop (result);
freeForBranchAsmop (right);
freeForBranchAsmop (left);
emitcode ("ljmp", "%05d$", IC_TRUE (ic)->key + 100);
- emitcode ("", "%05d$:", nlbl->key + 100);
+ emitLabel (nlbl);
}
else
{
freeForBranchAsmop (right);
freeForBranchAsmop (left);
emitcode ("ljmp", "%05d$", IC_FALSE (ic)->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
ic->generated = 1;
}
int bytelit = 0;
char buffer[10];
- D(emitcode ("; genAnd",""));
+ D (emitcode (";", "genAnd"));
aopOp ((left = IC_LEFT (ic)), ic, FALSE);
aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
}
else
{// what is this case? just found it in ds390/gen.c
- emitcode ("anl","a,#!constbyte",1 << (posbit & 0x07));
+ emitcode ("anl","a,#!constbyte",1 << (posbit & 0x07));
}
goto release;
}
if (size)
{
emitcode ("clr", "c");
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
// if(left & literal)
else
if (ifx)
jmpTrueOrFalse (ifx, tlbl, left, right, result);
else
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
goto release;
}
}
}
else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
{
- emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE));
+ MOVB (aopGet (left, offset, FALSE, FALSE));
MOVA (aopGet (right, offset, FALSE, FALSE));
emitcode ("anl", "a,b");
aopPut (result, "a", offset);
aopPut (result, "a", offset);
}
else
- emitcode ("anl", "%s,a",
- aopGet (left, offset, FALSE, TRUE));
+ emitcode ("anl", "%s,a", aopGet (left, offset, FALSE, TRUE));
}
}
}
{
if (offset)
emitcode("mov", "a,b");
- emitcode ("anl", "a,%s",
- aopGet (right, offset, FALSE, FALSE));
- } else {
- if (AOP_TYPE(left)==AOP_ACC)
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE));
+ }
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("anl", "a,b");
+ popB (pushedB);
+ }
+ else
{
- if (!offset)
- {
- bool pushedB = pushB ();
- emitcode("mov", "b,a");
- MOVA (aopGet (right, offset, FALSE, FALSE));
- emitcode("anl", "a,b");
- popB (pushedB);
- }
- else
- {
- MOVA (aopGet (right, offset, FALSE, FALSE));
- emitcode("anl", "a,b");
- }
- } else {
MOVA (aopGet (right, offset, FALSE, FALSE));
- emitcode ("anl", "a,%s",
- aopGet (left, offset, FALSE, FALSE));
+ emitcode("anl", "a,b");
+ }
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE));
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode ("anl", "a,b");
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE));
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE));
}
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, FALSE));
}
+
emitcode ("jnz", "%05d$", tlbl->key + 100);
offset++;
}
if (size)
{
CLRC;
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
outBitC (result);
}
else if (ifx)
jmpTrueOrFalse (ifx, tlbl, left, right, result);
else
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
else
{
}
// faster than result <- left, anl result,right
// and better if result is SFR
- if (AOP_TYPE (left) == AOP_ACC)
+ if ((AOP_TYPE(right)==AOP_REG || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+ && AOP_TYPE(left)==AOP_ACC)
{
if (offset)
emitcode("mov", "a,b");
emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE));
}
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("anl", "a,b");
+ popB (pushedB);
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("anl", "a,b");
+ }
+ }
else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
{
- emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE));
+ MOVB (aopGet (left, offset, FALSE, FALSE));
MOVA (aopGet (right, offset, FALSE, FALSE));
emitcode ("anl", "a,b");
}
unsigned long lit = 0L;
int bytelit = 0;
- D(emitcode ("; genOr",""));
+ D (emitcode (";", "genOr"));
aopOp ((left = IC_LEFT (ic)), ic, FALSE);
aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
else
{
CLRC;
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
}
}
symbol *tlbl = newiTempLabel (NULL);
emitcode ("jnz", "%05d$", tlbl->key + 100);
CLRC;
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
else
{
}
else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
{
- emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE));
+ MOVB (aopGet (left, offset, FALSE, FALSE));
MOVA (aopGet (right, offset, FALSE, FALSE));
emitcode ("orl", "a,b");
aopPut (result, "a", offset);
}
else
{
- emitcode ("orl", "%s,a",
- aopGet (left, offset, FALSE, TRUE));
+ emitcode ("orl", "%s,a", aopGet (left, offset, FALSE, TRUE));
}
}
}
emitcode ("setb", "c");
while (sizer--)
{
- if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
- if (offset)
- emitcode("mov", "a,b");
- emitcode ("orl", "a,%s",
- aopGet (right, offset, FALSE, FALSE));
- } else {
- MOVA (aopGet (right, offset, FALSE, FALSE));
- emitcode ("orl", "a,%s",
- aopGet (left, offset, FALSE, FALSE));
+ if ((AOP_TYPE(right)==AOP_REG || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+ && AOP_TYPE(left)==AOP_ACC)
+ {
+ if (offset)
+ emitcode("mov", "a,b");
+ emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE));
+ }
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("orl", "a,b");
+ popB (pushedB);
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("orl", "a,b");
+ }
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE));
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode ("orl", "a,b");
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE));
+ emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE));
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode ("orl", "a,%s", aopGet (left, offset, FALSE, FALSE));
}
+
emitcode ("jnz", "%05d$", tlbl->key + 100);
offset++;
}
if (size)
{
CLRC;
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
outBitC (result);
}
else if (ifx)
jmpTrueOrFalse (ifx, tlbl, left, right, result);
else
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
else
{
continue;
}
}
- // faster than result <- left, anl result,right
+ // faster than result <- left, orl result,right
// and better if result is SFR
- if (AOP_TYPE (left) == AOP_ACC)
+ if ((AOP_TYPE(right)==AOP_REG || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+ && AOP_TYPE(left)==AOP_ACC)
{
if (offset)
emitcode("mov", "a,b");
emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE));
}
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("orl", "a,b");
+ popB (pushedB);
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("orl", "a,b");
+ }
+ }
else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
{
- emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE));
+ MOVB (aopGet (left, offset, FALSE, FALSE));
MOVA (aopGet (right, offset, FALSE, FALSE));
emitcode ("orl", "a,b");
}
unsigned long lit = 0L;
int bytelit = 0;
- D(emitcode ("; genXor",""));
+ D (emitcode (";", "genXor"));
aopOp ((left = IC_LEFT (ic)), ic, FALSE);
aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
}
}
}
-
}
else
{
}
emitcode ("jnb", "%s,%05d$", AOP (left)->aopu.aop_dir, (tlbl->key + 100));
emitcode ("cpl", "c");
- emitcode ("", "%05d$:", (tlbl->key + 100));
+ emitLabel (tlbl);
}
// bit = c
// val = c
}
else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
{
- emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE));
+ MOVB (aopGet (left, offset, FALSE, FALSE));
MOVA (aopGet (right, offset, FALSE, FALSE));
emitcode ("xrl", "a,b");
aopPut (result, "a", offset);
aopPut (result, "a", offset);
}
else
- emitcode ("xrl", "%s,a",
- aopGet (left, offset, FALSE, TRUE));
+ emitcode ("xrl", "%s,a", aopGet (left, offset, FALSE, TRUE));
}
}
}
// if(!size && ifx), conditional oper: if(left ^ right)
symbol *tlbl = newiTempLabel (NULL);
int sizer = max (AOP_SIZE (left), AOP_SIZE (right));
+
if (size)
emitcode ("setb", "c");
while (sizer--)
{
MOVA (aopGet (left, offset, FALSE, FALSE));
}
+ else if ((AOP_TYPE(right)==AOP_REG || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+ && AOP_TYPE(left)==AOP_ACC)
+ {
+ if (offset)
+ emitcode("mov", "a,b");
+ emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE));
+ }
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("xrl", "a,b");
+ popB (pushedB);
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("xrl", "a,b");
+ }
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE));
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode ("xrl", "a,b");
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE));
+ emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE));
+ }
else
{
- if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
- if (offset)
- emitcode("mov", "a,b");
- emitcode ("xrl", "a,%s",
- aopGet (right, offset, FALSE, FALSE));
- } else {
- MOVA (aopGet (right, offset, FALSE, FALSE));
- emitcode ("xrl", "a,%s",
- aopGet (left, offset, FALSE, FALSE));
- }
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode ("xrl", "a,%s", aopGet (left, offset, FALSE, TRUE));
}
+
emitcode ("jnz", "%05d$", tlbl->key + 100);
offset++;
}
if (size)
{
CLRC;
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
outBitC (result);
}
else if (ifx)
for (; (size--); offset++)
{
// normal case
- // result = left & right
+ // result = left ^ right
if (AOP_TYPE (right) == AOP_LIT)
{
bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL);
continue;
}
}
- // faster than result <- left, anl result,right
+ // faster than result <- left, xrl result,right
// and better if result is SFR
- if (AOP_TYPE (left) == AOP_ACC)
+ if ((AOP_TYPE(right)==AOP_REG || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+ && AOP_TYPE(left)==AOP_ACC)
{
if (offset)
emitcode("mov", "a,b");
emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE));
}
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("xrl", "a,b");
+ popB (pushedB);
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE));
+ emitcode("xrl", "a,b");
+ }
+ }
else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
{
- emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE));
+ MOVB (aopGet (left, offset, FALSE, FALSE));
MOVA (aopGet (right, offset, FALSE, FALSE));
emitcode ("xrl", "a,b");
}
genRRC (iCode * ic)
{
operand *left, *result;
- int size, offset = 0;
+ int size, offset;
char *l;
- D(emitcode ("; genRRC",""));
+ D (emitcode (";", "genRRC"));
/* rotate right with carry */
left = IC_LEFT (ic);
genRLC (iCode * ic)
{
operand *left, *result;
- int size, offset = 0;
+ int size, offset;
char *l;
- D(emitcode ("; genRLC",""));
+ D (emitcode (";", "genRLC"));
/* rotate right with carry */
left = IC_LEFT (ic);
}
emitcode("rlc","a"); /* bit0 will be written later */
if (AOP_SIZE (result) > 1)
- aopPut (result, "a", offset++);
+ {
+ aopPut (result, "a", offset++);
+ }
+
while (size--)
{
l = aopGet (left, offset, FALSE, FALSE);
{
operand *left, *result;
- D(emitcode ("; genGetHbit",""));
+ D (emitcode (";", "genGetHbit"));
left = IC_LEFT (ic);
result = IC_RESULT (ic);
operand *left, *right, *result;
int shCount;
- D(emitcode ("; genGetAbit",""));
+ D (emitcode (";", "genGetAbit"));
left = IC_LEFT (ic);
right = IC_RIGHT (ic);
operand *left, *right, *result;
int offset;
- D(emitcode ("; genGetByte",""));
+ D (emitcode (";", "genGetByte"));
left = IC_LEFT (ic);
right = IC_RIGHT (ic);
operand *left, *right, *result;
int offset;
- D(emitcode ("; genGetWord",""));
+ D (emitcode (";", "genGetWord"));
left = IC_LEFT (ic);
right = IC_RIGHT (ic);
emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
emitcode ("orl", "a,#0x%02x",
(unsigned char) ~SRMask[shCount]);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
}
}
else
{
if (!sign)
- aopPut (result, l, offr);
+ {
+ aopPut (result, l, offr);
+ }
else
{
/* MSB sign in acc.7 ! */
emitcode ("orl", "a,#0x%02x",
(unsigned char) ~SRMask[shCount]); // 111AAAAA:BBBCCCCC
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
break; // SSSSAAAA:BBBCCCCC
case 6: // AABBBBBB:CCDDDDDD
emitcode ("orl", "a,#0x%02x",
(unsigned char) ~SRMask[shCount]); // 111111AA:BBBBBBCC
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
break;
case 7: // ABBBBBBB:CDDDDDDD
emitcode ("orl", "a,#0x%02x",
(unsigned char) ~SRMask[shCount]); // 1111111A:BBBBBBBC
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
break;
default:
break;
{
/* don't crash result[offr] */
MOVA (aopGet (left, offl, FALSE, FALSE));
- emitcode ("xch", "a,%s", aopGet (left, offl + MSB16, FALSE, FALSE));
- x = aopGet (result, offr, FALSE, FALSE);
+ x = xch_a_aopGet (left, offl + MSB16, FALSE, FALSE);
+ usedB = !strncmp(x, "b", 1);
}
else if (aopGetUsesAcc (result, offr))
{
{
/* don't crash result[offr] */
MOVA (aopGet (left, offl, FALSE, FALSE));
- emitcode ("xch", "a,%s", aopGet (left, offl + MSB16, FALSE, FALSE));
- x = aopGet (result, offr, FALSE, FALSE);
+ x = xch_a_aopGet (left, offl + MSB16, FALSE, FALSE);
+ usedB = !strncmp(x, "b", 1);
}
else if (aopGetUsesAcc (result, offr))
{
/* shift right accumulator */
AccRsh (shCount);
/* or with result */
- emitcode ("orl", "a,%s", aopGet (result, offr, FALSE, FALSE));
+ if (aopGetUsesAcc(result, offr))
+ {
+ emitcode ("xch", "a,b");
+ MOVA (aopGet (result, offr, FALSE, FALSE));
+ emitcode ("orl", "a,b");
+ }
+ else
+ {
+ emitcode ("orl", "a,%s", aopGet (result, offr, FALSE, FALSE));
+ }
/* back to result */
aopPut (result, "a", offr);
}
static void
genlshOne (operand * result, operand * left, int shCount)
{
- D(emitcode ("; genlshOne",""));
+ D (emitcode (";", "genlshOne"));
shiftL1Left2Result (left, LSB, result, LSB, shCount);
}
{
int size;
- D(emitcode ("; genlshTwo",""));
+ D (emitcode (";", "genlshTwo"));
size = getDataSize (result);
emitcode ("add", "a,acc");
if (sameRegs (AOP (left), AOP (result)) &&
size >= MSB16 + offr && offr != LSB)
- emitcode ("xch", "a,%s",
- aopGet (left, LSB + offr, FALSE, FALSE));
+ xch_a_aopGet (left, LSB + offr, FALSE, FALSE);
else
aopPut (result, "a", LSB + offr);
}
emitcode ("rlc", "a");
if (sameRegs (AOP (left), AOP (result)) &&
size >= MSB24 + offr && offr != LSB)
- emitcode ("xch", "a,%s",
- aopGet (left, MSB16 + offr, FALSE, FALSE));
+ xch_a_aopGet (left, MSB16 + offr, FALSE, FALSE);
else
aopPut (result, "a", MSB16 + offr);
}
emitcode ("rlc", "a");
if (sameRegs (AOP (left), AOP (result)) &&
size >= MSB32 + offr && offr != LSB)
- emitcode ("xch", "a,%s",
- aopGet (left, MSB24 + offr, FALSE, FALSE));
+ xch_a_aopGet (left, MSB24 + offr, FALSE, FALSE);
else
aopPut (result, "a", MSB24 + offr);
}
{
int size;
- D(emitcode ("; genlshFour",""));
+ D (emitcode (";", "genlshFour"));
size = AOP_SIZE (result);
int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
int size;
- D(emitcode ("; genLeftShiftLiteral",""));
+ D (emitcode (";", "genLeftShiftLiteral"));
freeAsmop (right, NULL, ic, TRUE);
movLeft2Result (left, size, result, size, 0);
}
}
-
else if (shCount >= (size * 8))
- while (size--)
- aopPut (result, zero, size);
+ {
+ while (size--)
+ {
+ aopPut (result, zero, size);
+ }
+ }
else
{
switch (size)
symbol *tlbl, *tlbl1;
bool pushedB;
- D(emitcode ("; genLeftShift",""));
+ D (emitcode (";", "genLeftShift"));
right = IC_RIGHT (ic);
left = IC_LEFT (ic);
largest size of an object can be only 32 bits ) */
pushedB = pushB ();
- emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE));
+ MOVB (aopGet (right, 0, FALSE, FALSE));
emitcode ("inc", "b");
freeAsmop (right, NULL, ic, TRUE);
aopOp (left, ic, FALSE);
l = aopGet (left, 0, FALSE, FALSE);
MOVA (l);
emitcode ("sjmp", "%05d$", tlbl1->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
emitcode ("add", "a,acc");
- emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitLabel (tlbl1);
emitcode ("djnz", "b,%05d$", tlbl->key + 100);
popB (pushedB);
aopPut (result, "a", 0);
reAdjustPreg (AOP (result));
emitcode ("sjmp", "%05d$", tlbl1->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
l = aopGet (result, offset, FALSE, FALSE);
MOVA (l);
emitcode ("add", "a,acc");
}
reAdjustPreg (AOP (result));
- emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitLabel (tlbl1);
emitcode ("djnz", "b,%05d$", tlbl->key + 100);
popB (pushedB);
release:
genrshOne (operand * result, operand * left,
int shCount, int sign)
{
- D(emitcode ("; genrshOne",""));
+ D (emitcode (";", "genrshOne"));
shiftR1Left2Result (left, LSB, result, LSB, shCount, sign);
}
genrshTwo (operand * result, operand * left,
int shCount, int sign)
{
- D(emitcode ("; genrshTwo",""));
+ D (emitcode (";", "genrshTwo"));
/* if shCount >= 8 */
if (shCount >= 8)
{
shCount -= 8;
if (shCount)
- shiftR1Left2Result (left, MSB16, result, LSB,
- shCount, sign);
+ shiftR1Left2Result (left, MSB16, result, LSB, shCount, sign);
else
movLeft2Result (left, MSB16, result, LSB, sign);
addSign (result, MSB16, sign);
shiftRLong (operand * left, int offl,
operand * result, int sign)
{
- bool useSameRegs = regsInCommon (left, result);
+ bool overlapping = regsInCommon (left, result) || operandsEqu(left, result);
- if (useSameRegs && offl>1)
+ if (overlapping && offl>1)
{
// we are in big trouble, but this shouldn't happen
werror(E_INTERNAL_ERROR, __FILE__, __LINE__);
{
emitcode ("rlc", "a");
emitcode ("subb", "a,acc");
- if (useSameRegs && sameReg (AOP (left), MSB32, AOP (result), MSB32))
+ if (overlapping && sameByte (AOP (left), MSB32, AOP (result), MSB32))
{
- emitcode ("xch", "a,%s", aopGet (left, MSB32, FALSE, FALSE));
+ xch_a_aopGet (left, MSB32, FALSE, FALSE);
}
else
{
}
else
{
- aopPut (result, zero, MSB32);
+ if (aopPutUsesAcc (result, zero, MSB32))
+ {
+ emitcode("xch", "a,b");
+ aopPut (result, zero, MSB32);
+ emitcode("xch", "a,b");
+ }
+ else
+ {
+ aopPut (result, zero, MSB32);
+ }
}
}
emitcode ("rrc", "a");
- if (useSameRegs && offl==MSB16 &&
- sameReg (AOP (left), MSB24, AOP (result), MSB32-offl))
+ if (overlapping && offl==MSB16 &&
+ sameByte (AOP (left), MSB24, AOP (result), MSB32-offl))
{
- emitcode ("xch", "a,%s",aopGet (left, MSB24, FALSE, FALSE));
+ xch_a_aopGet (left, MSB24, FALSE, FALSE);
}
else
{
- aopPut (result, "a", MSB32-offl);
+ aopPut (result, "a", MSB32 - offl);
MOVA (aopGet (left, MSB24, FALSE, FALSE));
}
emitcode ("rrc", "a");
- if (useSameRegs && offl==1 &&
- sameReg (AOP (left), MSB16, AOP (result), MSB24-offl))
+ if (overlapping && offl==MSB16 &&
+ sameByte (AOP (left), MSB16, AOP (result), MSB24-offl))
{
- emitcode ("xch", "a,%s",aopGet (left, MSB16, FALSE, FALSE));
+ xch_a_aopGet (left, MSB16, FALSE, FALSE);
}
else
{
- aopPut (result, "a", MSB24-offl);
+ aopPut (result, "a", MSB24 - offl);
MOVA (aopGet (left, MSB16, FALSE, FALSE));
}
+
emitcode ("rrc", "a");
if (offl != LSB)
{
}
else
{
- if (useSameRegs &&
- sameReg (AOP (left), LSB, AOP (result), MSB16-offl))
+ if (overlapping &&
+ sameByte (AOP (left), LSB, AOP (result), MSB16-offl))
{
- emitcode ("xch", "a,%s",aopGet (left, LSB, FALSE, FALSE));
+ xch_a_aopGet (left, LSB, FALSE, FALSE);
}
else
{
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 -= 8;
if (shCount == 1)
- shiftRLong (left, MSB16, result, sign);
+ {
+ shiftRLong (left, MSB16, result, sign);
+ }
else if (shCount == 0)
{
movLeft2Result (left, MSB16, result, LSB, 0);
}
}
else
- { /* 1 <= shCount <= 7 */
+ {
+ /* 1 <= shCount <= 7 */
if (shCount <= 2)
{
shiftRLong (left, LSB, result, sign);
int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
int size;
- D(emitcode ("; genRightShiftLiteral",""));
+ D (emitcode (";", "genRightShiftLiteral"));
freeAsmop (right, NULL, ic, TRUE);
else if (shCount >= (size * 8))
{
- if (sign) {
- /* get sign in acc.7 */
- MOVA (aopGet (left, size - 1, FALSE, FALSE));
- }
+ if (sign)
+ {
+ /* get sign in acc.7 */
+ MOVA (aopGet (left, size - 1, FALSE, FALSE));
+ }
addSign (result, LSB, sign);
}
else
symbol *tlbl, *tlbl1;
bool pushedB;
- D(emitcode ("; genSignedRightShift",""));
+ D (emitcode (";", "genSignedRightShift"));
/* we do it the hard way put the shift count in b
and loop thru preserving the sign */
largest size of an object can be only 32 bits ) */
pushedB = pushB ();
- emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE));
+ MOVB (aopGet (right, 0, FALSE, FALSE));
emitcode ("inc", "b");
freeAsmop (right, NULL, ic, TRUE);
aopOp (left, ic, FALSE);
l = aopGet (left, 0, FALSE, FALSE);
MOVA (l);
emitcode ("sjmp", "%05d$", tlbl1->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
emitcode ("mov", "c,ov");
emitcode ("rrc", "a");
- emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitLabel (tlbl1);
emitcode ("djnz", "b,%05d$", tlbl->key + 100);
popB (pushedB);
aopPut (result, "a", 0);
reAdjustPreg (AOP (result));
emitcode ("sjmp", "%05d$", tlbl1->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
emitcode ("mov", "c,ov");
while (size--)
{
aopPut (result, "a", offset--);
}
reAdjustPreg (AOP (result));
- emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitLabel (tlbl1);
emitcode ("djnz", "b,%05d$", tlbl->key + 100);
popB (pushedB);
symbol *tlbl, *tlbl1;
bool pushedB;
- D(emitcode ("; genRightShift",""));
+ D (emitcode (";", "genRightShift"));
/* if signed then we do it the hard way preserve the
sign bit moving it inwards */
largest size of an object can be only 32 bits ) */
pushedB = pushB ();
- emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE));
+ MOVB (aopGet (right, 0, FALSE, FALSE));
emitcode ("inc", "b");
freeAsmop (right, NULL, ic, TRUE);
aopOp (left, ic, FALSE);
if (!sameRegs (AOP (left), AOP (result)) &&
AOP_SIZE (result) > 1)
{
-
size = AOP_SIZE (result);
offset = 0;
while (size--)
l = aopGet (left, 0, FALSE, FALSE);
MOVA (l);
emitcode ("sjmp", "%05d$", tlbl1->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
CLRC;
emitcode ("rrc", "a");
- emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitLabel (tlbl1);
emitcode ("djnz", "b,%05d$", tlbl->key + 100);
popB (pushedB);
aopPut (result, "a", 0);
reAdjustPreg (AOP (result));
emitcode ("sjmp", "%05d$", tlbl1->key + 100);
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
CLRC;
while (size--)
{
}
reAdjustPreg (AOP (result));
- emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitLabel (tlbl1);
emitcode ("djnz", "b,%05d$", tlbl->key + 100);
popB (pushedB);
emitcode ("jnb", "acc.%d,%05d$", blen - 1, tlbl->key + 100);
emitcode ("orl", "a,#0x%02x", (unsigned char) (0xff << blen));
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
aopPut (result, "a", offset++);
goto finish;
emitcode ("jnb", "acc.%d,%05d$", rlen - 1, tlbl->key + 100);
emitcode ("orl", "a,#0x%02x", (unsigned char) (0xff << rlen));
- emitcode ("", "%05d$:", tlbl->key + 100);
+ emitLabel (tlbl);
}
aopPut (result, "a", offset++);
}
char buffer[256];
int size, offset = 0;
- D(emitcode ("; genDataPointerGet",""));
+ D (emitcode (";", "genDataPointerGet"));
aopOp (result, ic, TRUE);
/* get the string representation of the name */
l = aopGet (left, 0, FALSE, TRUE);
+ l++; // remove #
size = AOP_SIZE (result);
while (size--)
{
if (offset)
- sprintf (buffer, "(%s + %d)", l + 1, offset);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l, offset);
+ }
else
- sprintf (buffer, "%s", l + 1);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "%s", l);
+ }
aopPut (result, buffer, offset++);
}
sym_link *ltype = operandType (left);
char buffer[80];
- D(emitcode ("; genNearPointerGet",""));
+ D (emitcode (";", "genNearPointerGet"));
rtype = operandType (result);
retype = getSpec (rtype);
}
else
{
- sprintf (buffer, "@%s", rname);
+ SNPRINTF (buffer, sizeof(buffer), "@%s", rname);
aopPut (result, buffer, offset);
}
offset++;
char *rname;
sym_link *rtype, *retype;
- D(emitcode ("; genPagedPointerGet",""));
+ D (emitcode (";", "genPagedPointerGet"));
rtype = operandType (result);
retype = getSpec (rtype);
}
/*-----------------------------------------------------------------*/
-/* genFarPointerGet - gget value from far space */
+/* genFarPointerGet - get value from far space */
/*-----------------------------------------------------------------*/
static void
genFarPointerGet (operand * left,
int size, offset;
sym_link *retype = getSpec (operandType (result));
- D(emitcode ("; genFarPointerGet",""));
+ D (emitcode (";", "genFarPointerGet"));
aopOp (left, ic, FALSE);
loadDptrFromOperand (left, FALSE);
int size, offset;
sym_link *retype = getSpec (operandType (result));
- D(emitcode ("; genCodePointerGet",""));
+ D (emitcode (";", "genCodePointerGet"));
aopOp (left, ic, FALSE);
loadDptrFromOperand (left, FALSE);
int size, offset;
sym_link *retype = getSpec (operandType (result));
- D(emitcode ("; genGenPointerGet",""));
+ D (emitcode (";", "genGenPointerGet"));
aopOp (left, ic, FALSE);
loadDptrFromOperand (left, TRUE);
- /* so dptr know contains the address */
+ /* so dptr now contains the address */
aopOp (result, ic, FALSE);
/* if bit then unpack */
if (IS_BITFIELD (retype))
- genUnpackBits (result, "dptr", GPOINTER, ifx);
+ {
+ genUnpackBits (result, "dptr", GPOINTER, ifx);
+ }
else
{
size = AOP_SIZE (result);
sym_link *type, *etype;
int p_type;
- D(emitcode ("; genPointerGet",""));
+ D (emitcode (";", "genPointerGet"));
left = IC_LEFT (ic);
result = IC_RESULT (ic);
/* special case when cast remat */
if (p_type == GPOINTER && OP_SYMBOL(left)->remat &&
- IS_CAST_ICODE(OP_SYMBOL(left)->rematiCode)) {
- left = IC_RIGHT(OP_SYMBOL(left)->rematiCode);
- type = operandType (left);
- p_type = DCL_TYPE (type);
- }
+ IS_CAST_ICODE(OP_SYMBOL(left)->rematiCode))
+ {
+ left = IC_RIGHT(OP_SYMBOL(left)->rematiCode);
+ type = operandType (left);
+ p_type = DCL_TYPE (type);
+ }
/* now that we have the pointer type we assign
the pointer values */
switch (p_type)
genGenPointerGet (left, result, ic, pi, ifx);
break;
}
-
}
-
/*-----------------------------------------------------------------*/
/* genPackBits - generates code for packed bit storage */
/*-----------------------------------------------------------------*/
}
emitPtrByteSet (rname, p_type, "a");
}
-
}
int size, offset = 0;
char *l, buffer[256];
- D(emitcode ("; genDataPointerSet",""));
+ D (emitcode (";", "genDataPointerSet"));
aopOp (right, ic, FALSE);
l = aopGet (result, 0, FALSE, TRUE);
+ l++; //remove #
size = AOP_SIZE (right);
while (size--)
{
if (offset)
- sprintf (buffer, "(%s + %d)", l + 1, offset);
+ SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l, offset);
else
- sprintf (buffer, "%s", l + 1);
+ SNPRINTF (buffer, sizeof(buffer), "%s", l);
emitcode ("mov", "%s,%s", buffer,
aopGet (right, offset++, FALSE, FALSE));
}
sym_link *retype, *letype;
sym_link *ptype = operandType (result);
- D(emitcode ("; genNearPointerSet",""));
+ D (emitcode (";", "genNearPointerSet"));
retype = getSpec (operandType (right));
letype = getSpec (ptype);
+
aopOp (result, ic, FALSE);
/* if the result is rematerializable &
genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, rname, POINTER);
else
{
- /* we have can just get the values */
+ /* we can just get the values */
int size = AOP_SIZE (right);
int offset = 0;
while (size--)
{
l = aopGet (right, offset, FALSE, TRUE);
- if (*l == '@')
+ if ((*l == '@') || (strcmp (l, "acc") == 0))
{
MOVA (l);
emitcode ("mov", "@%s,a", rname);
char *rname, *l;
sym_link *retype, *letype;
- D(emitcode ("; genPagedPointerSet",""));
+ D (emitcode (";", "genPagedPointerSet"));
retype = getSpec (operandType (right));
letype = getSpec (operandType (result));
while (size--)
{
l = aopGet (right, offset, FALSE, TRUE);
-
MOVA (l);
emitcode ("movx", "@%s,a", rname);
aopOp (result, ic, FALSE);
loadDptrFromOperand (result, FALSE);
- /* so dptr know contains the address */
+ /* so dptr now contains the address */
aopOp (right, ic, FALSE);
/* if bit then unpack */
sym_link *retype = getSpec (operandType (right));
sym_link *letype = getSpec (operandType (result));
- D(emitcode ("; genGenPointerSet",""));
+ D (emitcode (";", "genGenPointerSet"));
aopOp (result, ic, FALSE);
loadDptrFromOperand (result, TRUE);
- /* so dptr know contains the address */
+ /* so dptr now contains the address */
aopOp (right, ic, FALSE);
/* if bit then unpack */
if (IS_BITFIELD (retype) || IS_BITFIELD (letype))
- genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, "dptr", GPOINTER);
+ {
+ genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, "dptr", GPOINTER);
+ }
else
{
size = AOP_SIZE (right);
sym_link *type, *etype;
int p_type;
- D(emitcode ("; genPointerSet",""));
+ D (emitcode (";", "genPointerSet"));
right = IC_RIGHT (ic);
result = IC_RESULT (ic);
type = operandType (result);
p_type = DCL_TYPE (type);
}
+
/* now that we have the pointer type we assign
the pointer values */
switch (p_type)
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"genPointerSet: illegal pointer type");
}
-
}
/*-----------------------------------------------------------------*/
int isbit = 0;
char *dup = NULL;
- D(emitcode ("; genIfx",""));
+ D (emitcode (";", "genIfx"));
aopOp (cond, ic, FALSE);
/* get the value into acc */
if (AOP_TYPE (cond) != AOP_CRY)
- toBoolean (cond);
+ {
+ toBoolean (cond);
+ }
else
{
isbit = 1;
if (AOP(cond)->aopu.aop_dir)
dup = Safe_strdup(AOP(cond)->aopu.aop_dir);
}
+
/* the result is now in the accumulator or a directly addressable bit */
freeAsmop (cond, NULL, ic, TRUE);
symbol *sym = OP_SYMBOL (IC_LEFT (ic));
int size, offset;
- D(emitcode ("; genAddrOf",""));
+ D (emitcode (";", "genAddrOf"));
aopOp (IC_RESULT (ic), ic, FALSE);
variable */
if (sym->onStack)
{
- /* if it has an offset then we need to compute
- it */
+ /* if it has an offset then we need to compute it */
if (sym->stack)
{
- emitcode ("mov", "a,%s", SYM_BP (sym));
- emitcode ("add", "a,#0x%02x", ((sym->stack < 0) ?
- ((char) (sym->stack - _G.nRegsSaved)) :
- ((char) sym->stack)) & 0xff);
- aopPut (IC_RESULT (ic), "a", 0);
+ int stack_offset = ((sym->stack < 0) ?
+ ((char) (sym->stack - _G.nRegsSaved)) :
+ ((char) sym->stack)) & 0xff;
+ if ((abs(stack_offset) == 1) &&
+ !AOP_NEEDSACC(IC_RESULT (ic)) &&
+ !isOperandVolatile (IC_RESULT (ic), FALSE))
+ {
+ aopPut (IC_RESULT (ic), SYM_BP (sym), 0);
+ if (stack_offset > 0)
+ emitcode ("inc", "%s", aopGet (IC_RESULT (ic), LSB, FALSE, FALSE));
+ else
+ emitcode ("dec", "%s", aopGet (IC_RESULT (ic), LSB, FALSE, FALSE));
+ }
+ else
+ {
+ emitcode ("mov", "a,%s", SYM_BP (sym));
+ emitcode ("add", "a,#0x%02x", stack_offset & 0xff);
+ aopPut (IC_RESULT (ic), "a", 0);
+ }
}
else
{
{
aopPut (IC_RESULT (ic), zero, offset++);
}
-
goto release;
}
sym->rname,
offset * 8);
else
- sprintf (s, "#%s", sym->rname);
+ SNPRINTF (s, sizeof(s), "#%s", sym->rname);
aopPut (IC_RESULT (ic), s, offset++);
}
int offset = 0;
char *l;
- D(emitcode ("; genFarFarAssign",""));
+ D (emitcode (";", "genFarFarAssign"));
/* first push the right side on to the stack */
while (size--)
int size, offset;
unsigned long lit = 0L;
- D(emitcode("; genAssign",""));
+ D (emitcode (";", "genAssign"));
result = IC_RESULT (ic);
right = IC_RIGHT (ic);
IS_TRUE_SYMOP (result) &&
isOperandInFarSpace (result))
{
-
genFarFarAssign (result, right, ic);
return;
}
/* if the result is a bit */
if (AOP_TYPE (result) == AOP_CRY)
{
-
/* if the right size is a literal then
we know what the value is */
if (AOP_TYPE (right) == AOP_LIT)
offset = 0;
if (AOP_TYPE (right) == AOP_LIT)
lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
if ((size > 1) &&
(AOP_TYPE (result) != AOP_REG) &&
(AOP_TYPE (right) == AOP_LIT) &&
offset++;
size--;
}
- emitcode ("clr", "a");
+ /* And now fill the rest with zeros. */
+ if (size)
+ {
+ emitcode ("clr", "a");
+ }
while (size--)
{
aopPut (result, "a", offset);
char *l;
unsigned int count;
- D(emitcode ("; genJumpTab",""));
+ D (emitcode (";", "genJumpTab"));
count = elementsInSet( IC_JTLABELS (ic) );
jtab = newiTempLabel (NULL);
emitcode ("mov", "dptr,#%05d$", jtab->key + 100);
emitcode ("jmp", "@a+dptr");
- emitcode ("", "%05d$:", jtab->key + 100);
+ emitLabel (jtab);
/* now generate the jump labels */
for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
jtab = setNextItem (IC_JTLABELS (ic)))
emitcode ("ret", "");
/* now generate jump table, LSB */
- emitcode ("", "%05d$:", jtablo->key + 100);
+ emitLabel (jtablo);
for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
jtab = setNextItem (IC_JTLABELS (ic)))
emitcode (".db", "%05d$", jtab->key + 100);
/* now generate jump table, MSB */
- emitcode ("", "%05d$:", jtabhi->key + 100);
+ emitLabel (jtabhi);
for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
jtab = setNextItem (IC_JTLABELS (ic)))
emitcode (".db", "%05d$>>8", jtab->key + 100);
operand *right = IC_RIGHT (ic);
int size, offset;
- D(emitcode("; genCast",""));
+ D (emitcode (";", "genCast"));
/* if they are equivalent then do nothing */
if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
aopOp (result, ic, FALSE);
/* if the result is a bit (and not a bitfield) */
- // if (AOP_TYPE (result) == AOP_CRY)
if (IS_BIT (OP_SYMBOL (result)->type))
- /* not for bitfields */
{
/* if the right size is a literal then
we know what the value is */
if (IS_GENPTR (ctype))
{
if (IS_PTR (type))
- p_type = DCL_TYPE (type);
+ {
+ p_type = DCL_TYPE (type);
+ }
else
{
if (SPEC_SCLS(etype)==S_REGISTER) {
if (!ifx)
return 0;
- D(emitcode ("; genDjnz",""));
-
/* if the if condition has a false label
then we cannot save */
if (IC_FALSE (ifx))
return 0;
- /* if the minus is not of the form
- a = a - 1 */
+ /* if the minus is not of the form a = a - 1 */
if (!isOperandEqual (IC_RESULT (ic), IC_LEFT (ic)) ||
!IS_OP_LITERAL (IC_RIGHT (ic)))
return 0;
return 0;
/* otherwise we can save BIG */
+
+ D (emitcode (";", "genDjnz"));
+
lbl = newiTempLabel (NULL);
lbl1 = newiTempLabel (NULL);
emitcode ("dec", "%s",
aopGet (IC_RESULT (ic), 0, FALSE, FALSE));
MOVA (aopGet (IC_RESULT (ic), 0, FALSE, FALSE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ ifx->generated = 1;
emitcode ("jnz", "%05d$", lbl->key + 100);
}
else
lbl->key + 100);
}
emitcode ("sjmp", "%05d$", lbl1->key + 100);
- emitcode ("", "%05d$:", lbl->key + 100);
+ emitLabel (lbl);
emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
- emitcode ("", "%05d$:", lbl1->key + 100);
+ emitLabel (lbl1);
- freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ if (!ifx->generated)
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
ifx->generated = 1;
return 1;
}
int size = getSize (operandType (IC_RESULT (ic)));
int offset = 0;
- D(emitcode ("; genReceive",""));
+ D (emitcode (";", "genReceive"));
if (ic->argreg == 1)
{ /* first parameter */
operand *op;
int size, offset;
- D(emitcode("; genDummyRead",""));
+ D (emitcode(";", "genDummyRead"));
op = IC_RIGHT (ic);
if (op && IS_SYMOP (op))
{
symbol *tlbl = newiTempLabel (NULL);
- D(emitcode("; genCritical",""));
+ D (emitcode(";", "genCritical"));
if (IC_RESULT (ic))
{
aopOp (IC_RESULT (ic), ic, TRUE);
- aopPut (IC_RESULT (ic), one, 0);
+ aopPut (IC_RESULT (ic), one, 0); /* save old ea in an operand */
emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
aopPut (IC_RESULT (ic), zero, 0);
- emitcode ("", "%05d$:", (tlbl->key + 100));
+ emitLabel (tlbl);
freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
else
emitcode ("setb", "c");
emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
emitcode ("clr", "c");
- emitcode ("", "%05d$:", (tlbl->key + 100));
+ emitLabel (tlbl);
emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/
}
}
/* print the allocation information */
if (allocInfo && currFunc)
- printAllocInfo (currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutBuf);
/* if debug information required */
if (options.debug && currFunc)
{
debugFile->writeCLine (ic);
}
if (!options.noCcodeInAsm) {
- emitcode ("", ";%s:%d: %s", ic->filename, ic->lineno,
+ emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno,
printCLine(ic->filename, ic->lineno));
}
cln = ic->lineno;
if (options.iCodeInAsm) {
char regsInUse[80];
int i;
+ char *iLine;
#if 0
for (i=0; i<8; i++) {
}
#endif
}
+ iLine = printILine(ic);
emitcode("", "; [%s] ic:%d: %s", regsInUse, ic->seq, printILine(ic));
+ dbuf_free(iLine);
}
/* if the result is marked as
spilt and rematerializable or code for
case NE_OP:
/* note these two are xlated by algebraic equivalence
- during parsing SDCC.y */
+ in decorateType() in SDCCast.c */
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"got '>=' or '<=' shouldn't have come here");
break;
case '=':
if (POINTER_SET (ic))
- genPointerSet (ic, hasInc (IC_RESULT(ic),ic,getSize(operandType(IC_RIGHT(ic)))));
+ genPointerSet (ic,
+ hasInc (IC_RESULT (ic), ic,
+ getSize (operandType (IC_RIGHT (ic)))));
else
genAssign (ic);
break;
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
return;
}