The TYPE_FUNC
operator is used with the func_type
derived
type class to describe the types of SUIF procedures. A function type
includes the type of the return value and optionally the types of the
arguments as well. The return_type
and set_return_type
methods access the return type field. The type system itself places no
restrictions on the return types, but the SUIF call and return
instructions do. See section Call Instructions
Most of the complexity of function types involves the arguments.
Pointers to the argument types are stored in a dynamically-allocated
array. The number of arguments, and thus the size of the array, is
stored in a field that can be accessed with the num_args
and
set_num_args
methods. The number of arguments can be changed at
any time; if necessary the argument array will be reallocated. The type
of a particular argument can be retrieved with the arg_type
method and set with the set_arg_type
method. The arguments are
numbered beginning with zero.
Argument types are under the same restrictions as result types of instructions (see section Result Types) -- they must be object types with known, non-zero size.
Since functions can be declared in C without complete prototypes, a
function type may not be able to include any information about the
arguments. This is indicated in a SUIF function type by the result of
the args_known
method. This flag can be set with the
set_args_known
and set_args_unknown
methods. Setting
args_known
FALSE sets the argument count to zero and the
has_varargs
flag to FALSE. Conversely, setting the argument
count to a non-zero value or the has_varargs
flag to TRUE sets
the args_known
flag to TRUE.
Some functions in C and other languages have a variable number of
arguments. The SUIF function types support this by keeping a flag to
indicate if there may be additional arguments besides the ones that are
explicitly listed. The has_varargs
and set_varargs
methods access this flag. Note that the has_varargs
flag should
not be used if nothing else is known about the arguments.