Node: Transforming DO WHILE, Next: , Previous: Statements Needing Temporaries, Up: Transforming Statements



Transforming DO WHILE

DO WHILE(expr) must be implemented so that temporaries needed to evaluate expr are generated just for the test, each time.

Consider how DO WHILE (A//B .NE. 'END'); ...; END DO is transformed:

     for (;;)
       {
         int temp0;
     
         {
           char temp1[large];
     
           libg77_catenate (temp1, a, b);
           temp0 = libg77_ne (temp1, 'END');
         }
     
         if (! temp0)
           break;
     
         ...
       }
     

In this case, it seems like a time/space tradeoff between allocating and deallocating temp1 for each iteration and allocating it just once for the entire loop.

However, if temp1 is allocated just once for the entire loop, it could be the wrong size for subsequent iterations of that loop in cases like DO WHILE (A(I:J)//B .NE. 'END'), because the body of the loop might modify I or J.

So, the above implementation is used, though a more optimal one can be used in specific circumstances.