-------------------------------------------------------------------------*/
//#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;
}
/*-----------------------------------------------------------------*/
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;
D (emitcode (";", "genLabel"));
- emitcode ("", "!tlabeldef", (IC_LABEL (ic)->key + 100));
+ emitLabel (IC_LABEL (ic));
}
/*-----------------------------------------------------------------*/
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 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;
}