X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fxa51%2Fgen.c;h=ecd1867ca027f20796cd0b5f98707af236b2902d;hb=195ee3f3ee25ce2c5f2a59fbd2779c4cb80527c3;hp=25dcc5dc550166b7925540f42bca22a943695e41;hpb=471d04e308e77523505e67ef7722ab94e7ec385a;p=fw%2Fsdcc diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 25dcc5dc..ecd1867c 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -35,23 +35,6 @@ #include "SDCCglobl.h" #include "newalloc.h" -#ifdef HAVE_SYS_ISA_DEFS_H -#include -#else -#ifdef HAVE_MACHINE_ENDIAN_H -#include -#else -#ifdef HAVE_ENDIAN_H -#include -#else -#if !defined(__BORLANDC__) && !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__CYGWIN__) -#warning "Cannot determine ENDIANESS of this machine assuming LITTLE_ENDIAN" -#warning "If you running sdcc on an INTEL 80x86 Platform you are okay" -#endif -#endif -#endif -#endif - #include "common.h" #include "SDCCpeeph.h" #include "ralloc.h" @@ -114,7 +97,7 @@ void bailOut (char *mesg) { static void emitcode (char *inst, char *fmt,...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; va_start (ap, fmt); @@ -129,7 +112,7 @@ static void emitcode (char *inst, char *fmt,...) { else vsprintf (lb, fmt, ap); - while (isspace ((int)*lbp)) + while (isspace (*lbp)) lbp++; if (lbp && *lbp) @@ -141,6 +124,19 @@ static void emitcode (char *inst, char *fmt,...) { va_end (ap); } +/*-----------------------------------------------------------------*/ +/* xa51_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +xa51_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + emitcode ("", "%s ==.", debugSym); + _G.debugLine = 0; +} + + char *getStackOffset(int stack) { static char gsoBuf[1024]; sprintf (gsoBuf, "r7+(%d%+d%+d)", stack, @@ -213,9 +209,9 @@ static asmop *aopForSym(symbol *sym, sprintf (aop->name[0], "r0"); return aop; case 3: - emitcode ("mov.w", "r0,[%s] ;aopForSym:stack:3", getStackOffset(sym->stack)); + emitcode ("mov.w", "r0,[%s] ;aopForSym:stack:3.w", getStackOffset(sym->stack)); sprintf (aop->name[0], "r0"); - emitcode ("mov.b", "r1l,[%s] ;aopForSym:stack:3", getStackOffset(sym->stack+2)); + emitcode ("mov.b", "r1l,[%s] ;aopForSym:stack:3.b", getStackOffset(sym->stack+2)); sprintf (aop->name[1], "r1l"); return aop; case 4: @@ -374,9 +370,9 @@ static asmop *aopForVal(operand *op) { sprintf (aop->name[1], "#0"); break; case 4: - sprintf (aop->name[0], "#0x%04lx", + sprintf (aop->name[0], "#0x%04x", SPEC_CVAL(operandType(op)).v_ulong & 0xffff); - sprintf (aop->name[1], "#0x%04lx", + sprintf (aop->name[1], "#0x%04x", SPEC_CVAL(operandType(op)).v_ulong >> 16); break; default: @@ -476,7 +472,7 @@ char *opRegName(operand *op, int offset, char *opName, bool decorate) { break; case V_INT: if (SPEC_LONG(OP_VALUE(op)->type)) { - sprintf (opName, "#%s0x%02lx", decorate?"(long)":"", + sprintf (opName, "#%s0x%02x", decorate?"(long)":"", SPEC_CVAL(OP_VALUE(op)->type).v_long); } else { sprintf (opName, "#%s0x%02x", decorate?"(int)":"", @@ -846,6 +842,8 @@ genEndFunction (iCode * ic) if (IFFUNC_ISNAKED(sym->type)) { emitcode(";", "naked function: no epilogue."); + if (options.debug && currFunc) + debugFile->writeEndFunction (currFunc, ic, 0); return; } @@ -854,6 +852,10 @@ genEndFunction (iCode * ic) emitcode ("add", "r7,#%d\t; release stack space for locals", sym->stack); } + if (options.debug && currFunc) { + debugFile->writeEndFunction (currFunc, ic, 1); + } + if (IFFUNC_ISISR(sym->type)) { emitcode ("reti", ""); } else { @@ -1105,15 +1107,16 @@ static void genCmp (iCode * ic, char *trueInstr, char *falseInstr) { char *instr; int jlbl; - if (!ifx) { - bailOut("genCmp: no ifx"); - } else { - ifx->generated=1; - } size=aopOp(left, TRUE, TRUE); aopOp(right, !aopIsPtr(left), TRUE); + if (size==1) { + instr="cmp.b"; + } else { + instr="cmp.w"; + } + if (IC_TRUE(ifx)) { isTrue=TRUE; jlbl=IC_TRUE(ifx)->key+100; @@ -1121,17 +1124,25 @@ static void genCmp (iCode * ic, char *trueInstr, char *falseInstr) { isTrue=FALSE; jlbl=IC_FALSE(ifx)->key+100; } - - if (size==1) { - instr="cmp.b"; + + if (!ifx) { + aopOp(IC_RESULT(ic), !aopIsPtr(left), TRUE); + jlbl=newiTempLabel(NULL)->key+100; + emitcode("mov", "%s,#-1", AOP_NAME(IC_RESULT(ic))[0]); + emitcode(instr, "%s,%s", AOP_NAME(left)[0], AOP_NAME(right)[0]); + emitcode(isTrue ? trueInstr : falseInstr, "%05d$", jlbl); + emitcode("cpl", "%s", AOP_NAME(IC_RESULT(ic))[0]); + emitcode("", "%05d$:", jlbl); } else { - instr="cmp.w"; + emitcode(instr, "%s,%s", AOP_NAME(left)[0], AOP_NAME(right)[0]); + emitcode(isTrue ? trueInstr : falseInstr, "%05d$", jlbl); + ifx->generated=1; } - emitcode(instr, "%s,%s", AOP_NAME(left)[0], AOP_NAME(right)[0]); - emitcode(isTrue ? trueInstr : falseInstr, "%05d$", jlbl); + if (size>2) { bailOut("genCmp: size > 2"); } + } /*-----------------------------------------------------------------*/ @@ -1196,7 +1207,7 @@ static iCode *hasInc (operand *op, iCode *ic, int osize) { } } /* if the operand used or deffed */ - if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) { + if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key) { return NULL; } /* if GOTO or IFX */ @@ -1897,58 +1908,65 @@ static void genReceive (iCode * ic) { printIc (0, "genReceive", ic, 1,0,0); } +/*-----------------------------------------------------------------*/ +/* genDummyRead - generate code for dummy read of volatiles */ +/*-----------------------------------------------------------------*/ +static void +genDummyRead (iCode * ic) +{ + emitcode ("; genDummyRead",""); + + ic = ic; +} + /*-----------------------------------------------------------------*/ /* gen51Code - generate code for 8051 based controllers */ /*-----------------------------------------------------------------*/ void genXA51Code (iCode * lic) { iCode *ic; int cln = 0; - + lineHead = lineCurr = NULL; - + /* if debug information required */ if (options.debug && currFunc) { - cdbSymbol (currFunc, cdbFile, FALSE, TRUE); - _G.debugLine = 1; - if (IS_STATIC (currFunc->etype)) - emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "G$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeFunction (currFunc, lic); } - + for (ic = lic; ic; ic = ic->next) { if (ic->lineno && cln != ic->lineno) { if (options.debug) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), ic->lineno, - ic->level, ic->block); - _G.debugLine = 0; + debugFile->writeCLine (ic); + } + if (!options.noCcodeInAsm) { + emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno, + printCLine(ic->filename, ic->lineno)); } - emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno, - printCLine(ic->filename, ic->lineno)); cln = ic->lineno; } + if (options.iCodeInAsm) { + emitcode("", ";ic:%d: %s", ic->key, printILine(ic)); + } + /* if the result is marked as spilt and rematerializable or code for this has already been generated then do nothing */ if (resultRemat (ic) || ic->generated) continue; - + /* depending on the operation */ switch (ic->op) { case '!': genNot (ic); break; - + case '~': genCpl (ic); break; - + case UNARYMINUS: genUminus (ic); break; @@ -2074,7 +2092,7 @@ void genXA51Code (iCode * lic) { case RLC: genRLC (ic); break; - + case GETHBIT: genGetHbit (ic); break; @@ -2117,22 +2135,26 @@ void genXA51Code (iCode * lic) { case RECEIVE: genReceive (ic); break; - + case SEND: addSet (&_G.sendSet, ic); break; - + + case DUMMY_READ_VOLATILE: + genDummyRead (ic); + break; + default: ic = ic; } } - - + + /* now we are ready to call the peep hole optimizer */ if (!options.nopeep) peepHole (&lineHead); - + /* now do the actual printing */ printLine (lineHead, codeOutFile); return;