for the next function.
*/
static int max_key=0;
+static int GpsuedoStkPtr=0;
+
unsigned int pic14aopLiteral (value *val, int offset);
const char *AopType(short type);
return pcop;
}
+pCodeOp *popRegFromIdx(int rIdx)
+{
+ pCodeOp *pcop;
+
+ DEBUGpic14_emitcode ("; ***","%s,%d , rIdx=0x%x",
+ __FUNCTION__,__LINE__,rIdx);
+
+ pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
+
+ PCOR(pcop)->rIdx = rIdx;
+ PCOR(pcop)->r = pic14_regWithIdx(rIdx);
+ PCOR(pcop)->r->isFree = 0;
+ PCOR(pcop)->r->wasUsed = 1;
+
+ pcop->type = PCOR(pcop)->r->pc_type;
+
+
+ return pcop;
+}
/*-----------------------------------------------------------------*/
/* popGet - asm operator to pcode operator conversion */
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void pushSide(operand * oper, int size)
{
+#if 0
int offset = 0;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
while (size--) {
} else
pic14_emitcode("push","%s",l);
}
+#endif
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void assignResultValue(operand * oper)
{
- int offset = 0;
- int size = AOP_SIZE(oper);
+ int offset = 0;
+ int size = AOP_SIZE(oper);
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- // The last byte in the assignment is in W
- aopPut(AOP(oper),"W",size-1);
+ if(!GpsuedoStkPtr) {
+ /* The last byte in the assignment is in W */
+ //aopPut(AOP(oper),"W",size-1);
+ emitpcode(POC_MOVWF, popGet(AOP(oper),0,FALSE,FALSE));
+ GpsuedoStkPtr++;
+ if(size == 1)
+ return;
+ size--;
+ offset++;
+ }
- if(size>1) {
- while (--size) {
- aopPut(AOP(oper),fReturn[offset],offset);
- offset++;
+ while (size--) {
+ emitpcode(POC_MOVFW,popRegFromIdx(GpsuedoStkPtr-1 + Gstack_base_addr));
+ emitpcode(POC_MOVWF, popGet(AOP(oper),offset,FALSE,FALSE));
+ offset++;
+ GpsuedoStkPtr++;
- }
- }
+ }
}
/*-----------------------------------------------------------------*/
static void genCall (iCode *ic)
{
- sym_link *dtype;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ sym_link *dtype;
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved)
- saveRegisters(ic);
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if we are calling a function that is not using
- the same register bank then we need to save the
- destination registers on the stack */
- dtype = operandType(IC_LEFT(ic));
- if (dtype &&
- (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)) &&
- IFFUNC_ISISR(currFunc->type) &&
- !ic->bankSaved)
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
+ saveRegisters(ic);
- saverbank(FUNC_REGBANK(dtype),ic,TRUE);
+ /* if we are calling a function that is not using
+ the same register bank then we need to save the
+ destination registers on the stack */
+ dtype = operandType(IC_LEFT(ic));
+ if (dtype &&
+ (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)) &&
+ IFFUNC_ISISR(currFunc->type) &&
+ !ic->bankSaved)
- /* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
+ saverbank(FUNC_REGBANK(dtype),ic,TRUE);
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
+ /* if send set is not empty the assign */
+ if (_G.sendSet) {
+ iCode *sic;
+ /* 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 :).
+ */
+ int psuedoStkPtr=0;
+ int firstTimeThruLoop = 1;
- aopOp(IC_LEFT(sic),sic,FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset,
- FALSE,FALSE);
- DEBUGpic14_emitcode(";","%d - left type %d",__LINE__,AOP(IC_LEFT(sic))->type);
+ for (sic = setFirstItem(_G.sendSet) ; sic ;
+ sic = setNextItem(_G.sendSet)) {
+ int size, offset = 0;
- if (strcmp(l,fReturn[offset])) {
+ aopOp(IC_LEFT(sic),sic,FALSE);
+ size = AOP_SIZE(IC_LEFT(sic));
- if ( ((AOP(IC_LEFT(sic))->type) == AOP_IMMD) ||
- ((AOP(IC_LEFT(sic))->type) == AOP_LIT) )
- emitpcode(POC_MOVLW,popGet(AOP(IC_LEFT(sic)),size,FALSE,FALSE));
- //pic14_emitcode("movlw","%s",l);
- else
- emitpcode(POC_MOVFW,popGet(AOP(IC_LEFT(sic)),size,FALSE,FALSE));
- //pic14_emitcode("movf","%s,w",l);
- // The last one is passed in W
- if(size)
- pic14_emitcode("movwf","%s",fReturn[offset]);
- }
- offset++;
- }
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
+ while (size--) {
+ char *l = aopGet(AOP(IC_LEFT(sic)),offset,
+ FALSE,FALSE);
+ DEBUGpic14_emitcode ("; ","%d left %s",__LINE__,
+ AopType(AOP_TYPE(IC_LEFT(sic))));
+
+ if(!firstTimeThruLoop) {
+ /* If 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. */
+ pic14_emitcode("movwf","%s",fReturn[offset]);
+ emitpcode(POC_MOVWF,popRegFromIdx(psuedoStkPtr + Gstack_base_addr));
+ psuedoStkPtr++;
+ DEBUGpic14_emitcode ("; ","%d save param in %d",__LINE__,
+ psuedoStkPtr+Gstack_base_addr);
}
- _G.sendSet = NULL;
- }
- /* make the call */
- emitpcode(POC_CALL,popGetWithString(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
- OP_SYMBOL(IC_LEFT(ic))->rname :
- OP_SYMBOL(IC_LEFT(ic))->name));
+ firstTimeThruLoop=0;
- pic14_emitcode("call","%s",(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
- OP_SYMBOL(IC_LEFT(ic))->rname :
- OP_SYMBOL(IC_LEFT(ic))->name));
+ if (strcmp(l,fReturn[offset])) {
- /* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+ if ( ((AOP(IC_LEFT(sic))->type) == AOP_IMMD) ||
+ ((AOP(IC_LEFT(sic))->type) == AOP_LIT) )
+ emitpcode(POC_MOVLW,popGet(AOP(IC_LEFT(sic)),size,FALSE,FALSE));
+ //pic14_emitcode("movlw","%s",l);
+ else
+ emitpcode(POC_MOVFW,popGet(AOP(IC_LEFT(sic)),size,FALSE,FALSE));
+ //pic14_emitcode("movf","%s,w",l);
- _G.accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE);
- _G.accInUse--;
+ /* The last one is passed in W but all others are passed on
+ the psuedo stack */
+ /*
+ if(size) {
+ pic14_emitcode("movwf","%s",fReturn[offset]);
+ emitpcode(POC_MOVWF,popRegFromIdx(offset + Gstack_base_addr));
+ }
+ */
+ }
+ offset++;
+ }
+ freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
+ }
+ _G.sendSet = NULL;
+ }
+ /* make the call */
+ emitpcode(POC_CALL,popGetWithString(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
+ OP_SYMBOL(IC_LEFT(ic))->rname :
+ OP_SYMBOL(IC_LEFT(ic))->name));
+
+ GpsuedoStkPtr=0;
+ /* if we need assign a result value */
+ if ((IS_ITEMP(IC_RESULT(ic)) &&
+ (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
+ OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
+ IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+
+ _G.accInUse++;
+ aopOp(IC_RESULT(ic),ic,FALSE);
+ _G.accInUse--;
- assignResultValue(IC_RESULT(ic));
+ assignResultValue(IC_RESULT(ic));
+
+ DEBUGpic14_emitcode ("; ","%d left %s",__LINE__,
+ AopType(AOP_TYPE(IC_RESULT(ic))));
- freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
- }
+ freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
+ }
- /* adjust the stack for parameters if
- required */
- if (ic->parmBytes) {
- int i;
- if (ic->parmBytes > 3) {
- pic14_emitcode("mov","a,%s",spname);
- pic14_emitcode("add","a,#0x%02x", (- ic->parmBytes) & 0xff);
- pic14_emitcode("mov","%s,a",spname);
- } else
- for ( i = 0 ; i < ic->parmBytes ;i++)
- pic14_emitcode("dec","%s",spname);
+ /* adjust the stack for parameters if
+ required */
+ if (ic->parmBytes) {
+ int i;
+ if (ic->parmBytes > 3) {
+ pic14_emitcode("mov","a,%s",spname);
+ pic14_emitcode("add","a,#0x%02x", (- ic->parmBytes) & 0xff);
+ pic14_emitcode("mov","%s,a",spname);
+ } else
+ for ( i = 0 ; i < ic->parmBytes ;i++)
+ pic14_emitcode("dec","%s",spname);
- }
+ }
- /* if register bank was saved then pop them */
- if (ic->bankSaved)
- unsaverbank(FUNC_REGBANK(dtype),ic,TRUE);
+ /* if register bank was saved then pop them */
+ if (ic->bankSaved)
+ unsaverbank(FUNC_REGBANK(dtype),ic,TRUE);
- /* if we hade saved some registers then unsave them */
- if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype))
- unsaveRegisters (ic);
+ /* if we hade saved some registers then unsave them */
+ if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype))
+ unsaveRegisters (ic);
}
labelOffset += (max_key+4);
max_key=0;
-
+ GpsuedoStkPtr=0;
_G.nRegsSaved = 0;
/* create the function header */
pic14_emitcode(";","-----------------------------------------");
/*-----------------------------------------------------------------*/
static void genRet (iCode *ic)
{
- int size,offset = 0 , pushed = 0;
+ int size,offset = 0 , pushed = 0;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if we have no return value then
- just generate the "ret" */
- if (!IC_LEFT(ic))
- goto jumpret;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* if we have no return value then
+ just generate the "ret" */
+ if (!IC_LEFT(ic))
+ goto jumpret;
- /* we have something to return then
- move the return value into place */
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
+ /* we have something to return then
+ move the return value into place */
+ aopOp(IC_LEFT(ic),ic,FALSE);
+ size = AOP_SIZE(IC_LEFT(ic));
- while (size--) {
- char *l ;
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) {
- /* #NOCHANGE */
- l = aopGet(AOP(IC_LEFT(ic)),offset++,
- FALSE,TRUE);
- pic14_emitcode("push","%s",l);
- pushed++;
- } else {
- l = aopGet(AOP(IC_LEFT(ic)),offset,
- FALSE,FALSE);
- if (strcmp(fReturn[offset],l)) {
- if( ( (AOP(IC_LEFT(ic))->type) == AOP_IMMD) ||
- ((AOP(IC_LEFT(ic))->type) == AOP_LIT) )
- pic14_emitcode("movlw","%s",l);
- else
- pic14_emitcode("movf","%s,w",l);
- if(size)
- pic14_emitcode("movwf","%s",fReturn[offset]);
- offset++;
- }
- }
- }
-
- if (pushed) {
- while(pushed) {
- pushed--;
- if (strcmp(fReturn[pushed],"a"))
- pic14_emitcode("pop",fReturn[pushed]);
- else
- pic14_emitcode("pop","acc");
+ while (size--) {
+ char *l ;
+ if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) {
+ /* #NOCHANGE */
+ l = aopGet(AOP(IC_LEFT(ic)),offset++,
+ FALSE,TRUE);
+ pic14_emitcode("push","%s",l);
+ pushed++;
+ } else {
+ l = aopGet(AOP(IC_LEFT(ic)),offset,
+ FALSE,FALSE);
+ if (strcmp(fReturn[offset],l)) {
+ if( ( (AOP(IC_LEFT(ic))->type) == AOP_IMMD) ||
+ ((AOP(IC_LEFT(ic))->type) == AOP_LIT) ) {
+ emitpcode(POC_MOVLW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+ pic14_emitcode("movlw","%s",l);
+ }else {
+ emitpcode(POC_MOVFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+ pic14_emitcode("movf","%s,w",l);
}
+ if(size) {
+ emitpcode(POC_MOVWF,popRegFromIdx(offset + Gstack_base_addr));
+ pic14_emitcode("movwf","%s",fReturn[offset]);
+ }
+ offset++;
+ }
+ }
+ }
+
+ if (pushed) {
+ while(pushed) {
+ pushed--;
+ if (strcmp(fReturn[pushed],"a"))
+ pic14_emitcode("pop",fReturn[pushed]);
+ else
+ pic14_emitcode("pop","acc");
}
- freeAsmop (IC_LEFT(ic),NULL,ic,TRUE);
+ }
+ freeAsmop (IC_LEFT(ic),NULL,ic,TRUE);
jumpret:
- /* generate a jump to the return label
- if the next is not the return statement */
- if (!(ic->next && ic->next->op == LABEL &&
- IC_LABEL(ic->next) == returnLabel)) {
+ /* generate a jump to the return label
+ if the next is not the return statement */
+ if (!(ic->next && ic->next->op == LABEL &&
+ IC_LABEL(ic->next) == returnLabel)) {
- emitpcode(POC_GOTO,popGetLabel(returnLabel->key));
- pic14_emitcode("goto","_%05d_DS_",returnLabel->key+100 + labelOffset);
- }
+ emitpcode(POC_GOTO,popGetLabel(returnLabel->key));
+ pic14_emitcode("goto","_%05d_DS_",returnLabel->key+100 + labelOffset);
+ }
}
static char *get_op( pCodeInstruction *pcc);
int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd);
int pCodePeepMatchRule(pCode *pc);
+void pBlockStats(FILE *of, pBlock *pb);
pCodeInstruction pciADDWF = {
return;
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
- if(getpBlock_dbName(pb) == dbName)
+ if(getpBlock_dbName(pb) == dbName) {
+ pBlockStats(of,pb);
printpBlock(of,pb);
+ }
}
}
}
}
}
+/*-----------------------------------------------------------------*/
+/* int RegCond(pCodeOp *pcop) - if pcop points to the STATUS reg- */
+/* ister, RegCond will return the bit being referenced. */
+/* */
+/* fixme - why not just OR in the pcop bit field */
+/*-----------------------------------------------------------------*/
+
static int RegCond(pCodeOp *pcop)
{
}
+/*-----------------------------------------------------------------*/
+/* pCodeLabelDestruct - free memory used by a label. */
+/*-----------------------------------------------------------------*/
static void pCodeLabelDestruct(pCode *pc)
{
}
/*-----------------------------------------------------------------*/
-/* newpCodeChai0n - create a new chain of pCodes */
+/* newpCodeChain - create a new chain of pCodes */
/*-----------------------------------------------------------------*
*
* This function will create a new pBlock and the pointer to the
return pcop;
}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
pCodeOp *newpCodeOpLit(int lit)
{
char *s = buffer;
return pcop;
}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
pCodeOp *newpCodeOpWild(int id, pCodePeep *pcp, pCodeOp *subtype)
{
char *s = buffer;
return pcop;
}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
pCodeOp *newpCodeOpBit(char *s, int bit, int inBitSpace)
{
pCodeOp *pcop;
}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
void pBlockRegs(FILE *of, pBlock *pb)
{
}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
static pBranch * pBranchAppend(pBranch *h, pBranch *n)
{
pBranch *b;
} else
npc = npc->next;
}
+ /* reached the end of the pcode chain without finding
+ * an instruction we could link to. */
}
}
}
}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
void AnalyzepBlock(pBlock *pb)
{
if(PCI(pc)->pcop && PCI(pc)->pcop->type == PO_GPR_TEMP) {
/* Loop through all of the registers declared so far in
- this block and see if we find this new there */
+ this block and see if we find this one there */
regs *r = setFirstItem(pb->registers);
}
}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
int OptimizepBlock(pBlock *pb)
{
pCode *pc;
pCode *pc;
regs *r;
- fprintf(of,"***\n pBlock Stats\n***\n");
+ fprintf(of,";***\n; pBlock Stats\n;***\n");
// for now just print the first element of each set
pc = setFirstItem(pb->function_entries);
if(pc) {
- fprintf(of,"entry\n");
+ fprintf(of,";entry: ");
pc->print(of,pc);
}
pc = setFirstItem(pb->function_exits);
if(pc) {
- fprintf(of,"has an exit\n");
- pc->print(of,pc);
+ fprintf(of,";has an exit\n");
+ //pc->print(of,pc);
}
pc = setFirstItem(pb->function_calls);
if(pc) {
- fprintf(of,"functions called\n");
+ fprintf(of,";functions called:\n");
while(pc) {
+ fprintf(of,"; ");
pc->print(of,pc);
pc = setNextItem(pb->function_calls);
}
if(r) {
int n = elementsInSet(pb->registers);
- fprintf(of,"%d compiler assigned register%c:\n",n, ( (n!=1) ? 's' : ' '));
+ fprintf(of,";%d compiler assigned register%c:\n",n, ( (n!=1) ? 's' : ' '));
while (r) {
- fprintf(of," %s\n",r->name);
+ fprintf(of,"; %s\n",r->name);
r = setNextItem(pb->registers);
}
}
r2 = setFirstItem(pb->registers);
- while(r2) {
+ while(r2 && (r1->type != REG_STK)) {
if(r2->rIdx == r1->rIdx) {
- newreg = pic14_findFreeReg();
+ newreg = pic14_findFreeReg(REG_GPR);
if(!newreg) {
/* Collisions have been resolved. Now free the registers in the call path */
r1 = setFirstItem(registersInCallPath);
while(r1) {
- newreg = pic14_regWithIdx(r1->rIdx);
- newreg->isFree = 1;
+ if(r1->type != REG_STK) {
+ newreg = pic14_regWithIdx(r1->rIdx);
+ newreg->isFree = 1;
+ }
r1 = setNextItem(registersInCallPath);
}
};
#else
+
+int Gstack_base_addr=0x38; /* The starting address of registers that
+ * are used to pass and return parameters */
regs regspic14[] =
{
{REG_GPR, PO_GPR_TEMP, 0x20, "r0x20", "r0x20", 0x20, 1, 0},
{REG_GPR, PO_GPR_TEMP, 0x35, "r0x35", "r0x35", 0x35, 1, 0},
{REG_GPR, PO_GPR_TEMP, 0x36, "r0x36", "r0x36", 0x36, 1, 0},
{REG_GPR, PO_GPR_TEMP, 0x37, "r0x37", "r0x37", 0x37, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x38, "r0x38", "r0x38", 0x38, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x39, "r0x39", "r0x39", 0x39, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3A, "r0x3A", "r0x3A", 0x3A, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3B, "r0x3B", "r0x3B", 0x3B, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3C, "r0x3C", "r0x3C", 0x3C, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3D, "r0x3D", "r0x3D", 0x3D, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3E, "r0x3E", "r0x3E", 0x3E, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3F, "r0x3F", "r0x3F", 0x3F, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x40, "r0x40", "r0x40", 0x40, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x41, "r0x41", "r0x41", 0x41, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x42, "r0x42", "r0x42", 0x42, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x43, "r0x43", "r0x43", 0x43, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x44, "r0x44", "r0x44", 0x44, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x45, "r0x45", "r0x45", 0x45, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x46, "r0x46", "r0x46", 0x46, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x47, "r0x47", "r0x47", 0x47, 1, 0},
{REG_PTR, PO_FSR, 4, "FSR", "FSR", 4, 1, 0},
if (regspic14[i].rIdx == idx)
return ®spic14[i];
- return ®spic14[0];
-
+ //return ®spic14[0];
+ fprintf(stderr,"%s %d - requested register: 0x%x\n",__FUNCTION__,__LINE__,idx);
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"regWithIdx not found");
exit (1);
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
regs *
-pic14_findFreeReg(void)
+pic14_findFreeReg(short type)
{
int i;
- for (i = 0; i < pic14_nRegs; i++)
- if (regspic14[i].isFree)
+ for (i = 0; i < pic14_nRegs; i++) {
+ if (!type && regspic14[i].isFree)
return ®spic14[i];
-
+ if (regspic14[i].isFree &&
+ regspic14[i].type == type)
+ return ®spic14[i];
+ }
return NULL;
}
/*-----------------------------------------------------------------*/