X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmcs51%2Fgen.c;h=a2841f70701081452a7f27e7ba5da925a466433a;hb=3062f96ccb55d1d05caf9c8782f4961f87b341ce;hp=576d529e25ab66efa3e117a09f809707e0f561dc;hpb=0085df3b97e24b41738b93441d0aa012c618cba9;p=fw%2Fsdcc diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 576d529e..a2841f70 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -42,6 +42,7 @@ #include "SDCCpeeph.h" #include "ralloc.h" #include "gen.h" +#include "dbuf_string.h" char *aopLiteral (value * val, int offset); char *aopLiteralLong (value * val, int offset, int size); @@ -117,7 +118,7 @@ static char *rb1regs[] = { "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7" }; -extern FILE *codeOutFile; +extern struct dbuf_s *codeOutBuf; static void saveRBank (int, iCode *, bool); #define RESULTONSTACK(x) \ @@ -149,32 +150,33 @@ static unsigned char SRMask[] = /* 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); + dbuf_append_char (&dbuf, '\t'); + dbuf_tvprintf (&dbuf, fmt, ap); } - - tvsprintf (lb + strlen(lb), sizeof(lb) - strlen(lb), 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++; @@ -192,12 +194,15 @@ emitcode (char *inst, const char *fmt,...) lineCurr->ic = _G.current_iCode; lineCurr->isComment = (*lbp==';'); va_end (ap); + + dbuf_destroy(&dbuf); } static void emitLabel (symbol *tlbl) { emitcode ("", "%05d$:", tlbl->key + 100); + lineCurr->isLabel = 1; } /*-----------------------------------------------------------------*/ @@ -3206,12 +3211,6 @@ resultRemat (iCode * ic) 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 */ /*-----------------------------------------------------------------*/ @@ -3255,6 +3254,7 @@ genFunction (iCode * ic) emitcode (";", "-----------------------------------------"); emitcode ("", "%s:", sym->rname); + lineCurr->isLabel = 1; ftype = operandType (IC_LEFT (ic)); _G.currentFunc = sym; @@ -4020,7 +4020,7 @@ genLabel (iCode * ic) if (IC_LABEL (ic) == entryLabel) return; - emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100)); + emitLabel (IC_LABEL (ic)); } /*-----------------------------------------------------------------*/ @@ -11714,7 +11714,7 @@ gen51Code (iCode * lic) /* print the allocation information */ if (allocInfo && currFunc) - printAllocInfo (currFunc, codeOutFile); + printAllocInfo (currFunc, codeOutBuf); /* if debug information required */ if (options.debug && currFunc) { @@ -11753,6 +11753,7 @@ gen51Code (iCode * lic) if (options.iCodeInAsm) { char regsInUse[80]; int i; + char *iLine; #if 0 for (i=0; i<8; i++) { @@ -11769,7 +11770,9 @@ gen51Code (iCode * lic) } #endif } + 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 @@ -12008,6 +12011,6 @@ gen51Code (iCode * lic) peepHole (&lineHead); /* now do the actual printing */ - printLine (lineHead, codeOutFile); + printLine (lineHead, codeOutBuf); return; }