From adba9ed9f7c1428e05f5bf245196f96f7777067e Mon Sep 17 00:00:00 2001 From: sdattalo Date: Wed, 7 Nov 2001 00:05:06 +0000 Subject: [PATCH] - Parameter passing now works - Added comments - pBlock statistics are now displayed in .asm files (debugging stuff) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1516 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/pic/gen.c | 346 ++++++++++++++++++++++++----------------- src/pic/main.c | 6 +- src/pic/pcode.c | 60 +++++-- src/pic/ralloc.c | 34 +++- src/pic/ralloc.h | 17 +- src/regression/call1.c | 88 +++++++++-- 6 files changed, 360 insertions(+), 191 deletions(-) diff --git a/src/pic/gen.c b/src/pic/gen.c index cc8c0ee5..912840c4 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -83,6 +83,8 @@ static int optimized_for_speed = 0; 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); @@ -1137,6 +1139,25 @@ pCodeOp *popRegFromString(char *str) 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 */ /*-----------------------------------------------------------------*/ @@ -1943,6 +1964,7 @@ static void unsaveRegisters (iCode *ic) /*-----------------------------------------------------------------*/ static void pushSide(operand * oper, int size) { +#if 0 int offset = 0; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); while (size--) { @@ -1955,6 +1977,7 @@ static void pushSide(operand * oper, int size) } else pic14_emitcode("push","%s",l); } +#endif } /*-----------------------------------------------------------------*/ @@ -1962,21 +1985,29 @@ static void pushSide(operand * oper, int size) /*-----------------------------------------------------------------*/ 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++; - } - } + } } @@ -2198,105 +2229,133 @@ static void saverbank (int bank, iCode *ic, bool pushPsw) /*-----------------------------------------------------------------*/ 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); } @@ -2468,7 +2527,7 @@ static void genFunction (iCode *ic) labelOffset += (max_key+4); max_key=0; - + GpsuedoStkPtr=0; _G.nRegsSaved = 0; /* create the function header */ pic14_emitcode(";","-----------------------------------------"); @@ -2787,63 +2846,68 @@ static void genEndFunction (iCode *ic) /*-----------------------------------------------------------------*/ 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); + } } diff --git a/src/pic/main.c b/src/pic/main.c index 60443f66..28af756d 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -67,10 +67,10 @@ _pic14_regparm (sym_link * l) { /* for this processor it is simple can pass only the first parameter in a register */ - if (regParmFlg) - return 0; + //if (regParmFlg) + // return 0; - regParmFlg = 1; + regParmFlg++;// = 1; return 1; } diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 24f624bb..5f17b87c 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -70,6 +70,7 @@ static void pCodeOpPrint(FILE *of, pCodeOp *pcop); 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 = { @@ -958,8 +959,10 @@ void copypCode(FILE *of, char dbName) 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); + } } } @@ -999,6 +1002,13 @@ void pcode_test(void) } } } +/*-----------------------------------------------------------------*/ +/* 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) { @@ -1175,6 +1185,9 @@ pCode *newpCodeFunction(char *mod,char *f) } +/*-----------------------------------------------------------------*/ +/* pCodeLabelDestruct - free memory used by a label. */ +/*-----------------------------------------------------------------*/ static void pCodeLabelDestruct(pCode *pc) { @@ -1250,7 +1263,7 @@ pBlock *newpBlock(void) } /*-----------------------------------------------------------------*/ -/* 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 @@ -1298,6 +1311,8 @@ pCodeOp *newpCodeOpLabel(int key) return pcop; } +/*-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ pCodeOp *newpCodeOpLit(int lit) { char *s = buffer; @@ -1319,6 +1334,8 @@ pCodeOp *newpCodeOpLit(int lit) return pcop; } +/*-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ pCodeOp *newpCodeOpWild(int id, pCodePeep *pcp, pCodeOp *subtype) { char *s = buffer; @@ -1343,6 +1360,8 @@ pCodeOp *newpCodeOpWild(int id, pCodePeep *pcp, pCodeOp *subtype) return pcop; } +/*-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ pCodeOp *newpCodeOpBit(char *s, int bit, int inBitSpace) { pCodeOp *pcop; @@ -1512,6 +1531,8 @@ static void genericDestruct(pCode *pc) } +/*-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ void pBlockRegs(FILE *of, pBlock *pb) { @@ -1785,6 +1806,8 @@ static void unlinkpCodeFromBranch(pCode *pcl , pCode *pc) } +/*-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ static pBranch * pBranchAppend(pBranch *h, pBranch *n) { pBranch *b; @@ -1915,6 +1938,8 @@ static void genericAnalyze(pCode *pc) } else npc = npc->next; } + /* reached the end of the pcode chain without finding + * an instruction we could link to. */ } } } @@ -2035,6 +2060,8 @@ static void AnalyzeRETURN(pCode *pc) } +/*-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ void AnalyzepBlock(pBlock *pb) { @@ -2049,7 +2076,7 @@ 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); @@ -2075,6 +2102,8 @@ void AnalyzepBlock(pBlock *pb) } } +/*-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ int OptimizepBlock(pBlock *pb) { pCode *pc; @@ -2395,25 +2424,26 @@ void pBlockStats(FILE *of, pBlock *pb) 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); } @@ -2423,10 +2453,10 @@ void pBlockStats(FILE *of, pBlock *pb) 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); } } @@ -2504,10 +2534,10 @@ set *register_usage(pBlock *pb) 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) { @@ -2535,8 +2565,10 @@ set *register_usage(pBlock *pb) /* 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); } diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index a9264d7b..142e0098 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -88,6 +88,9 @@ regs regspic14[] = }; #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}, @@ -114,6 +117,22 @@ regs regspic14[] = {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}, @@ -505,8 +524,8 @@ pic14_regWithIdx (int idx) 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); @@ -515,14 +534,17 @@ pic14_regWithIdx (int idx) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ 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; } /*-----------------------------------------------------------------*/ diff --git a/src/pic/ralloc.h b/src/pic/ralloc.h index 37e37dbc..c0801c28 100644 --- a/src/pic/ralloc.h +++ b/src/pic/ralloc.h @@ -44,6 +44,7 @@ enum #define REG_GPR 0x02 #define REG_CND 0x04 #define REG_SFR 0x08 +#define REG_STK 0x10 /* Use a register as a psuedo stack */ /* definition for the registers */ typedef struct regs @@ -64,23 +65,11 @@ typedef struct regs regs; extern regs regspic14[]; extern int pic14_nRegs; +extern int Gstack_base_addr; regs *pic14_regWithIdx (int); void pic14_freeAllRegs (); void pic14_deallocateAllRegs (); -regs *pic14_findFreeReg(void); - -enum PIC_register_types - { - PIC_INDF, - PIC_TMR0, - PIC_FSR, - PIC_STATUS, - PIC_IOPORT, - PIC_IOTRIS, - PIC_GPR, /* A general purpose file register */ - PIC_SFR /* A special function register */ - }; - +regs *pic14_findFreeReg(short type); #endif diff --git a/src/regression/call1.c b/src/regression/call1.c index b86285c0..fe35b81d 100644 --- a/src/regression/call1.c +++ b/src/regression/call1.c @@ -5,10 +5,10 @@ unsigned char failures = 0; unsigned char dummy = 0; bit bit0 = 0; -unsigned int aint0 = 0; -unsigned int aint1 = 0; -unsigned char achar0 = 0; -unsigned char achar1 = 0; +unsigned int uint0 = 0; +unsigned int uint1 = 0; +unsigned char uchar0 = 0; +unsigned char uchar1 = 0; unsigned char call3 (void); @@ -38,7 +38,7 @@ call2 (unsigned int ui0) unsigned char call3 (void) { - if (achar0) + if (uchar0) failures++; return (failures); @@ -50,7 +50,7 @@ call4 (void) { unsigned int i = 0; - if (aint0) + if (uint0) i++; return (i); @@ -68,19 +68,81 @@ call5 (unsigned int k) } +unsigned char +call6a(unsigned char uc) +{ + + if(uc>uchar1) + return 1; + else + return 0; + +} + +unsigned char +call6(unsigned char uc) +{ + + return(call6a(uc)); +} + +unsigned int +call7a(unsigned int ui) +{ + if(ui) + return 1; + else + return 0; + +} + +unsigned int +call7(unsigned int ui) +{ + + return(call7a(ui)); +} + +unsigned char +call8(unsigned char uc1,unsigned char uc2) +{ + + return uc1+uc2; +} + void main (void) { - call1 (achar0); - call2 (aint0); - achar1 = call3 (); - aint1 = call4 (); - if (aint1) + call1 (uchar0); + call2 (uint0); + uchar1 = call3 (); + uint1 = call4 (); + if (uint1) + failures++; + + uint1 = call5 (uint0); + if (uint1) + failures++; + + if(call6(uchar0)) failures++; - aint1 = call5 (aint0); - if (aint1) + + if(call7(0)) + failures++; + + if(!call7(1)) + failures++; + + if(!call7(0xff00)) + failures++; + + uchar0=4; + uchar1=3; + uchar0 = call8(uchar0,uchar1); + + if(uchar0 != 7) failures++; success = failures; -- 2.30.2