Go to the first, previous, next, last section, table of contents.

Operands

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:

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.


Go to the first, previous, next, last section, table of contents.