Skip to content

Commit bfc9b76

Browse files
committed
add collect_writes.rs
1 parent 3f0ce08 commit bfc9b76

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/librustc_mir/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
3939
#![feature(collection_placement)]
4040
#![feature(nonzero)]
4141
#![feature(underscore_lifetimes)]
42+
#![feature(crate_visibility_modifier)]
4243

4344
extern crate arena;
4445
#[macro_use]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
2+
// option. This file may not be copied, modified, or distributed
3+
// except according to those terms.
4+
5+
use rustc::mir::{Local, Location};
6+
use rustc::mir::Mir;
7+
use rustc::mir::visit::PlaceContext;
8+
use rustc::mir::visit::Visitor;
9+
10+
pub struct FindLocalAssignmentVisitor {
11+
needle: Local,
12+
locations: Vec<Location>,
13+
}
14+
15+
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
16+
fn visit_local(&mut self,
17+
local: &Local,
18+
place_context: PlaceContext<'tcx>,
19+
location: Location) {
20+
if self.needle != *local {
21+
return;
22+
}
23+
24+
match place_context {
25+
PlaceContext::Store | PlaceContext::Call => {
26+
self.locations.push(location);
27+
}
28+
PlaceContext::AsmOutput | PlaceContext::Drop| PlaceContext::Inspect |
29+
PlaceContext::Borrow{..}| PlaceContext::Projection(..)| PlaceContext::Copy|
30+
PlaceContext::Move| PlaceContext::StorageLive| PlaceContext::StorageDead|
31+
PlaceContext::Validate => {
32+
}
33+
}
34+
35+
Visitor::visit_local(self,local,place_context,location)
36+
}
37+
}
38+
39+
crate trait FindAssignments {
40+
fn find_assignments(&self, local: Local) -> Vec<Location>;
41+
}
42+
43+
impl<'tcx> FindAssignments for Mir<'tcx>{
44+
fn find_assignments(&self, local: Local) -> Vec<Location>{
45+
let mut visitor = FindLocalAssignmentVisitor{ needle: local, locations: vec![]};
46+
visitor.visit_mir(self);
47+
visitor.locations
48+
}
49+
}
50+

0 commit comments

Comments
 (0)