Go to the previous, next section.

Symbolic Information

SUIF includes detailed symbolic information. Symbols and types are defined in nested scopes corresponding to the block structure of the program. A symbol table is attached to each element of the main SUIF hierarchy that defines a new scope. Symbols record information about variables, labels, and procedures. The SUIF type system is similar to C but also has some support for Fortran and other languages.

The symbol tables (see section Symbol Tables) are defined in a tree structure that forms a hierarchy parallel to the main SUIF hierarchy. Each table records a pointer to its parent and keeps a list of its children. The global symbol table at the root is attached to the file set and is shared across all the files. Its children are the file symbol tables attached to the file set entries. The procedure symbol tables for the AST procedure nodes are in the next level down, followed by the block symbol tables for block nodes within the ASTs. The block symbol tables may be nested to any level.

Each symbol table contains a list of symbols (see section Symbols) that are defined within the corresponding scope. There are three different kinds of symbols: variables, labels, and procedures. Symbols are identified by name or ID number. The ID numbers are assigned automatically and should always be unique within a particular scope. Each symbol also has a set of flags to record various attributes.

Variable symbols (see section Variable Symbols) may be declared in any scope. A variable symbol contains a pointer to the type for the variable. The type determines the amount of storage used to hold the variable as well as the interpretation of its contents. Some additional flags are used for variable symbols. These flags identify variables that are formal parameters of the procedure and variables that have their addresses taken. Another flag is used to identify variables that represent machine registers. For variables that are not allocated on the stack, a separate variable definition (see section Variable Definitions) must be entered in the symbol table. A variable definition records the alignment restriction for the variable's storage and its initial contents.

Label symbols (see section Label Symbols) can only be declared within procedures. The position of a label in the code is marked with a special instruction.

Procedure symbols (see section Procedure Symbols) can only be declared in the global and file scopes. A procedure symbol contains a pointer to the AST for the body of the procedure if it exists. It also provides methods to read the body from an input file, write it to an output file, and flush it from memory. The procedure symbol also has a pointer to the type for the procedure.

The SUIF type system (see section Types) is quite powerful. It can represent most, if not all, high-level types for C programs and for many other languages. The types are implemented with various kinds of type nodes. Each type node contains an operator that specifies the kind of node. Some of the type operators define base types that stand alone, while other operators refer to other types nodes. For example, a type node with the TYPE_INT operator defines a new integer type. A node with the TYPE_PTR operator can then refer to the integer type node to create a type for pointers to integers. Operators are available for integers, floating-point types, pointers, arrays, functions, structures, unions, and enumerations. Each type has a particular size. For some types, such as integers, the size can be set directly, but for others it is determined automatically.

Go to the previous, next section.