Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Last active December 12, 2015 03:48
Show Gist options
  • Save alexcrichton/4709170 to your computer and use it in GitHub Desktop.
Save alexcrichton/4709170 to your computer and use it in GitHub Desktop.
pub mod graph {
use core::hashmap::linear::LinearMap;
pub type NodeId = uint;
pub struct Graph<N, E> {
priv nodes: LinearMap<NodeId, N>,
}
impl<N, E> Graph<N, E> {
pure fn node(&self, id: NodeId) -> &self/N {
self.nodes.get(&id)
}
}
}
mod ssa {
use graph::*;
pub trait Statement {
fn each_def(&self, &fn(uint) -> bool);
fn phi_info(&self) -> Option<(uint, &self/uint)>;
}
pub type CFG<T> = Graph<~[@T], ()>;
}
use ssa::{CFG, Statement};
fn liveness<T: Statement>(c: &CFG<T>) -> bool {
let foo = c.node(4);
for vec::rev_each(*foo) |ins| {
for ins.each_def |_| {
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment