Man page for sf2c.1
Table of Contents

NAME

sf2c - first pass of the SUIF Fortran 77 front end

SYNOPSIS

sf2c [ options ] infile

DESCRIPTION

The sf2c program forms the first part of the SUIF Fortran 77 front end. It is typically run automatically by scc, not directly by the user. The output of sf2c should be run through cpp (the usual C pre-processor, not a part of SUIF) snoot, fixfortran, and the porky -defaults passes, in that order, to complete the SUIF Fortran front end.

The sf2c pass converts Fortran code into a special kind of C code. The C code is legal and has the same semantics as the Fortran program, but it also has special Fortran-specific information encoded in things like assignments to dummy variables. The most important information this encodes is the original array type and bound information, including symbolic bounds.

This special C program is passed through cpp and then snoot, the regular ANSI C front end, to translate it into SUIF code. Then fixfortran extracts the Fortran information that had been encoded in C, restoring array types, call-by-reference and common-block variables, and more, when possible. Note that fixfortran is tightly coupled with sf2c and expects its input to be in exactly the form sf2c put it in. Other Fortran to C converters will not work. It is vital that no changes are made to the C code before cpp and snoot or to the SUIF code coming out of snoot before it gets to fixfortran. If any changes are made, fixfortran will become confused and probably die with some error message, but it is possible it will produce incorrect code in that case.

Our sf2c pass is based largely on a version of the Bell Labs f2c Fortran-to-C converter. Most of the original f2c options and features are available in sf2c. The major changes we've made have been aimed at getting more high-level Fortran information encoded in the C output. There are some strange contortions we put sf2c and fixfortran through to preserve this information given the structure of the old f2c. It is strongly recommended that the output of sf2c never be used directly; the entire front end of sf2c-cpp-snoot-fixfortran-porky should be treated as a black box. There are a few command line flags to sf2c that might be of general interest, but the internals of the front end are not.

The sf2c pass takes arguments that end with .f or .F as Fortran 77 source programs. If no output file is specified (the -o option), the output (the special C file) is given the same name but put in the current directory with an extension of .c. If no arguments are given, then sf2c reads Fortran from standard input and writes the special C file to standard output.

The resulting C code needs to include the sf2c.h header file, but this is normally taken care of automatically by scc. The code must eventually be linked with the libraries libF77 (or its variant, libF77_doall, in the case of parallelized code) and libI77, which are included in the SUIF distribution. This, too, is normally handled automatically when you use scc to link.

OPTIONS ADDED FOR SUIF

-g Insert C ``#line'' directives to indicate the line numbers in the original Fortran source. That way the eventual SUIF file's "line" annotations will correctly refer to line numbers in the Fortran source, not an intermediate Fortran file.

Unfortunately, f2c was not set up to keep careful track of line numbers, so the result is line numbers that are often off by one in some parts of the program. They are close enough to be quite useful, though.

Note that this option replaces the -g flag in f2c. The old version of this flag printed the line numbers in comments, not ``#line'' directives.

-o filename
Use the given filename as the output file, instead of trying to figure out an output file based on the input file name.

-pp Put each array reference on a separate line. Line breaks are introduced after each array reference if this option is used. Then if the -g option is not used, array refernce instructions can be uniquely identified by their line numbers.

-lab Put a semicolon after each label. Why this might be useful is unclear.

-version
Print version information to stderr and exit immediately. This is consistent with the -version flag for most other SUIF passes that is implemented in the main SUIF library.

-quiet
Do not print verbose commentary while compiling. Without this flag, sf2c prints out the names of procedures as they are encountered, among other things.

OPTIONS IDENTICAL TO f77 AND f2c

-C Compile code to check that subscripts are within declared array bounds.

-I2 Render INTEGER and LOGICAL as short, INTEGER*4 as long int. Assume the default libF77 and libI77: allow only INTEGER*4 (and no LOGICAL) variables in INQUIREs. This flag is incompatible with the -I4 flag.

-onetrip
The semantics of a DO loop are changed so that their bodies are performed at least once if reached. (Fortran 77 DO loops are not performed at all if the upper limit is smaller than the lower limit.)

-U Honor the case of variables and external names. Fortran keywords must be in lower case.

