Skip to content

Commit 515f5ac

Browse files
committed
Introduce methods for obtaining Location for statements and terminators
1 parent 8bc120a commit 515f5ac

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

compiler/stable_mir/src/mir/visit.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,20 @@ impl Location {
465465
}
466466
}
467467

468-
impl From<Span> for Location {
469-
fn from(span: Span) -> Self {
470-
Location(span)
471-
}
468+
/// Location of the statement at the given index for a given basic block. Assumes that `stmt_idx`
469+
/// and `bb_idx` are valid for a given body.
470+
pub fn statement_location(body: &Body, bb_idx: &BasicBlockIdx, stmt_idx: usize) -> Location {
471+
let bb = &body.blocks[*bb_idx];
472+
let stmt = &bb.statements[stmt_idx];
473+
Location(stmt.span)
474+
}
475+
476+
/// Location of the terminator for a given basic block. Assumes that `bb_idx` is valid for a given
477+
/// body.
478+
pub fn terminator_location(body: &Body, bb_idx: &BasicBlockIdx) -> Location {
479+
let bb = &body.blocks[*bb_idx];
480+
let terminator = &bb.terminator;
481+
Location(terminator.span)
472482
}
473483

474484
/// Reference to a place used to represent a partial projection.

0 commit comments

Comments
 (0)