0, // second literal operand
POC_NOP,
PCC_REGISTER, // inCond
- PCC_REGISTER2, // outCond
+ PCC_REGISTER, // outCond
PCI_MAGIC
};
initialized = 1;
- pic16_initStack(0xfff, 8);
+// pic16_initStack(0xfff, 8);
pic16_init_pic(port->processor);
pic16_pc_status.r = pic16_allocProcessorRegister(IDX_STATUS,"STATUS", PO_STATUS, 0x80);
} else
pcf->fname = NULL;
- return ( (pCode *)pcf);
+ pcf->stackusage = 0;
+ return ( (pCode *)pcf);
}
/*-----------------------------------------------------------------*/
PCOI(pcop)->r = r;
if(r) {
-// fprintf(stderr, "%s:%d %s reg %s exists\n",__FILE__, __LINE__, __FUNCTION__, name);
+// fprintf(stderr, "%s:%d %s reg %s exists (r: %p)\n",__FILE__, __LINE__, __FUNCTION__, name, r);
PCOI(pcop)->rIdx = r->rIdx;
} else {
-// fprintf(stderr, "%s:%d %s reg %s doesn't exist\n",
-// __FILE__, __LINE__, __FUNCTION__, name);
+// fprintf(stderr, "%s:%d %s reg %s doesn't exist\n", __FILE__, __LINE__, __FUNCTION__, name);
PCOI(pcop)->rIdx = -1;
}
// fprintf(stderr,"%s %s %d\n",__FUNCTION__,name,offset);
PCORB(pcop)->subtype = subt;
/* pCodeOpBit is derived from pCodeOpReg. We need to init this too */
- PCOR(pcop)->r = NULL;
- PCOR(pcop)->rIdx = 0;
+ PCOR(pcop)->r = pic16_dirregWithName(s); //NULL;
+// PCOR(pcop)->rIdx = 0;
return pcop;
}
pCode *pc = pci;
while(pc) {
- pc = pc->prev;
if((pc->type == PC_OPCODE)
|| (pc->type == PC_WILD)
fprintf(stderr,"pic16_findPrevInstruction: ");
printpCode(stderr, pc);
#endif
+ pc = pc->prev;
}
//fprintf(stderr,"Couldn't find instruction\n");
return PCOR(PCI(pc)->pcop)->r;
case PO_IMMEDIATE:
+// return pic16_dirregWithName(PCOI(PCI(pc)->pcop)->r->name);
+
if(PCOI(PCI(pc)->pcop)->r)
return (PCOI(PCI(pc)->pcop)->r);
-
+ else
+ return NULL;
+
case PO_GPR_BIT:
return PCOR(PCI(pc)->pcop)->r;
return PCOR(PCOR2(PCI(pc)->pcop)->pcop2)->r;
case PO_IMMEDIATE:
-// break;
-#if 1
+#if 0
// if(PCOI(PCI(pc)->pcop)->r)
// return (PCOI(PCOR2(PCI(pc)->pcop)->pcop2)->r);
//fprintf(stderr, "pic16_getRegFromInstruction2 - immediate\n");
- return pic16_dirregWithName(PCOR(PCOR2(PCI(pc)->pcop)->pcop2)->r->name);
- //return NULL; // PCOR(PCI(pc)->pcop)->r;
+ return pic16_dirregWithName(PCOI(PCOR2(PCI(pc)->pcop)->pcop2)->r->name);
#endif
+ if(PCOI(PCOR2(PCI(pc)->pcop)->pcop2)->r)
+ return (PCOI(PCOR2(PCI(pc)->pcop)->pcop2)->r);
+ else
+ return NULL;
+
+
case PO_GPR_BIT:
break;
// return PCOR2(PCI(pc)->pcop)->r;
static char *pcc_str[] = {
//"PCC_NONE",
"PCC_REGISTER",
- "PCC_REGISTER2",
"PCC_C",
"PCC_Z",
"PCC_DC",
tlbl = newiTempLabel(NULL);
/* invert skip instruction */
- pcprev = pic16_findPrevInstruction(pc);
+ pcprev = pic16_findPrevInstruction(pc->prev);
ipci = PCI(pcprev)->inverted_op;
npci = pic16_newpCode(ipci, PCI(pcprev)->pcop);
pBranch *pbr;
pBlock *pb;
pCode *pc;
-
+ regs *r;
+
if(!the_pFile)
return;
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
pCode *pc_fstart=NULL;
for(pc = pb->pcHead; pc; pc = pc->next) {
+
+ if(isPCI(pc) && pc_fstart) {
+ if(PCI(pc)->is2MemOp) {
+ r = pic16_getRegFromInstruction2(pc);
+ if(r && !strcmp(r->name, "POSTDEC1"))
+ PCF(pc_fstart)->stackusage++;
+ } else {
+ r = pic16_getRegFromInstruction(pc);
+ if(r && !strcmp(r->name, "PREINC1"))
+ PCF(pc_fstart)->stackusage--;
+ }
+ }
+
if(isPCF(pc)) {
if (PCF(pc)->fname) {
r = setNextItem(pb->tregisters);
}
}
+
+ fprintf(of, "; uses %d bytes of stack\n", 1+ elementsInSet(pb->tregisters));
}
/*-----------------------------------------------------------------*/
/* pct2 - writes the call tree to a file */
/* */
/*-----------------------------------------------------------------*/
-static void pct2(FILE *of,pBlock *pb,int indent)
+static void pct2(FILE *of,pBlock *pb,int indent,int usedstack)
{
pCode *pc,*pcn;
int i;
if(!of)
return;
- if(indent > 10)
+ if(indent > 10) {
+ fprintf(of, "recursive function\n");
return; //recursion ?
+ }
pc = setFirstItem(pb->function_entries);
pb->visited = 0;
for(i=0;i<indent;i++) // Indentation
- fputc(' ',of);
+ fputs("+ ", of);
+ fputs("+- ", of);
- if(pc->type == PC_FUNCTION)
- fprintf(of,"%s\n",PCF(pc)->fname);
- else
- return; // ???
+ if(pc->type == PC_FUNCTION) {
+ usedstack += PCF(pc)->stackusage;
+ fprintf(of,"%s (stack: %i)\n",PCF(pc)->fname, usedstack);
+ } else return; // ???
pc = setFirstItem(pb->function_calls);
pcn = findFunction(dest);
if(pcn)
- pct2(of,pcn->pb,indent+1);
+ pct2(of,pcn->pb,indent+1, usedstack); // + PCF(pcn)->stackusage);
} else
fprintf(of,"BUG? pCode isn't a POC_CALL %d\n",__LINE__);
pBlockStats(of,pb);
-
fprintf(of,"Call Tree\n");
pbr = the_pFile->functions;
while(pbr) {
fprintf(of,"\n**************\n\na better call tree\n");
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
- if(pb->visited)
- pct2(of,pb,0);
+// if(pb->visited)
+ pct2(of,pb,0,0);
}
for(pb = the_pFile->pbHead; pb; pb = pb->next) {