add -Zunpretty=hir-tree
This uses the debug impls to dump the raw HIR. Particularly useful when learning how the compiler works.
This commit is contained in:
parent
a7d98c7837
commit
1058c89c69
1 changed files with 42 additions and 0 deletions
|
@ -77,6 +77,7 @@ pub enum PpFlowGraphMode {
|
||||||
pub enum PpMode {
|
pub enum PpMode {
|
||||||
PpmSource(PpSourceMode),
|
PpmSource(PpSourceMode),
|
||||||
PpmHir(PpSourceMode),
|
PpmHir(PpSourceMode),
|
||||||
|
PpmHirTree(PpSourceMode),
|
||||||
PpmFlowGraph(PpFlowGraphMode),
|
PpmFlowGraph(PpFlowGraphMode),
|
||||||
PpmMir,
|
PpmMir,
|
||||||
PpmMirCFG,
|
PpmMirCFG,
|
||||||
|
@ -93,6 +94,7 @@ impl PpMode {
|
||||||
PpmSource(PpmExpandedIdentified) |
|
PpmSource(PpmExpandedIdentified) |
|
||||||
PpmSource(PpmExpandedHygiene) |
|
PpmSource(PpmExpandedHygiene) |
|
||||||
PpmHir(_) |
|
PpmHir(_) |
|
||||||
|
PpmHirTree(_) |
|
||||||
PpmMir |
|
PpmMir |
|
||||||
PpmMirCFG |
|
PpmMirCFG |
|
||||||
PpmFlowGraph(_) => true,
|
PpmFlowGraph(_) => true,
|
||||||
|
@ -125,6 +127,7 @@ pub fn parse_pretty(sess: &Session,
|
||||||
("hir", true) => PpmHir(PpmNormal),
|
("hir", true) => PpmHir(PpmNormal),
|
||||||
("hir,identified", true) => PpmHir(PpmIdentified),
|
("hir,identified", true) => PpmHir(PpmIdentified),
|
||||||
("hir,typed", true) => PpmHir(PpmTyped),
|
("hir,typed", true) => PpmHir(PpmTyped),
|
||||||
|
("hir-tree", true) => PpmHirTree(PpmNormal),
|
||||||
("mir", true) => PpmMir,
|
("mir", true) => PpmMir,
|
||||||
("mir-cfg", true) => PpmMirCFG,
|
("mir-cfg", true) => PpmMirCFG,
|
||||||
("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default),
|
("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default),
|
||||||
|
@ -969,6 +972,23 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(PpmHirTree(s), None) => {
|
||||||
|
let out: &mut Write = &mut out;
|
||||||
|
s.call_with_pp_support_hir(sess,
|
||||||
|
cstore,
|
||||||
|
hir_map,
|
||||||
|
analysis,
|
||||||
|
resolutions,
|
||||||
|
arena,
|
||||||
|
arenas,
|
||||||
|
output_filenames,
|
||||||
|
crate_name,
|
||||||
|
move |_annotation, krate| {
|
||||||
|
debug!("pretty printing source code {:?}", s);
|
||||||
|
write!(out, "{:#?}", krate)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
(PpmHir(s), Some(uii)) => {
|
(PpmHir(s), Some(uii)) => {
|
||||||
let out: &mut Write = &mut out;
|
let out: &mut Write = &mut out;
|
||||||
s.call_with_pp_support_hir(sess,
|
s.call_with_pp_support_hir(sess,
|
||||||
|
@ -1003,6 +1023,28 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||||
pp_state.s.eof()
|
pp_state.s.eof()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(PpmHirTree(s), Some(uii)) => {
|
||||||
|
let out: &mut Write = &mut out;
|
||||||
|
s.call_with_pp_support_hir(sess,
|
||||||
|
cstore,
|
||||||
|
hir_map,
|
||||||
|
analysis,
|
||||||
|
resolutions,
|
||||||
|
arena,
|
||||||
|
arenas,
|
||||||
|
output_filenames,
|
||||||
|
crate_name,
|
||||||
|
move |_annotation, _krate| {
|
||||||
|
debug!("pretty printing source code {:?}", s);
|
||||||
|
for node_id in uii.all_matching_node_ids(hir_map) {
|
||||||
|
let node = hir_map.get(node_id);
|
||||||
|
write!(out, "{:#?}", node)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue