Skip to content

Commit 82eefe3

Browse files
committed
add --xpretty flowgraph,unlabelled variant.
1 parent b21a6da commit 82eefe3

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

src/librustc/middle/cfg/graphviz.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub struct LabelledCFG<'a, 'ast: 'a> {
2828
pub ast_map: &'a ast_map::Map<'ast>,
2929
pub cfg: &'a cfg::CFG,
3030
pub name: String,
31+
/// `labelled_edges` controls whether we emit labels on the edges
32+
pub labelled_edges: bool,
3133
}
3234

3335
fn replace_newline_with_backslash_l(s: String) -> String {
@@ -75,6 +77,9 @@ impl<'a, 'ast> dot::Labeller<'a, Node<'a>, Edge<'a>> for LabelledCFG<'a, 'ast> {
7577

7678
fn edge_label(&self, e: &Edge<'a>) -> dot::LabelText<'a> {
7779
let mut label = String::new();
80+
if !self.labelled_edges {
81+
return dot::LabelText::EscStr(label.into_cow());
82+
}
7883
let mut put_one = false;
7984
for (i, &node_id) in e.data.exiting_scopes.iter().enumerate() {
8085
if put_one {

src/librustc_driver/pretty.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,20 @@ pub enum PpSourceMode {
5353
PpmExpandedHygiene,
5454
}
5555

56+
57+
#[derive(Copy, PartialEq, Show)]
58+
pub enum PpFlowGraphMode {
59+
Default,
60+
/// Drops the labels from the edges in the flowgraph output. This
61+
/// is mostly for use in the --xpretty flowgraph run-make tests,
62+
/// since the labels are largely uninteresting in those cases and
63+
/// have become a pain to maintain.
64+
UnlabelledEdges,
65+
}
5666
#[derive(Copy, PartialEq, Show)]
5767
pub enum PpMode {
5868
PpmSource(PpSourceMode),
59-
PpmFlowGraph,
69+
PpmFlowGraph(PpFlowGraphMode),
6070
}
6171

6272
pub fn parse_pretty(sess: &Session,
@@ -73,12 +83,13 @@ pub fn parse_pretty(sess: &Session,
7383
("expanded,identified", _) => PpmSource(PpmExpandedIdentified),
7484
("expanded,hygiene", _) => PpmSource(PpmExpandedHygiene),
7585
("identified", _) => PpmSource(PpmIdentified),
76-
("flowgraph", true) => PpmFlowGraph,
86+
("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default),
87+
("flowgraph,unlabelled", true) => PpmFlowGraph(PpFlowGraphMode::UnlabelledEdges),
7788
_ => {
7889
if extended {
7990
sess.fatal(format!(
8091
"argument to `xpretty` must be one of `normal`, \
81-
`expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
92+
`expanded`, `flowgraph[,unlabelled]=<nodeid>`, `typed`, `identified`, \
8293
`expanded,identified`, or `everybody_loops`; got {}", name).as_slice());
8394
} else {
8495
sess.fatal(format!(
@@ -417,7 +428,7 @@ fn needs_ast_map(ppm: &PpMode, opt_uii: &Option<UserIdentifiedItem>) -> bool {
417428
PpmSource(PpmExpandedIdentified) |
418429
PpmSource(PpmExpandedHygiene) |
419430
PpmSource(PpmTyped) |
420-
PpmFlowGraph => true
431+
PpmFlowGraph(_) => true
421432
}
422433
}
423434

@@ -431,7 +442,7 @@ fn needs_expansion(ppm: &PpMode) -> bool {
431442
PpmSource(PpmExpandedIdentified) |
432443
PpmSource(PpmExpandedHygiene) |
433444
PpmSource(PpmTyped) |
434-
PpmFlowGraph => true
445+
PpmFlowGraph(_) => true
435446
}
436447
}
437448

@@ -589,7 +600,7 @@ pub fn pretty_print_input(sess: Session,
589600
pp::eof(&mut pp_state.s)
590601
}),
591602

592-
(PpmFlowGraph, opt_uii) => {
603+
(PpmFlowGraph(mode), opt_uii) => {
593604
debug!("pretty printing flow graph for {:?}", opt_uii);
594605
let uii = opt_uii.unwrap_or_else(|| {
595606
sess.fatal(&format!("`pretty flowgraph=..` needs NodeId (int) or
@@ -613,7 +624,7 @@ pub fn pretty_print_input(sess: Session,
613624
&arenas,
614625
id,
615626
resolve::MakeGlobMap::No);
616-
print_flowgraph(variants, analysis, code, out)
627+
print_flowgraph(variants, analysis, code, mode, out)
617628
}
618629
None => {
619630
let message = format!("--pretty=flowgraph needs \
@@ -635,20 +646,23 @@ pub fn pretty_print_input(sess: Session,
635646
fn print_flowgraph<W:io::Writer>(variants: Vec<borrowck_dot::Variant>,
636647
analysis: ty::CrateAnalysis,
637648
code: blocks::Code,
649+
mode: PpFlowGraphMode,
638650
mut out: W) -> io::IoResult<()> {
639651
let ty_cx = &analysis.ty_cx;
640652
let cfg = match code {
641653
blocks::BlockCode(block) => cfg::CFG::new(ty_cx, &*block),
642654
blocks::FnLikeCode(fn_like) => cfg::CFG::new(ty_cx, &*fn_like.body()),
643655
};
656+
let labelled_edges = mode != PpFlowGraphMode::UnlabelledEdges;
657+
let lcfg = LabelledCFG {
658+
ast_map: &ty_cx.map,
659+
cfg: &cfg,
660+
name: format!("node_{}", code.id()),
661+
labelled_edges: labelled_edges,
662+
};
644663

645664
match code {
646665
_ if variants.len() == 0 => {
647-
let lcfg = LabelledCFG {
648-
ast_map: &ty_cx.map,
649-
cfg: &cfg,
650-
name: format!("node_{}", code.id()),
651-
};
652666
let r = dot::render(&lcfg, &mut out);
653667
return expand_err_details(r);
654668
}
@@ -662,11 +676,6 @@ fn print_flowgraph<W:io::Writer>(variants: Vec<borrowck_dot::Variant>,
662676
let (bccx, analysis_data) =
663677
borrowck::build_borrowck_dataflow_data_for_fn(ty_cx, fn_parts);
664678

665-
let lcfg = LabelledCFG {
666-
ast_map: &ty_cx.map,
667-
cfg: &cfg,
668-
name: format!("node_{}", code.id()),
669-
};
670679
let lcfg = borrowck_dot::DataflowLabeller {
671680
inner: lcfg,
672681
variants: variants,

0 commit comments

Comments
 (0)