diff options
| author | bors <bors@rust-lang.org> | 2017-11-23 00:52:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-23 00:52:15 +0000 |
| commit | 6af4515de6c065bc4e4ac91035fbf51643172305 (patch) | |
| tree | 5dc8538448dc20e97400c9ca1e60101209eee4c2 | |
| parent | 45594d5dec4237f49e794a2a854a69f50b63d31e (diff) | |
| parent | 61f31fd559ba5925022a103a46e90db66eaa37be (diff) | |
| download | rust-6af4515de6c065bc4e4ac91035fbf51643172305.tar.gz rust-6af4515de6c065bc4e4ac91035fbf51643172305.zip | |
Auto merge of #45721 - nikomatsakis:hir-tree, r=arielb1
add -Zunpretty=hir-tree This uses the debug impls to dump the raw HIR. Particularly useful when learning how the compiler works. cc @qmx
| -rw-r--r-- | src/librustc_driver/pretty.rs | 42 | ||||
| -rw-r--r-- | src/test/run-make/hir-tree/Makefile | 9 | ||||
| -rw-r--r-- | src/test/run-make/hir-tree/input.rs | 13 |
3 files changed, 64 insertions, 0 deletions
diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 85ccacb43fb..bf1579acf53 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -77,6 +77,7 @@ pub enum PpFlowGraphMode { pub enum PpMode { PpmSource(PpSourceMode), PpmHir(PpSourceMode), + PpmHirTree(PpSourceMode), PpmFlowGraph(PpFlowGraphMode), PpmMir, PpmMirCFG, @@ -93,6 +94,7 @@ impl PpMode { PpmSource(PpmExpandedIdentified) | PpmSource(PpmExpandedHygiene) | PpmHir(_) | + PpmHirTree(_) | PpmMir | PpmMirCFG | PpmFlowGraph(_) => true, @@ -125,6 +127,7 @@ pub fn parse_pretty(sess: &Session, ("hir", true) => PpmHir(PpmNormal), ("hir,identified", true) => PpmHir(PpmIdentified), ("hir,typed", true) => PpmHir(PpmTyped), + ("hir-tree", true) => PpmHirTree(PpmNormal), ("mir", true) => PpmMir, ("mir-cfg", true) => PpmMirCFG, ("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default), @@ -971,6 +974,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)) => { let out: &mut Write = &mut out; s.call_with_pp_support_hir(sess, @@ -1005,6 +1025,28 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, 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!(), } .unwrap(); diff --git a/src/test/run-make/hir-tree/Makefile b/src/test/run-make/hir-tree/Makefile new file mode 100644 index 00000000000..59e4ae8a30d --- /dev/null +++ b/src/test/run-make/hir-tree/Makefile @@ -0,0 +1,9 @@ +-include ../tools.mk + +# Test that hir-tree output doens't crash and includes +# the string constant we would expect to see. + +all: + $(RUSTC) -o $(TMPDIR)/input.hir -Z unstable-options \ + --unpretty=hir-tree input.rs + grep '"Hello, Rustaceans!\\n"' $(TMPDIR)/input.hir diff --git a/src/test/run-make/hir-tree/input.rs b/src/test/run-make/hir-tree/input.rs new file mode 100644 index 00000000000..12adc083bcd --- /dev/null +++ b/src/test/run-make/hir-tree/input.rs @@ -0,0 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + println!("Hello, Rustaceans!"); +} |
