diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-11-11 18:26:14 +1300 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-11-12 09:23:37 +1300 |
| commit | f7dc917ba44c13e5ec00503dd82b857211437f48 (patch) | |
| tree | 4bc5443e5f6fa40d48822b3b66bd4e4e7d93ff03 /src/librustc_driver | |
| parent | f1f5c04c07f2e888c43cb577810659a7c1d87a00 (diff) | |
| download | rust-f7dc917ba44c13e5ec00503dd82b857211437f48.tar.gz rust-f7dc917ba44c13e5ec00503dd82b857211437f48.zip | |
Add -Zinput-stats
Emits loc, and node count - before and after expansion. E.g., ``` rustc: x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore Lines of code: 32060 Pre-expansion node count: 120205 Post-expansion node count: 482749 ```
Diffstat (limited to 'src/librustc_driver')
| -rw-r--r-- | src/librustc_driver/driver.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index ba9bf4bac7d..def8d3bc404 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -52,6 +52,8 @@ use syntax::feature_gate::UnstableFeatures; use syntax::fold::Folder; use syntax::parse; use syntax::parse::token; +use syntax::util::node_count::NodeCounter; +use syntax::visit; use syntax; pub fn compile_input(sess: Session, @@ -398,6 +400,11 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input) println!("{}", json::as_json(&krate)); } + if sess.opts.debugging_opts.input_stats { + println!("Lines of code: {}", sess.codemap().count_lines()); + println!("Pre-expansion node count: {}", count_nodes(&krate)); + } + if let Some(ref s) = sess.opts.show_span { syntax::show_span::run(sess.diagnostic(), s, &krate); } @@ -405,6 +412,12 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input) krate } +fn count_nodes(krate: &ast::Crate) -> usize { + let mut counter = NodeCounter::new(); + visit::walk_crate(&mut counter, krate); + counter.count +} + // For continuing compilation after a parsed crate has been // modified @@ -606,6 +619,10 @@ pub fn phase_2_configure_and_expand(sess: &Session, sess.abort_if_errors(); }); + if sess.opts.debugging_opts.input_stats { + println!("Post-expansion node count: {}", count_nodes(&krate)); + } + Some(krate) } |
