+ if(!from || !to || !to->pcflow || !from->pcflow)
+ return;
+
+ fromLink = newpCodeFlowLink(from->pcflow);
+ toLink = newpCodeFlowLink(to->pcflow);
+
+ addSetIfnotP(&(from->pcflow->to), toLink); //to->pcflow);
+ addSetIfnotP(&(to->pcflow->from), fromLink); //from->pcflow);
+
+}
+
+/*-----------------------------------------------------------------*
+* void LinkFlow(pBlock *pb)
+*
+* In BuildFlow, the PIC code has been partitioned into contiguous
+* non-branching segments. In LinkFlow, we determine the execution
+* order of these segments. For example, if one of the segments ends
+* with a skip, then we know that there are two possible flow segments
+* to which control may be passed.
+*-----------------------------------------------------------------*/
+void LinkFlow(pBlock *pb)
+{
+ pCode *pc=NULL;
+ pCode *pcflow;
+ pCode *pct;
+
+ //fprintf(stderr,"linkflow \n");
+
+ for( pcflow = findNextpCode(pb->pcHead, PC_FLOW);
+ pcflow != NULL;
+ pcflow = findNextpCode(pcflow->next, PC_FLOW) ) {
+
+ if(!isPCFL(pcflow))
+ fprintf(stderr, "LinkFlow - pcflow is not a flow object ");
+
+ //fprintf(stderr," link: ");
+ //pcflow->print(stderr,pcflow);
+
+ //FillFlow(PCFL(pcflow));
+
+ /* find last instruction in flow */
+ pc = findPrevInstruction (PCFL(pcflow)->end);
+ if (!pc) {
+ fprintf(stderr, "%s: flow without end (%u)?\n",
+ __FUNCTION__, pcflow->seq );
+ continue;
+ }
+
+ //fprintf(stderr, "LinkFlow - flow block (seq=%d) ", pcflow->seq);
+ //pc->print(stderr, pc);
+ if(isPCI_SKIP(pc)) {
+ //fprintf(stderr, "ends with skip\n");
+ //pc->print(stderr,pc);
+ pct=findNextInstruction(pc->next);
+ LinkFlow_pCode(PCI(pc),PCI(pct));
+ pct=findNextInstruction(pct->next);
+ LinkFlow_pCode(PCI(pc),PCI(pct));
+ continue;
+ }
+
+ if(isPCI_BRANCH(pc)) {
+ pCodeOpLabel *pcol = PCOLAB(PCI(pc)->pcop);
+
+ //fprintf(stderr, "ends with branch\n ");
+ //pc->print(stderr,pc);
+
+ if(!(pcol && isPCOLAB(pcol))) {
+ if((PCI(pc)->op != POC_RETLW)
+ && (PCI(pc)->op != POC_RETURN)
+ && (PCI(pc)->op != POC_CALL)
+ && (PCI(pc)->op != POC_RETFIE) )
+ {
+ pc->print(stderr,pc);
+ fprintf(stderr, "ERROR: %s, branch instruction doesn't have label\n",__FUNCTION__);
+ }
+ } else {
+
+ if( (pct = findLabelinpBlock(pb,pcol)) != NULL)
+ LinkFlow_pCode(PCI(pc),PCI(pct));
+ else
+ fprintf(stderr, "ERROR: %s, couldn't find label. key=%d,lab=%s\n",
+ __FUNCTION__,pcol->key,((PCOP(pcol)->name)?PCOP(pcol)->name:"-"));
+ //fprintf(stderr,"newpCodeOpLabel: key=%d, name=%s\n",key,((s)?s:""));
+ }
+ /* link CALLs to next instruction */
+ if (PCI(pc)->op != POC_CALL) continue;
+ }
+
+ if(isPCI(pc)) {
+ //fprintf(stderr, "ends with non-branching instruction:\n");
+ //pc->print(stderr,pc);
+
+ LinkFlow_pCode(PCI(pc),PCI(findNextInstruction(pc->next)));
+
+ continue;
+ }
+
+ if(pc) {
+ //fprintf(stderr, "ends with unknown\n");
+ //pc->print(stderr,pc);
+ continue;
+ }
+
+ fprintf(stderr, "ends with nothing: ERROR\n");
+
+ }
+}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/