*/
+extern set *externs;
+
/* max_key keeps track of the largest label number used in
a function. This is then used to adjust the label offset
for the next function.
}
}
+void pic16_testStackOverflow(void)
+{
+#define GSTACK_TEST_NAME "__gstack_test"
+
+ pic16_emitpcode(POC_CALL, pic16_popGetWithString( GSTACK_TEST_NAME ));
+
+ {
+ symbol *sym;
+
+ sym = newSymbol( GSTACK_TEST_NAME , 0 );
+ strcpy(sym->rname, GSTACK_TEST_NAME);
+ checkAddSym(&externs, sym);
+ }
+
+}
/* push pcop into stack */
void pic16_pushpCodeOp(pCodeOp *pcop)
{
// DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pcop, pic16_popCopyReg(&pic16_pc_postdec1)));
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pcop, pic16_popCopyReg(&pic16_pc_postdec1)));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
+
}
/* pop pcop from stack */
void pic16_poppCodeOp(pCodeOp *pcop)
{
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_preinc1), pcop));
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_preinc1), pcop));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
/*-----------------------------------------------------------------*/
void pushw(void)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_postdec1));
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_postdec1));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
/*-----------------------------------------------------------------*/
void pushaop(asmop *aop, int offset)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2(PCOR(pic16_popGet(aop, offset)), &pic16_pc_postdec1, 0));
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ if(is_LitAOp(aop)) {
+ pic16_emitpcode(POC_MOVLW, pic16_popGet(aop, offset));
+ pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_postdec1));
+ } else {
+ pic16_emitpcode(POC_MOVFF,
+ pic16_popGet2p(pic16_popGet(aop, offset), pic16_popCopyReg(&pic16_pc_postdec1)));
+ }
+
+// pic16_emitpcode(POC_MOVFF, pic16_popCombine2(PCOR(pic16_popGet(aop, offset)), &pic16_pc_postdec1, 0));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
void popaop(asmop *aop, int offset)
{
- DEBUGpic16_emitcode("; ***", "%s %d", __FUNCTION__, __LINE__);
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2(&pic16_pc_preinc1, PCOR(pic16_popGet(aop, offset)), 0));
+ DEBUGpic16_emitcode("; ***", "%s %d", __FUNCTION__, __LINE__);
+ pic16_emitpcode(POC_MOVFF, pic16_popCombine2(&pic16_pc_preinc1, PCOR(pic16_popGet(aop, offset)), 0));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
void popaopidx(asmop *aop, int offset, int index)
{
int ofs=1;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(STACK_MODEL_LARGE)ofs++;
+ if(STACK_MODEL_LARGE)ofs++;
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(index + ofs));
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2(&pic16_pc_plusw2, PCOR(pic16_popGet(aop, offset)), 0));
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(index + ofs));
+ pic16_emitpcode(POC_MOVFF, pic16_popCombine2(&pic16_pc_plusw2, PCOR(pic16_popGet(aop, offset)), 0));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
/*-----------------------------------------------------------------*/
/* >32-bits, result on stack, and FSR0 points to beginning.
* Fix stack when done */
/* FIXME FIXME */
+// debugf("WARNING: Possible bug when returning more than 4-bytes\n");
while (size--) {
// DEBUGpic16_emitcode("; ", "POC_MOVLW %d", GpsuedoStkPtr);
// DEBUGpic16_emitcode("; ", "POC_MOVFW PLUSW2");
} else {
int areg = 0; /* matching argument register */
- debugf("_G.useWreg = %d\n", _G.useWreg);
+// debugf("_G.useWreg = %d\tGpsuedoStkPtr = %d\n", _G.useWreg, GpsuedoStkPtr);
areg = SPEC_ARGREG( OP_SYM_ETYPE( oper ) ) - 1;
size--;
pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(oper), offset /*size*/));
offset++;
+// debugf("receive from WREG\n", 0);
}
}
// GpsuedoStkPtr++;
size--;
GpsuedoStkPtr++;
popaopidx(AOP(oper), offset, GpsuedoStkPtr);
+// debugf("receive from STACK\n", 0);
offset++;
}
}
DEBUGpic16_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__);
-
if(ic->parmPush) {
pic16_aopOp(IC_LEFT(ic), ic, FALSE );
#endif /* 0 */
+static int wparamCmp(void *p1, void *p2)
+{
+ return (!strcmp((char *)p1, (char *)p2));
+}
+
+int inWparamList(char *s)
+{
+ return isinSetWith(wparamList, s, wparamCmp);
+}
+
+
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
sym_link *ftype;
int stackParms=0;
int use_wreg=0;
+ int inwparam=0;
char *fname;
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
// stackParms = psuedoStkPtr;
// fprintf(stderr, "%s:%d ic parmBytes = %d\n", __FILE__, __LINE__, ic->parmBytes);
fname = OP_SYMBOL(IC_LEFT(ic))->rname[0]?OP_SYMBOL(IC_LEFT(ic))->rname:OP_SYMBOL(IC_LEFT(ic))->name;
+ inwparam = inWparamList(OP_SYMBOL(IC_LEFT(ic))->name);
#if 0
gpsimDebug_StackDump(__FILE__, __LINE__, fname );
if (_G.sendSet) {
iCode *sic;
int psuedoStkPtr=-1;
-#if USE_WREG_IN_FUNC_PARAMS
int firstTimeThruLoop = 1;
-#endif
-#if 1
+
/* reverse sendSet if function is not reentrant */
if(!IFFUNC_ISREENT(ftype))
_G.sendSet = reverseSet(_G.sendSet);
-#endif
/* First figure how many parameters are getting passed */
-
-/* do we really need to know this ? -- VR
- for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
- pic16_aopOp(IC_LEFT(sic),sic,FALSE);
- psuedoStkPtr += AOP_SIZE(IC_LEFT(sic));
- pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE);
- }
-*/
-
-
-// stackParms = psuedoStkPtr;
stackParms = 0;
use_wreg = 0;
for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
int size;
-#if USE_WREG_IN_FUNC_PARAMS
- int offset = 0;
-#endif
+// int offset = 0;
+
pic16_aopOp(IC_LEFT(sic),sic,FALSE);
size = AOP_SIZE(IC_LEFT(sic));
stackParms += size;
- /* set the following to 1 to enable passing arguments via WREG */
-#if USE_WREG_IN_FUNC_PARAMS
- while (size--) {
- DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
- pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
- DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
+ /* pass the last byte through WREG */
+ if(inwparam) {
- if(!firstTimeThruLoop) {
- /* If this is not the first time we've been through the loop
- * then we need to save the parameter in a temporary
- * register. The last byte of the last parameter is
- * passed in W. */
+ while (size--) {
+ DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
+ pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
+ DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
- pushw();
-// --psuedoStkPtr; // sanity check
- use_wreg = 1;
- }
+ if(!firstTimeThruLoop) {
+ /* If this is not the first time we've been through the loop
+ * then we need to save the parameter in a temporary
+ * register. The last byte of the last parameter is
+ * passed in W. */
+
+ pushw();
+// --psuedoStkPtr; // sanity check
+ use_wreg = 1;
+ }
- firstTimeThruLoop=0;
+ firstTimeThruLoop=0;
- mov2w (AOP(IC_LEFT(sic)), size);
+ mov2w (AOP(IC_LEFT(sic)), size);
- offset++;
- }
-#else
- /* all arguments are passed via stack */
- while (size--) {
- DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
- pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
- DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
-
- mov2w (AOP(IC_LEFT(sic)), size);
- pushw();
+// offset++;
+ }
+ } else {
+ /* all arguments are passed via stack */
+ use_wreg = 0;
+
+ while (size--) {
+ DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
+ pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
+ DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
+
+// pushaop(AOP(IC_LEFT(sic)), size);
+ mov2w (AOP(IC_LEFT(sic)), size);
+ pushw();
+ }
}
-#endif
pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
}
-#if USE_WREG_IN_FUNC_PARAMS
- /* save last parameter to stack if functions has varargs */
- if(IFFUNC_HASVARARGS(ftype) || IFFUNC_ISREENT(ftype))pushw();
- else use_wreg = 1; /* last parameter in WREG */
-#endif
+ if(inwparam) {
+ if(IFFUNC_HASVARARGS(ftype) || IFFUNC_ISREENT(ftype)) {
+ pushw(); /* save last parameter to stack if functions has varargs */
+ use_wreg = 0;
+ } else
+ use_wreg = 1;
+ } else use_wreg = 0;
_G.stackRegSet = _G.sendSet;
_G.sendSet = NULL;
pic16_emitpcode(POC_CALL,pic16_popGetWithString(fname));
GpsuedoStkPtr=0;
+
/* if we need to assign a result value */
if ((IS_ITEMP(IC_RESULT(ic))
&& (OP_SYMBOL(IC_RESULT(ic))->nRegs
/*-----------------------------------------------------------------*/
static void genPcall (iCode *ic)
{
- sym_link *ftype;
+ sym_link *ftype, *fntype;
int stackParms=0;
- int use_wreg=0;
symbol *retlbl = newiTempLabel(NULL);
pCodeOp *pcop_lbl = pic16_popGetLabel(retlbl->key);
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
ftype = OP_SYM_TYPE(IC_LEFT(ic));
-
+ fntype = operandType( IC_LEFT(ic) )->next;
+
/* if send set is not empty the assign */
if (_G.sendSet) {
iCode *sic;
int psuedoStkPtr=-1;
-#if USE_WREG_IN_FUNC_PARAMS
- int firstTimeThruLoop = 1;
-#endif
-
- /* For the Pic port, there is no data stack.
- * So parameters passed to functions are stored
- * in registers. (The pCode optimizer will get
- * rid of most of these :). */
-
-#if 1
/* reverse sendSet if function is not reentrant */
- if(!IFFUNC_ISREENT(ftype))
+ if(!IFFUNC_ISREENT(fntype))
_G.sendSet = reverseSet(_G.sendSet);
-#endif
-
- /* First figure how many parameters are getting passed */
-#if 0
- for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
- pic16_aopOp(IC_LEFT(sic),sic,FALSE);
- psuedoStkPtr += AOP_SIZE(IC_LEFT(sic));
- pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE);
- }
-#endif
-// stackParms = psuedoStkPtr;
stackParms = 0;
-
+
for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
int size;
-#if USE_WREG_IN_FUNC_PARAMS
- int offset = 0;
-#endif
pic16_aopOp(IC_LEFT(sic),sic,FALSE);
size = AOP_SIZE(IC_LEFT(sic));
stackParms += size;
-#if USE_WREG_IN_FUNC_PARAMS
- while (size--) {
- DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
- pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
- DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
-
- if(!firstTimeThruLoop) {
- /* If this is not the first time we've been through the loop
- * then we need to save the parameter in a temporary
- * register. The last byte of the last parameter is
- * passed in W. */
-
- pushw();
- --psuedoStkPtr; // sanity check
- }
-
- firstTimeThruLoop=0;
-
- mov2w (AOP(IC_LEFT(sic)), size);
- use_wreg = 1;
-
- offset++;
- }
-#else
+ /* all parameters are passed via stack, since WREG is clobbered
+ * by the calling sequence */
while (size--) {
DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
mov2w (AOP(IC_LEFT(sic)), size);
pushw();
}
-#endif
pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
}
-#if USE_WREG_IN_FUNC_PARAMS
- if(IFFUNC_HASVARARGS(ftype) || IFFUNC_ISREENT(ftype))pushw();
- else use_wreg = 1; /* last parameter in WREG */
-#endif
-
_G.stackRegSet = _G.sendSet;
_G.sendSet = NULL;
}
pic16_freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
}
- stackParms -= use_wreg;
+// stackParms -= use_wreg;
if(stackParms>0) {
pic16_emitpcode(POC_MOVLW, pic16_popGetLit(stackParms));
if(strcmp(sym->name, "main")) {
if(1 /*!options.ommitFramePtr || sym->regsUsed*/) {
/* setup the stack frame */
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr2l, &pic16_pc_postdec1, 0));
+ if(STACK_MODEL_LARGE)
+ pic16_pushpCodeOp(pic16_popCopyReg(&pic16_pc_fsr2h));
+ pic16_pushpCodeOp(pic16_popCopyReg(&pic16_pc_fsr2l));
+// pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr2l, &pic16_pc_postdec1, 0));
pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr1l, &pic16_pc_fsr2l, 0));
if(STACK_MODEL_LARGE)
pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr1h, &pic16_pc_fsr2h, 0));
pic16_emitpcode(POC_DECF, pic16_popCopyReg(&pic16_pc_fsr1h));
}
-#if USE_WREG_IN_FUNC_PARAMS
- if(IFFUNC_HASVARARGS(sym->type) || IFFUNC_ISREENT(sym->type))
+ if(inWparamList(sym->name)) {
+ if(IFFUNC_HASVARARGS(sym->type) || IFFUNC_ISREENT(sym->type))
+ _G.useWreg = 0;
+ else
+ _G.useWreg = 1;
+ } else
_G.useWreg = 0;
- else _G.useWreg = 1;
-#else
- _G.useWreg = 0;
-#endif
/* if callee-save to be used for this function
* then save the registers being used in this function */
if(1/*!options.ommitFramePtr ||*/ /*sym->regsUsed*/) {
/* restore stack frame */
if(STACK_MODEL_LARGE)
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_preinc1, &pic16_pc_fsr2h, 0));
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_preinc1, &pic16_pc_fsr2l, 0));
+ pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_fsr2h ));
+// pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_preinc1, &pic16_pc_fsr2h, 0));
+ pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_fsr2l ));
+// pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_preinc1, &pic16_pc_fsr2l, 0));
}
}
}
#endif
-extern set *externs;
/*-----------------------------------------------------------------*/
/* genGenPointerGet - gget value from generic pointer space */
* by the support function this restoring the stack. The important
* thing is that there is no need to manually restore stack pointer
* here */
- mov2fp(pic16_popCopyReg(&pic16_pc_postdec1), AOP(right), 0);
+ pushaop(AOP(right), 0);
+// mov2fp(pic16_popCopyReg(&pic16_pc_postdec1), AOP(right), 0);
if(size>1)mov2fp(pic16_popCopyReg(&pic16_pc_prodh), AOP(right), 1);
if(size>2)mov2fp(pic16_popCopyReg(&pic16_pc_tblptrl), AOP(right), 2);
if(size>3)mov2fp(pic16_popCopyReg(&pic16_pc_tblptrh), AOP(right), 3);
} else if (AOP_TYPE(right) == AOP_CRY) {
pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset));
if(offset == 0) {
- debugf("%s: BTFSS offset == 0\n", __FUNCTION__);
+// debugf("%s: BTFSS offset == 0\n", __FUNCTION__);
pic16_emitpcode(POC_BTFSS, pic16_popGet(AOP(right),0));
pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),0));
}
pic16_emitcode("jmp","@a+dptr");
pic16_emitcode("","%05d_DS_:",jtab->key+100);
+#if 0
pic16_emitpcode(POC_MOVLW, pic16_popGetLabel(jtab->key));
pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(IC_JTCOND(ic)),0));
emitSKPNC;
pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_pcl));
pic16_emitpLabel(jtab->key);
+#else
+
+ pCodeOp *jt_offs = pic16_popGetTempReg(0);
+ pCodeOp *jt_offs_hi = pic16_popGetTempReg(1);
+ pCodeOp *jt_label = pic16_popGetLabel (jtab->key);
+ //fprintf (stderr, "Creating jump table...\n");
+
+ // calculate offset into jump table (idx * sizeof (GOTO))
+ pic16_emitpcode(POC_CLRF , jt_offs_hi);
+ pic16_emitpcode(POC_RLCFW , pic16_popGet(AOP(IC_JTCOND(ic)),0));
+ pic16_emitpcode(POC_RLCF , jt_offs_hi);
+ pic16_emitpcode(POC_RLCFW , pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RLCF , jt_offs_hi);
+ pic16_emitpcode(POC_ANDLW , pic16_popGetLit (0xFC));
+ pic16_emitpcode(POC_MOVWF , jt_offs);
+
+ // prepare PCLATx (set to first entry in jump table)
+ pic16_emitpcode(POC_MOVLW , pic16_popGetImmd(jt_label->name, 2, 0));
+ pic16_emitpcode(POC_MOVWF , pic16_popCopyReg(&pic16_pc_pclatu));
+ pic16_emitpcode(POC_MOVLW , pic16_popGetImmd(jt_label->name, 1, 0));
+ pic16_emitpcode(POC_MOVWF , pic16_popCopyReg(&pic16_pc_pclath));
+ pic16_emitpcode(POC_MOVLW , pic16_popGetImmd(jt_label->name, 0, 0));
+
+ // set PCLATx to selected entry (new PCL is stored in jt_offs)
+ pic16_emitpcode(POC_ADDWF , jt_offs);
+ pic16_emitpcode(POC_MOVFW , jt_offs_hi);
+ pic16_emitpcode(POC_ADDWFC, pic16_popCopyReg(&pic16_pc_pclath));
+ emitSKPNC;
+ pic16_emitpcode(POC_INCF , pic16_popCopyReg(&pic16_pc_pclatu));
+
+ // release temporaries and prepare jump into table (new PCL --> WREG)
+ pic16_emitpcode(POC_MOVFW , jt_offs);
+ pic16_popReleaseTempReg (jt_offs_hi, 1);
+ pic16_popReleaseTempReg (jt_offs, 0);
+
+ // jump into the table
+ pic16_emitpcode(POC_MOVWF , pic16_popCopyReg(&pic16_pc_pcl));
+
+ // this goto prevents the next label from being removed...
+ pic16_emitpcode(POC_GOTO, jt_label);
+ pic16_emitpLabel(jtab->key);
+
+#endif
pic16_freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
/* now generate the jump labels */
pCodeOp *pic16_popCopyReg(pCodeOpReg *pc);
extern void pic16_pCodeConstString(char *name, char *value);
-#define debugf(frm, rest) _debugf(__FILE__, __LINE__, frm, rest)
-extern void _debugf(char *f, int l, char *frm, ...);
/*-----------------------------------------------------------------*/
/* aopLiteral - string from a literal value */
&& !(sym->ival && !sym->level)
) {
regs *reg;
- /* add it to udata list */
-
-// fprintf(stderr, "%s:%d adding %s (%s) remat=%d\n", __FILE__, __LINE__,
-// sym->name, sym->rname, sym->remat);
-
- //, OP_SYMBOL(operandFromSymbol(sym))->name);
+ sectSym *ssym;
+ int found=0;
#define SET_IMPLICIT 1
#if SET_IMPLICIT
reg = pic16_allocDirReg( operandFromSymbol( sym ));
- {
- sectSym *ssym;
- int found=0;
-
+ if(reg) {
#if 1
- for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
- if(!strcmp(ssym->name, reg->name))found=1;
- }
+ for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
+ if(!strcmp(ssym->name, reg->name))found=1;
+ }
#endif
+ if(!found)
+ checkAddReg(&pic16_rel_udata, reg);
+ else
+ checkAddSym(&publics, sym);
- if(!found)
- checkAddReg(&pic16_rel_udata, reg);
- else
- checkAddSym(&publics, sym);
-
- }
+ }
}
/* if extern then do nothing or is a function
sym->rname, reg, (reg?reg->name:"<<NULL>>"));
#endif
-#if 1
- for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
- if(!strcmp(ssym->name, reg->name))found=1;
- }
-#endif
-
- if(!found)
- if(checkAddReg(&pic16_rel_udata, reg)) {
- addSetHead(&publics, sym);
- }
+ if(reg) {
+ for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
+ if(!strcmp(ssym->name, reg->name))found=1;
+ }
+ if(!found)
+ if(checkAddReg(&pic16_rel_udata, reg)) {
+ addSetHead(&publics, sym);
+ }
+ }
}
/*-----------------------------------------------------------------*/
/* printGPointerType - generates ival for generic pointer type */
/*-----------------------------------------------------------------*/
-void pic16_printGPointerType (const char *iname, const char *oname, const unsigned int itype,
- const unsigned int type, char ptype, void *p)
+void pic16_printGPointerType (const char *iname, const unsigned int itype,
+ char ptype, void *p)
{
char buf[256];
switch( itype ) {
case FPOINTER:
case CPOINTER:
+ case FUNCTION:
{
sprintf(buf, "UPPER(%s)", iname);
pic16_emitDS(buf, ptype, p);
sprintf(buf, "0x80");
pic16_emitDS(buf, ptype, p);
break;
+ default:
+// debugf("itype = %d\n", itype );
+ assert( 0 );
}
pic16_flushDB(ptype, p);
// this is a literal string
type=CPOINTER;
}
- pic16_printGPointerType(val->name, sym->name, type, type, ptype, p);
+ pic16_printGPointerType(val->name, type, ptype, p);
}
else
{
/* now generate the name */
if (!val->sym) {
- pic16_printPointerType (val->name, ptype, p);
+ pic16_printGPointerType (val->name, DCL_TYPE(val->type), ptype, p);
} else {
- pic16_printPointerType (val->sym->rname, ptype, p);
+ pic16_printGPointerType (val->sym->rname, DCL_TYPE(val->type), ptype, p);
- if(IS_FUNC(val->sym->type) && !val->sym->used) {
+ if(IS_FUNC(val->sym->type) && !val->sym->used && !IS_STATIC(val->sym->etype)) {
if(!checkSym(publics, val->sym))
- checkAddSym(&externs, val->sym);
-
- /* this has not been declared as extern
- * so declare it as a 'late extern' just after the symbol */
- if(ptype == 'f') {
- fprintf((FILE *)p, "declare symbol as extern");
- fprintf((FILE *)p, "\textern\t%s\n", val->sym->rname);
- fprintf((FILE *)p, "continue variable declaration");
- }
+ if(checkAddSym(&externs, val->sym) && (ptype == 'f')) {
+ /* this has not been declared as extern
+ * so declare it as a 'late extern' just after the symbol */
+ fprintf((FILE *)p, ";\tdeclare symbol as extern\n");
+ fprintf((FILE *)p, "\textern\t%s\n", val->sym->rname);
+ fprintf((FILE *)p, ";\tcontinue variable declaration\n");
+ }
}
}
}
else if (size == 3)
{
- pic16_printGPointerType (val->name, sym->name, (IS_PTR(type)?DCL_TYPE(type):PTR_TYPE(SPEC_OCLS(sym->etype))),
- (IS_PTR (val->type) ? DCL_TYPE (val->type) :
- PTR_TYPE (SPEC_OCLS (val->etype))), ptype, p);
+ pic16_printGPointerType (val->name, (IS_PTR(type)?DCL_TYPE(type):PTR_TYPE(SPEC_OCLS(sym->etype))),
+ ptype, p);
} else
assert(0);
return;