Trait cranelift_codegen::cursor::Cursor
source · pub trait Cursor {
Show 32 methods
fn position(&self) -> CursorPosition;
fn set_position(&mut self, pos: CursorPosition);
fn srcloc(&self) -> SourceLoc;
fn set_srcloc(&mut self, srcloc: SourceLoc);
fn layout(&self) -> &Layout;
fn layout_mut(&mut self) -> &mut Layout;
fn with_srcloc(self, srcloc: SourceLoc) -> Self
where
Self: Sized,
{ ... }
fn at_position(self, pos: CursorPosition) -> Self
where
Self: Sized,
{ ... }
fn at_inst(self, inst: Inst) -> Self
where
Self: Sized,
{ ... }
fn at_first_insertion_point(self, ebb: Ebb) -> Self
where
Self: Sized,
{ ... }
fn at_first_inst(self, ebb: Ebb) -> Self
where
Self: Sized,
{ ... }
fn at_last_inst(self, ebb: Ebb) -> Self
where
Self: Sized,
{ ... }
fn after_inst(self, inst: Inst) -> Self
where
Self: Sized,
{ ... }
fn at_top(self, ebb: Ebb) -> Self
where
Self: Sized,
{ ... }
fn at_bottom(self, ebb: Ebb) -> Self
where
Self: Sized,
{ ... }
fn current_ebb(&self) -> Option<Ebb> { ... }
fn current_inst(&self) -> Option<Inst> { ... }
fn goto_after_inst(&mut self, inst: Inst) { ... }
fn goto_inst(&mut self, inst: Inst) { ... }
fn goto_first_insertion_point(&mut self, ebb: Ebb) { ... }
fn goto_first_inst(&mut self, ebb: Ebb) { ... }
fn goto_last_inst(&mut self, ebb: Ebb) { ... }
fn goto_top(&mut self, ebb: Ebb) { ... }
fn goto_bottom(&mut self, ebb: Ebb) { ... }
fn next_ebb(&mut self) -> Option<Ebb> { ... }
fn prev_ebb(&mut self) -> Option<Ebb> { ... }
fn next_inst(&mut self) -> Option<Inst> { ... }
fn prev_inst(&mut self) -> Option<Inst> { ... }
fn insert_inst(&mut self, inst: Inst) { ... }
fn remove_inst(&mut self) -> Inst { ... }
fn remove_inst_and_step_back(&mut self) -> Inst { ... }
fn insert_ebb(&mut self, new_ebb: Ebb) { ... }
}
Expand description
All cursor types implement the Cursor
which provides common navigation operations.
Required Methods§
sourcefn position(&self) -> CursorPosition
fn position(&self) -> CursorPosition
Get the current cursor position.
sourcefn set_position(&mut self, pos: CursorPosition)
fn set_position(&mut self, pos: CursorPosition)
Set the current position.
sourcefn srcloc(&self) -> SourceLoc
fn srcloc(&self) -> SourceLoc
Get the source location that should be assigned to new instructions.
sourcefn set_srcloc(&mut self, srcloc: SourceLoc)
fn set_srcloc(&mut self, srcloc: SourceLoc)
Set the source location that should be assigned to new instructions.
sourcefn layout(&self) -> &Layout
fn layout(&self) -> &Layout
Borrow a reference to the function layout that this cursor is navigating.
sourcefn layout_mut(&mut self) -> &mut Layout
fn layout_mut(&mut self) -> &mut Layout
Borrow a mutable reference to the function layout that this cursor is navigating.
Provided Methods§
sourcefn with_srcloc(self, srcloc: SourceLoc) -> Selfwhere
Self: Sized,
fn with_srcloc(self, srcloc: SourceLoc) -> Selfwhere
Self: Sized,
Exchange this cursor for one with a set source location.
This is intended to be used as a builder method:
fn edit_func(func: &mut Function, srcloc: SourceLoc) {
let mut pos = FuncCursor::new(func).with_srcloc(srcloc);
// Use `pos`...
}
sourcefn at_position(self, pos: CursorPosition) -> Selfwhere
Self: Sized,
fn at_position(self, pos: CursorPosition) -> Selfwhere
Self: Sized,
Rebuild this cursor positioned at pos
.
sourcefn at_inst(self, inst: Inst) -> Selfwhere
Self: Sized,
fn at_inst(self, inst: Inst) -> Selfwhere
Self: Sized,
Rebuild this cursor positioned at inst
.
This is intended to be used as a builder method:
fn edit_func(func: &mut Function, inst: Inst) {
let mut pos = FuncCursor::new(func).at_inst(inst);
// Use `pos`...
}
sourcefn at_first_insertion_point(self, ebb: Ebb) -> Selfwhere
Self: Sized,
fn at_first_insertion_point(self, ebb: Ebb) -> Selfwhere
Self: Sized,
Rebuild this cursor positioned at the first insertion point for ebb
.
This differs from at_first_inst
in that it doesn’t assume that any
instructions have been inserted into ebb
yet.
This is intended to be used as a builder method:
fn edit_func(func: &mut Function, ebb: Ebb) {
let mut pos = FuncCursor::new(func).at_first_insertion_point(ebb);
// Use `pos`...
}
sourcefn at_first_inst(self, ebb: Ebb) -> Selfwhere
Self: Sized,
fn at_first_inst(self, ebb: Ebb) -> Selfwhere
Self: Sized,
Rebuild this cursor positioned at the first instruction in ebb
.
This is intended to be used as a builder method:
fn edit_func(func: &mut Function, ebb: Ebb) {
let mut pos = FuncCursor::new(func).at_first_inst(ebb);
// Use `pos`...
}
sourcefn at_last_inst(self, ebb: Ebb) -> Selfwhere
Self: Sized,
fn at_last_inst(self, ebb: Ebb) -> Selfwhere
Self: Sized,
Rebuild this cursor positioned at the last instruction in ebb
.
This is intended to be used as a builder method:
fn edit_func(func: &mut Function, ebb: Ebb) {
let mut pos = FuncCursor::new(func).at_last_inst(ebb);
// Use `pos`...
}
sourcefn after_inst(self, inst: Inst) -> Selfwhere
Self: Sized,
fn after_inst(self, inst: Inst) -> Selfwhere
Self: Sized,
Rebuild this cursor positioned after inst
.
This is intended to be used as a builder method:
fn edit_func(func: &mut Function, inst: Inst) {
let mut pos = FuncCursor::new(func).after_inst(inst);
// Use `pos`...
}
sourcefn at_top(self, ebb: Ebb) -> Selfwhere
Self: Sized,
fn at_top(self, ebb: Ebb) -> Selfwhere
Self: Sized,
Rebuild this cursor positioned at the top of ebb
.
This is intended to be used as a builder method:
fn edit_func(func: &mut Function, ebb: Ebb) {
let mut pos = FuncCursor::new(func).at_top(ebb);
// Use `pos`...
}
sourcefn at_bottom(self, ebb: Ebb) -> Selfwhere
Self: Sized,
fn at_bottom(self, ebb: Ebb) -> Selfwhere
Self: Sized,
Rebuild this cursor positioned at the bottom of ebb
.
This is intended to be used as a builder method:
fn edit_func(func: &mut Function, ebb: Ebb) {
let mut pos = FuncCursor::new(func).at_bottom(ebb);
// Use `pos`...
}
sourcefn current_ebb(&self) -> Option<Ebb>
fn current_ebb(&self) -> Option<Ebb>
Get the EBB corresponding to the current position.
sourcefn current_inst(&self) -> Option<Inst>
fn current_inst(&self) -> Option<Inst>
Get the instruction corresponding to the current position, if any.
sourcefn goto_after_inst(&mut self, inst: Inst)
fn goto_after_inst(&mut self, inst: Inst)
Go to the position after a specific instruction, which must be inserted
in the layout. New instructions will be inserted after inst
.
sourcefn goto_inst(&mut self, inst: Inst)
fn goto_inst(&mut self, inst: Inst)
Go to a specific instruction which must be inserted in the layout.
New instructions will be inserted before inst
.
sourcefn goto_first_insertion_point(&mut self, ebb: Ebb)
fn goto_first_insertion_point(&mut self, ebb: Ebb)
Go to the position for inserting instructions at the beginning of ebb
,
which unlike goto_first_inst
doesn’t assume that any instructions have
been inserted into ebb
yet.
sourcefn goto_first_inst(&mut self, ebb: Ebb)
fn goto_first_inst(&mut self, ebb: Ebb)
Go to the first instruction in ebb
.
sourcefn goto_last_inst(&mut self, ebb: Ebb)
fn goto_last_inst(&mut self, ebb: Ebb)
Go to the last instruction in ebb
.
sourcefn goto_top(&mut self, ebb: Ebb)
fn goto_top(&mut self, ebb: Ebb)
Go to the top of ebb
which must be inserted into the layout.
At this position, instructions cannot be inserted, but next_inst()
will move to the first
instruction in ebb
.
sourcefn goto_bottom(&mut self, ebb: Ebb)
fn goto_bottom(&mut self, ebb: Ebb)
Go to the bottom of ebb
which must be inserted into the layout.
At this position, inserted instructions will be appended to ebb
.
sourcefn next_ebb(&mut self) -> Option<Ebb>
fn next_ebb(&mut self) -> Option<Ebb>
Go to the top of the next EBB in layout order and return it.
- If the cursor wasn’t pointing at anything, go to the top of the first EBB in the function.
- If there are no more EBBs, leave the cursor pointing at nothing and return
None
.
Examples
The next_ebb()
method is intended for iterating over the EBBs in layout order:
fn edit_func(func: &mut Function) {
let mut cursor = FuncCursor::new(func);
while let Some(ebb) = cursor.next_ebb() {
// Edit ebb.
}
}
sourcefn prev_ebb(&mut self) -> Option<Ebb>
fn prev_ebb(&mut self) -> Option<Ebb>
Go to the bottom of the previous EBB in layout order and return it.
- If the cursor wasn’t pointing at anything, go to the bottom of the last EBB in the function.
- If there are no more EBBs, leave the cursor pointing at nothing and return
None
.
Examples
The prev_ebb()
method is intended for iterating over the EBBs in backwards layout order:
fn edit_func(func: &mut Function) {
let mut cursor = FuncCursor::new(func);
while let Some(ebb) = cursor.prev_ebb() {
// Edit ebb.
}
}
sourcefn next_inst(&mut self) -> Option<Inst>
fn next_inst(&mut self) -> Option<Inst>
Move to the next instruction in the same EBB and return it.
- If the cursor was positioned before an EBB, go to the first instruction in that EBB.
- If there are no more instructions in the EBB, go to the
After(ebb)
position and returnNone
. - If the cursor wasn’t pointing anywhere, keep doing that.
This method will never move the cursor to a different EBB.
Examples
The next_inst()
method is intended for iterating over the instructions in an EBB like
this:
fn edit_ebb(func: &mut Function, ebb: Ebb) {
let mut cursor = FuncCursor::new(func).at_top(ebb);
while let Some(inst) = cursor.next_inst() {
// Edit instructions...
}
}
The loop body can insert and remove instructions via the cursor.
Iterating over all the instructions in a function looks like this:
fn edit_func(func: &mut Function) {
let mut cursor = FuncCursor::new(func);
while let Some(ebb) = cursor.next_ebb() {
while let Some(inst) = cursor.next_inst() {
// Edit instructions...
}
}
}
sourcefn prev_inst(&mut self) -> Option<Inst>
fn prev_inst(&mut self) -> Option<Inst>
Move to the previous instruction in the same EBB and return it.
- If the cursor was positioned after an EBB, go to the last instruction in that EBB.
- If there are no more instructions in the EBB, go to the
Before(ebb)
position and returnNone
. - If the cursor wasn’t pointing anywhere, keep doing that.
This method will never move the cursor to a different EBB.
Examples
The prev_inst()
method is intended for iterating backwards over the instructions in an
EBB like this:
fn edit_ebb(func: &mut Function, ebb: Ebb) {
let mut cursor = FuncCursor::new(func).at_bottom(ebb);
while let Some(inst) = cursor.prev_inst() {
// Edit instructions...
}
}
sourcefn insert_inst(&mut self, inst: Inst)
fn insert_inst(&mut self, inst: Inst)
Insert an instruction at the current position.
- If pointing at an instruction, the new instruction is inserted before the current instruction.
- If pointing at the bottom of an EBB, the new instruction is appended to the EBB.
- Otherwise panic.
In either case, the cursor is not moved, such that repeated calls to insert_inst()
causes
instructions to appear in insertion order in the EBB.
sourcefn remove_inst(&mut self) -> Inst
fn remove_inst(&mut self) -> Inst
Remove the instruction under the cursor.
The cursor is left pointing at the position following the current instruction.
Return the instruction that was removed.
sourcefn remove_inst_and_step_back(&mut self) -> Inst
fn remove_inst_and_step_back(&mut self) -> Inst
Remove the instruction under the cursor.
The cursor is left pointing at the position preceding the current instruction.
Return the instruction that was removed.
sourcefn insert_ebb(&mut self, new_ebb: Ebb)
fn insert_ebb(&mut self, new_ebb: Ebb)
Insert an EBB at the current position and switch to it.
As far as possible, this method behaves as if the EBB header were an instruction inserted at the current position.
- If the cursor is pointing at an existing instruction, the current EBB is split in two and the current instruction becomes the first instruction in the inserted EBB.
- If the cursor points at the bottom of an EBB, the new EBB is inserted after the current one, and moved to the bottom of the new EBB where instructions can be appended.
- If the cursor points to the top of an EBB, the new EBB is inserted above the current one.
- If the cursor is not pointing at anything, the new EBB is placed last in the layout.
This means that it is always valid to call this method, and it always leaves the cursor in a state that will insert instructions into the new EBB.