-------------------------------------------------------------------------*/
//#define D(x)
-#define D(x) x
+#define D(x) do if (!options.noGenComments) {x;} while(0)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "SDCCglobl.h"
#include "newalloc.h"
+#include "dbuf_string.h"
#include "common.h"
#include "main.h"
emitcode ("setb","F1"); \
emitcode ("jbc","EA,!tlabel",lbl->key+100); \
emitcode ("clr","F1"); \
- emitcode ("","!tlabeldef",lbl->key+100); \
+ emitLabel (lbl); \
}}
#define UNPROTECT_SP { if (options.protect_sp_update) { \
emitcode ("mov","EA,F1"); \
/* 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);
- }
-
- tvsprintf (lb + strlen(lb), sizeof(lb) - strlen(lb), fmt, ap);
+ dbuf_append_char (&dbuf, '\t');
+ dbuf_tvprintf (&dbuf, 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->isDebug = _G.debugLine;
lineCurr->ic = _G.current_iCode;
lineCurr->aln = ds390newAsmLineNode(_currentDPS);
+ lineCurr->isComment = (*lbp == ';');
va_end (ap);
+
+ dbuf_destroy(&dbuf);
}
static void
emitLabel (symbol *tlbl)
{
emitcode ("", "!tlabeldef", tlbl->key + 100);
+ lineCurr->isLabel = 1;
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/* genSetDPTR: generate code to select which DPTR is in use (zero */
/* selects standard DPTR (DPL/DPH/DPX), non-zero selects DS390 */
-/* alternate DPTR (DPL1/DPH1/DPX1). */
+/* alternate DPTR (DPL1/DPH1/DPX1). */
/*-----------------------------------------------------------------*/
static void
genSetDPTR (int n)
}
/*-----------------------------------------------------------------*/
-/* _endLazyDPSEvaluation: end lazy DPS evaluation block. */
-/* */
-/* Forces us back to the safe state (standard DPTR selected). */
+/* _endLazyDPSEvaluation: end lazy DPS evaluation block. */
+/* */
+/* Forces us back to the safe state (standard DPTR selected). */
/*-----------------------------------------------------------------*/
static void
_endLazyDPSEvaluation (void)
{
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 (sym->onStack && options.stack10bit)
{
- short stack_val = -((sym->stack < 0) ?
- ((short) (sym->stack - _G.nRegsSaved)) :
- ((short) sym->stack)) ;
- if (_G.dptrInUse ) {
- emitcode ("push",dpl);
- emitcode ("push",dph);
- emitcode ("push",dpx);
- }
+ short stack_val = -((sym->stack < 0) ?
+ ((short) (sym->stack - _G.nRegsSaved)) :
+ ((short) sym->stack)) ;
+ if (_G.dptrInUse ) {
+ emitcode ("push",dpl);
+ emitcode ("push",dph);
+ emitcode ("push",dpx);
+ }
/* It's on the 10 bit stack, which is located in
* far data space.
*/
{ /* between -5 & -1 */
if (options.model == MODEL_FLAT24)
{
- emitcode ("mov", "%s,#!constbyte", dpx,
- (options.stack_loc >> 16) & 0xff);
+ emitcode ("mov", "%s,#!constbyte", dpx,
+ (options.stack_loc >> 16) & 0xff);
}
emitcode ("mov", "%s,_bpx+1", dph);
emitcode ("mov", "%s,_bpx", dpl);
return TRUE;
return FALSE;
case AOP_DPTR:
+ case AOP_DPTR2:
+ case AOP_DPTRn:
return TRUE;
case AOP_IMMD:
return FALSE;
genSetDPTR (0);
}
- if (saveAcc)
+ if (saveAcc)
{
- TR_AP("#2");
- emitcode ("xch", "a, %s", saveAcc);
-// if (strcmp(saveAcc, "_ap"))
-// {
-// emitcode(";", "spiffy: non _ap return from aopGet.");
-// }
+ TR_AP("#2");
+ emitcode ("xch", "a, %s", saveAcc);
+// if (strcmp(saveAcc, "_ap"))
+// {
+// emitcode(";", "spiffy: non _ap return from aopGet.");
+// }
- return saveAcc;
+ return saveAcc;
}
return (dname ? "acc" : "a");
case AOP_IMMD:
if (aop->aopu.aop_immd.from_cast_remat && (offset == (aop->size-1)))
- {
+ {
SNPRINTF(buffer, sizeof(buffer),
"%s",aop->aopu.aop_immd.aop_immd2);
- }
+ }
else if (bit16)
- {
- SNPRINTF(buffer, sizeof(buffer),
- "#%s", aop->aopu.aop_immd.aop_immd1);
- }
+ {
+ SNPRINTF(buffer, sizeof(buffer),
+ "#%s", aop->aopu.aop_immd.aop_immd1);
+ }
else if (offset)
- {
+ {
switch (offset) {
case 1:
tsprintf(buffer, sizeof(buffer),
aop->aopu.aop_immd.aop_immd1,
offset * 8);
}
- }
+ }
else
- {
- SNPRINTF (buffer, sizeof(buffer),
- "#%s",
- aop->aopu.aop_immd.aop_immd1);
- }
+ {
+ SNPRINTF (buffer, sizeof(buffer),
+ "#%s",
+ aop->aopu.aop_immd.aop_immd1);
+ }
return Safe_strdup(buffer);
case AOP_DIR:
return NULL; // not reached, but makes compiler happy.
}
-/*-----------------------------------------------------------------*/
-/* aopPutUsesAcc - indicates ahead of time whether aopPut() will */
-/* clobber the accumulator */
-/*-----------------------------------------------------------------*/
-#if 0
-static bool
-aopPutUsesAcc (operand * oper, const char *s, int offset)
-{
- asmop * aop = AOP (oper);
-
- if (offset > (aop->size - 1))
- return FALSE;
-
- switch (aop->type)
- {
- case AOP_DUMMY:
- return TRUE;
- case AOP_DIR:
- return FALSE;
- case AOP_REG:
- wassert(strcmp(aop->aopu.aop_reg[offset]->name, "a"));
- return FALSE;
- case AOP_DPTR:
- return TRUE;
- case AOP_R0:
- case AOP_R1:
- return ((aop->paged) || (*s == '@'));
- case AOP_STK:
- return (*s == '@');
- case AOP_CRY:
- return (!aop->aopu.aop_dir || strcmp(s, aop->aopu.aop_dir));
- case AOP_STR:
- return FALSE;
- case AOP_IMMD:
- return FALSE;
- case AOP_ACC:
- return FALSE;
- default:
- /* Error case --- will have been caught already */
- wassert(0);
- return FALSE;
- }
-}
-#endif
-
/*-----------------------------------------------------------------*/
/* aopPut - puts a string for a aop and indicates if acc is in use */
/*-----------------------------------------------------------------*/
emitcode ("mov", "%s,c", aop->aopu.aop_dir);
else if (strcmp (s, aop->aopu.aop_dir))
{
- MOVA (s);
- /* set C, if a >= 1 */
- emitcode ("add", "a,#!constbyte",0xff);
- emitcode ("mov", "%s,c", aop->aopu.aop_dir);
- }
+ MOVA (s);
+ /* set C, if a >= 1 */
+ emitcode ("add", "a,#!constbyte",0xff);
+ emitcode ("mov", "%s,c", aop->aopu.aop_dir);
}
+ }
break;
case AOP_STR:
emitcode("mov", "b,a");
while (--size)
{
- MOVA (aopGet (oper, offset++, FALSE, FALSE, NULL));
+ MOVA (aopGet (oper, offset++, FALSE, FALSE, NULL));
emitcode ("orl", "b,a");
}
MOVA (aopGet (oper, offset++, FALSE, FALSE, NULL));
static void savermask(bitVect *rs_mask)
{
int i;
+
if (options.useXstack)
{
if (bitVectBitValue (rs_mask, R0_IDX))
do nothing */
if (ic->regsSaved
|| (IS_SYMOP(IC_LEFT(ic)) && IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT(ic))) && !TARGET_IS_DS400) )
- return ;
+ return;
/* special case if DPTR alive across a function call then must save it
even though callee saves */
/*-----------------------------------------------------------------*/
static void unsavermask(bitVect *rs_mask)
{
- int i;
- if (options.useXstack) {
- emitcode ("mov", "r0,%s", spname);
+ int i;
+
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
for (i = ds390_nRegs; i >= 0; i--)
{
if (bitVectBitValue (rs_mask, i))
bool bits_popped = FALSE;
for (i = ds390_nRegs; i >= 0; i--)
{
- if (bitVectBitValue (rs_mask, i))
+ if (bitVectBitValue (rs_mask, i))
{
bits_popped = popReg (i, bits_popped);
}
}
else
{
- emitcode ("push", "%s", l);
- }
+ emitcode ("push", "%s", l);
+ }
}
_endLazyDPSEvaluation ();
}
regs *r = NULL;
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,_spx", r->name);
MOVA (r->name);
emitcode ("add", "a,#%d", count);
emitcode ("mov", "_spx,a");
- }
+ }
for (i = 0; i < 8; i++) /* only R0-R7 needs saving */
{
if (options.useXstack)
- {
+ {
emitcode ("mov", "a,(%s+%d)",
regs390[i].base, 8 * bank + regs390[i].offset);
emitcode ("movx", "@%s,a", r->name);
else
{
emitcode ("push", "psw");
- }
+ }
emitcode ("mov", "psw,#!constbyte", (bank << 3) & 0x00ff);
}
if (aop)
- {
+ {
freeAsmop (NULL, aop, ic, TRUE);
- }
+ }
if (ic)
{
if (options.useXstack)
{
- if (!ic)
+ if (!ic)
{
/* Assume r0 is available for use. */
r = REG_WITH_INDEX (R0_IDX);;
}
- else
+ else
{
aop = newAsmop (0);
r = getFreePtr (ic, &aop, FALSE);
}
- emitcode ("mov", "%s,_spx", r->name);
+ emitcode ("mov", "%s,_spx", r->name);
}
if (popPsw)
else
{
emitcode ("pop", "(%s+%d)",
- regs390[i].base, 8 * bank + regs390[i].offset);
+ regs390[i].base, 8 * bank + regs390[i].offset);
}
}
}
if (aop)
- {
- freeAsmop (NULL, aop, ic, TRUE);
- }
+ {
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void genSend(set *sendSet)
{
- iCode *sic;
+ iCode *sic;
int bit_count = 0;
- int sendCount = 0 ;
- static int rb1_count = 0;
+ int sendCount = 0 ;
+ static int rb1_count = 0;
/* first we do all bit parameters */
- for (sic = setFirstItem (sendSet); sic;
+ for (sic = setFirstItem (sendSet); sic;
sic = setNextItem (sendSet))
{
if (sic->argreg > 12)
if (strcmp (l, fReturn[offset]))
{
emitcode ("mov", "%s,%s", fReturn[offset], l);
- }
+ }
offset++;
- }
+ }
_endLazyDPSEvaluation ();
freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
rb1_count =0;
swapBanks = TRUE;
}
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved)
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
saveRegisters (ic);
/* if send set is not empty then assign */
}
if (swapBanks)
- {
- emitcode ("mov", "psw,#!constbyte",
- ((FUNC_REGBANK(dtype)) << 3) & 0xff);
- }
+ {
+ emitcode ("mov", "psw,#!constbyte",
+ ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+ }
/* make the call */
emitcode ("lcall", "%s", (OP_SYMBOL (IC_LEFT (ic))->rname[0] ?
emitcode ("push", "acc");
accPushed = TRUE;
}
- if (IS_BIT (OP_SYM_ETYPE (IC_LEFT (ic))) &&
- IS_BIT (OP_SYM_ETYPE (IC_RESULT (ic))) &&
- !assignResultGenerated)
- {
- emitcode ("mov", "F0,c");
- resultInF0 = TRUE;
- }
+ if (IS_BIT (OP_SYM_ETYPE (IC_LEFT (ic))) &&
+ IS_BIT (OP_SYM_ETYPE (IC_RESULT (ic))) &&
+ !assignResultGenerated)
+ {
+ emitcode ("mov", "F0,c");
+ resultInF0 = TRUE;
+ }
emitcode ("mov", "a,%s", spname);
emitcode ("add", "a,#!constbyte", (-ic->parmBytes) & 0xff);
emitcode ("mov", "a,%s", spname);
emitcode ("add", "a,#!constbyte", (-ic->parmBytes) & 0xff);
emitcode ("mov", "%s,a", spname);
- }
+ }
else
for (i = 0; i < ic->parmBytes; i++)
emitcode ("dec", "%s", spname);
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 */
/*-----------------------------------------------------------------*/
{
symbol *sym = OP_SYMBOL (IC_LEFT (ic));
sym_link *ftype;
- bool switchedPSW = FALSE;
+ bool switchedPSW = FALSE;
bool fReentrant = (IFFUNC_ISREENT (sym->type) || options.stackAuto);
D (emitcode (";", "genFunction"));
emitcode (";", "-----------------------------------------");
emitcode ("", "%s:", sym->rname);
+ lineCurr->isLabel = 1;
ftype = operandType (IC_LEFT (ic));
_G.currentFunc = sym;
}
if (IFFUNC_ISISR (sym->type))
- { /* is ISR */
+ { /* is ISR */
/* now we need to restore the registers */
/* if this isr has no bank i.e. is going to
registers :-) */
if (!FUNC_REGBANK (sym->type))
{
- int i;
+ int i;
/* if this function does not call any other
function then we can be economical and
save only those registers that are used */
unsaveRBank (0, ic, FALSE);
}
}
- else
+ else
{
/* This ISR uses a non-zero bank.
*
D (emitcode (";", "genLabel"));
- emitcode ("", "!tlabeldef", (IC_LABEL (ic)->key + 100));
+ emitLabel (IC_LABEL (ic));
}
/*-----------------------------------------------------------------*/
emitcode ("rlc", "a");
emitcode ("subb", "a,acc");
while (size--)
- {
- aopPut (result, "a", offset++);
- }
+ {
+ aopPut (result, "a", offset++);
+ }
}
else
{
genIfxJump (ifx, buffer);
}
else
- {
- emitcode ("anl","a,#!constbyte",1 << (posbit & 0x07));
- }
+ {
+ emitcode ("anl","a,#!constbyte",1 << (posbit & 0x07));
+ }
goto release;
}
}
else
{
if (AOP_TYPE (left) == AOP_ACC)
- emitcode ("anl", "a,%s",
- aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ {
+ if (offset)
+ emitcode("mov", "a,b");
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("anl", "a,b");
+ aopPut (result, "a", offset);
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ aopPut (result, "a", offset);
+ }
else
{
MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
if (IS_AOP_PREG (result))
{
- emitcode ("anl", "a,%s",
- aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
+ emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
aopPut (result, "a", offset);
}
else
- emitcode ("anl", "%s,a",
- aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
+ emitcode ("anl", "%s,a", aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
}
}
}
emitcode ("setb", "c");
while (sizer--)
{
- if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
- emitcode ("anl", "a,%s",
- aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
- } else {
- 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)
{
- bool pushedB = pushB ();
- emitcode("mov", "b,a");
- MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
- emitcode("anl", "a,b");
- popB (pushedB);
+ if (offset)
+ emitcode("mov", "a,b");
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, NULL));
}
- else
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+ emitcode("anl", "a,b");
+ popB (pushedB);
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+ emitcode("anl", "a,b");
+ }
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE, NULL));
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("anl", "a,b");
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else
{
MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
- emitcode ("anl", "a,%s",
- aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
}
- }
+
emitcode ("jnz", "!tlabel", tlbl->key + 100);
offset++;
}
aopPut (result, zero, offset);
continue;
}
- D (emitcode (";", "better literal AND."));
- MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
- emitcode ("anl", "a, %s", aopGet (right, offset,
- FALSE, FALSE, DP2_RESULT_REG));
-
+ else if (AOP_TYPE (left) == AOP_ACC)
+ {
+ if (!offset)
+ {
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, NULL));
+ aopPut (result, "a", offset);
+ continue;
+ }
+ else
+ {
+ emitcode ("anl", "b,%s", aopGet (right, offset, FALSE, FALSE, NULL));
+ aopPut (result, "b", offset);
+ continue;
+ }
+ }
}
- else
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if ((AOP_TYPE(right)==AOP_REG || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+ && AOP_TYPE(left)==AOP_ACC)
{
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE (left) == AOP_ACC)
+ if (offset)
+ emitcode("mov", "a,b");
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, NULL));
+ }
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
{
- emitcode ("anl", "a,%s",
- aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+ emitcode("anl", "a,b");
+ popB (pushedB);
}
else
{
- char *rOp = aopGet (right, offset, FALSE, FALSE, NULL);
- if (!strcmp(rOp, "a") || !strcmp(rOp, "acc"))
- {
- emitcode("mov", "b,a");
- rOp = "b";
- }
-
- MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
- emitcode ("anl", "a,%s", rOp);
+ MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+ emitcode("anl", "a,b");
}
}
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("anl", "a,b");
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+ emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+ emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
aopPut (result, "a", offset);
}
}
{
if (AOP_TYPE (left) == AOP_ACC)
{
- emitcode ("orl", "a,%s",
- aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ if (offset)
+ emitcode("mov", "a,b");
+ emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE, NULL));
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("orl", "a,b");
+ aopPut (result, "a", offset);
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+ emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ aopPut (result, "a", offset);
}
else
{
emitcode ("setb", "c");
while (sizer--)
{
- if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
- emitcode ("orl", "a,%s",
- aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
- } else {
- MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
- emitcode ("orl", "a,%s",
- aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
+ 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, DP2_RESULT_REG));
+ }
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode("orl", "a,b");
+ popB (pushedB);
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode("orl", "a,b");
+ }
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("orl", "a,b");
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+ emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+ emitcode ("orl", "a,%s", aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
}
+
emitcode ("jnz", "!tlabel", tlbl->key + 100);
offset++;
}
aopPut (result, "#0xFF", offset);
continue;
}
- D (emitcode (";", "better literal OR."));
- MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
- emitcode ("orl", "a, %s",
- aopGet (right, offset,
- FALSE, FALSE, DP2_RESULT_REG));
-
}
- else
+ // faster than result <- left, orl result,right
+ // and better if result is SFR
+ 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, DP2_RESULT_REG));
+ }
+ else if (AOP_TYPE(left)==AOP_ACC)
{
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE (left) == AOP_ACC)
+ if (!offset)
{
- emitcode ("orl", "a,%s",
- aopGet (right, offset,
- FALSE, FALSE, DP2_RESULT_REG));
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode("orl", "a,b");
+ popB (pushedB);
}
else
{
- char *rOp = aopGet (right, offset, FALSE, FALSE, NULL);
-
- if (!strcmp(rOp, "a") || !strcmp(rOp, "acc"))
- {
- emitcode("mov", "b,a");
- rOp = "b";
- }
-
- MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
- emitcode ("orl", "a,%s", rOp);
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode("orl", "a,b");
}
}
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("orl", "a,b");
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+ emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+ emitcode ("orl", "a,%s", aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
aopPut (result, "a", offset);
}
_endLazyDPSEvaluation();
}
}
}
-
}
else
{
else
{
if (AOP_TYPE (left) == AOP_ACC)
- emitcode ("xrl", "a,%s",
- aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ {
+ if (offset)
+ emitcode("mov", "a,b");
+ emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("xrl", "a,b");
+ aopPut (result, "a", offset);
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+ emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ aopPut (result, "a", offset);
+ }
else
{
MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
{
MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
}
+ 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, DP2_RESULT_REG));
+ }
+ else if (AOP_TYPE(left)==AOP_ACC)
+ {
+ if (!offset)
+ {
+ bool pushedB = pushB ();
+ emitcode("mov", "b,a");
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode("xrl", "a,b");
+ popB (pushedB);
+ }
+ else
+ {
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode("xrl", "a,b");
+ }
+ }
+ else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+ {
+ MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+ MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ emitcode ("xrl", "a,b");
+ }
+ else if (aopGetUsesAcc (left, offset))
+ {
+ MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+ emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+ }
else
{
- if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
- emitcode ("xrl", "a,%s",
- aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
- } else {
- char *rOp = aopGet (right, offset, FALSE, FALSE, NULL);
- if (!strcmp(rOp, "a") || !strcmp(rOp, "acc"))
- {
- emitcode("mov", "b,a");
- rOp = "b";
- }
-
- MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
- emitcode ("xrl", "a,%s", rOp);
- }
+ MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+ emitcode ("xrl", "a,%s", aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
}
+
emitcode ("jnz", "!tlabel", tlbl->key + 100);
offset++;
}
else
{
if (!sign)
- {
- aopPut (result, l, offr);
- }
+ {
+ aopPut (result, l, offr);
+ }
else
{
/* MSB sign in acc.7 ! */
shiftL1Left2Result (left, LSB, result, LSB, shCount);
else
shiftL2Left2Result (left, LSB, result, LSB, shCount);
- }
+ }
}
#endif
shiftRLong (operand * left, int offl,
operand * result, int sign)
{
- int isSameRegs=sameRegs(AOP(left),AOP(result));
+ bool overlapping = regsInCommon (left, result) || operandsEqu(left, result);
- if (isSameRegs && offl>1) {
- // we are in big trouble, but this shouldn't happen
- werror(E_INTERNAL_ERROR, __FILE__, __LINE__);
- }
+ if (overlapping && offl>1)
+ {
+ // we are in big trouble, but this shouldn't happen
+ werror(E_INTERNAL_ERROR, __FILE__, __LINE__);
+ }
MOVA (aopGet (left, MSB32, FALSE, FALSE, NULL));
emitcode ("rrc", "a");
- if (isSameRegs && offl==MSB16) {
- emitcode ("xch",
- "a,%s",aopGet (left, MSB24, FALSE, FALSE, DP2_RESULT_REG));
- } else {
- aopPut (result, "a", MSB32);
- MOVA (aopGet (left, MSB24, FALSE, FALSE, NULL));
- }
+ if (overlapping && offl==MSB16)
+ {
+ emitcode ("xch", "a,%s", aopGet (left, MSB24, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else
+ {
+ aopPut (result, "a", MSB32 - offl);
+ MOVA (aopGet (left, MSB24, FALSE, FALSE, NULL));
+ }
emitcode ("rrc", "a");
- if (isSameRegs && offl==1) {
- emitcode ("xch", "a,%s",
- aopGet (left, MSB16, FALSE, FALSE, DP2_RESULT_REG));
- } else {
- aopPut (result, "a", MSB24);
- MOVA (aopGet (left, MSB16, FALSE, FALSE, NULL));
- }
- emitcode ("rrc", "a");
- aopPut (result, "a", MSB16 - offl);
- if (offl == LSB)
+ if (overlapping && offl==MSB16)
+ {
+ emitcode ("xch", "a,%s", aopGet (left, MSB16, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else
+ {
+ aopPut (result, "a", MSB24 - offl);
+ MOVA (aopGet (left, MSB16, FALSE, FALSE, NULL));
+ }
+
+ emitcode ("rrc", "a");
+ if (offl != LSB)
+ {
+ aopPut (result, "a", MSB16 - offl);
+ }
+ else
{
- MOVA (aopGet (left, LSB, FALSE, FALSE, NULL));
+ if (overlapping && offl==MSB16)
+ {
+ emitcode ("xch", "a,%s", aopGet (left, LSB, FALSE, FALSE, DP2_RESULT_REG));
+ }
+ else
+ {
+ aopPut (result, "a", MSB16 - offl);
+ MOVA (aopGet (left, LSB, FALSE, FALSE, NULL));
+ }
emitcode ("rrc", "a");
aopPut (result, "a", LSB);
}
}
offset++;
if (size || pi)
- emitcode ("inc", "%s", rname);
- }
+ emitcode ("inc", "%s", rname);
}
+ }
/* now some housekeeping stuff */
if (aop) /* we had to allocate for this iCode */
genFarPointerGet (operand * left,
operand * result, iCode * ic, iCode *pi)
{
- int size, offset, dopi=1;
+ int size, offset, dopi=1;
sym_link *retype = getSpec (operandType (result));
sym_link *letype = getSpec (operandType (left));
D (emitcode (";", "genFarPointerGet"););
}
/*-----------------------------------------------------------------*/
-/* genCodePointerGet - get value from code space */
+/* genCodePointerGet - get value from code space */
/*-----------------------------------------------------------------*/
static void
genCodePointerGet (operand * left,
_endLazyDPSEvaluation ();
}
pi->generated = 1;
- } else if ((OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) &&
+ } else if (IS_SYMOP(left) &&
+ (OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) &&
AOP_SIZE(result) > 1 &&
(OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
/* get the value into acc */
if (AOP_TYPE (cond) != AOP_CRY)
{
- toBoolean (cond);
+ toBoolean (cond);
}
else
{
- isbit = 1;
+ isbit = 1;
if (AOP(cond)->aopu.aop_dir)
dup = Safe_strdup(AOP(cond)->aopu.aop_dir);
}
if (popIc)
genIpop (popIc);
- /* if the condition is a bit variable */
+ /* if the condition is a bit variable */
if (isbit && dup)
genIfxJump (ic, dup);
else if (isbit && IS_ITEMP (cond) && SPIL_LOC (cond))
while (size--)
{
aopPut (IC_RESULT (ic), zero, offset++);
- }
+ }
}
goto release;
}
emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
freeAsmop (count, NULL, ic, FALSE);
emitcode ("mov", "dps,#!constbyte",0x21); /* Select DPTR2 & auto-toggle. */
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
if (fromc) {
emitcode ("clr","a");
emitcode ("movc", "a,@a+dptr");
emitcode ("addc","a,#!constbyte",0xFF);
emitcode ("mov","b,a");
emitcode ("sjmp","!tlabel",lbl->key+100);
- emitcode ("","!tlabeldef",lbl1->key+100);
+ emitLabel (lbl1);
}
emitcode ("mov", "dps,#0");
_G.dptrInUse = _G.dptr1InUse = 0;
emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
freeAsmop (count, NULL, ic, FALSE);
emitcode ("mov", "dps,#!constbyte",0x21); /* Select DPTR2 & auto-toggle. */
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
if (fromc) {
emitcode ("clr","a");
emitcode ("movc", "a,@a+dptr");
emitcode ("addc","a,#!constbyte",0xFF);
emitcode ("mov","b,a");
emitcode ("sjmp","!tlabel",lbl->key+100);
- emitcode ("","!tlabeldef",lbl1->key+100);
+ emitLabel (lbl1);
emitcode ("clr","a");
- emitcode ("","!tlabeldef",lbl2->key+100);
+ emitLabel (lbl2);
aopOp (IC_RESULT(ic), ic, FALSE,FALSE);
aopPut(IC_RESULT(ic),"a",0);
freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
emitcode ("mov", "dps,#!constbyte",0x1); /* Select DPTR2 */
emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL));
freeAsmop (count, NULL, ic, FALSE);
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
emitcode ("movx", "a,@dptr"); /* read data from port */
emitcode ("dec","dps"); /* switch to DPTR */
emitcode ("movx", "@dptr,a"); /* save into location */
emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
freeAsmop (count, NULL, ic, FALSE);
emitcode ("mov", "dps,#!constbyte",0x1); /* Select DPTR2 */
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
emitcode ("movx", "a,@dptr");
emitcode ("dec","dps"); /* switch to DPTR */
emitcode ("movx", "@dptr,a");
emitcode ("addc","a,#!constbyte",0xFF);
emitcode ("mov","b,a");
emitcode ("sjmp","!tlabel",lbl->key+100);
- emitcode ("","!tlabeldef",lbl1->key+100);
+ emitLabel (lbl1);
}
emitcode ("mov", "dps,#0");
_G.dptrInUse = _G.dptr1InUse = 0;
emitcode (";","OH JOY auto increment with djnz (very fast)");
emitcode ("mov", "dps,#!constbyte",0x0); /* Select DPTR */
emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL));
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
emitcode ("movx", "a,@dptr"); /* read data from port */
emitcode ("inc","dps"); /* switch to DPTR2 */
emitcode ("movx", "@dptr,a"); /* save into location */
emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
freeAsmop (count, NULL, ic, FALSE);
emitcode ("mov", "dps,#!constbyte",0x0); /* Select DPTR */
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
emitcode ("movx", "a,@dptr");
emitcode ("inc", "dptr");
emitcode ("inc","dps"); /* switch to DPTR2 */
emitcode ("addc","a,#!constbyte",0xFF);
emitcode ("mov","b,a");
emitcode ("sjmp","!tlabel",lbl->key+100);
- emitcode ("","!tlabeldef",lbl1->key+100);
+ emitLabel (lbl1);
}
emitcode ("mov", "dps,#0");
_G.dptrInUse = _G.dptr1InUse = 0;
l = aopGet(val, 0, FALSE, FALSE, NULL);
emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL));
MOVA(l);
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
emitcode ("movx", "@dptr,a");
emitcode ("inc", "dptr");
emitcode ("djnz","b,!tlabel",lbl->key+100);
emitcode ("mov","_ap,%s",aopGet (count, 0, FALSE, TRUE, NULL));
emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
MOVA (aopGet(val, 0, FALSE, FALSE, NULL));
emitcode ("movx", "@dptr,a");
emitcode ("inc", "dptr");
emitcode ("addc","a,#!constbyte",0xFF);
emitcode ("mov","b,a");
emitcode ("sjmp","!tlabel",lbl->key+100);
- emitcode ("","!tlabeldef",lbl1->key+100);
+ emitLabel (lbl1);
}
freeAsmop (count, NULL, ic, FALSE);
unsavermask(rsave);
aopPut(IC_RESULT(ic),"r3",1);
}
freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
unsavermask(rsave);
}
emitcode ("jz","!tlabel",lbl->key+100);
emitcode ("mov","r2,#!constbyte",0xff);
emitcode ("mov","r3,#!constbyte",0xff);
- emitcode ("","!tlabeldef",lbl->key+100);
+ emitLabel (lbl);
/* we don't care about the pointer : we just save the handle */
rsym = OP_SYMBOL(IC_RESULT(ic));
if (rsym->liveFrom != rsym->liveTo) {
if (AOP_TYPE(IC_RESULT(ic)) != AOP_STR) {
_startLazyDPSEvaluation ();
- aopPut(IC_RESULT(ic),"dpl",0);
- aopPut(IC_RESULT(ic),"dph",1);
- aopPut(IC_RESULT(ic),"dpx",2);
+ aopPut(IC_RESULT(ic),"dpl",0);
+ aopPut(IC_RESULT(ic),"dph",1);
+ aopPut(IC_RESULT(ic),"dpx",2);
_endLazyDPSEvaluation ();
#if 1
/* print the allocation information */
if (allocInfo && currFunc)
- printAllocInfo (currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutBuf);
#endif
/* if debug information required */
if (options.debug && currFunc)
cln = ic->lineno;
}
if (options.iCodeInAsm) {
- emitcode("", ";ic:%d: %s", ic->key, printILine(ic));
+ char *iLine = printILine(ic);
+ emitcode("", ";ic:%d: %s", ic->key, iLine);
+ dbuf_free(iLine);
}
/* if the result is marked as
spilt and rematerializable or code for
#endif
default:
- ic = ic;
- }
+ /* This should never happen, right? */
+ fprintf(stderr, "*** Probable error: unsupported op 0x%x (%c) in %s @ %d\n",
+ ic->op, ic->op, __FILE__, __LINE__);
+ ic = ic;
+ }
}
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
return;
}