Skip to content

Commit

Permalink
auto merge of #12387 : cmr/rust/ast-json, r=alexcrichton
Browse files Browse the repository at this point in the history
See the commits
  • Loading branch information
bors committed Feb 20, 2014
2 parents ea00582 + 34ffe3c commit 879e8aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ use middle;
use util::common::time;
use util::ppaux;

use extra::json;
use serialize::Encodable;

use std::cell::{Cell, RefCell};
use std::hashmap::{HashMap,HashSet};
use std::io;
Expand Down Expand Up @@ -154,7 +157,7 @@ pub enum Input {

pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
-> ast::Crate {
time(sess.time_passes(), "parsing", (), |_| {
let krate = time(sess.time_passes(), "parsing", (), |_| {
match *input {
FileInput(ref file) => {
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
Expand All @@ -166,7 +169,15 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
sess.parse_sess)
}
}
})
});

if sess.opts.debugging_opts & session::AST_JSON_NOEXPAND != 0 {
let mut stdout = io::stdout();
let mut json = json::PrettyEncoder::new(&mut stdout);
krate.encode(&mut json);
}

krate
}

// For continuing compilation after a parsed crate has been
Expand Down Expand Up @@ -220,8 +231,16 @@ pub fn phase_2_configure_and_expand(sess: Session,
krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, krate));

time(time_passes, "assinging node ids and indexing ast", krate, |krate|
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate))
let (krate, map) = time(time_passes, "assinging node ids and indexing ast", krate, |krate|
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));

if sess.opts.debugging_opts & session::AST_JSON != 0 {
let mut stdout = io::stdout();
let mut json = json::PrettyEncoder::new(&mut stdout);
krate.encode(&mut json);
}

(krate, map)
}

pub struct CrateAnalysis {
Expand Down Expand Up @@ -428,15 +447,15 @@ pub fn stop_after_phase_1(sess: Session) -> bool {
debug!("invoked with --parse-only, returning early from compile_input");
return true;
}
return false;
return sess.opts.debugging_opts & session::AST_JSON_NOEXPAND != 0;
}

pub fn stop_after_phase_2(sess: Session) -> bool {
if sess.opts.no_analysis {
debug!("invoked with --no-analysis, returning early from compile_input");
return true;
}
return false;
return sess.opts.debugging_opts & session::AST_JSON != 0;
}

pub fn stop_after_phase_5(sess: Session) -> bool {
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ debugging_opts!(
GC,
PRINT_LINK_ARGS,
PRINT_LLVM_PASSES,
LTO
LTO,
AST_JSON,
AST_JSON_NOEXPAND
]
0
)
Expand Down Expand Up @@ -97,6 +99,8 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, u64)] {
"Prints the llvm optimization passes being run",
PRINT_LLVM_PASSES),
("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),
]
}

Expand Down

0 comments on commit 879e8aa

Please sign in to comment.