X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fpic%2Fgen.c;h=169fc0f3d620bc2bdb6b5aab1db0acde3dc40e94;hb=a8bb05787ea1db826c32df658be9ac091ad1cf76;hp=9a221d2572e7dc313a9e59175548df408d33b20b;hpb=52eb93f73f643bc7175d8f6ea06ec78b1026f001;p=fw%2Fsdcc diff --git a/src/pic/gen.c b/src/pic/gen.c index 9a221d25..169fc0f3 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -5,7 +5,7 @@ and - Jean-Louis VERN.jlvern@writeme.com (1999) Bug Fixes - Wojciech Stryjewski wstryj1@tiger.lsu.edu (1999 v2.1.9a) PIC port - Scott Dattalo scott@dattalo.com (2000) - cont'd - Raphael Neider rneider@web.de (2005) + cont'd - Raphael Neider (2005) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -34,8 +34,15 @@ #include #include #include +#ifndef __sun__ +#if defined(_MSC_VER) + #include "pstdint.h" +#else + #include +#endif +#endif #include "SDCCglobl.h" -#include "newalloc.h" +#include "newalloc.h" #include "common.h" #include "SDCCpeeph.h" @@ -48,6 +55,10 @@ #define GPTRTAG_DATA 0x00 #define GPTRTAG_CODE 0x80 +/* The PIC port(s) need not differentiate between POINTER and FPOINTER. */ +#define PIC_IS_DATA_PTR(x) (IS_DATA_PTR(x) || IS_FARPTR(x)) +#define PIC_IS_FARPTR(x) (PIC_IS_DATA_PTR(x)) + extern void genUMult8X8_16 (operand *, operand *,operand *,pCodeOpReg *); extern void genSMult8X8_16 (operand *, operand *,operand *,pCodeOpReg *); void genMult8X8_8 (operand *, operand *,operand *); @@ -55,6 +66,7 @@ extern void printpBlock(FILE *of, pBlock *pb); static int labelOffset=0; extern int debug_verbose; +extern int pic14_hasInterrupt; //static int optimized_for_speed = 0; /* max_key keeps track of the largest label number used in @@ -185,7 +197,7 @@ void DEBUGpic14_emitcode (char *inst,char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; - unsigned char *lbp = lb; + unsigned char *lbp = (unsigned char *)lb; if(!debug_verbose && !options.debug) return; @@ -288,7 +300,7 @@ void pic14_emitcode (char *inst,char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; - unsigned char *lbp = lb; + unsigned char *lbp = (unsigned char *)lb; va_start(ap,fmt); @@ -937,9 +949,12 @@ void aopOp (operand *op, iCode *ic, bool result) /* else spill location */ if (sym->usl.spillLoc) { + asmop *oldAsmOp = NULL; + if (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; } DEBUGpic14_emitcode(";","%s %d %s sym->rname = %s, offset %d", @@ -948,6 +963,11 @@ void aopOp (operand *op, iCode *ic, bool result) sym->rname, sym->usl.spillLoc->offset); sym->aop = op->aop = aop = newAsmop(AOP_PCODE); + 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->aopu.pcop = popGetImmd(sym->usl.spillLoc->rname,0,sym->usl.spillLoc->offset); aop->aopu.pcop = popRegFromString(sym->usl.spillLoc->rname, getSize(sym->type), @@ -2591,7 +2611,7 @@ static void genCall (iCode *ic) { sym_link *dtype; symbol *sym; - unsigned char *name; + char *name; int isExtern; FENTRY; @@ -2762,7 +2782,7 @@ static void genPcall (iCode *ic) */ emitpcode(POC_CALL,popGetLabel(albl->key)); pcop = popGetLabel(blbl->key); - emitpcode(POC_PAGESEL,popGetWithString(pcop->name,0)); /* Must restore PCLATH before goto, without destroying W */ + emitpcode(POC_PAGESEL,pcop); /* Must restore PCLATH before goto, without destroying W */ emitpcode(POC_GOTO,pcop); emitpLabel(albl->key); @@ -2921,6 +2941,7 @@ static void genFunction (iCode *ic) emitpcode(POC_CLRF, popCopyReg(&pc_pclath));/* during an interrupt PCLATH must be cleared before a goto or call statement */ pBlockConvert2ISR(pb); + pic14_hasInterrupt = 1; #if 0 if (!inExcludeList("acc")) pic14_emitcode ("push","acc"); @@ -8450,6 +8471,7 @@ emitPtrByteGet (operand *src, int p_type, bool alreadyAddressed) switch (p_type) { case POINTER: + case FPOINTER: if (!alreadyAddressed) setup_fsr (src); emitpcode(POC_MOVFW, popCopyReg (&pc_fsr)); break; @@ -8491,6 +8513,7 @@ emitPtrByteSet (operand *dst, int p_type, bool alreadyAddressed) switch (p_type) { case POINTER: + case FPOINTER: if (!alreadyAddressed) setup_fsr (dst); emitpcode(POC_MOVWF, popCopyReg (&pc_fsr)); break; @@ -8559,6 +8582,7 @@ static void genUnpackBits (operand *result, operand *left, int ptype, iCode *ifx break; case POINTER: + case FPOINTER: case GPOINTER: case CPOINTER: emitPtrByteGet (left, ptype, FALSE); @@ -8596,6 +8620,7 @@ static void genUnpackBits (operand *result, operand *left, int ptype, iCode *ifx break; case POINTER: + case FPOINTER: case GPOINTER: case CPOINTER: emitPtrByteGet (left, ptype, FALSE); @@ -8692,7 +8717,7 @@ static void genNearPointerGet (operand *left, lower 128 bytes of space */ if (AOP_TYPE(left) == AOP_PCODE && //AOP_TYPE(left) == AOP_IMMD && !IS_BITVAR(retype) && - DCL_TYPE(ltype) == POINTER) { + PIC_IS_DATA_PTR(ltype)) { genDataPointerGet (left,result,ic); return ; } @@ -9126,6 +9151,7 @@ static void genPointerGet (iCode *ic) switch (p_type) { case POINTER: + case FPOINTER: //case IPOINTER: genNearPointerGet (left,result,ic); break; @@ -9192,6 +9218,7 @@ static void genPackBits(sym_link *etype,operand *result,operand *right,int p_typ break; case POINTER: + case FPOINTER: setup_fsr (result); emitpcode(lit?POC_BSF:POC_BCF,newpCodeOpBit(PCOP(&pc_indf)->name,bstr,0)); break; @@ -9231,6 +9258,7 @@ static void genPackBits(sym_link *etype,operand *result,operand *right,int p_typ break; case POINTER: + case FPOINTER: case GPOINTER: emitPtrByteGet(result, p_type, FALSE); if ((litval|mask) != 0x00ff) @@ -9267,6 +9295,7 @@ static void genPackBits(sym_link *etype,operand *result,operand *right,int p_typ break; case POINTER: + case FPOINTER: case GPOINTER: emitPtrByteGet (result, p_type, FALSE); emitpcode(POC_BTFSS, newpCodeOpBit (aopGet(AOP(right), 0, FALSE, FALSE), bstr, 0)); @@ -9308,6 +9337,7 @@ static void genPackBits(sym_link *etype,operand *result,operand *right,int p_typ break; case POINTER: + case FPOINTER: case GPOINTER: emitPtrByteGet (result, p_type, FALSE); emitpcode(POC_ANDLW, popGetLit (mask)); @@ -9338,10 +9368,10 @@ bitpatternFromVal (value *val) { union { float d; - unsigned long l; + uint32_t l; } float_long; - assert (sizeof (float) == sizeof (long)); + assert (sizeof (float) == sizeof (uint32_t)); //fprintf (stderr, "%s:%u(%s): val=%lf, type: %d, etype: %d\n", __FILE__, __LINE__, __FUNCTION__, floatFromVal(val), SPEC_NOUN(val->type), SPEC_NOUN(val->etype)); @@ -9449,7 +9479,7 @@ static void genNearPointerSet (operand *right, in data space & not a bit variable */ //if (AOP_TYPE(result) == AOP_IMMD && if (AOP_TYPE(result) == AOP_PCODE && - DCL_TYPE(ptype) == POINTER && + PIC_IS_DATA_PTR(ptype) && !IS_BITVAR (retype) && !IS_BITVAR (letype)) { genDataPointerSet (right,result,ic); @@ -9774,6 +9804,7 @@ static void genPointerSet (iCode *ic) switch (p_type) { case POINTER: + case FPOINTER: //case IPOINTER: genNearPointerSet (right,result,ic); break; @@ -9814,8 +9845,6 @@ static void genIfx (iCode *ic, iCode *popIc) pic14_toBoolean(cond); else isbit = 1; - /* the result is now in the accumulator */ - freeAsmop(cond,NULL,ic,TRUE); /* if there was something to be popped then do it */ if (popIc) @@ -9823,11 +9852,32 @@ static void genIfx (iCode *ic, iCode *popIc) if (isbit) { - assert (!"genIfx not implemented for bit variables..."); + /* This assumes that CARRY is set iff cond is true */ + if (IC_TRUE(ic)) + { + assert (!IC_FALSE(ic)); + emitpcode(POC_BTFSC, popGet(AOP(cond), 0)); + //emitSKPNC; + emitpcode(POC_GOTO, popGetLabel(IC_TRUE(ic)->key)); + } else { + assert (IC_FALSE(ic)); + emitpcode(POC_BTFSS, popGet(AOP(cond), 0)); + //emitSKPC; + emitpcode(POC_GOTO, popGetLabel(IC_FALSE(ic)->key)); + } + if (0) + { + static int hasWarned = 0; + if (!hasWarned) + { + fprintf (stderr, "WARNING: using untested code for %s:%u -- please check the .asm output and report bugs.\n", ic->filename, ic->lineno); + hasWarned = 1; + } + } } else { - /* now Z if set iff !cond */ + /* now Z is set iff !cond */ if (IC_TRUE(ic)) { assert (!IC_FALSE(ic)); @@ -9841,6 +9891,8 @@ static void genIfx (iCode *ic, iCode *popIc) ic->generated = 1; + /* the result is now in the accumulator */ + freeAsmop(cond,NULL,ic,TRUE); } /*-----------------------------------------------------------------*/