X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmcs51%2Fgen.c;h=a2841f70701081452a7f27e7ba5da925a466433a;hb=3062f96ccb55d1d05caf9c8782f4961f87b341ce;hp=1f0107050d4ae11ea862a81249af04999c8e2c1f;hpb=b39b9a851fa0122a6fb71bb1e40badc28f6192f0;p=fw%2Fsdcc diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 1f010705..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; } /*-----------------------------------------------------------------*/ @@ -244,9 +249,9 @@ movb (const char *x) static void movc (const char *s) { - if (s == zero) + if (!strcmp (s, zero)) CLRC; - else if (s == one) + else if (!strcmp (s, one)) SETC; else if (strcmp (s, "c")) {/* it's not in carry already */ @@ -649,7 +654,7 @@ aopForSym (iCode * ic, symbol * sym, bool result) if (accuse) emitcode ("push", "acc"); emitcode ("mov", "a,%s", SYM_BP (sym)); - emitcode ("add", "a,#0x%02x", offset); + emitcode ("add", "a,#0x%02x", offset & 0xff); emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name); if (accuse) emitcode ("pop", "acc"); @@ -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; @@ -3616,14 +3616,14 @@ genFunction (iCode * ic) if (i > 3 && accIsFree) { emitcode ("mov", "a,_spx"); - emitcode ("add", "a,#0x%02x", i); + emitcode ("add", "a,#0x%02x", i & 0xff); emitcode ("mov", "_spx,a"); } else if (i > 5) { emitcode ("push", "acc"); emitcode ("mov", "a,_spx"); - emitcode ("add", "a,#0x%02x", i); + emitcode ("add", "a,#0x%02x", i & 0xff); emitcode ("mov", "_spx,a"); emitcode ("pop", "acc"); } @@ -4020,7 +4020,7 @@ genLabel (iCode * ic) if (IC_LABEL (ic) == entryLabel) return; - emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100)); + emitLabel (IC_LABEL (ic)); } /*-----------------------------------------------------------------*/ @@ -10912,7 +10912,7 @@ genAddrOf (iCode * ic) else { emitcode ("mov", "a,%s", SYM_BP (sym)); - emitcode ("add", "a,#0x%02x", stack_offset); + emitcode ("add", "a,#0x%02x", stack_offset & 0xff); aopPut (IC_RESULT (ic), "a", 0); } } @@ -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; }