-
- char *s=NULL;
-
- if(isPCI(pc) &&
- (PCI(pc)->pcop) &&
- (PCI(pc)->pcop->type == PO_LABEL)) {
-
- pCodeOpLabel *pcol = PCOLAB(PCI(pc)->pcop);
-
- //fprintf(stderr,"changing label key from %d to %d\n",pcol->key, pcl->key);
- if(pcol->pcop.name)
- free(pcol->pcop.name);
-
- /* If the key is negative, then we (probably) have a label to
- * a function and the name is already defined */
-
- if(pcl->key>0)
- sprintf(s=buffer,"_%05d_DS_",pcl->key);
- else
- s = pcl->label;
-
- //sprintf(buffer,"_%05d_DS_",pcl->key);
- if(!s) {
- fprintf(stderr, "ERROR %s:%d function label is null\n",__FUNCTION__,__LINE__);
- }
- pcol->pcop.name = Safe_strdup(s);
- pcol->key = pcl->key;
- //pc->print(stderr,pc);
-
- }
-
-
-}
-
-/*-----------------------------------------------------------------*/
-/* pBlockRemoveUnusedLabels - remove the pCode labels from the */
-/* pCode chain if they're not used. */
-/*-----------------------------------------------------------------*/
-void pBlockRemoveUnusedLabels(pBlock *pb)
-{
- pCode *pc; pCodeLabel *pcl;
-
- if(!pb)
- return;
-
- for(pc = pb->pcHead; (pc=findNextInstruction(pc->next)) != NULL; ) {
-
- pBranch *pbr = PCI(pc)->label;
- if(pbr && pbr->next) {
- pCode *pcd = pb->pcHead;
-
- //fprintf(stderr, "multiple labels\n");
- //pc->print(stderr,pc);
-
- pbr = pbr->next;
- while(pbr) {
-
- while ( (pcd = findInstructionUsingLabel(PCL(PCI(pc)->label->pc), pcd)) != NULL) {
- //fprintf(stderr,"Used by:\n");
- //pcd->print(stderr,pcd);
-
- exchangeLabels(PCL(pbr->pc),pcd);
-
- pcd = pcd->next;
- }
- pbr = pbr->next;
- }
- }
- }
-
- for(pc = pb->pcHead; pc; pc = pc->next) {
-
- if(isPCL(pc)) // pc->type == PC_LABEL)
- pcl = PCL(pc);
- else if (isPCI(pc) && PCI(pc)->label) //((pc->type == PC_OPCODE) && PCI(pc)->label)
- pcl = PCL(PCI(pc)->label->pc);
- else continue;
-
- //fprintf(stderr," found A LABEL !!! key = %d, %s\n", pcl->key,pcl->label);
-
- /* This pCode is a label, so search the pBlock to see if anyone
- * refers to it */
-
- if( (pcl->key>0) && (!findInstructionUsingLabel(pcl, pb->pcHead))) {
- //if( !findInstructionUsingLabel(pcl, pb->pcHead)) {
- /* Couldn't find an instruction that refers to this label
- * So, unlink the pCode label from it's pCode chain
- * and destroy the label */
- //fprintf(stderr," removed A LABEL !!! key = %d, %s\n", pcl->key,pcl->label);
-
- DFPRINTF((stderr," !!! REMOVED A LABEL !!! key = %d, %s\n", pcl->key,pcl->label));
- if(pc->type == PC_LABEL) {
- unlinkpCode(pc);
- pCodeLabelDestruct(pc);
- } else {
- unlinkpCodeFromBranch(pc, PCODE(pcl));
- /*if(pc->label->next == NULL && pc->label->pc == NULL) {
- free(pc->label);
- }*/
- }
-
- }
- }
-
-}
-
-
-/*-----------------------------------------------------------------*/
-/* pBlockMergeLabels - remove the pCode labels from the pCode */
-/* chain and put them into pBranches that are */
-/* associated with the appropriate pCode */
-/* instructions. */
-/*-----------------------------------------------------------------*/
-void pBlockMergeLabels(pBlock *pb)
-{
- pBranch *pbr;
- pCode *pc, *pcnext=NULL;
-
- if(!pb)
- return;
-
- /* First, Try to remove any unused labels */
- //pBlockRemoveUnusedLabels(pb);
-
- /* Now loop through the pBlock and merge the labels with the opcodes */
-
- pc = pb->pcHead;
- // for(pc = pb->pcHead; pc; pc = pc->next) {
-
- while(pc) {
- pCode *pcn = pc->next;
-
- if(pc->type == PC_LABEL) {
-
- //fprintf(stderr," checking merging label %s\n",PCL(pc)->label);
- //fprintf(stderr,"Checking label key = %d\n",PCL(pc)->key);
- if((pcnext = findNextInstruction(pc) )) {
-
- // Unlink the pCode label from it's pCode chain
- unlinkpCode(pc);