From: sdattalo Date: Fri, 11 Apr 2003 05:17:18 +0000 (+0000) Subject: The function name in a pointer to function variable was getting declared X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=ac7f59d094a9fa185121facfae77e478d163a33d;p=fw%2Fsdcc The function name in a pointer to function variable was getting declared in data space. (reported by Steve Tell). git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2503 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/pic/gen.c b/src/pic/gen.c index c4a5a8bf..95b75a28 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -60,7 +60,7 @@ static int optimized_for_speed = 0; static int max_key=0; static int GpsuedoStkPtr=0; -pCodeOp *popGetImmd(char *name, unsigned int offset, int index); +pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func); unsigned int pic14aopLiteral (value *val, int offset); const char *AopType(short type); static iCode *ifxForOp ( operand *op, iCode *ic ); @@ -523,11 +523,19 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result) /* special case for a function */ if (IS_FUNC(sym->type)) { + + sym->aop = aop = newAsmop(AOP_PCODE); + aop->aopu.pcop = popGetImmd(sym->rname,0,0,1); + PCOI(aop->aopu.pcop)->_const = IN_CODESPACE(space); + PCOI(aop->aopu.pcop)->_function = 1; + PCOI(aop->aopu.pcop)->index = 0; + aop->size = FPTRSIZE; + /* sym->aop = aop = newAsmop(AOP_IMMD); - //_ALLOC_ATOMIC(aop->aopu.aop_immd,strlen(sym->rname)+1); aop->aopu.aop_immd = Safe_calloc(1,strlen(sym->rname)+1); strcpy(aop->aopu.aop_immd,sym->rname); aop->size = FPTRSIZE; + */ DEBUGpic14_emitcode(";","%d size = %d, name =%s",__LINE__,aop->size,sym->rname); return aop; } @@ -537,7 +545,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result) /* in which case DPTR gets the address */ sym->aop = aop = newAsmop(AOP_PCODE); - aop->aopu.pcop = popGetImmd(sym->rname,0,0); + aop->aopu.pcop = popGetImmd(sym->rname,0,0,0); PCOI(aop->aopu.pcop)->_const = IN_CODESPACE(space); PCOI(aop->aopu.pcop)->index = 0; @@ -592,7 +600,7 @@ static asmop *aopForRemat (operand *op) // x symbol *sym) } offset = OP_SYMBOL(IC_LEFT(ic))->offset; - aop->aopu.pcop = popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname,0,val); + aop->aopu.pcop = popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname,0,val,0); PCOI(aop->aopu.pcop)->_const = IS_PTR_CONST(operandType(op)); PCOI(aop->aopu.pcop)->index = val; @@ -1216,10 +1224,10 @@ pCodeOp *popGetLit(unsigned int lit) /*-----------------------------------------------------------------*/ /* popGetImmd - asm operator to pcode immediate conversion */ /*-----------------------------------------------------------------*/ -pCodeOp *popGetImmd(char *name, unsigned int offset, int index) +pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func) { - return newpCodeOpImmd(name, offset,index, 0); + return newpCodeOpImmd(name, offset,index, 0, is_func); } @@ -1323,7 +1331,7 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname) case AOP_IMMD: DEBUGpic14_emitcode(";","%d",__LINE__); - return popGetImmd(aop->aopu.aop_immd,offset,0); + return popGetImmd(aop->aopu.aop_immd,offset,0,0); case AOP_DIR: return popRegFromString(aop->aopu.aop_dir, aop->size, offset); @@ -1449,7 +1457,7 @@ void aopPut (asmop *aop, char *s, int offset) emitpcode(POC_CLRF,popGet(aop,offset)); break; } else - emitpcode(POC_MOVLW,popGetImmd(s,offset,0)); + emitpcode(POC_MOVLW,popGetImmd(s,offset,0,0)); } emitpcode(POC_MOVWF,popGet(aop,offset)); @@ -9335,13 +9343,8 @@ static void genAssign (iCode *ic) emitpcode(POC_BTFSS, popGet(AOP(right),0)); emitpcode(POC_INCF, popGet(AOP(result),0)); } - } else if (AOP_TYPE(right) == AOP_IMMD) { - DEBUGpic14_emitcode ("; ***","%s %d AOP_IMMD",__FUNCTION__,__LINE__); - emitpcode(POC_MOVLW, popGet(AOP(right),offset)); - emitpcode(POC_MOVWF, popGet(AOP(result),offset)); } else { - DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - emitpcode(POC_MOVFW, popGet(AOP(right),offset)); + mov2w (AOP(right), offset); emitpcode(POC_MOVWF, popGet(AOP(result),offset)); } diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 8dbfda78..f9951002 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -2082,15 +2082,19 @@ pCodeOp *newpCodeOpLit(int lit) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space) +pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space, int is_func) { pCodeOp *pcop; pcop = Safe_calloc(1,sizeof(pCodeOpImmd) ); pcop->type = PO_IMMEDIATE; if(name) { - regs *r = dirregWithName(name); + regs *r = NULL; pcop->name = Safe_strdup(name); + + if(!is_func) + r = dirregWithName(name); + PCOI(pcop)->r = r; if(r) { //fprintf(stderr, " newpCodeOpImmd reg %s exists\n",name); @@ -2107,6 +2111,7 @@ pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space) PCOI(pcop)->index = index; PCOI(pcop)->offset = offset; PCOI(pcop)->_const = code_space; + PCOI(pcop)->_function = is_func; return pcop; } diff --git a/src/pic/pcode.h b/src/pic/pcode.h index 46010a3f..e8b44159 100644 --- a/src/pic/pcode.h +++ b/src/pic/pcode.h @@ -312,9 +312,10 @@ typedef struct pCodeOpLit typedef struct pCodeOpImmd { pCodeOp pcop; - int offset; /* low,med, or high byte of immediat value */ + int offset; /* low,med, or high byte of immediate value */ int index; /* add this to the immediate value */ unsigned _const:1; /* is in code space */ + unsigned _function:1; /* is a (pointer to a) function */ int rIdx; /* If this immd points to a register */ struct regs *r; /* then this is the reg. */ @@ -806,7 +807,7 @@ void pCodePeepInit(void); void pBlockConvert2ISR(pBlock *pb); pCodeOp *newpCodeOpLabel(char *name, int key); -pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space); +pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space,int is_func); pCodeOp *newpCodeOpLit(int lit); pCodeOp *newpCodeOpBit(char *name, int bit,int inBitSpace); pCodeOp *newpCodeOpRegFromStr(char *name); diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index 9acc689f..e3c98d80 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -1931,6 +1931,7 @@ pCodeOp *pCodeOpCopy(pCodeOp *pcop) PCOI(pcopnew)->index = PCOI(pcop)->index; PCOI(pcopnew)->offset = PCOI(pcop)->offset; PCOI(pcopnew)->_const = PCOI(pcop)->_const; + PCOI(pcopnew)->_function = PCOI(pcop)->_function; break; case PO_LITERAL: diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 4307f236..42ec8f84 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -35,6 +35,9 @@ #define STRCASECMP strcasecmp #endif +/* this should go in SDCCicode.h, but it doesn't. */ +#define IS_REF(op) (IS_SYMOP(op) && op->operand.symOperand->isref == 1) + /*-----------------------------------------------------------------*/ /* At this point we start getting processor specific although */ /* some routines are non-processor specific & can be reused when */ @@ -2711,7 +2714,10 @@ packRegsForAssign (iCode * ic, eBBlock * ebp) if (!IS_ITEMP (IC_RIGHT (ic))) { debugLog (" %d - not packing - right is not temp\n", __LINE__); - allocDirReg(IC_RIGHT (ic)); + + /* only pack if this is not a function pointer */ + if (!IS_REF (IC_RIGHT (ic))) + allocDirReg(IC_RIGHT (ic)); return 0; }