1
Fork 0

Simplify basic_block.rs

This commit is contained in:
Mark-Simulacrum 2016-12-17 08:24:17 -07:00 committed by Mark Simulacrum
parent cc1e210ee8
commit 449c6d82a7
2 changed files with 6 additions and 14 deletions

View file

@ -10,18 +10,15 @@
use llvm;
use llvm::BasicBlockRef;
use value::{Users, Value};
use std::iter::{Filter, Map};
use value::Value;
#[derive(Copy, Clone)]
pub struct BasicBlock(pub BasicBlockRef);
pub type Preds = Map<Filter<Users, fn(&Value) -> bool>, fn(Value) -> BasicBlock>;
/// Wrapper for LLVM BasicBlockRef
impl BasicBlock {
pub fn get(&self) -> BasicBlockRef {
let BasicBlock(v) = *self; v
self.0
}
pub fn as_value(self) -> Value {
@ -30,16 +27,10 @@ impl BasicBlock {
}
}
pub fn pred_iter(self) -> Preds {
fn is_a_terminator_inst(user: &Value) -> bool { user.is_a_terminator_inst() }
let is_a_terminator_inst: fn(&Value) -> bool = is_a_terminator_inst;
fn get_parent(user: Value) -> BasicBlock { user.get_parent().unwrap() }
let get_parent: fn(Value) -> BasicBlock = get_parent;
pub fn pred_iter(self) -> impl Iterator<Item=BasicBlock> {
self.as_value().user_iter()
.filter(is_a_terminator_inst)
.map(get_parent)
.filter(|user| user.is_a_terminator_inst())
.map(|user| user.get_parent().unwrap())
}
pub fn get_single_predecessor(self) -> Option<BasicBlock> {

View file

@ -36,6 +36,7 @@
#![feature(slice_patterns)]
#![feature(staged_api)]
#![feature(unicode)]
#![feature(conservative_impl_trait)]
use rustc::dep_graph::WorkProduct;