#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] == REG_WITH_INDEX(R0_IDX) || \
static void
emitLabel (symbol *tlbl)
{
- emitcode ("", "%05d$:", (tlbl->key +100));
+ emitcode ("", "%05d$:", tlbl->key + 100);
}
/*-----------------------------------------------------------------*/
(*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 */
+ /* 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;
{
(*aopp)->type = AOP_R1;
return REG_WITH_INDEX (R1_IDX);
- }
+ }
/* now this is REALLY the end of the world */
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
{
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)))
/* 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);
}
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 + %d)",
- aop->aopu.aop_dir,
- offset);
+ aop->aopu.aop_dir,
+ offset);
}
else
{
}
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),
+ 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"))
{
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 (options.useXstack)
{
if (!ic)
- {
+ {
/* Assume r0 is available for use. */
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);
}
else if (sym->stack || FUNC_HASSTACKPARM(sym->type))
{
- emitcode ("mov", "sp,_bp");
+ if (sym->stack)
+ emitcode ("mov", "sp,_bp");
emitcode ("pop", "_bp");
}
}
&& (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;
}
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);
}
}
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) &&
&& (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 (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));
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;
}
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;
+ }
}
CLRC;
while (size--)
if (sign && size == 0)
{
emitcode ("xrl", "a,#0x80");
- if (AOP_TYPE (right) == AOP_LIT)
+ if (!rightInB)
{
- 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)
- {
- pushedB = pushB ();
- rightInB++;
- MOVB (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
{
}
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;
}
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);
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--)
}
}
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
char buffer[256];
int size, offset = 0;
- D(emitcode ("; genDataPointerGet",""));
+ D (emitcode (";", "genDataPointerGet"));
aopOp (result, ic, TRUE);
"(%s + %d)", l + 1, offset);
}
else
- sprintf (buffer, "%s", l + 1);
+ {
+ SNPRINTF (buffer, sizeof(buffer),
+ "%s", l + 1);
+ }
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);
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);
while (size--)
{
if (offset)
- sprintf (buffer, "(%s + %d)", l + 1, offset);
+ SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l + 1, offset);
else
- sprintf (buffer, "%s", l + 1);
+ SNPRINTF (buffer, sizeof(buffer), "%s", l + 1);
emitcode ("mov", "%s,%s", buffer,
aopGet (right, offset++, FALSE, FALSE));
}
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 */
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--)
char *l;
unsigned int count;
- D(emitcode ("; genJumpTab",""));
+ D (emitcode (";", "genJumpTab"));
count = elementsInSet( IC_JTLABELS (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 (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);
emitLabel (tlbl);
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;
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;