-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor refactoring and features in rustc driver for embedders #15820
Changes from 4 commits
4ec97fb
a232626
df102ef
7d87b53
d9c60f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,7 @@ pub struct Options { | |
pub color: ColorConfig, | ||
pub externs: HashMap<String, Vec<String>>, | ||
pub crate_name: Option<String>, | ||
pub alt_std_name: Option<String> | ||
} | ||
|
||
/// Some reasonable defaults | ||
|
@@ -124,6 +125,7 @@ pub fn basic_options() -> Options { | |
color: Auto, | ||
externs: HashMap::new(), | ||
crate_name: None, | ||
alt_std_name: None, | ||
} | ||
} | ||
|
||
|
@@ -593,24 +595,10 @@ fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig { | |
} | ||
|
||
pub fn build_session_options(matches: &getopts::Matches) -> Options { | ||
let mut crate_types: Vec<CrateType> = Vec::new(); | ||
|
||
let unparsed_crate_types = matches.opt_strs("crate-type"); | ||
for unparsed_crate_type in unparsed_crate_types.iter() { | ||
for part in unparsed_crate_type.as_slice().split(',') { | ||
let new_part = match part { | ||
"lib" => default_lib_output(), | ||
"rlib" => CrateTypeRlib, | ||
"staticlib" => CrateTypeStaticlib, | ||
"dylib" => CrateTypeDylib, | ||
"bin" => CrateTypeExecutable, | ||
_ => { | ||
early_error(format!("unknown crate type: `{}`", | ||
part).as_slice()) | ||
} | ||
}; | ||
crate_types.push(new_part) | ||
} | ||
} | ||
let crate_types = parse_crate_types_from_list(unparsed_crate_types) | ||
.unwrap_or_else(|e| early_error(e.as_slice())); | ||
|
||
let parse_only = matches.opt_present("parse-only"); | ||
let no_trans = matches.opt_present("no-trans"); | ||
|
@@ -801,9 +789,33 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { | |
color: color, | ||
externs: externs, | ||
crate_name: crate_name, | ||
alt_std_name: None | ||
} | ||
} | ||
|
||
pub fn parse_crate_types_from_list(crate_types_list_list: Vec<String>) -> Result<Vec<CrateType>, String> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Travis says this line is >100 characters. |
||
|
||
let mut crate_types: Vec<CrateType> = Vec::new(); | ||
for unparsed_crate_type in crate_types_list_list.iter() { | ||
for part in unparsed_crate_type.as_slice().split(',') { | ||
let new_part = match part { | ||
"lib" => default_lib_output(), | ||
"rlib" => CrateTypeRlib, | ||
"staticlib" => CrateTypeStaticlib, | ||
"dylib" => CrateTypeDylib, | ||
"bin" => CrateTypeExecutable, | ||
_ => { | ||
return Err(format!("unknown crate type: `{}`", | ||
part)); | ||
} | ||
}; | ||
crate_types.push(new_part) | ||
} | ||
} | ||
|
||
return Ok(crate_types); | ||
} | ||
|
||
impl fmt::Show for CrateType { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you adjust the doc comment on this to include something like "initial |
||
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, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a doc-comment here?