add collect_writes.rs
This commit is contained in:
parent
3f0ce0858e
commit
bfc9b76159
2 changed files with 51 additions and 0 deletions
|
|
@ -39,6 +39,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
|
|||
#![feature(collection_placement)]
|
||||
#![feature(nonzero)]
|
||||
#![feature(underscore_lifetimes)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
|
||||
extern crate arena;
|
||||
#[macro_use]
|
||||
|
|
|
|||
50
src/librustc_mir/util/collect_writes.rs
Normal file
50
src/librustc_mir/util/collect_writes.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use rustc::mir::{Local, Location};
|
||||
use rustc::mir::Mir;
|
||||
use rustc::mir::visit::PlaceContext;
|
||||
use rustc::mir::visit::Visitor;
|
||||
|
||||
pub struct FindLocalAssignmentVisitor {
|
||||
needle: Local,
|
||||
locations: Vec<Location>,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
|
||||
fn visit_local(&mut self,
|
||||
local: &Local,
|
||||
place_context: PlaceContext<'tcx>,
|
||||
location: Location) {
|
||||
if self.needle != *local {
|
||||
return;
|
||||
}
|
||||
|
||||
match place_context {
|
||||
PlaceContext::Store | PlaceContext::Call => {
|
||||
self.locations.push(location);
|
||||
}
|
||||
PlaceContext::AsmOutput | PlaceContext::Drop| PlaceContext::Inspect |
|
||||
PlaceContext::Borrow{..}| PlaceContext::Projection(..)| PlaceContext::Copy|
|
||||
PlaceContext::Move| PlaceContext::StorageLive| PlaceContext::StorageDead|
|
||||
PlaceContext::Validate => {
|
||||
}
|
||||
}
|
||||
|
||||
Visitor::visit_local(self,local,place_context,location)
|
||||
}
|
||||
}
|
||||
|
||||
crate trait FindAssignments {
|
||||
fn find_assignments(&self, local: Local) -> Vec<Location>;
|
||||
}
|
||||
|
||||
impl<'tcx> FindAssignments for Mir<'tcx>{
|
||||
fn find_assignments(&self, local: Local) -> Vec<Location>{
|
||||
let mut visitor = FindLocalAssignmentVisitor{ needle: local, locations: vec![]};
|
||||
visitor.visit_mir(self);
|
||||
visitor.locations
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue