Go to the previous, next section.

Immediate Values

An immediate value may be an integer constant, string constant, floating-point constant, SUIF type, symbolic address, expression operand, or instruction, or it can be undefined. It can be used as the source of an ldc (load constant) instruction (see section Load Constant Instructions) or as an element of an annotation (see section Annotations). Only integers, floating-point values, and symbolic addresses may be used in ldc instructions, while any kind of immediate value may appear in an annotation. Immediate values are implemented by the immed class defined in the files `immed.h' and `immed.cc'.

The kind of value in an immed is identified by the kind method. This returns a member of the immed_kinds enumerated type. The members of this enumeration are:

im_int
Integer. The is_integer method tests for this kind of immediate and the integer method returns the integer value.

im_string
Character string. The string is automatically entered in the lexicon (see section Lexicon) when the immed is created. The is_string method checks if an immed is a string, and the string method returns a pointer to the string.

im_float
Floating-point value. The SUIF library stores all floating-point values using the double type, so the precision is limited by the precision for the double type. The is_flt method checks for this kind of immediate, and the flt method returns the value.

im_symbol
Symbolic address. See section Symbolic Addresses. The is_symbol method checks if an immed is a symbolic address. The addr method returns the entire sym_addr object, but the symbol and offset methods are also available to retrieve the symbol pointer and integer offset separately.

im_type
SUIF type. The is_type method checks for this kind of immediate, and the type method returns a pointer to the SUIF type node.

im_op
Expression operand. The immed is considered to "own" the entire expression tree when it's in an annotation, so the same expression shouldn't be used in another annotation or as the source for an instruction; instead a copy should be made with the clone method. The is_op method checks for this kind of immediate, and the op method returns the expression.

im_instr
SUIF instruction. The immed is considered to "own" the instruction and its expression trees when it's in an annotation, so the same instruction shouldn't be used in another annotation or in a tree_node or expression; instead a copy should be made with the clone method. The is_instr method checks for this kind of immediate, and the instr method returns the instruction.

im_undef
Undefined value. This is included to signal errors by marking an immediate as undefined. The is_error method also checks for this condition.

Since an immediate value is small, there are no methods to change the value of an immed. Instead a variety of constructors are provided to make it easy to create new immediate values. That is, you can initialize different kinds of immediates by providing arguments of various types to constructors.

The immed class provides two print methods, print and rawprint. The difference between them is that the latter doesn't escape `"' and `\' when printing strings.

Go to the previous, next section.