]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/cfg/mod.rs
bb758ec7c38b73082254fa654dafd375419ac1f0
[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 /*!
12
13 Module that constructs a control-flow graph representing an item.
14 Uses `Graph` as the underlying representation.
15
16 */
17
18 use middle::graph;
19 use middle::ty;
20 use syntax::ast;
21 use util::nodemap::NodeMap;
22
23 mod construct;
24 pub mod graphviz;
25
26 pub struct CFG {
27     pub exit_map: NodeMap<CFGIndex>,
28     pub graph: CFGGraph,
29     pub entry: CFGIndex,
30     pub exit: CFGIndex,
31 }
32
33 pub struct CFGNodeData {
34     pub id: ast::NodeId
35 }
36
37 pub struct CFGEdgeData {
38     pub exiting_scopes: Vec<ast::NodeId>
39 }
40
41 pub type CFGIndex = graph::NodeIndex;
42
43 pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
44
45 pub type CFGNode = graph::Node<CFGNodeData>;
46
47 pub type CFGEdge = graph::Edge<CFGEdgeData>;
48
49 impl CFG {
50     pub fn new(tcx: &ty::ctxt,
51                blk: &ast::Block) -> CFG {
52         construct::construct(tcx, blk)
53     }
54 }