Skip to content

Commit 1058c89

Browse files
committed
add -Zunpretty=hir-tree
This uses the debug impls to dump the raw HIR. Particularly useful when learning how the compiler works.
1 parent a7d98c7 commit 1058c89

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/librustc_driver/pretty.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub enum PpFlowGraphMode {
7777
pub enum PpMode {
7878
PpmSource(PpSourceMode),
7979
PpmHir(PpSourceMode),
80+
PpmHirTree(PpSourceMode),
8081
PpmFlowGraph(PpFlowGraphMode),
8182
PpmMir,
8283
PpmMirCFG,
@@ -93,6 +94,7 @@ impl PpMode {
9394
PpmSource(PpmExpandedIdentified) |
9495
PpmSource(PpmExpandedHygiene) |
9596
PpmHir(_) |
97+
PpmHirTree(_) |
9698
PpmMir |
9799
PpmMirCFG |
98100
PpmFlowGraph(_) => true,
@@ -125,6 +127,7 @@ pub fn parse_pretty(sess: &Session,
125127
("hir", true) => PpmHir(PpmNormal),
126128
("hir,identified", true) => PpmHir(PpmIdentified),
127129
("hir,typed", true) => PpmHir(PpmTyped),
130+
("hir-tree", true) => PpmHirTree(PpmNormal),
128131
("mir", true) => PpmMir,
129132
("mir-cfg", true) => PpmMirCFG,
130133
("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default),
@@ -969,6 +972,23 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
969972
})
970973
}
971974

975+
(PpmHirTree(s), None) => {
976+
let out: &mut Write = &mut out;
977+
s.call_with_pp_support_hir(sess,
978+
cstore,
979+
hir_map,
980+
analysis,
981+
resolutions,
982+
arena,
983+
arenas,
984+
output_filenames,
985+
crate_name,
986+
move |_annotation, krate| {
987+
debug!("pretty printing source code {:?}", s);
988+
write!(out, "{:#?}", krate)
989+
})
990+
}
991+
972992
(PpmHir(s), Some(uii)) => {
973993
let out: &mut Write = &mut out;
974994
s.call_with_pp_support_hir(sess,
@@ -1003,6 +1023,28 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
10031023
pp_state.s.eof()
10041024
})
10051025
}
1026+
1027+
(PpmHirTree(s), Some(uii)) => {
1028+
let out: &mut Write = &mut out;
1029+
s.call_with_pp_support_hir(sess,
1030+
cstore,
1031+
hir_map,
1032+
analysis,
1033+
resolutions,
1034+
arena,
1035+
arenas,
1036+
output_filenames,
1037+
crate_name,
1038+
move |_annotation, _krate| {
1039+
debug!("pretty printing source code {:?}", s);
1040+
for node_id in uii.all_matching_node_ids(hir_map) {
1041+
let node = hir_map.get(node_id);
1042+
write!(out, "{:#?}", node)?;
1043+
}
1044+
Ok(())
1045+
})
1046+
}
1047+
10061048
_ => unreachable!(),
10071049
}
10081050
.unwrap();

0 commit comments

Comments
 (0)