if(!pc)
return;
+ pic16_unlinkpCode(pc);
+
// if((pc->type == PC_LABEL) && PCL(pc)->label)
// Safe_free(PCL(pc)->label);
fprintf(stderr,"Unlinking: ");
printpCode(stderr, pc);
#endif
- if(pc->prev)
+ if(pc->prev) {
pc->prev->next = pc->next;
- if(pc->next)
+ } else if (pc->pb && (pc->pb->pcHead == pc)) {
+ pc->pb->pcHead = pc->next;
+ }
+ if(pc->next) {
pc->next->prev = pc->prev;
+ } else if (pc->pb && (pc->pb->pcTail == pc)) {
+ pc->pb->pcTail = pc->prev;
+ }
/* move C source line down (or up) */
if (isPCI(pc) && PCI(pc)->cline) {
pBranch *pb1,*pb2;
pCode *pc1;
- if(!pc->prev || !pc->next) {
- fprintf(stderr,"unlinking bad pCode in %s:%d\n",__FILE__,__LINE__);
- exit(1);
- }
-
- /* move C source line down (or up) */
- if (isPCI(pc) && PCI(pc)->cline) {
- pc1 = pic16_findNextInstruction (pc->next);
- if (pc1 && isPCI(pc1) && !PCI(pc1)->cline) {
- PCI(pc1)->cline = PCI(pc)->cline;
- } else {
- pc1 = pic16_findPrevInstruction (pc->prev);
- if (pc1 && isPCI(pc1) && !PCI(pc1)->cline)
- PCI(pc1)->cline = PCI(pc)->cline;
- }
+ if (!pc) {
+ return;
}
- /* first remove the pCode from the chain */
- pc->prev->next = pc->next;
- pc->next->prev = pc->prev;
-
- pc->prev = pc->next = NULL;
-
- /* Now for the hard part... */
-
/* Remove the branches */
pb1 = PCI(pc)->from;
pb1 = pb1->next;
}
+ pic16_unlinkpCode (pc);
}
#endif
}
+#if 0
/*-----------------------------------------------------------------*/
/*int compareBankFlow - compare the banking requirements between */
/* flow objects. */
return 1;
}
+#endif
#if 0
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/* buildCallTree - Look at the flow and extract all of the calls. */
/*-----------------------------------------------------------------*/
+#if 0
static set *register_usage(pBlock *pb);
+#endif
static void buildCallTree(void )
{
return NULL;
}
+#if 0
static void MarkUsedRegisters(set *regset)
{
r2->wasUsed = 1;
}
}
+#endif
static void pBlockStats(FILE *of, pBlock *pb)
{
}
#endif
+#if 0
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static set *register_usage(pBlock *pb)
return registers;
}
+#endif
/*-----------------------------------------------------------------*/
/* pct2 - writes the call tree to a file */
/* bank so that we can make sure the bytes are laid out sequentially in memory) */
/* TODO: Symbols with an abslute address must be handled specially! */
/*------------------------------------------------------------------------------------*/
-int assignToSameBank (int bank0, int bank1, int doAbs)
+int assignToSameBank (int bank0, int bank1, int doAbs, int force)
{
int eff0, eff1, dummy;
pseudoBank *pbank0, *pbank1;
#endif
if (pbank1) {
- if (pbank0->size + pbank1->size > MAX_COMMON_BANK_SIZE) {
+ if (!force && (pbank0->size + pbank1->size > MAX_COMMON_BANK_SIZE)) {
#if 0
fprintf (stderr, "bank #%d: %u, bank #%d: %u --> bank #%d': %u > %u (%s,%s)\n",
pbank0->bank, pbank0->size, pbank1->bank, pbank1->size,
bankNr = reg->address >> 8;
node = getOrAddGNode (adj, NULL, bankNr);
bankNr = (pseudoBankNr) getEffectiveBank (getPseudoBankNrFromOperand(reg->name));
- assignToSameBank (node->hash, bankNr, 1);
+ assignToSameBank (node->hash, bankNr, 1, 1);
assert (bankNr >= 0);
pbank = (pseudoBank *) hTabFindByKey (coerce, bankNr % coerce->size, (void *) bankNr, &comparePtr);
} else {
assert (pbank->bank == (reg->address >> 8));
pbank->bank = reg->address >> 8; //FIXED_BANK;
+ pbank->size++;
}
//fprintf (stderr, "ABS: %s (%d bytes) at %x in bank %u\n", reg->name, reg->size, reg->address, bankNr);
} // for reg
node1next = node1->next;
base_symbol1 = getSymbolFromOperand (getSymFromBank (getEffectiveBank (node1->hash)), &len1);
if (len0 == len1 && len0 > 0 && strncmp (base_symbol0, base_symbol1, len0) == 0) {
+ int res;
// TODO: check for symbols with absolute addresses -- these might be placed across bank boundaries!
//fprintf (stderr, "merging %s and %s\n", getSymFromBank (getEffectiveBank(node->hash)), getSymFromBank (getEffectiveBank(node1->hash)));
- if (assignToSameBank (node->hash, node1->hash, 0)) {
- fprintf (stderr, "%s(%d) == %s(%d)\n", base_symbol0, len0, base_symbol1, len1);
+ if (0 != (res = assignToSameBank (node->hash, node1->hash, 0, 1))) {
+ fprintf (stderr, "%s(%d) == %s(%d), res=%d\n", base_symbol0, len0, base_symbol1, len1, res);
assert (0 && "Could not assign a symbol to a bank!");
}
mergeGraphNodes (node, node1);
node = getGNode (adj, max->src->data, max->src->hash);
node1 = getGNode (adj, max->node->data, max->node->hash);
- if (0 == assignToSameBank (max->src->hash, max->node->hash, 0)) {
+ if (0 == assignToSameBank (max->src->hash, max->node->hash, 0, 0)) {
if (max->src->hash < max->node->hash)
mergeGraphNodes (node, node1);
else
} // for
pc = pic16_findNextInstruction (pb->pcHead);
+ if (!pc) {
+ // empty function, avoid NULL pointer dereference
+ return;
+ } // if
todo = NULL; blacklist = NULL;
addSetHead (&todo, PCI(pc)->pcflow);