-------------------------------------------------------------------------*/
/* Use the D macro for basic (unobtrusive) debugging messages */
-//#define D(x)
-#define D(x) x
+#define D(x) do if (options.verboseAsm) {x;} while(0)
/* Use the DD macro for detailed debugging messages */
#define DD(x)
//#define DD(x) x
extern int hc08_ptrRegReq;
extern int hc08_nRegs;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
//static void saveRBank (int, iCode *, bool);
static bool operandsEqu (operand * op1, operand * op2);
static void loadRegFromConst (regs *reg, char *c);
emitLabel (symbol *tlbl)
{
emitcode ("", "%05d$:", (tlbl->key +100));
+ lineCurr->isLabel = 1;
}
/*-----------------------------------------------------------------*/
if (sym1 == sym2)
return TRUE;
+ /* if they have the same rname */
if (sym1->rname[0] && sym2->rname[0]
&& strcmp (sym1->rname, sym2->rname) == 0)
return TRUE;
emitcode ("tsta", "");
emitcode ("bne", "%05d$", (tlbl->key + 100));
emitcode ("tstx", "");
- emitcode ("", "%05d$:", (tlbl->key + 100));
+ emitLabel (tlbl);
}
else
{
emitcode ("tst", "%s", aopAdrStr (aop, 0, FALSE));
emitcode ("bne", "%05d$", (tlbl->key + 100));
emitcode ("tst", "%s", aopAdrStr (aop, 1, FALSE));
- emitcode ("", "%05d$:", (tlbl->key + 100));
+ emitLabel (tlbl);
break;
}
}
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.stackOfs = 0;
debugFile->writeLabel(IC_LABEL (ic), ic);
- emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100));
+ emitLabel (IC_LABEL (ic));
}
return EQ_OP; /* shouldn't happen, but need to return something */
}
-/* compile only if the debugging macro D is enabled */
-#if (D(1) -0)
+/*------------------------------------------------------------------*/
+/* nameCmp : helper function for human readable debug output */
+/*------------------------------------------------------------------*/
static char *
nameCmp (int opcode)
{
return "invalid";
}
}
-#endif
/*------------------------------------------------------------------*/
/* branchInstCmp : returns the conditional branch instruction that */
genInline (iCode * ic)
{
char *buffer, *bp, *bp1;
+ bool inComment = FALSE;
D(emitcode ("; genInline",""));
_G.inLine += (!options.asmpeep);
- buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
- strcpy (buffer, IC_INLINE (ic));
+ buffer = bp = bp1 = Safe_strdup (IC_INLINE(ic));
/* emit each line as a code */
while (*bp)
{
- if (*bp == '\n')
- {
- *bp++ = '\0';
- /* emitcode (bp1, ""); */
- emitinline (ic, bp1);
- bp1 = bp;
- }
- else
- {
- if (*bp == ':')
- {
- bp++;
- *bp = '\0';
- bp++;
- emitcode (bp1, "");
- bp1 = bp;
- }
- else
- bp++;
- }
+ switch (*bp)
+ {
+ case ';':
+ inComment = TRUE;
+ ++bp;
+ break;
+
+ case '\n':
+ inComment = FALSE;
+ *bp++ = '\0';
+ emitinline (ic, bp1);
+ bp1 = bp;
+ break;
+
+ default:
+ /* Add \n for labels, not dirs such as c:\mydir */
+ if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
+ {
+ ++bp;
+ *bp = '\0';
+ ++bp;
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ ++bp;
+ break;
+ }
}
if (bp1 != bp)
- {
- /* emitcode (bp1, ""); */
- emitinline (ic, bp1);
- }
- /* emitcode("",buffer); */
+ emitinline (ic, bp1);
+
+ Safe_free (buffer);
+
_G.inLine -= (!options.asmpeep);
}
hc08_freeReg (hc08_reg_a);
break;
case 2: /* swap bytes in a word */
- if (operandsEqu (left, result))
+ if (operandsEqu (left, result) || sameRegs (AOP (left), AOP (result)))
{
loadRegFromAop (hc08_reg_a, AOP (left), 0);
hc08_useReg (hc08_reg_a);
/* print the allocation information */
if (allocInfo && currFunc)
- printAllocInfo (currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutBuf);
/* if debug information required */
if (options.debug && currFunc)
{
if (options.iCodeInAsm) {
char regsInUse[80];
int i;
+ char *iLine;
for (i=0; i<6; i++) {
sprintf (®sInUse[i],
"%c", ic->riu & (1<<i) ? i+'0' : '-');
}
regsInUse[i]=0;
+ 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
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
return;
}