Skip to content

Commit

Permalink
Dump results of analysis phase as CSV
Browse files Browse the repository at this point in the history
Adds the option -Zsave-analysis which will dump the results of syntax and type checking into CSV files. These can be interpreted by tools such as DXR to provide semantic information about Rust programs for code search, cross-reference, etc.

Authored by Nick Cameron and Peter Elmers (@pelmers; including enums, type parameters/generics).
  • Loading branch information
nrc committed Jun 13, 2014
1 parent c20aed0 commit 984e9af
Show file tree
Hide file tree
Showing 11 changed files with 2,531 additions and 37 deletions.
7 changes: 5 additions & 2 deletions src/librustc/driver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ debugging_opts!(
LTO,
AST_JSON,
AST_JSON_NOEXPAND,
LS
LS,
SAVE_ANALYSIS
]
0
)
Expand Down Expand Up @@ -206,7 +207,9 @@ pub fn debugging_opts_map() -> Vec<(&'static str, &'static str, u64)> {
("lto", "Perform LLVM link-time optimizations", LTO),
("ast-json", "Print the AST as JSON and halt", AST_JSON),
("ast-json-noexpand", "Print the pre-expansion AST as JSON and halt", AST_JSON_NOEXPAND),
("ls", "List the symbols defined by a library crate", LS))
("ls", "List the symbols defined by a library crate", LS),
("save-analysis", "Write syntax and type analysis information \
in addition to normal output", SAVE_ANALYSIS))
}

/// Declare a macro that will define all CodegenOptions fields and parsers all
Expand Down
12 changes: 12 additions & 0 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn compile_input(sess: Session,
if stop_after_phase_2(&sess) { return; }

let analysis = phase_3_run_analysis_passes(sess, &expanded_crate, ast_map);
phase_save_analysis(&analysis.ty_cx.sess, &expanded_crate, &analysis, outdir);
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate,
analysis, &outputs);
Expand Down Expand Up @@ -370,6 +371,17 @@ pub fn phase_3_run_analysis_passes(sess: Session,
}
}

pub fn phase_save_analysis(sess: &Session,
krate: &ast::Crate,
analysis: &CrateAnalysis,
odir: &Option<Path>) {
if (sess.opts.debugging_opts & config::SAVE_ANALYSIS) == 0 {
return;
}
time(sess.time_passes(), "save analysis", krate, |krate|
middle::save::process_crate(sess, krate, analysis, odir));
}

pub struct CrateTranslation {
pub context: ContextRef,
pub module: ModuleRef,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use syntax::{ast, codemap};
use std::os;
use std::cell::{Cell, RefCell};


pub struct Session {
pub targ_cfg: config::Config,
pub opts: config::Options,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub mod middle {
pub mod expr_use_visitor;
pub mod dependency_format;
pub mod weak_lang_items;
pub mod save;
}

pub mod front {
Expand Down
Loading

1 comment on commit 984e9af

@nrc
Copy link
Owner Author

@nrc nrc commented on 984e9af Jun 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=brson (fixed a bug in the run_make test and rebased again)

Please sign in to comment.