Go to the previous, next section.

Variable Definitions

Variable definitions are used to allocate storage for variables that are not on the stack. These variable definitions are implemented by the var_def class, which is defined in the `vardef.h' and `vardef.cc' files. Each variable definition contains a field with a pointer to the corresponding variable. The variable and set_variable methods access this field.

The effects of a variable definition depend on the kind of variable. Without separate variable definitions, the symbols for global variables are merely declarations of external symbols. Adding a definition for a global variable changes it from a declaration to an actual definition. The local variables in a procedure or nested scope are allocated on the stack by default. Adding a definition for a local variable makes it static. Similarly, if you remove a definition of a local variable, it reverts to being allocated on the stack. Because of their special status, register variables cannot have definitions. Sub-variables are also not allowed to have their own definitions.

The location of a var_def identifies the place where the variable is defined. For most variables, the var_def will be in the same symbol table as the variable. However, variables in the global symbol table must be defined in exactly one of the source files. Thus, the var_def for a variable in the global symbol table must be in one of the file symbol tables.

Besides identifying the location of the definition, a var_def also specifies the alignment restriction for the variable's storage. The alignment method retrieves the size of the alignment unit in bits, and the set_alignment method sets the alignment unit size. The alignment unit should be at least as big as the smallest addressable unit for the target architecture.

The initial data for a static variable can be specified by attaching annotations to the variable definition. These annotations are optional. If omitted, the initial data is assumed to be all zeros. The initial data annotations are described elsewhere in this manual. See section Initial Data Annotations.

Variable definitions are printed out as part of each symbol table. The print method is used for this. You may also use this method for debugging. The optional depth parameter specifies the indentation level for the output.

Go to the previous, next section.