|
Nearly CC
An educational compiler skeleton
|
InstructionSequence class, which represents a linear sequence of Instruction objects. More...
#include "instruction_seq.h"
Public Types | |
| typedef ISeqIterator< std::vector< Slot >::const_iterator > | const_iterator |
| Iterator over instructions in forward order. | |
| typedef ISeqIterator< std::vector< Slot >::const_reverse_iterator > | const_reverse_iterator |
| Iterator over instructions in reverse order. | |
Public Member Functions | |
| InstructionSequence () | |
| Default constructor. | |
| InstructionSequence (BasicBlockKind kind, int code_order, const std::string &block_label) | |
| Constructor from BasicBlockKind, code order value, and block label. More... | |
| InstructionSequence * | duplicate () const |
| Return a dynamically-allocated duplicate of this InstructionSequence. More... | |
| const_iterator | cbegin () const |
| Get begin forward iterator over the instructions. More... | |
| const_iterator | cend () const |
| Get end forward iterator over the instructions. More... | |
| const_reverse_iterator | crbegin () const |
| Get begin reverse iterator over the instructions. More... | |
| const_reverse_iterator | crend () const |
| Get end reverse iterator over the instructions. More... | |
| template<typename Fn > | |
| void | apply_to_all (Fn f) |
| void | append (Instruction *ins) |
| Append an Instruction. More... | |
| unsigned | get_length () const |
| Get number of instructions. More... | |
| Instruction * | get_instruction (unsigned index) const |
| Get Instruction at specified index. More... | |
| Instruction * | get_last_instruction () const |
| Get the last Instruction. More... | |
| void | define_label (const std::string &label) |
| Define a label. More... | |
| bool | has_label (unsigned index) const |
| Determine if Instruction at given index has a label. More... | |
| std::string | get_label_at_index (unsigned index) const |
| Get label of the Instruction at the specified index. More... | |
| bool | has_label (const_iterator iter) const |
| Determine if Instruction referred to by specified iterator has a label. More... | |
| bool | has_label_at_end () const |
| Determine if the InstructionSequence has a label at the end This can happen in code generation for control constructs, when a label is generated as a target for the code that comes after the construct. More... | |
| const_iterator | get_iterator_at_labeled_position (const std::string &label) const |
| Return a forward const iterator positioned at the instruction with the specified label, or the end iterator if there is no instruction with the specified label. More... | |
| Instruction * | find_labeled_instruction (const std::string &label) const |
| Find Instruction labeled with specified label. More... | |
| unsigned | get_index_of_labeled_instruction (const std::string &label) const |
| Return the index of instruction labeled with the specified label. More... | |
| BasicBlockKind | get_kind () const |
| Get the BasicBlockKind. More... | |
| void | set_kind (BasicBlockKind kind) |
| Set the BasicBlockKind. More... | |
| bool | has_block_label () const |
| Check whether the first Instruction is labeled. More... | |
| std::string | get_block_label () const |
| Get the label of the first Instruction. More... | |
| void | set_block_label (const std::string &block_label) |
| Set the label on the first Instruction. More... | |
| unsigned | get_block_id () const |
| Get the basic block id. More... | |
| void | set_block_id (unsigned block_id) |
| Set the basic block id. More... | |
| int | get_code_order () const |
| Get the code order value of this block. More... | |
| void | set_code_order (int code_order) |
| Set the code order value of this block. More... | |
InstructionSequence class, which represents a linear sequence of Instruction objects.
This can be used for both a "flat" IR for a function (with control flow), or a basic block in a ControlFlowGraph (where a branch or function call can only be the last instruction in the block.)
| InstructionSequence::InstructionSequence | ( | BasicBlockKind | kind, |
| int | code_order, | ||
| const std::string & | block_label | ||
| ) |
Constructor from BasicBlockKind, code order value, and block label.
This is useful for creating an InstructionSequence to be used as a basic block in a ControlFlowGraph.
| kind | the BasicBlockKind |
| code_order | the relative order of this basic block |
| block_label | label of first Instruction in the basic block |
| void InstructionSequence::append | ( | Instruction * | ins | ) |
Append an Instruction.
The InstructionSequence will assume responsibility for deleting the Instruction object.
| ins | pointer to the Instruction to append (and adopt) |
|
inline |
| Fn | the type of the function to apply |
| fn | the function to apply to each instruction |
|
inline |
Get begin forward iterator over the instructions.
|
inline |
Get end forward iterator over the instructions.
|
inline |
Get begin reverse iterator over the instructions.
|
inline |
Get end reverse iterator over the instructions.
| void InstructionSequence::define_label | ( | const std::string & | label | ) |
Define a label.
The next Instruction appended will be labeled with this label. This is useful for labeling an instruction as a control-flow target.
| label | the label to apply to use for the next appended Instruction |
| InstructionSequence * InstructionSequence::duplicate | ( | ) | const |
Return a dynamically-allocated duplicate of this InstructionSequence.
| Instruction * InstructionSequence::find_labeled_instruction | ( | const std::string & | label | ) | const |
Find Instruction labeled with specified label.
Returns null pointer if no Instruction has the specified label.
| label | a label |
|
inline |
Get the basic block id.
This is an arbitrary integer whose only significance is that it is different than the id of any other basic block.
| std::string InstructionSequence::get_block_label | ( | ) | const |
Get the label of the first Instruction.
|
inline |
Get the code order value of this block.
This represents the relative position of the basic block's instructions in the original "flat" InstructionSequence.
| unsigned InstructionSequence::get_index_of_labeled_instruction | ( | const std::string & | label | ) | const |
Return the index of instruction labeled with the specified label.
| label | a label |
| the | index of the Instruction with this label |
| RuntimeError | if there is no instruction with the label |
| Instruction * InstructionSequence::get_instruction | ( | unsigned | index | ) | const |
Get Instruction at specified index.
| index | index of instruction to get (0 for first, etc.) |
| InstructionSequence::const_iterator InstructionSequence::get_iterator_at_labeled_position | ( | const std::string & | label | ) | const |
Return a forward const iterator positioned at the instruction with the specified label, or the end iterator if there is no instruction with the specified label.
| label | a label |
|
inline |
Get the BasicBlockKind.
This is useful for checking a basic block to see if it is the entry or exit block.
|
inline |
Get label of the Instruction at the specified index.
| index | index of instruction to get (0 for first, etc.) |
| Instruction * InstructionSequence::get_last_instruction | ( | ) | const |
Get the last Instruction.
| unsigned InstructionSequence::get_length | ( | ) | const |
Get number of instructions.
| bool InstructionSequence::has_block_label | ( | ) | const |
Check whether the first Instruction is labeled.
This is useful for identifying whether a basic block is targeted by a branch instruction.
|
inline |
Determine if Instruction referred to by specified iterator has a label.
| iter | a forward iterator |
|
inline |
Determine if Instruction at given index has a label.
| index | index of instruction to get (0 for first, etc.) |
| bool InstructionSequence::has_label_at_end | ( | ) | const |
Determine if the InstructionSequence has a label at the end This can happen in code generation for control constructs, when a label is generated as a target for the code that comes after the construct.
|
inline |
Set the basic block id.
| block_id | the basic block id to set |
| void InstructionSequence::set_block_label | ( | const std::string & | block_label | ) |
Set the label on the first Instruction.
This is used by ControlFlowGraphBuilder when constructing a ControlFlowGraph from a "flat" InstructionSequence.
| block_label | the label to set on the first Instruction |
|
inline |
Set the code order value of this block.
| code_order | the code order value to set |
|
inline |
Set the BasicBlockKind.
| kind | the BasicBlockKind to set |