The opcode
and set_opcode
methods may be used to access
the opcode field in an instruction. These opcodes are members of the
if_ops
enumerated type. The internal names for the opcodes all
begin with io_
, but that prefix is omitted in this documentation.
The if_ops_name
function takes an opcode and returns a character
string holding the opcode name (without the io_
prefix). This is
used by the library when it prints out instructions, but you may also
call it directly.
Each opcode is associated with a particular instruction format. The
formats are specified by members of the inst_format
enumeration.
The format
method may be used to retrieve the format for a
particular instruction. Alternatively, the which_format
function
takes an opcode and returns its format without reference to any
particular instruction. Each format corresponds to a particular derived
instruction class:
inf_rrr
in_rrr
class.
inf_bj
in_bj
class.
inf_ldc
in_ldc
class.
inf_cal
in_cal
class.
inf_array
in_array
class.
inf_mbr
in_mbr
class.
inf_lab
in_lab
class.
inf_gen
in_gen
class.
The format
method is often used in switch
statements for
dealing with different kinds of instructions. For example, the
following code computes the number of source operands in an instruction
(instead of using the num_srcs
method):
instruction *i; switch (i->format()) { case inf_rrr: { n += 2; break; } case inf_bj: { n += 1; break; } case inf_cal: { in_cal *cali = (in_cal *)i; n += 1 + cali->num_args(); break; } case inf_array: { in_array *arri = (in_array *)i; n += 2 + 2 * arri->dims(); break; } case inf_mbr: { n += 1; break; } case inf_gen: { in_gen *geni = (in_gen *)i; n += geni->num_srcs(); break; } default: { /* other formats (inf_ldc and inf_lab) have no source operands */ break; } }
The opcodes and instruction formats are defined in the `opcodes.h' and `opcodes.cc' files.