|
Nearly CC
An educational compiler skeleton
|
Instruction object type. More...
#include "instruction.h"
Public Member Functions | |
| Instruction (int opcode) | |
| Contructor from opcode. More... | |
| Instruction (int opcode, const Operand &op1) | |
| Constructor from opcode and one Operand. More... | |
| Instruction (int opcode, const Operand &op1, const Operand &op2) | |
| Constructor from opcode and two Operands. More... | |
| Instruction (int opcode, const Operand &op1, const Operand &op2, const Operand &op3, unsigned num_operands=3) | |
| Constructor from opcode and up to three operands. More... | |
| Instruction * | duplicate () const |
| Return an exact duplicate of this Instruction. More... | |
| int | get_opcode () const |
| Get the opcode value. More... | |
| unsigned | get_num_operands () const |
| Get the number of operands. More... | |
| const Operand & | get_operand (unsigned index) const |
| Get the specified Operand. More... | |
| void | set_operand (unsigned index, const Operand &operand) |
| Modify the specified Operand. More... | |
| Operand | get_last_operand () const |
| Return a copy of the last (rightmost) Operand. More... | |
| void | set_comment (const std::string &comment) |
| Set a textual comment for this Instruction. More... | |
| bool | has_comment () const |
| Check whether this Instruction has a comment set. More... | |
| const std::string & | get_comment () const |
| Get the textual comment for this Instruction. More... | |
| void | set_symbol (Symbol *sym) |
| Set a symbol table entry (Symbol). More... | |
| Symbol * | get_symbol () const |
| Return the symbol table entry (Symbol). More... | |
Instruction object type.
This is a traditional "quad"-style instruction representation. Can be used for either high-level or low-level code.
| Instruction::Instruction | ( | int | opcode | ) |
Contructor from opcode.
The initialized Instruction object will not have any operands.
| opcode | the high-level or low-level opcode value |
| Instruction::Instruction | ( | int | opcode, |
| const Operand & | op1 | ||
| ) |
|
inline |
Return an exact duplicate of this Instruction.
|
inline |
Get the textual comment for this Instruction.
| Operand Instruction::get_last_operand | ( | ) | const |
| unsigned Instruction::get_num_operands | ( | ) | const |
Get the number of operands.
| int Instruction::get_opcode | ( | ) | const |
Get the opcode value.
In general, this will be the ordinal value of either a HighLevelOpcode or LowLevelOpcode enumeration member, depending on whether the object is a high-level or low-level Instuctiion.
| const Operand & Instruction::get_operand | ( | unsigned | index | ) | const |
|
inline |
Return the symbol table entry (Symbol).
|
inline |
Check whether this Instruction has a comment set.
|
inline |
Set a textual comment for this Instruction.
The comment will appear in the printed representation of the Instruction. This is useful for debugging. For example, when a high-level Instruction is translated to a sequence of low-level Instructions, a string representation of the high-level instruction can be set as a comment for the first low-level Instruction.
| comment | the comment to set |
| void Instruction::set_operand | ( | unsigned | index, |
| const Operand & | operand | ||
| ) |
Modify the specified Operand.
| index | the Operand to modify (0 for first, etc.) |
| operand | the value to copy to the specified Operand of the Instruction |
|
inline |
Set a symbol table entry (Symbol).
This is useful for function calls, to link the function call with information (such as the FunctionType) of the called function.
| sym | the Symbol to set |