/* Forward declarations */
/****************************************************************/
-#if 0
-static void genericAnalyze(pCode *pc);
-static void AnalyzeGOTO(pCode *pc);
-static void AnalyzeSKIP(pCode *pc);
-static void AnalyzeRETURN(pCode *pc);
-#endif
-
static void genericDestruct(pCode *pc);
static void genericPrint(FILE *of,pCode *pc);
static pCodeInstruction pciADDWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_ADDWF,
static pCodeInstruction pciADDFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_ADDFW,
static pCodeInstruction pciADDLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_ADDLW,
static pCodeInstruction pciANDLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_ANDLW,
static pCodeInstruction pciANDWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_ANDWF,
static pCodeInstruction pciANDFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_ANDFW,
static pCodeInstruction pciBCF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_BCF,
static pCodeInstruction pciBSF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_BSF,
static pCodeInstruction pciBTFSC = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeSKIP,
genericDestruct,
genericPrint},
POC_BTFSC,
static pCodeInstruction pciBTFSS = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeSKIP,
genericDestruct,
genericPrint},
POC_BTFSS,
static pCodeInstruction pciCALL = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_CALL,
static pCodeInstruction pciCOMF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_COMF,
static pCodeInstruction pciCOMFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_COMFW,
static pCodeInstruction pciCLRF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_CLRF,
static pCodeInstruction pciCLRW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_CLRW,
static pCodeInstruction pciCLRWDT = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_CLRWDT,
static pCodeInstruction pciDECF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_DECF,
static pCodeInstruction pciDECFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_DECFW,
static pCodeInstruction pciDECFSZ = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeSKIP,
genericDestruct,
genericPrint},
POC_DECFSZ,
static pCodeInstruction pciDECFSZW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeSKIP,
genericDestruct,
genericPrint},
POC_DECFSZW,
static pCodeInstruction pciGOTO = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeGOTO,
genericDestruct,
genericPrint},
POC_GOTO,
static pCodeInstruction pciINCF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_INCF,
static pCodeInstruction pciINCFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_INCFW,
static pCodeInstruction pciINCFSZ = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeSKIP,
genericDestruct,
genericPrint},
POC_INCFSZ,
static pCodeInstruction pciINCFSZW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeSKIP,
genericDestruct,
genericPrint},
POC_INCFSZW,
static pCodeInstruction pciIORWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_IORWF,
static pCodeInstruction pciIORFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_IORFW,
static pCodeInstruction pciIORLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_IORLW,
static pCodeInstruction pciMOVF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_MOVF,
static pCodeInstruction pciMOVFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_MOVFW,
static pCodeInstruction pciMOVWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_MOVWF,
static pCodeInstruction pciRETFIE = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeRETURN,
genericDestruct,
genericPrint},
POC_RETFIE,
static pCodeInstruction pciRETLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeRETURN,
genericDestruct,
genericPrint},
POC_RETLW,
static pCodeInstruction pciRETURN = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // AnalyzeRETURN,
genericDestruct,
genericPrint},
POC_RETURN,
static pCodeInstruction pciRLF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_RLF,
static pCodeInstruction pciRLFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_RLFW,
static pCodeInstruction pciRRF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_RRF,
static pCodeInstruction pciRRFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_RRFW,
static pCodeInstruction pciSUBWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_SUBWF,
static pCodeInstruction pciSUBFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_SUBFW,
static pCodeInstruction pciSUBLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_SUBLW,
static pCodeInstruction pciSWAPF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_SWAPF,
static pCodeInstruction pciSWAPFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_SWAPFW,
static pCodeInstruction pciTRIS = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_TRIS,
static pCodeInstruction pciXORWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_XORWF,
static pCodeInstruction pciXORFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_XORFW,
static pCodeInstruction pciXORLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_XORLW,
static pCodeInstruction pciBANKSEL = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_BANKSEL,
static pCodeInstruction pciPAGESEL = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
- // genericAnalyze,
genericDestruct,
genericPrint},
POC_PAGESEL,
return pb->dbName;
}
+
void pBlockConvert2ISR(pBlock *pb)
{
if(!pb)
}
}
}
+
/*-----------------------------------------------------------------*/
/* int RegCond(pCodeOp *pcop) - if pcop points to the STATUS reg- */
/* ister, RegCond will return the bit being referenced. */
pcw->pci.from = pcw->pci.to = pcw->pci.label = NULL;
pcw->pci.pc.pb = NULL;
- // pcw->pci.pc.analyze = genericAnalyze;
pcw->pci.pc.destruct = genericDestruct;
pcw->pci.pc.print = genericPrint;
}
-/*-----------------------------------------------------------------*/
-/* newPcodeInlineP - create a new pCode from a char string */
-/*-----------------------------------------------------------------*/
-
-#if 0
-static pCode *newpCodeInlineP(char *cP)
-{
-
- pCodeComment *pcc ;
-
- pcc = Safe_calloc(1,sizeof(pCodeComment));
-
- pcc->pc.type = PC_INLINE;
- pcc->pc.prev = pcc->pc.next = NULL;
- pcc->pc.id = PCodeID();
- //pcc->pc.from = pcc->pc.to = pcc->pc.label = NULL;
- pcc->pc.pb = NULL;
-
- // pcc->pc.analyze = genericAnalyze;
- pcc->pc.destruct = genericDestruct;
- pcc->pc.print = genericPrint;
-
- if(cP)
- pcc->comment = Safe_strdup(cP);
- else
- pcc->comment = NULL;
-
- return ( (pCode *)pcc);
-
-}
-#endif
-
/*-----------------------------------------------------------------*/
/* newPcodeCharP - create a new pCode from a char string */
/*-----------------------------------------------------------------*/
//pcc->pc.from = pcc->pc.to = pcc->pc.label = NULL;
pcc->pc.pb = NULL;
- // pcc->pc.analyze = genericAnalyze;
pcc->pc.destruct = genericDestruct;
pcc->pc.print = genericPrint;
//pcf->pc.from = pcf->pc.to = pcf->pc.label = NULL;
pcf->pc.pb = NULL;
- // pcf->pc.analyze = genericAnalyze;
pcf->pc.destruct = genericDestruct;
pcf->pc.print = pCodePrintFunction;
pcflow->pc.prev = pcflow->pc.next = NULL;
pcflow->pc.pb = NULL;
- // pcflow->pc.analyze = genericAnalyze;
pcflow->pc.destruct = destructpCodeFlow;
pcflow->pc.print = genericPrint;
//pcl->pc.from = pcl->pc.to = pcl->pc.label = NULL;
pcl->pc.pb = NULL;
- // pcl->pc.analyze = genericAnalyze;
pcl->pc.destruct = pCodeLabelDestruct;
pcl->pc.print = pCodePrintLabel;
return pcop;
}
-#if 0
-static pCodeOp *newpCodeOpBitReg(regs *reg, int ibit, int inBitSpace)
-{
- pCodeOp *pcop;
-
- assert(reg);
-
- pcop = Safe_calloc(1,sizeof(pCodeOpRegBit));
- pcop->name = reg->name;
- pcop->type = PO_GPR_BIT;
- PCORB(pcop)->bit = ibit;
- PCORB(pcop)->inBitSpace = inBitSpace;
- PCOR(pcop)->r = reg;
- PCOR(pcop)->index = 0;
- PCOR(pcop)->rIdx = reg->rIdx;
- return pcop;
-}
-#endif
-
/*-----------------------------------------------------------------*
* pCodeOp *newpCodeOpReg(int rIdx) - allocate a new register
*
return pcop;
}
-#if 0
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-static void pCodeConstString(char *name, char *value)
-{
- pBlock *pb;
- unsigned i;
-
- // fprintf(stderr, " %s %s %s\n",__FUNCTION__,name,value);
-
- if(!name || !value)
- return;
-
- pb = newpCodeChain(NULL, 'P',newpCodeCharP("; Starting pCode block"));
-
- addpBlock(pb);
-
- sprintf(buffer,"; %s = %s",name,value);
- for (i=strlen(buffer); i--; ) {
- unsigned char c = buffer[i];
- if (c=='\r' || c=='\n') {
- memmove(buffer+i+1,buffer+i,strlen(buffer)-i+1);
- buffer[i] = '\\';
- if (c=='\r') buffer[i+1] = 'r';
- else if (c=='\n') buffer[i+1] = 'n';
- }
- }
-
- addpCode2pBlock(pb,newpCodeCharP(buffer));
- addpCode2pBlock(pb,newpCodeLabel(name,-1));
-
- do {
- addpCode2pBlock(pb,newpCode(POC_RETLW,newpCodeOpLit(*value)));
- }while (*value++);
-
-
-}
-
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-static void pCodeReadCodeTable(void)
-{
- pBlock *pb;
-
- fprintf(stderr, " %s\n",__FUNCTION__);
-
- pb = newpCodeChain(NULL, 'P',newpCodeCharP("; Starting pCode block"));
-
- addpBlock(pb);
-
- addpCode2pBlock(pb,newpCodeCharP("; ReadCodeTable - built in function"));
- addpCode2pBlock(pb,newpCodeCharP("; Inputs: temp1,temp2 = code pointer"));
- addpCode2pBlock(pb,newpCodeCharP("; Outpus: W (from RETLW at temp2:temp1)"));
- addpCode2pBlock(pb,newpCodeLabel("ReadCodeTable:",-1));
-
- addpCode2pBlock(pb,newpCode(POC_MOVFW,newpCodeOpRegFromStr("temp2")));
- addpCode2pBlock(pb,newpCode(POC_MOVWF,newpCodeOpRegFromStr("PCLATH")));
- addpCode2pBlock(pb,newpCode(POC_MOVFW,newpCodeOpRegFromStr("temp1")));
- addpCode2pBlock(pb,newpCode(POC_MOVWF,newpCodeOpRegFromStr("PCL")));
-
-
-}
-#endif
-
/*-----------------------------------------------------------------*/
/* addpCode2pBlock - place the pCode into the pBlock linked list */
/*-----------------------------------------------------------------*/
}
}
-#if 0
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-static void pBlockRegs(FILE *of, pBlock *pb)
-{
-
- regs *r;
-
- r = setFirstItem(pb->tregisters);
- while (r) {
- r = setNextItem(pb->tregisters);
- }
-}
-#endif
-
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
char *get_op(pCodeOp *pcop,char *buffer, size_t size)
fprintf(of,",rIdx=r0x%X",pcor->rIdx);
}
}
-#if 0
- {
- pBranch *dpb = pc->to; // debug
- while(dpb) {
- switch ( dpb->pc->type) {
- case PC_OPCODE:
- fprintf(of, "\t;%s", PCI(dpb->pc)->mnemonic);
- break;
- case PC_LABEL:
- fprintf(of, "\t;label %d", PCL(dpb->pc)->key);
- break;
- case PC_FUNCTION:
- fprintf(of, "\t;function %s", ( (PCF(dpb->pc)->fname) ? (PCF(dpb->pc)->fname) : "[END]"));
- break;
- case PC_FLOW:
- fprintf(of, "\t;flow");
- break;
- case PC_COMMENT:
- case PC_WILD:
- break;
- }
- dpb = dpb->next;
- }
- }
-#endif
fprintf(of,"\n");
break;
break;
case PC_CSOURCE:
-// fprintf(of,";#CSRC\t%s %d\n; %s\n", PCCS(pc)->file_name, PCCS(pc)->line_number, PCCS(pc)->line);
fprintf(of,"%s\t.line\t%d; \"%s\"\t%s\n", (options.debug?"":";"), PCCS(pc)->line_number, PCCS(pc)->file_name, PCCS(pc)->line);
break;
fprintf(of,"; exit point [can't find entry point]\n");
}
}
+
/*-----------------------------------------------------------------*/
/* pCodePrintLabel - prints label */
/*-----------------------------------------------------------------*/
return h;
-}
+}
+
/*-----------------------------------------------------------------*/
/* pBranchLink - given two pcodes, this function will link them */
/* together through their pBranches */
}
-#if 0
-/*-----------------------------------------------------------------*/
-/* pBranchFind - find the pBranch in a pBranch chain that contains */
-/* a pCode */
-/*-----------------------------------------------------------------*/
-static pBranch *pBranchFind(pBranch *pb,pCode *pc)
-{
- while(pb) {
-
- if(pb->pc == pc)
- return pb;
-
- pb = pb->next;
- }
-
- return NULL;
-}
-
-/*-----------------------------------------------------------------*/
-/* pCodeUnlink - Unlink the given pCode from its pCode chain. */
-/*-----------------------------------------------------------------*/
-static void pCodeUnlink(pCode *pc)
-{
- pBranch *pb1,*pb2;
- pCode *pc1;
-
- if(!pc->prev || !pc->next) {
- fprintf(stderr,"unlinking bad pCode in %s:%d\n",__FILE__,__LINE__);
- exit(1);
- }
-
- /* first remove the pCode from the chain */
- pc->prev->next = pc->next;
- pc->next->prev = pc->prev;
-
- /* Now for the hard part... */
-
- /* Remove the branches */
-
- pb1 = pc->from;
- while(pb1) {
- pc1 = pb1->pc; /* Get the pCode that branches to the
- * one we're unlinking */
-
- /* search for the link back to this pCode (the one we're
- * unlinking) */
- if(pb2 = pBranchFind(pc1->to,pc)) {
- pb2->pc = pc->to->pc; // make the replacement
-
- /* if the pCode we're unlinking contains multiple 'to'
- * branches (e.g. this a skip instruction) then we need
- * to copy these extra branches to the chain. */
- if(pc->to->next)
- pBranchAppend(pb2, pc->to->next);
- }
-
- pb1 = pb1->next;
- }
-
-
-}
-#endif
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-#if 0
-static void genericAnalyze(pCode *pc)
-{
- switch(pc->type) {
- case PC_WILD:
- case PC_COMMENT:
- return;
- case PC_LABEL:
- case PC_FUNCTION:
- case PC_OPCODE:
- {
- // Go through the pCodes that are in pCode chain and link
- // them together through the pBranches. Note, the pCodes
- // are linked together as a contiguous stream like the
- // assembly source code lines. The linking here mimics this
- // except that comments are not linked in.
- //
- pCode *npc = pc->next;
- while(npc) {
- if(npc->type == PC_OPCODE || npc->type == PC_LABEL) {
- pBranchLink(pc,npc);
- return;
- } else
- npc = npc->next;
- }
- /* reached the end of the pcode chain without finding
- * an instruction we could link to. */
- }
- break;
- case PC_FLOW:
- fprintf(stderr,"analyze PC_FLOW\n");
-
- return;
- case PC_BAD:
- fprintf(stderr,";A bad pCode is being used\n");
-
- }
-}
-#endif
-
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static int compareLabel(pCode *pc, pCodeOpLabel *pcop_label)
return NULL;
}
-#if 0
-/*-----------------------------------------------------------------*/
-/* findLabel - Search the pCode for a particular label */
-/*-----------------------------------------------------------------*/
-static pCode * findLabel(pCodeOpLabel *pcop_label)
-{
- pBlock *pb;
- pCode *pc;
-
- if(!the_pFile)
- return NULL;
-
- for(pb = the_pFile->pbHead; pb; pb = pb->next) {
- if( (pc = findLabelinpBlock(pb,pcop_label)) != NULL)
- return pc;
- }
-
- fprintf(stderr,"Couldn't find label %s\n", pcop_label->pcop.name);
- return NULL;
-}
-#endif
-
/*-----------------------------------------------------------------*/
/* findNextpCode - given a pCode, find the next of type 'pct' */
/* in the linked list */
return NULL;
}
-#if 0
-/*-----------------------------------------------------------------*/
-/* findFunctionEnd - given a pCode find the end of the function */
-/* that contains it */
-/*-----------------------------------------------------------------*/
-static pCode * findFunctionEnd(pCode *pc)
-{
- while(pc) {
- if(pc->type == PC_FUNCTION && !(PCF(pc)->fname))
- return pc;
-
- pc = pc->next;
- }
-
- fprintf(stderr,"Couldn't find function end\n");
- return NULL;
-}
-#endif
-
-#if 0
-/*-----------------------------------------------------------------*/
-/* AnalyzeLabel - if the pCode is a label, then merge it with the */
-/* instruction with which it is associated. */
-/*-----------------------------------------------------------------*/
-static void AnalyzeLabel(pCode *pc)
-{
-
- pCodeUnlink(pc);
-
-}
-#endif
-
-#if 0
-static void AnalyzeGOTO(pCode *pc)
-{
-
- pBranchLink(pc,findLabel( (pCodeOpLabel *) (PCI(pc)->pcop) ));
-
-}
-
-static void AnalyzeSKIP(pCode *pc)
-{
-
- pBranchLink(pc,findNextInstruction(pc->next));
- pBranchLink(pc,findNextInstruction(pc->next->next));
-
-}
-
-static void AnalyzeRETURN(pCode *pc)
-{
-
- // branch_link(pc,findFunctionEnd(pc->next));
-
-}
-
-#endif
-
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
regs * getRegFromInstruction(pCode *pc)
}
}
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-
-#if 0
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-static int isPCinFlow(pCode *pc, pCode *pcflow)
-{
-
- if(!pc || !pcflow)
- return 0;
-
- if(!isPCI(pc) || !PCI(pc)->pcflow || !isPCFL(pcflow) )
- return 0;
-
- if( PCI(pc)->pcflow->pc.seq == pcflow->seq)
- return 1;
-
- return 0;
-}
-#endif
-
-#if 0
-static int isREGinBank(regs *reg, int bank)
-{
-
- if(!reg || !pic)
- return 0;
-
- if((int)((reg->address | reg->alias) & pic->bankMask & bank) == bank)
- return 1;
-
- return 0;
-}
-
-static int REGallBanks(regs *reg)
-{
-
- if(!reg || !pic)
- return 0;
-
- return ((reg->address | reg->alias) & pic->bankMask);
-
-}
-#endif
-
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-/*
-static void BanksUsedFlow2(pCode *pcflow)
-{
- pCode *pc=NULL;
-
- int bank = -1;
- bool RegUsed = 0;
-
- regs *reg;
-
- if(!isPCFL(pcflow)) {
- fprintf(stderr, "BanksUsed - pcflow is not a flow object ");
- return;
- }
-
- pc = findNextInstruction(pcflow->next);
-
- PCFL(pcflow)->lastBank = -1;
-
- while(isPCinFlow(pc,pcflow)) {
-
- int bank_selected = isBankInstruction(pc);
-
- //if(PCI(pc)->pcflow)
- //fprintf(stderr,"BanksUsedFlow2, looking at seq %d\n",PCI(pc)->pcflow->pc.seq);
-
- if(bank_selected > 0) {
- //fprintf(stderr,"BanksUsed - mucking with bank %d\n",bank_selected);
-
- // This instruction is modifying banking bits before accessing registers
- if(!RegUsed)
- PCFL(pcflow)->firstBank = -1;
-
- if(PCFL(pcflow)->lastBank == -1)
- PCFL(pcflow)->lastBank = 0;
-
- bank = (1 << (bank_selected & (PIC_RP0_BIT | PIC_RP1_BIT)));
- if(bank_selected & SET_BANK_BIT)
- PCFL(pcflow)->lastBank |= bank;
-
-
- } else {
- reg = getRegFromInstruction(pc);
-
- if(reg && !isREGinBank(reg, bank)) {
- int allbanks = REGallBanks(reg);
- if(bank == -1)
- PCFL(pcflow)->firstBank = allbanks;
-
- PCFL(pcflow)->lastBank = allbanks;
-
- bank = allbanks;
- }
- RegUsed = 1;
- }
-
- pc = findNextInstruction(pc->next);
- }
-
- // fprintf(stderr,"BanksUsedFlow2 flow seq=%3d, first bank = 0x%03x, Last bank 0x%03x\n",
- // pcflow->seq,PCFL(pcflow)->firstBank,PCFL(pcflow)->lastBank);
-}
-*/
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-/*
-static void BanksUsedFlow(pBlock *pb)
-{
- pCode *pcflow;
-
-
- //pb->pcHead->print(stderr, pb->pcHead);
-
- pcflow = findNextpCode(pb->pcHead, PC_FLOW);
- //pcflow->print(stderr,pcflow);
-
- for( pcflow = findNextpCode(pb->pcHead, PC_FLOW);
- pcflow != NULL;
- pcflow = findNextpCode(pcflow->next, PC_FLOW) ) {
-
- BanksUsedFlow2(pcflow);
- }
-
-}
-*/
static void pCodeReplace (pCode *old, pCode *new)
{
AnalyzeFlow(0);
AnalyzeFlow(1);
- // for(pb = the_pFile->pbHead; pb; pb = pb->next)
- // BanksUsedFlow(pb);
for(pb = the_pFile->pbHead; pb; pb = pb->next)
FixRegisterBanking(pb);
buildCallTree();
}
-#if 0
-/*-----------------------------------------------------------------*/
-/* ispCodeFunction - returns true if *pc is the pCode of a */
-/* function */
-/*-----------------------------------------------------------------*/
-static bool ispCodeFunction(pCode *pc)
-{
-
- if(pc && pc->type == PC_FUNCTION && PCF(pc)->fname)
- return 1;
-
- return 0;
-}
-#endif
-
/*-----------------------------------------------------------------*/
/* findFunction - Search for a function by name (given the name) */
/* in the set of all functions that are in a pBlock */
return NULL;
}
-#if 0
-static void MarkUsedRegisters(set *regset)
-{
-
- regs *r1,*r2;
-
- for(r1=setFirstItem(regset); r1; r1=setNextItem(regset)) {
- r2 = pic14_regWithIdx(r1->rIdx);
- if (r2) {
- r2->isFree = 0;
- r2->wasUsed = 1;
- }
- }
-}
-#endif
-
static void pBlockStats(FILE *of, pBlock *pb)
{
}
}
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-#if 0
-static void sequencepCode(void)
-{
- pBlock *pb;
- pCode *pc;
-
-
- for(pb = the_pFile->pbHead; pb; pb = pb->next) {
-
- pb->seq = GpCodeSequenceNumber+1;
-
- for( pc = pb->pcHead; pc; pc = pc->next)
- pc->seq = ++GpCodeSequenceNumber;
- }
-
-}
-#endif
-
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-/*
-static set *register_usage(pBlock *pb)
-{
- pCode *pc,*pcn;
- set *registers=NULL;
- set *registersInCallPath = NULL;
-
- / * check recursion * /
-
- pc = setFirstItem(pb->function_entries);
-
- if(!pc)
- return registers;
-
- pb->visited = 1;
-
- if(pc->type != PC_FUNCTION)
- fprintf(stderr,"%s, first pc is not a function???\n",__FUNCTION__);
-
- pc = setFirstItem(pb->function_calls);
- for( ; pc; pc = setNextItem(pb->function_calls)) {
-
- if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL) {
- char *dest = get_op_from_instruction(PCI(pc));
-
- pcn = findFunction(dest);
- if(pcn)
- registersInCallPath = register_usage(pcn->pb);
- } else
- fprintf(stderr,"BUG? pCode isn't a POC_CALL %d\n",__LINE__);
-
- }
-
-#ifdef PCODE_DEBUG
- pBlockStats(stderr,pb); // debug
-#endif
-
- // Mark the registers in this block as used.
-
- MarkUsedRegisters(pb->tregisters);
- if(registersInCallPath) {
- / * registers were used in the functions this pBlock has called * /
- / * so now, we need to see if these collide with the ones we are * /
- / * using here * /
-
- regs *r1,*r2, *newreg;
-
- DFPRINTF((stderr,"comparing registers\n"));
-
- r1 = setFirstItem(registersInCallPath);
- while(r1) {
- if (r1->type != REG_STK) {
- r2 = setFirstItem(pb->tregisters);
-
- while(r2 && (r2->type != REG_STK)) {
-
- if(r2->rIdx == r1->rIdx) {
- newreg = pic14_findFreeReg(REG_GPR);
-
-
- if(!newreg) {
- DFPRINTF((stderr,"Bummer, no more registers.\n"));
- exit(1);
- }
-
- DFPRINTF((stderr,"Cool found register collision nIdx=%d moving to %d\n",
- r1->rIdx, newreg->rIdx));
- r2->rIdx = newreg->rIdx;
- if(newreg->name)
- r2->name = Safe_strdup(newreg->name);
- else
- r2->name = NULL;
- newreg->isFree = 0;
- newreg->wasUsed = 1;
- }
- r2 = setNextItem(pb->tregisters);
- }
- }
-
- r1 = setNextItem(registersInCallPath);
- }
-
- / * Collisions have been resolved. Now free the registers in the call path * /
- r1 = setFirstItem(registersInCallPath);
- while(r1) {
- newreg = pic14_regWithIdx(r1->rIdx);
- if (newreg) newreg->isFree = 1;
- r1 = setNextItem(registersInCallPath);
- }
-
- }// else
- // MarkUsedRegisters(pb->registers);
-
- registers = unionSets(pb->tregisters, registersInCallPath, THROW_NONE);
-#ifdef PCODE_DEBUG
- if(registers)
- DFPRINTF((stderr,"returning regs\n"));
- else
- DFPRINTF((stderr,"not returning regs\n"));
-
- DFPRINTF((stderr,"pBlock after register optim.\n"));
- pBlockStats(stderr,pb); // debug
-#endif
-
- return registers;
-}
-*/
-
/*-----------------------------------------------------------------*/
/* printCallTree - writes the call tree to a file */
/* */
}
#if 0
+/*-----------------------------------------------------------------*/
+/* ispCodeFunction - returns true if *pc is the pCode of a */
+/* function */
+/*-----------------------------------------------------------------*/
+static bool ispCodeFunction(pCode *pc)
+{
+
+ if(pc && pc->type == PC_FUNCTION && PCF(pc)->fname)
+ return 1;
+
+ return 0;
+}
+
/*-----------------------------------------------------------------*/
/* printCallTree - writes the call tree to a file */
/* */