- int i;
-
- hTab *pointers ;
-
- /* for each basic block do */
- for (i = 0 ; i < count ; i++ ) {
- iCode *ic;
-
- setToNull((void **) &pointers);
- /* iterate thru intructions in the basic block */
- for (ic = ebbs[i]->sch ; ic ; ic = ic->next ) {
-
- if (SKIP_IC(ic) ||ic->op == IFX)
- continue ;
-
- if (pointers)
- pointerArithOpts(ic,pointers);
-
- if (!POINTER_SET(ic) && IC_RESULT(ic))
- /* delete from pointer access */
- hTabDeleteItem (&pointers, IC_RESULT(ic)->key,NULL,DELETE_CHAIN,NULL);
-
- /* set up for pointers */
- if ((ic->op == ADDRESS_OF || ADD_SUBTRACT_ITEMP(ic)) &&
- IS_ITEMP(IC_RESULT(ic)) ) {
- operand *sym ;
- operand *asym ;
- long cval ;
-
- if ( ic->op == ADDRESS_OF){
- sym = IC_RESULT(ic);
- asym = NULL ;
- cval = 0;
- } else {
- sym = IC_LEFT(ic);
- asym = IC_RESULT(ic);
- cval = operandLitValue(IC_RIGHT(ic));
- }
-
- /* put it in the pointer set */
- }
- }
-
- }
+ /* this is what we do. look for sequences like
+
+ iTempX := _SOME_POINTER_;
+ iTempY := _SOME_POINTER_ + nn ; nn = sizeof (pointed to object)
+ _SOME_POINTER_ := iTempY;
+ either
+ iTempZ := @[iTempX];
+ or
+ *(iTempX) := ..something..
+ if we find this then transform this to
+ iTempX := _SOME_POINTER_;
+ either
+ iTempZ := @[iTempX];
+ or
+ *(iTempX) := ..something..
+ iTempY := _SOME_POINTER_ + nn ; nn = sizeof (pointed to object)
+ _SOME_POINTER_ := iTempY; */
+
+ /* sounds simple enough so lets start , here I use -ve
+ tests all the way to return if any test fails */
+ iCode *pgs, *sh,*st;
+
+ if (!( sic->next && sic->next->next && sic->next->next->next))
+ return ;
+ if (sic->next->op != '+' && sic->next->op != '-') return;
+ if (!(sic->next->next->op == '=' &&
+ !POINTER_SET(sic->next->next))) return;
+ if (!isOperandEqual(IC_LEFT(sic->next),IC_RIGHT(sic)) ||
+ !IS_OP_LITERAL(IC_RIGHT(sic->next)) ) return;
+ if (operandLitValue(IC_RIGHT(sic->next)) !=
+ getSize(operandType(IC_RIGHT(sic))->next)) return;
+ if (!isOperandEqual(IC_RESULT(sic->next->next),
+ IC_RIGHT(sic))) return;
+ if (!isOperandEqual(IC_RESULT(sic->next),IC_RIGHT(sic->next->next))) return;
+ if (!(pgs = findPointerGetSet(sic->next->next,IC_RESULT(sic))))
+ return;
+
+ /* found the patter .. now do the transformation */
+ sh = sic->next; st = sic->next->next ;
+
+ /* take the two out of the chain */
+ sic->next = st->next;
+ st->next->prev = sic;
+
+ /* and put them after the pointer get/set icode */
+ if ((st->next = pgs->next))
+ st->next->prev = st;
+ pgs->next = sh;
+ sh->prev = pgs;
+