NAGWare Fortran Tools - f77 Tools - nag_struct

 

Index

NAME
DESCRIPTION
OPTIONS
HANDLING OF SPECIFIC CONSTRUCTS
LIMITATIONS
SEE ALSO
 

NAME

nag_struct - NAGWare f77 Tools Restructurer

 

DESCRIPTION

nag_struct is the NAGWare f77 Tools restructurer. Its purpose is to rebuild the flow of control, within each processed program unit, to a standardised form.

nag_struct is based on the structuring algorithm described in [An Algorithm for Structuring Flowgraphs. Brenda S. Baker [1977]. J. ACM 24, 1 (January 1977), 98-120.]. Unlike the Unix(tm) struct, however, its input and output languages are the same, that is, the NAGWare Fortran 77 language definition, see nag_Fortran77.

Upon successful completion each input file is backed up to file.orig and is replaced by the polished output file.

 

OPTIONS

"Use ENDDO" (-enddo)
End DO loops with the END DO statement. Please note that this is a non standard extension.

"Add WHILE" (--while)
When appropriate generate DO WHILE statements. Please note that this is a non standard extension.

"Use logical IFs" (-logifs)
If this option is set then, where appropriate, logical IFs are output. If this option is not set block IFs are generated.

"Relabel" (-norelabel)
As a side effect of structuring, the program is completely relabelled, with any redundant labels (e.g. on specification statements) removed. nag_struct normally enforces statement relabelling by the polish routines which are called by the restructurer. This results in neater labelling of, for example, DO loop end labels.

 

HANDLING OF SPECIFIC CONSTRUCTS

Logical IF statements

The structuring of logical IF statements is controlled by the option -logifs and -std. If either of these options is set then logical Ifs are output and block IFs with a single statement consequence are output as logical IFs. If neither is set logical IFs are converted to block IFs.

DO WHILE statements

If the -while option is set DO WHILE statements will be constructed from appropriate loops. The DO WHILE statement is not ANSI standard Fortran 77. If this option is not set or the -std option is set standard Fortran 77 constructs (Block IF and GOTO) are generated instead.

DO loop termination

This is controlled by the -enddo option. If this option is set DO loops are terminated by an END DO statement. The END DO statement is not ANSI standard Fortran 77. If this option is not set or the -std option is set then standard Fortran 77 constructs (Labelled CONTINUE) are generated instead.

Arithmetic IF statements

Arithmetic IF statements are altered into logical IF statements unless the three transfer labels are different: in this case the arithmetic IF is left unchanged and will appear in the same form in the output.

Assigned GOTO statements

All assigned GOTO statements are converted into computed GOTO statements, and the ASSIGN statements changed to assignment statements. The "fall-through" option of the computed GOTO is used for the first alternative (ASSIGN) seen.

If there is only one possible target for the assigned GOTO, it is converted into a simple GOTO (which could be removed during structuring). If there are no possible targets for the assigned GOTO, nag_struct terminates with a fatal error message.

ASSIGN statements which reference FORMAT statements (for use in READ and WRITE) are left unchanged.

RETURN statements

Simple RETURN statements are treated by nag_struct as transfers of control to the END statement. As such they may disappear or be merged in the output. Similarly, any transfer of control to the END statement (of a SUBROUTINE or FUNCTION) in the output is represented by a RETURN (and not a GOTO).

Alternative RETURN statements are treated as ordinary straight-line code followed by an implicit transfer of control to the END statement.

STOP statements

STOP statements are treated by nag_struct as ordinary straight-line code; i.e. they are not "understood", and code following them will continue to follow them. This may on occasion lead to STOP statements being followed by a GOTO statement.

Dead code

Executable statements (except for END, END IF, etc.) which follow an unconditional transfer of control are not reachable and are thus "dead". Since there will be no path to them in the flowgraph nag-struct will automatically remove them. A warning message is produced for each such unreachable statement informing the user that they have been removed.

Comments

Comments which are either before or embedded within an executable statement will remain with that statement in the output. Comments associated with a flow-of-control statement (e.g. CONTINUE, GOTO, or ENDIF), are treated as executable statements for the purpose of flowgraphing. (This is because flow of control statements are eliminated during flowgraphing and only added to the output where necessary).

A consequence of the treatment of comments associated with control flow statements is that in rare circumstances nag_struct may fail to identify certain constructs as a comment breaks the sequence of statements.

nag_struct may find comments, including blank lines, which are apparently associated with unreachable statements. Such comments are moved to the end of the program unit and a warning message issued.

 

LIMITATIONS

nag_struct cannot handle "irreducible" flowgraphs. A program which has an irreducible flowgraph has a loop which is entered in two places; this means that without modifying the program, there must be a jump into the middle of a loop. An irreducible flowgraph can always be manually converted into a reducible (and thus structurable) flowgraph either by code duplication or the addition of control variables.

Program units containing an irreducible flowgraph are output with no change to the structure. BLOCK DATA subprograms cannot be structured and are simply polished and output.

 

SEE ALSO

nag_Fortran77, nag_polopt

Copyright, Numerical Algorithms Group, Oxford, 1991-2001