Made everything static
-------------------------------------------------------------------------*/
-#define D(x) do if (!options.noGenComments) {x;} while(0)
+#define D(x) do if (options.verboseAsm) {x;} while(0)
#include <stdio.h>
#include <stdlib.h>
lbp++;
}
- if (lbp && *lbp)
+ if (lbp)
{
rtrackUpdate (lbp);
lineCurr = (lineCurr ?
connectLine (lineCurr, newLineNode (lb)) :
(lineHead = newLineNode (lb)));
+
+ lineCurr->isInline = _G.inLine;
+ lineCurr->isDebug = _G.debugLine;
+ lineCurr->ic = _G.current_iCode;
+ lineCurr->isComment = (*lbp==';');
}
- lineCurr->isInline = _G.inLine;
- lineCurr->isDebug = _G.debugLine;
- lineCurr->ic = _G.current_iCode;
- lineCurr->isComment = (*lbp==';');
va_end (ap);
dbuf_destroy(&dbuf);
if (sym->regType == REG_CND)
{
sym->aop = op->aop = aop = newAsmop (AOP_CRY);
- aop->size = 0;
+ aop->size = sym->ruonly ? 1 : 0;
return;
}
if (sym->remat)
{
sym->aop = op->aop = aop = aopForRemat (sym);
- aop->size = getSize (sym->type);
+ aop->size = operandSize (op);
return;
}
bool bvolatile = isOperandVolatile (result, FALSE);
bool accuse = FALSE;
asmop * aop = AOP (result);
+ const char *d = NULL;
if (aop->size && offset > (aop->size - 1))
{
break;
case AOP_CRY:
- /* if result no bit variable */
- if (!aop->aopu.aop_dir)
- {
- assert (!strcmp (s, "c"));
- /* inefficient: move carry into A and use jz/jnz */
- emitcode ("clr", "a");
- emitcode ("rlc", "a");
- accuse = TRUE;
- }
- else if (s == zero)
- emitcode ("clr", "%s", aop->aopu.aop_dir);
- else if (s == one)
- emitcode ("setb", "%s", aop->aopu.aop_dir);
- else if (!strcmp (s, "c"))
- emitcode ("mov", "%s,c", aop->aopu.aop_dir);
- else if (strcmp (s, aop->aopu.aop_dir))
+ // destination is carry for return-use-only
+ d = (IS_OP_RUONLY (result)) ? "c" : aop->aopu.aop_dir;
+ // source is no literal and not in carry
+ if ((s != zero) && (s != one) && strcmp (s, "c"))
{
MOVA (s);
/* set C, if a >= 1 */
emitcode ("add", "a,#0xff");
- emitcode ("mov", "%s,c", aop->aopu.aop_dir);
+ s = "c";
}
+ // now source is zero, one or carry
+
+ /* if result no bit variable */
+ if (!d)
+ {
+ if (!strcmp (s, "c"))
+ {
+ /* inefficient: move carry into A and use jz/jnz */
+ emitcode ("clr", "a");
+ emitcode ("rlc", "a");
+ accuse = TRUE;
+ }
+ else
+ {
+ MOVA (s);
+ accuse = TRUE;
+ }
+ }
+ else if (s == zero)
+ emitcode ("clr", "%s", d);
+ else if (s == one)
+ emitcode ("setb", "%s", d);
+ else if (strcmp (s, d))
+ emitcode ("mov", "%s,c", d);
break;
case AOP_STR:
/* if the result is bit */
if (AOP_TYPE (result) == AOP_CRY)
{
- if (!OP_SYMBOL (result)->ruonly)
+ if (!IS_OP_RUONLY (result))
aopPut (result, "c", 0);
}
else
}
else
{
- emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ toCarry (IC_LEFT (ic));
emitcode ("cpl", "c");
outBitC (IC_RESULT (ic));
}
}
if (ic)
- {
- ic->bankSaved = 1;
- }
+ {
+ ic->bankSaved = 1;
+ }
}
/*-----------------------------------------------------------------*/
}
}
}
- else
+ else
{
/* This ISR uses a non-zero bank.
*
int ofs;
_G.current_iCode = ric;
- D(emitcode ("; genReceive",""));
+ D(emitcode (";", "genReceive"));
for (ofs=0; ofs < sym->recvSize; ofs++)
{
if (!strcmp (fReturn[ofs], "a"))
int ofs;
_G.current_iCode = ric;
- D(emitcode ("; genReceive",""));
+ D(emitcode (";", "genReceive"));
for (ofs=0; ofs < sym->recvSize; ofs++)
{
emitcode ("mov", "%s,%s", rsym->regs[ofs]->name, fReturn[ofs]);
if (IS_BIT(_G.currentFunc->etype))
{
- if (!OP_SYMBOL (IC_LEFT (ic))->ruonly)
+ if (!IS_OP_RUONLY (IC_LEFT (ic)))
toCarry (IC_LEFT (ic));
}
else
&& (SPEC_ADDR (OP_SYM_ETYPE (op)) & 0xff) == 0
)
{
- D(emitcode ("; genPlus aligned array",""));
+ D(emitcode (";", "genPlus aligned array"));
aopPut (IC_RESULT (ic),
aopGet (rightOp, 0, FALSE, FALSE),
0);
skip_bytes++;
}
if (skip_bytes)
- D(emitcode ("; genPlus shortcut",""));
+ D(emitcode (";", "genPlus shortcut"));
}
while (size--)
char *l;
bool pushedB;
- D(emitcode ("; genDivbits",""));
+ D(emitcode (";", "genDivbits"));
pushedB = pushB ();
symbol *lbl;
int size, offset;
- D(emitcode ("; genDivOneByte",""));
+ D(emitcode (";", "genDivOneByte"));
/* Why is it necessary that genDivOneByte() can return an int result?
Have a look at:
D (emitcode (";", "genDiv"));
- /* assign the amsops */
+ /* assign the asmops */
aopOp (left, ic, FALSE);
aopOp (right, ic, FALSE);
aopOp (result, ic, TRUE);
retype = getSpec (operandType (right));
sign = !((SPEC_USIGN (letype) && !(IS_CHAR (letype) && IS_LITERAL (letype))) ||
(SPEC_USIGN (retype) && !(IS_CHAR (retype) && IS_LITERAL (retype))));
- /* assign the amsops */
+ /* assign the asmops */
aopOp (result, ic, TRUE);
aopOp (left, ic, FALSE);
aopOp (right, ic, FALSE);
retype = getSpec (operandType (right));
sign = !((SPEC_USIGN (letype) && !(IS_CHAR (letype) && IS_LITERAL (letype))) ||
(SPEC_USIGN (retype) && !(IS_CHAR (retype) && IS_LITERAL (retype))));
- /* assign the amsops */
+ /* assign the asmops */
aopOp (result, ic, TRUE);
aopOp (left, ic, FALSE);
aopOp (right, ic, FALSE);
/* if the left side is a literal or
if the right is in a pointer register and left
is not */
- if ((AOP_TYPE (left) == AOP_LIT) ||
+ if ((AOP_TYPE (left) == AOP_LIT) ||
(AOP_TYPE (left) == AOP_IMMD) ||
+ (AOP_TYPE (left) == AOP_DIR) ||
(IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
{
operand *t = right;
/* gencjne - compare and jump if not equal */
/*-----------------------------------------------------------------*/
static void
-gencjne (operand * left, operand * right, symbol * lbl)
+gencjne (operand * left, operand * right, symbol * lbl, bool useCarry)
{
symbol *tlbl = newiTempLabel (NULL);
gencjneshort (left, right, lbl);
- emitcode ("mov", "a,%s", one);
+ if (useCarry)
+ SETC;
+ else
+ MOVA (one);
emitcode ("sjmp", "%05d$", tlbl->key + 100);
emitLabel (lbl);
- emitcode ("clr", "a");
+ if (useCarry)
+ CLRC;
+ else
+ MOVA (zero);
emitLabel (tlbl);
}
}
else
{
- gencjne (left, right, newiTempLabel (NULL));
if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
{
- aopPut (result, "a", 0);
+ gencjne (left, right, newiTempLabel (NULL), TRUE);
+ aopPut (result, "c", 0);
goto release;
}
+ gencjne (left, right, newiTempLabel (NULL), FALSE);
if (ifx)
{
genIfxJump (ifx, "a", left, right, result);
aopOp ((result = IC_RESULT (ic)), ic, TRUE);
#ifdef DEBUG_TYPE
- emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ emitcode (";", "Type res[%d] = l[%d]&r[%d]",
AOP_TYPE (result),
AOP_TYPE (left), AOP_TYPE (right));
- emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ emitcode (";", "Size res[%d] = l[%d]&r[%d]",
AOP_SIZE (result),
AOP_SIZE (left), AOP_SIZE (right));
#endif
if (AOP_TYPE (right) == AOP_CRY)
{
// c = bit & bit;
- emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
- emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+ if (IS_OP_ACCUSE (left))
+ {
+ emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+ }
+ else
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
}
else
{
aopOp ((result = IC_RESULT (ic)), ic, TRUE);
#ifdef DEBUG_TYPE
- emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ emitcode (";", "Type res[%d] = l[%d]&r[%d]",
AOP_TYPE (result),
AOP_TYPE (left), AOP_TYPE (right));
- emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ emitcode (";", "Size res[%d] = l[%d]&r[%d]",
AOP_SIZE (result),
AOP_SIZE (left), AOP_SIZE (right));
#endif
if (AOP_TYPE (right) == AOP_CRY)
{
// c = bit | bit;
- emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
- emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir);
+ if (IS_OP_ACCUSE (left))
+ {
+ emitcode ("orl", "c,%s", AOP (right)->aopu.aop_dir);
+ }
+ else
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
}
else
{
aopOp ((result = IC_RESULT (ic)), ic, TRUE);
#ifdef DEBUG_TYPE
- emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ emitcode (";", "Type res[%d] = l[%d]&r[%d]",
AOP_TYPE (result),
AOP_TYPE (left), AOP_TYPE (right));
- emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ emitcode (";", "Size res[%d] = l[%d]&r[%d]",
AOP_SIZE (result),
AOP_SIZE (left), AOP_SIZE (right));
#endif
right = left;
left = tmp;
}
+
if (AOP_TYPE (right) == AOP_LIT)
lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
if (AOP_TYPE (right) == AOP_CRY)
{
// c = bit ^ bit;
- emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ if (IS_OP_ACCUSE (left))
+ {// left already is in the carry
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ else
+ {
+ toCarry (right);
+ }
}
else
{
- int sizer = AOP_SIZE (right);
// c = bit ^ val
- // if val>>1 != 0, result = 1
- emitcode ("setb", "c");
- while (sizer)
- {
- MOVA (aopGet (right, sizer - 1, FALSE, FALSE));
- if (sizer == 1)
- // test the msb of the lsb
- emitcode ("anl", "a,#0xfe");
- emitcode ("jnz", "%05d$", tlbl->key + 100);
- sizer--;
- }
- // val = (0,1)
- emitcode ("rrc", "a");
+ toCarry (right);
}
emitcode ("jnb", "%s,%05d$", AOP (left)->aopu.aop_dir, (tlbl->key + 100));
emitcode ("cpl", "c");
// val = c
if (size)
outBitC (result);
- // if(bit | ...)
+ // if(bit ^ ...)
else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
genIfxJump (ifx, "c", left, right, result);
goto release;
genInline (iCode * ic)
{
char *buffer, *bp, *bp1;
+ bool inComment = FALSE;
D (emitcode (";", "genInline"));
_G.inLine += (!options.asmpeep);
- buffer = bp = bp1 = Safe_strdup(IC_INLINE(ic));
+ buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic));
/* emit each line as a code */
while (*bp)
{
- if (*bp == '\n')
+ switch (*bp)
{
+ case ';':
+ inComment = TRUE;
+ ++bp;
+ break;
+
+ case '\n':
+ inComment = FALSE;
*bp++ = '\0';
emitcode (bp1, "");
bp1 = bp;
- }
- else
- {
+ break;
+
+ default:
/* Add \n for labels, not dirs such as c:\mydir */
- if ( (*bp == ':') && (isspace((unsigned char)bp[1])) )
+ if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
{
- bp++;
+ ++bp;
*bp = '\0';
- bp++;
+ ++bp;
emitcode (bp1, "");
bp1 = bp;
}
else
- bp++;
+ ++bp;
+ break;
}
}
if (bp1 != bp)
emitcode (bp1, "");
- /* emitcode("",buffer); */
+
+ Safe_free (buffer);
+
_G.inLine -= (!options.asmpeep);
}
{
operand *left, *result;
- D(emitcode ("; genSwap",""));
+ D(emitcode (";", "genSwap"));
left = IC_LEFT (ic);
result = IC_RESULT (ic);
int bstr; /* bitfield starting bit within byte */
char buffer[10];
- D(emitcode ("; genUnpackBits",""));
+ D(emitcode (";", "genUnpackBits"));
etype = getSpec (operandType (result));
rsize = getSize (operandType (result));
else
{
wassertl(FALSE, "need pointerCode");
- emitcode ("", "; mov b,???");
+ emitcode (";", "mov b,???");
/* genPointerGet and genPointerSet originally did different
** things for this case. Both seem wrong.
** from genPointerGet:
int litval; /* source literal value (if AOP_LIT) */
unsigned char mask; /* bitmask within current byte */
- D(emitcode ("; genPackBits",""));
+ D(emitcode (";", "genPackBits"));
blen = SPEC_BLEN (etype);
bstr = SPEC_BSTR (etype);
l = aopGet (result, 0, FALSE, TRUE);
l++; //remove #
- size = AOP_SIZE (right);
+ size = max (AOP_SIZE (right), AOP_SIZE (result));
while (size--)
{
if (offset)
aopGet (right, offset++, FALSE, FALSE));
}
- freeAsmop (result, NULL, ic, TRUE);
freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
-/* genNearPointerSet - emitcode for near pointer put */
+/* genNearPointerSet - emitcode for near pointer put */
/*-----------------------------------------------------------------*/
static void
genNearPointerSet (operand * right,
}
/* done */
- if (pi) pi->generated = 1;
- freeAsmop (result, NULL, ic, TRUE);
+ if (pi)
+ pi->generated = 1;
freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
sym_link *retype = getSpec (operandType (right));
sym_link *letype = getSpec (operandType (result));
- D(emitcode ("; genFarPointerSet",""));
+ D(emitcode (";", "genFarPointerSet"));
aopOp (result, ic, FALSE);
loadDptrFromOperand (result, FALSE);
static void
genEndCritical (iCode *ic)
{
- D(emitcode("; genEndCritical",""));
+ D(emitcode(";", "genEndCritical"));
if (IC_RIGHT (ic))
{
debugFile->writeCLine (ic);
}
if (!options.noCcodeInAsm) {
- emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno,
+ emitcode (";", "%s:%d: %s", ic->filename, ic->lineno,
printCLine(ic->filename, ic->lineno));
}
cln = ic->lineno;
#if 0
if (ic->seqPoint && ic->seqPoint != cseq)
{
- emitcode ("", "; sequence point %d", ic->seqPoint);
+ emitcode (";", "sequence point %d", ic->seqPoint);
cseq = ic->seqPoint;
}
#endif
#endif
}
iLine = printILine(ic);
- emitcode("", "; [%s] ic:%d: %s", regsInUse, ic->seq, printILine(ic));
+ emitcode(";", "[%s] ic:%d: %s", regsInUse, ic->seq, iLine);
dbuf_free(iLine);
}
/* if the result is marked as