NAME
s2c - convert a SUIF file to C
SYNOPSIS
s2c [ options ] SUIF-file [C-file]
DESCRIPTION
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.
OPTIONS
-logic-simp
Do simple logical simplification on the resulting C code before writing it.
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
``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
["s2c pragma": "no side effects" <sqrt,0>]
which would give this output line:
#pragma no side effects sqrt
``s2c pound line''
This annotation provides a general way to insert preprocessing 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 preprocessing directives at all to be inserted into the code. Whoever creates these annotations is of course responsible for insuring that they are valid preprocessing 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
["s2c pound line": "line" 37 "\"file.c\""]
which would give this output line:
#line 37 "file.c"
``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:
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.
EXAMPLES:
HISTORY
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.