X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Favr%2Fgen.c;h=59dbabcebc9e0eddf6839aaa1a806be213999ade;hb=976b6c5e009dbfffa9e8281f1af2b17a959de5ad;hp=62329c5086a1f303d9cc3375205f852cfd50d8d6;hpb=3d58cb9a66f19d279fd1643f531a3f2f6cc4dcb3;p=fw%2Fsdcc diff --git a/src/avr/gen.c b/src/avr/gen.c index 62329c50..59dbabce 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- - avrgen.c - source file for code generation for ATMEL AVR + gen.c - source file for code generation for ATMEL AVR Written By - Sandeep Dutta . sandeep.dutta@usa.net (2000) @@ -249,7 +249,7 @@ emitcode (char *inst, char *fmt, ...) else vsprintf (lb, fmt, ap); - while (isspace (*lbp)) + while (isspace ((unsigned char)*lbp)) lbp++; if (lbp && *lbp) @@ -261,6 +261,18 @@ emitcode (char *inst, char *fmt, ...) va_end (ap); } +/*-----------------------------------------------------------------*/ +/* avr_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +avr_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + emitcode ("", "%s ==.", debugSym); + _G.debugLine = 0; +} + /*-----------------------------------------------------------------*/ /* hasInc - operand is incremented before any other use */ /*-----------------------------------------------------------------*/ @@ -284,7 +296,7 @@ hasInc (operand *op, iCode *ic) return lic; } /* 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; } lic = lic->next; @@ -746,6 +758,8 @@ aopOp (operand * op, iCode * ic, bool result) b) has a spill location */ if (sym->isspilt || sym->nRegs == 0) { + asmop *oldAsmOp = NULL; + /* rematerialize it NOW */ if (sym->remat) { sym->aop = op->aop = aop = aopForRemat (sym); @@ -769,10 +783,15 @@ aopOp (operand * op, iCode * ic, bool result) /* else spill location */ if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) { /* force a new aop if sizes differ */ + oldAsmOp = sym->usl.spillLoc->aop; sym->usl.spillLoc->aop = NULL; } sym->aop = op->aop = aop = aopForSym (ic, sym->usl.spillLoc, result); + if (getSize(sym->type) != getSize(sym->usl.spillLoc->type)) { + /* Don't reuse the new aop, go with the last one */ + sym->usl.spillLoc->aop = oldAsmOp; + } aop->size = getSize (sym->type); return; } @@ -1029,7 +1048,7 @@ aopPut (asmop * aop, char *s, int offset) break; case AOP_REG: - if (toupper (*s) != 'R') { + if (toupper ((unsigned char)*s) != 'R') { if (s == zero) { emitcode ("clr", "%s", aop->aopu.aop_reg[offset]->name); @@ -1097,7 +1116,7 @@ aopPut (asmop * aop, char *s, int offset) case AOP_CRY: /* if used only for a condition code check */ - assert (toupper (*s) == 'R'); + assert (toupper ((unsigned char)*s) == 'R'); if (offset == 0) { emitcode ("xrl", "r0,r0"); emitcode ("cpi", "%s,0", s); @@ -1533,7 +1552,7 @@ static void genCall (iCode * ic) { - /* if send set is not empty the assign */ + /* if send set is not empty then assign */ if (_G.sendSet) { iCode *sic; int rnum = 16; @@ -1815,6 +1834,10 @@ genEndFunction (iCode * ic) if (IFFUNC_ISCRITICAL (sym->type)) emitcode ("sti", ""); + if (options.debug && currFunc) { + debugFile->writeEndFunction (currFunc, ic, 1); + } + if (IFFUNC_ISISR (sym->type)) { emitcode ("rti", ""); } @@ -2663,7 +2686,7 @@ genBitWise (iCode * ic, iCode * ifx, int bitop) (int) floatFromVal (AOP (right)->aopu. aop_lit); int p2 = powof2 (lit); - if (bitop == AVR_AND && p2) { /* right side is a power of 2 */ + if (bitop == AVR_AND && (p2 >= 0)) { /* right side is a power of 2 */ l = aopGet (AOP (left), p2 / 8); if (IC_TRUE (ifx)) { emitcode ("sbrc", "%s,%d", l, @@ -4955,7 +4978,7 @@ genCast (iCode * ic) exit(1); } - sprintf(gpValStr, "#0x%d", gpVal); + sprintf(gpValStr, "#0x%x", gpVal); aopPut (AOP (result), gpValStr, GPTRSIZE - 1); } goto release; @@ -5086,6 +5109,18 @@ genReceive (iCode * ic) freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); } +/*-----------------------------------------------------------------*/ +/* genDummyRead - generate code for dummy read of volatiles */ +/*-----------------------------------------------------------------*/ +static void +genDummyRead (iCode * ic) +{ + emitcode ("; genDummyRead",""); + emitcode ("; not implemented",""); + + ic = ic; +} + /*-----------------------------------------------------------------*/ /* gen51Code - generate code for 8051 based controllers */ /*-----------------------------------------------------------------*/ @@ -5101,12 +5136,8 @@ genAVRCode (iCode * lic) if (allocInfo) printAllocInfo (currFunc, codeOutFile); /* if debug information required */ - /* if (options.debug && currFunc) { */ - if (currFunc) { - cdbSymbol (currFunc, cdbFile, FALSE, TRUE); - _G.debugLine = 1; -/* emitcode ("", ".type %s,@function", currFunc->name); */ - _G.debugLine = 0; + if (options.debug && currFunc) { + debugFile->writeFunction (currFunc, lic); } /* stack pointer name */ spname = "sp"; @@ -5116,11 +5147,7 @@ genAVRCode (iCode * lic) if (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); } emitcode (";", "%s %d", ic->filename, ic->lineno); cln = ic->lineno; @@ -5317,6 +5344,10 @@ genAVRCode (iCode * lic) addSet (&_G.sendSet, ic); break; + case DUMMY_READ_VOLATILE: + genDummyRead (ic); + break; + default: ic = ic; }