Most SUIF instructions have operands that are represented by objects of
the operand
class, which is implemented in the files
`operand.h' and operand.cc
. An operand may have three
different kinds of values:
is_null
method tests for this
case. Null operands occur when an operand field in an instruction is
unused.
is_symbol
method tests for this case. The symbol
and
set_symbol
methods access the symbol field. A variable in a
source operand indicates that the contents of the variable are used. In
a destination operand, a variable is assigned the result of the
instruction.
is_instr
method tests for this, and the instr
and set_instr
methods
access the pointer field. This is used to implement expression trees
and, in low-SUIF, to refer to the results of other instructions in a
flat list. An instruction pointer in a source operand means that the
result of that instruction is used as the operand. Conversely, an
instruction pointer in a destination operand indicates that the result
value is used by that instruction.
The is_expr
method is very similar to is_instr
. Besides
checking if the operand holds an instruction pointer, it also tests if
that instruction is a subexpression that is not contained in a separate
tree_instr
node (i.e. it's not in a flat list). This method
should not be used for destination operands.
Before changing a source operand from an instruction pointer to some
other value, the instruction must be removed. The remove
method
checks if the operand is an instruction, and if so, calls the
instruction's remove
method. See section Source Operands.
The operand class includes several methods to simplify common
operations. One frequently needs to know the type of a particular
operand. This can be determined from the variable's type or the
instruction's result type, but checking for these different kinds of
operands and then extracting the type is cumbersome. Instead, you can
use the type
method which performs this operation for you. It
returns the SUIF void
type for null operands. Another common
operation is testing an operand to see if it contains an integer
constant from a load constant instruction. The is_const_int
method checks if this is the case, and if so, it also returns the value
of the constant.
Operands have two different methods for printing themselves out to a
file as text. The print
method is used by the library when
printing instructions. Because source and destination operands are
handled differently, print
requires that you specify the
instruction that contains the operand so that it can determine how the
operand is being used. However, when debugging a program, you may not
know which instruction contains an operand. If you do know that it is
used as a source operand, you can use the print_source
method to
print it without specifying the instruction.