Skip to content

Commit 69a3ad0

Browse files
committed
Add MutMirVisitor
Implement `make_mir_visitor` macro to generate `MirVisitor` and `MutMirVisitor`. Add `ret_local_mut()`, `arg_locals_mut()` and `inner_locals_mut()` to `Body`, specifically for `MutMirVisitor`.
1 parent a96fa31 commit 69a3ad0

File tree

3 files changed

+428
-332
lines changed

3 files changed

+428
-332
lines changed

compiler/stable_mir/src/mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ pub mod pretty;
55
pub mod visit;
66

77
pub use body::*;
8-
pub use visit::MirVisitor;
8+
pub use visit::{MirVisitor, MutMirVisitor};

compiler/stable_mir/src/mir/body.rs

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ impl Body {
7777
&self.locals[self.arg_count + 1..]
7878
}
7979

80+
/// Returns a mutable reference to the local that holds this function's return value.
81+
pub(crate) fn ret_local_mut(&mut self) -> &mut LocalDecl {
82+
&mut self.locals[RETURN_LOCAL]
83+
}
84+
85+
/// Returns a mutable slice of locals corresponding to this function's arguments.
86+
pub(crate) fn arg_locals_mut(&mut self) -> &mut [LocalDecl] {
87+
&mut self.locals[1..][..self.arg_count]
88+
}
89+
90+
/// Returns a mutable slice of inner locals for this function.
91+
/// Inner locals are those that are neither the return local nor the argument locals.
92+
pub(crate) fn inner_locals_mut(&mut self) -> &mut [LocalDecl] {
93+
&mut self.locals[self.arg_count + 1..]
94+
}
95+
8096
/// Convenience function to get all the locals in this function.
8197
///
8298
/// Locals are typically accessed via the more specific methods `ret_local`,

0 commit comments

Comments
 (0)