-u Make the default type of a variable `undefined' rather than using the default Fortran rules.

-w
-w66 Suppress warning messages. The -w form supresses all warning messages, the -w66, form supresses only Fortran 66 compatibility warnings.

OPTIONS RETAINED FROM f2c

-A Use ANSI C constructs. The default is old-style (pre-ANSI) C. SUIF note: this option is irrelevant as far as SUIF is concerned because the old-style C used is a common subset of old C and ANSI C. The snoot pass is fine with or without this option, as it understands the complete ANSI C language.

-a Give local variables automatic (rather than static) storage unless they appear in a DATA, EQUIVALENCE, or SAVE statement. SUIF note: for SUIF it's usually better to use this option because it's easier to analyze automatic variables. But SUIF will still be correct whether or not this flag is set.

-c Insert comments showing the original Fortran source. SUIF note: if this option is used along with the appropriate cpp and snoot options, comments can be retained all through the SUIF code in the form of annotations on mark instructions.

-E Declare uninitialized struct created for COMMON to be Extern (which sf2c.h W#defines to be extern if it is otherwise undefined).

-ec
-e1c These options are meaningless for SUIF. They cause sf2c to emit a separate file for each uninitialized COMMON; e.g. COMMON /ABC/ yields abc_com.c, which defines abc_. If the option is -e1c, then bundle the separate files that would result from -ec into the output file, along with comments giving a sed (1) script that separates the output file into the files that -ec would give.

-ext Complain about f77 extensions.

-i2 Do something similar to what is done by -I2, but assume a modified libF77 and libI77 (compiled with -Df2c_i2), so INTEGER and LOGICAL variables may be assigned in INQUIREs. This is incompatible with the -I4 option.

-R Do not promote REAL functions and operations to DOUBLE PRECISION (as f77 does).

-r8 Promote REAL to DOUBLE PRECISION, COMPLEX to DOUBLE COMPLEX.

-Tdir
Put temporary files in directory dir.

-w8 Do not complain when COMMON or EQUIVALENCE forces doubles to be word-aligned.

-Wn Assume n characters/word (default 4) when initializing numeric variables with character data.

-z Do not implicitly recognize DOUBLE COMPLEX.

!I Disable the included statement.

OPTIONS THAT ARE UNDOCUMENTED IN f77

-66 Disallow all extensions to Fortran 66.

-d Turn on debugging mode. Some effects of debugging mode are that temporary intermediate files are not removed and some verbose information is generated.

-1 Undocumented synonym for the -onetrip flag.

-I4 Render INTEGER and LOGICAL as `long int'. If this option is used, neither of the options -I2 or -i2 may be used, as they contradict this option.

-Is Use `short int' as the type for array subscripts.

-On Set the maximum number of register variables to use. For SUIF we ignore whether the variable was declared ``register'' in C anyway, so this option is meaningless.

-Nqn
-Nxn
-Nsn
-Ncn
-Nnn Set various implementation size limits (internal table sizes). These flags set, respectively, limits on the number of equivalences (default 150), external symbols (default 200), statement labels (default 801), nesting of loops or if-then-elses (default 20), and identifier names (default 401).

-p Use #defines within each procedure to make references to common block variables look to human readers like local variables. For SUIF this is irrelevant since the macros will have been expanded by the C pre-processor before SUIF code is ever produced. SUIF's Fortran mode allows SUIF programs to see common block variables as locals.

-Frformat-string
-Fdformat-string
Use the specified string to format, respectively, `float' or `double' data written to the output C file. The defaults are "(float)%s" (or "%sf" if the -A flag is used to specify ANSI-C) for `float' and "%.17g" for `double'.

-ev This option might mean to #define things in equivalences to look like ordinary local variables to human readers of the C file. If so, it is irrelevant to SUIF since the C pre-processor substitutes for the macros before the code is converted to SUIF.

SEE ALSO

scc, snoot, fixfortran, porky, and f77.

HISTORY

The version of f2c upon which sf2c is based calls itself, "VERSION 14 December 1989 7:55:33". It was adapted for an early version of SUIF by Dror Maydan. Chris Wilson made more modifications to get the information required by the current SUIF system.

Parts of this document were taken from the man page distributed with f2c.


Table of Contents