Skip to content

Commit 984e9af

Browse files
committed
Dump results of analysis phase as CSV
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).
1 parent c20aed0 commit 984e9af

File tree

11 files changed

+2531
-37
lines changed

11 files changed

+2531
-37
lines changed

src/librustc/driver/config.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ debugging_opts!(
172172
LTO,
173173
AST_JSON,
174174
AST_JSON_NOEXPAND,
175-
LS
175+
LS,
176+
SAVE_ANALYSIS
176177
]
177178
0
178179
)
@@ -206,7 +207,9 @@ pub fn debugging_opts_map() -> Vec<(&'static str, &'static str, u64)> {
206207
("lto", "Perform LLVM link-time optimizations", LTO),
207208
("ast-json", "Print the AST as JSON and halt", AST_JSON),
208209
("ast-json-noexpand", "Print the pre-expansion AST as JSON and halt", AST_JSON_NOEXPAND),
209-
("ls", "List the symbols defined by a library crate", LS))
210+
("ls", "List the symbols defined by a library crate", LS),
211+
("save-analysis", "Write syntax and type analysis information \
212+
in addition to normal output", SAVE_ANALYSIS))
210213
}
211214

212215
/// Declare a macro that will define all CodegenOptions fields and parsers all

src/librustc/driver/driver.rs

+12
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub fn compile_input(sess: Session,
8787
if stop_after_phase_2(&sess) { return; }
8888

8989
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate, ast_map);
90+
phase_save_analysis(&analysis.ty_cx.sess, &expanded_crate, &analysis, outdir);
9091
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
9192
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate,
9293
analysis, &outputs);
@@ -370,6 +371,17 @@ pub fn phase_3_run_analysis_passes(sess: Session,
370371
}
371372
}
372373

374+
pub fn phase_save_analysis(sess: &Session,
375+
krate: &ast::Crate,
376+
analysis: &CrateAnalysis,
377+
odir: &Option<Path>) {
378+
if (sess.opts.debugging_opts & config::SAVE_ANALYSIS) == 0 {
379+
return;
380+
}
381+
time(sess.time_passes(), "save analysis", krate, |krate|
382+
middle::save::process_crate(sess, krate, analysis, odir));
383+
}
384+
373385
pub struct CrateTranslation {
374386
pub context: ContextRef,
375387
pub module: ModuleRef,

src/librustc/driver/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use syntax::{ast, codemap};
2828
use std::os;
2929
use std::cell::{Cell, RefCell};
3030

31+
3132
pub struct Session {
3233
pub targ_cfg: config::Config,
3334
pub opts: config::Options,

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub mod middle {
8484
pub mod expr_use_visitor;
8585
pub mod dependency_format;
8686
pub mod weak_lang_items;
87+
pub mod save;
8788
}
8889

8990
pub mod front {

0 commit comments

Comments
 (0)