1
Fork 0

rustc: Pass optional additional plugins to compile_input

This provides a way for clients of the rustc library to add
their own features to the pipeline.
This commit is contained in:
Brian Anderson 2014-07-19 21:54:37 -07:00 committed by Alex Crichton
parent 1c3655bed1
commit c88bf10c37
6 changed files with 30 additions and 12 deletions

View file

@ -69,7 +69,8 @@ pub fn compile_input(sess: Session,
cfg: ast::CrateConfig,
input: &Input,
outdir: &Option<Path>,
output: &Option<Path>) {
output: &Option<Path>,
addl_plugins: Option<Plugins>) {
// We need nested scopes here, because the intermediate results can keep
// large chunks of memory alive and we want to free them as soon as
// possible to keep the peak memory usage low
@ -85,7 +86,8 @@ pub fn compile_input(sess: Session,
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
input);
let (expanded_crate, ast_map)
= match phase_2_configure_and_expand(&sess, krate, id.as_slice()) {
= match phase_2_configure_and_expand(&sess, krate, id.as_slice(),
addl_plugins) {
None => return,
Some(p) => p,
};
@ -186,7 +188,8 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
/// Returns `None` if we're aborting after handling -W help.
pub fn phase_2_configure_and_expand(sess: &Session,
mut krate: ast::Crate,
crate_name: &str)
crate_name: &str,
addl_plugins: Option<Plugins>)
-> Option<(ast::Crate, syntax::ast_map::Map)> {
let time_passes = sess.time_passes();
@ -212,9 +215,10 @@ pub fn phase_2_configure_and_expand(sess: &Session,
krate = time(time_passes, "configuration 1", krate, |krate|
front::config::strip_unconfigured_items(krate));
let mut addl_plugins = Some(addl_plugins);
let Plugins { macros, registrars }
= time(time_passes, "plugin loading", (), |_|
plugin::load::load_plugins(sess, &krate));
plugin::load::load_plugins(sess, &krate, addl_plugins.take_unwrap()));
let mut registry = Registry::new(&krate);
@ -697,7 +701,7 @@ pub fn pretty_print_input(sess: Session,
PpmExpanded | PpmExpandedIdentified | PpmTyped | PpmFlowGraph(_) => {
let (krate, ast_map)
= match phase_2_configure_and_expand(&sess, krate,
id.as_slice()) {
id.as_slice(), None) {
None => return,
Some(p) => p,
};

View file

@ -124,7 +124,7 @@ fn run_compiler(args: &[String]) {
return;
}
driver::compile_input(sess, cfg, &input, &odir, &ofile);
driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
}
/// Prints version information and returns None on success or an error

View file

@ -117,7 +117,7 @@ fn test_env(_test_name: &str,
let input = driver::StrInput(source_string.to_string());
let krate = driver::phase_1_parse_input(&sess, krate_config, &input);
let (krate, ast_map) =
driver::phase_2_configure_and_expand(&sess, krate, "test")
driver::phase_2_configure_and_expand(&sess, krate, "test", None)
.expect("phase 2 aborted");
// run just enough stuff to build a tcx:

View file

@ -66,10 +66,24 @@ impl<'a> PluginLoader<'a> {
}
/// Read plugin metadata and dynamically load registrar functions.
pub fn load_plugins(sess: &Session, krate: &ast::Crate) -> Plugins {
pub fn load_plugins(sess: &Session, krate: &ast::Crate,
addl_plugins: Option<Plugins>) -> Plugins {
let mut loader = PluginLoader::new(sess);
visit::walk_crate(&mut loader, krate, ());
loader.plugins
let mut plugins = loader.plugins;
match addl_plugins {
Some(addl_plugins) => {
// Add in the additional plugins requested by the frontend
let Plugins { macros: addl_macros, registrars: addl_registrars } = addl_plugins;
plugins.macros.push_all_move(addl_macros);
plugins.registrars.push_all_move(addl_registrars);
}
None => ()
}
return plugins;
}
// note that macros aren't expanded yet, and therefore macros can't add plugins.

View file

@ -121,7 +121,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>)
&input);
let (krate, ast_map)
= phase_2_configure_and_expand(&sess, krate, name.as_slice())
= phase_2_configure_and_expand(&sess, krate, name.as_slice(), None)
.expect("phase_2_configure_and_expand aborted in rustdoc!");
let driver::driver::CrateAnalysis {

View file

@ -69,7 +69,7 @@ pub fn run(input: &str,
}));
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let (krate, _) = driver::phase_2_configure_and_expand(&sess, krate,
"rustdoc-test")
"rustdoc-test", None)
.expect("phase_2_configure_and_expand aborted in rustdoc!");
let ctx = box(GC) core::DocContext {
@ -166,7 +166,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
let out = Some(outdir.path().clone());
let cfg = config::build_configuration(&sess);
let libdir = sess.target_filesearch().get_lib_path();
driver::compile_input(sess, cfg, &input, &out, &None);
driver::compile_input(sess, cfg, &input, &out, &None, None);
if no_run { return }