s2c - convert a SUIF file to C
s2c [ options ] SUIF-file [C-file]
The s2c program reads the specified SUIF file and prints out its translation into the Standard C language, if possible. If the C-file specification is given, it is used for output, otherwise the C code is written to standard output.
The output conforms to the ANSI/ISO specifications for Standard C. Each output file is self contained and does not use #include to include any other files. The output is not machine independent, however. The SUIF system determines the sizes of all data types and the locations of fields in structures and elements in arrays. To produce C output that retains type information for debugging, readability of the C code, and to allow for easier optimizations by the back-end C compiler, SUIF structures and arrays are translated into the corresponding C types, and direct structure and array accesses are translated into their C versions. In doing all of this, s2c makes assumptions about how the back-end C compiler will lay out and align the data within structures and arrays. It also must make assumptions about sizes of all types when doing pointer arithmetic or array indexing.
For these reasons, the C compiler used as a back end must use the same data size, alignment, and layout rules used by snoot, the SUIF C front end. If a particular existing C compiler is to be used as a back end for SUIF, snoot must have its configuration parameters set up to match that compiler. See the snoot documentation for more information.
-logic-simp
Do simple logical simplification on the resulting C
code before writing it.
The pseudo-C written sticks as close to C as possible. The idea is that even if the C code can't be run, the pseudo-C provides an easy-to-read way of looking at the contents of a SUIF file.
fses -- all file set entries
nodes -- all tree nodes (except tree_instr nodes, because no permanent annotations are allowed on tree_instrs)
loops -- all ``loop'' nodes
fors -- all ``for'' nodes
ifs -- all ``if'' nodes
blocks -- all ``block'' nodes
all-instrs -- all instructions
symtabs -- all symbol tables
all-syms -- all symbols
vars -- all variable symbols
proc-syms -- all procedure symbols
labels -- all label symbols
var-defs -- all variable definitions
types -- all types
The s2c program reserves all annotations names beginning with the prefix ``s2c `' for its own use. Some annotations it uses internally, and some are recognized on input files and may be used to affect the behavior of s2c. The following are the annotations s2c recognizes on its input.
``s2c comments''
This annotation is used to specify comments to be
inserted into the C code. Its data should be a
list of any number of strings, each of which is
interpreted as a separate comment. Each comment
should consist of all the text between the ``/*''
and ``*/'' markers. Comments can be put on SUIF
``mark'' instructions, in which case they will be
put on lines of their own, or they may be put on
any other SUIF object and they will be put in the C
code near the C code that most directly results
from that SUIF object.
``s2c pragma''
This annotation is used to specify pragmas to be
inserted into the C code. s2c looks for this annotation
on file_set_entries, symbol tables, and
io_mrk instructions. There may be multiple pragma
annotations on an object. Each such annotation
generates one pragma line in the output.
The exact form of the output line is the string ``#pragma'' followed by a space followed by the printed representations of the immeds in the annotation, separated by a space if there are multiple immeds. Strings are printed without extra quotes around them or any other interpretation, so a pragma annotation with a single string immed as its data allows the form of the pragma line to be specified exactly. All other immeds are printed in natural ways.
An example of the use of this annotation would be with a global symbol table containing an annotation of
pragma": no side effects <sqrt,0>]
which would give this output line:
``s2c preamble pragma''
This annotation is is just like the ``s2c pragma''
annotation except that it only has an effect when
it is placed on the global symbol table and the
pragmas for this annotation are printed before the
declarations for the global symbol table instead of
after those declarations.
``s2c pound line''
This annotation provides a general way to insert
pre-processing directives into the C code. They
are similar to ``s2c pragma'' annotation except
that instead of beginning with ``#pragma'' and a
space, the lines in the C code begin with only
``#'' and no space, followed directly by the
immeds. This allows ``#define'', ``#ifdef'',
``#line'', or any other pre-processing directives
at all to be inserted into the code. Whoever creates
these annotations is of course responsible for
insuring that they are valid pre-processing directives
and that they interact properly with whatever
else s2c puts in the C file.
An example of the use of this annotation would be with an io_mrk instruction containing an annotation of
pound line": line 37 \"file.c\""]
which would give this output line:
``s2c genop format''
This annotation may be used on the global symbol
table to specify the way that SUIF ``io_genop''
instructions will be written. Note that
``io_genop'' instructions cannot in general be
translated to valid C code, so this annotation is
useful only with the -pseudo command-line option.
In that case, s2c functions to make the SUIF code
easy to read for a human. To that end, this annotation
allows flexibility in the way ``io_genop''
instructions are written.
There are two forms that are recognized for the data of this annotation. The first is two strings. The first string specifies the name of a ``genop'' and the other is a format string for printing the ``genop''. The other form for the data is a string, then an integer, then another string. In this case the first and last string have the same meanings as before, but the integer specifies the number of arguments, and only ``genop''s with that number of arguments use that format string.
For each ``genop'' to be printed, if there is a format annotation specifying the right number of arguments, that is used. Otherwise, if there is a format annotations not specifying anything about arguments, that is used. If neither of these cases apply, the default method of printing ``genop'' instructions is used: they are printed as function calls with the name of the ``genop'' as the function name.
Each format string is interpreted as follows. The ``%'' character is used as an escape in the format string -- other characters are generally printed directly. The following escape sequences are recognized:
Note that there can be any number of ``%a'' directives, possibly before and after the ``%n'' directive, but there may only be one ``%n'' directive. Arguments to all ``%a'' directives are matched first, either from the beginning of the argument list for those preceeding a ``%n'' directive or from the end for those coming after one. It is an error for there to be too few arguments to match all ``%a'' directives, but it is not an error to have too many arguments.
Within a ``%n'' directive, the text string may include ``%%'', which translates to one ``%'', but no other occurances of ``%''.
Note that the default format if nothing else is given is equivalent to ``<name>(%n, %)'' if there are any arguments or ``<name>'' if there are no arguments, where <name> is the name of the generic instruction.
Robert French wrote an s2c program for an earlier version of the SUIF system. Due primarily to limitations of the SUIF format of that time, the output of the early version wasn't quite correct C code, but instead provided a useful way to format a SUIF file for easy reading. Todd Smith updated portions of the code to compensate for drastic changes in the SUIF system. Chris Wilson made more updates and rewrote parts of the program to produce correct C output.