Skip to content

Commit c119903

Browse files
committed
auto merge of #13222 : nick29581/rust/dxr4, r=brson
Adds a -Z flag `save-analysis` which runs after the analysis phase of the compiler and saves a bunch of info into a CSV file for the crate. This is designed to work with the DXR code browser, but is frontend-independent, that is this info should be useful for all kinds of code browsers, IDEs, or other tools. I need to squash commits before landing (there will probably be a fair few to come), please ignore them for now and just comment on the changes.
2 parents 5d9bceb + 984e9af commit c119903

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)