- eBBlock **ebbs = NULL ;
- iCode *loop = ic;
-
- *count = 0 ;
-
- /* allocate for the first entry */
- ALLOC(ebbs,sizeof(eBBlock **));
-
- while (loop) {
-
- /* convert 2 block */
- eBBlock *ebb = iCode2eBBlock(loop);
- loop = ebb->ech->next ;
-
- ebb->ech->next = NULL ; /* mark the end of this chain */
- if (loop)
- loop->prev = NULL ;
- ebb->bbnum = *count ; /* save this block number */
- /* put it in the array */
- ebbs[(*count)++] = ebb ;
-
- /* allocate for the next one */
- if (!(ebbs = GC_realloc(ebbs,(*count + 1)*sizeof(eBBlock **)))) {
- werror(E_OUT_OF_MEM,__FILE__,(*count + 1)*sizeof(eBBlock **));
- exit (1);
- }
-
- /* if this one ends in a goto or a conditional */
- /* branch then check if the block it is going */
- /* to already exists, if yes then this could */
- /* be a loop, add a preheader to the block it */
- /* goes to if it does not already have one */
- if (ebbs[(*count) - 1]->ech &&
- (ebbs[(*count) - 1]->ech->op == GOTO ||
- ebbs[(*count) - 1]->ech->op == IFX )) {
-
- symbol *label ;
- eBBlock *destBlock;
-
- if (ebbs[(*count) - 1]->ech->op == GOTO)
- label = IC_LABEL(ebbs[(*count)-1]->ech);
- else
- if (!(label = IC_TRUE(ebbs[(*count)-1]->ech)))
- label = IC_FALSE(ebbs[(*count)-1]->ech);
-
- if ((destBlock = eBBWithEntryLabel(ebbs,label,(*count))) &&
- destBlock->preHeader == NULL &&
- otherPathsPresent(ebbs,destBlock) ) {
-
- symbol *preHeaderLabel = newiTempPreheaderLabel();
- int i,j ;
- eBBlock *pBlock ;
-
- /* go thru all block replacing the entryLabel with new label */
- /* till we reach the block , then we insert a new ebblock */
- for ( i = 0 ; i < (*count) ; i++ ) {
- if ( ebbs[i] == destBlock )
- break ;
- replaceLabel(ebbs[i],label,preHeaderLabel);
- }
-
- (*count)++ ;
- /* if we have stopped at the block , allocate for an extra one */
- if (!(ebbs = GC_realloc(ebbs,(*count + 1)*sizeof(eBBlock **)))) {
- werror(E_OUT_OF_MEM,__FILE__,(*count + 1)*sizeof(eBBlock **));
- exit (1);
+ eBBlock **ebbs = NULL;
+ iCode *loop = ic;
+ ebbIndex *ebbi;
+
+ ebbi = Safe_alloc (sizeof (ebbIndex));
+ ebbi->count = 0;
+ ebbi->dfOrder = NULL; /* no depth first order information yet */
+
+ /* allocate for the first entry */
+
+ ebbs = Safe_alloc (sizeof (eBBlock *));
+ ebbi->bbOrder = ebbs;
+
+ while (loop)
+ {
+
+ /* convert 2 block */
+ eBBlock *ebb = iCode2eBBlock (loop);
+ loop = ebb->ech->next;
+
+ ebb->ech->next = NULL; /* mark the end of this chain */
+ if (loop)
+ loop->prev = NULL;
+ ebb->bbnum = ebbi->count; /* save this block number */
+ /* put it in the array */
+ ebbs[(ebbi->count)++] = ebb;
+
+ /* allocate for the next one. Remember to clear the new */
+ /* pointer at the end, that was created by realloc. */
+
+ ebbs = Safe_realloc (ebbs, (ebbi->count + 1) * sizeof (eBBlock *));
+ ebbi->bbOrder = ebbs;
+
+ ebbs[ebbi->count] = 0;
+
+ /* if this one ends in a goto or a conditional */
+ /* branch then check if the block it is going */
+ /* to already exists, if yes then this could */
+ /* be a loop, add a preheader to the block it */
+ /* goes to if it does not already have one */
+ if (ebbs[(ebbi->count) - 1]->ech &&
+ (ebbs[(ebbi->count) - 1]->ech->op == GOTO ||
+ ebbs[(ebbi->count) - 1]->ech->op == IFX))
+ {
+
+ symbol *label;
+ eBBlock *destBlock;
+
+ if (ebbs[(ebbi->count) - 1]->ech->op == GOTO)
+ label = IC_LABEL (ebbs[(ebbi->count) - 1]->ech);
+ else if (!(label = IC_TRUE (ebbs[(ebbi->count) - 1]->ech)))
+ label = IC_FALSE (ebbs[(ebbi->count) - 1]->ech);
+
+ if ((destBlock = eBBWithEntryLabel (ebbi, label)) &&
+ destBlock->preHeader == NULL &&
+ otherPathsPresent (ebbs, destBlock))
+ {
+
+ symbol *preHeaderLabel = newiTempLoopHeaderLabel (1);
+ int i, j;
+ eBBlock *pBlock;
+
+ /* go thru all block replacing the entryLabel with new label */
+ /* till we reach the block , then we insert a new ebblock */
+ for (i = 0; i < (ebbi->count); i++)
+ {
+ if (ebbs[i] == destBlock)
+ break;
+ replaceLabel (ebbs[i], label, preHeaderLabel);