]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/cfg/mod.rs
/*! -> //!
[rust.git] / src / librustc / middle / cfg / mod.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Module that constructs a control-flow graph representing an item.
12 //! Uses `Graph` as the underlying representation.
13
14 use middle::graph;
15 use middle::ty;
16 use syntax::ast;
17 use util::nodemap::NodeMap;
18
19 mod construct;
20 pub mod graphviz;
21
22 pub struct CFG {
23     pub exit_map: NodeMap<CFGIndex>,
24     pub graph: CFGGraph,
25     pub entry: CFGIndex,
26     pub exit: CFGIndex,
27 }
28
29 pub struct CFGNodeData {
30     pub id: ast::NodeId
31 }
32
33 pub struct CFGEdgeData {
34     pub exiting_scopes: Vec<ast::NodeId>
35 }
36
37 pub type CFGIndex = graph::NodeIndex;
38
39 pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
40
41 pub type CFGNode = graph::Node<CFGNodeData>;
42
43 pub type CFGEdge = graph::Edge<CFGEdgeData>;
44
45 impl CFG {
46     pub fn new(tcx: &ty::ctxt,
47                blk: &ast::Block) -> CFG {
48         construct::construct(tcx, blk)
49     }
50 }