forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#1089 from bjorn3/custom_driver
Add custom rustc driver that uses cg_clif
- Loading branch information
Showing
14 changed files
with
191 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_data_structures; | ||
extern crate rustc_driver; | ||
extern crate rustc_interface; | ||
extern crate rustc_session; | ||
extern crate rustc_target; | ||
|
||
use rustc_data_structures::profiling::print_time_passes_entry; | ||
use rustc_interface::interface; | ||
use rustc_session::config::ErrorOutputType; | ||
use rustc_session::early_error; | ||
use rustc_target::spec::PanicStrategy; | ||
|
||
#[derive(Default)] | ||
pub struct TimePassesCallbacks { | ||
time_passes: bool, | ||
} | ||
|
||
impl rustc_driver::Callbacks for TimePassesCallbacks { | ||
fn config(&mut self, config: &mut interface::Config) { | ||
// If a --prints=... option has been given, we don't print the "total" | ||
// time because it will mess up the --prints output. See #64339. | ||
self.time_passes = config.opts.prints.is_empty() | ||
&& (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time); | ||
|
||
// FIXME workaround for an ICE | ||
config.opts.debugging_opts.trim_diagnostic_paths = false; | ||
|
||
config.opts.cg.panic = Some(PanicStrategy::Abort); | ||
config.opts.debugging_opts.panic_abort_tests = true; | ||
config.opts.maybe_sysroot = Some( | ||
std::env::current_exe() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.join("build_sysroot") | ||
.join("sysroot"), | ||
); | ||
} | ||
} | ||
|
||
fn main() { | ||
let start = std::time::Instant::now(); | ||
rustc_driver::init_rustc_env_logger(); | ||
let mut callbacks = TimePassesCallbacks::default(); | ||
rustc_driver::install_ice_hook(); | ||
let exit_code = rustc_driver::catch_with_exit_code(|| { | ||
let mut use_jit = false; | ||
|
||
let mut args = std::env::args_os() | ||
.enumerate() | ||
.map(|(i, arg)| { | ||
arg.into_string().unwrap_or_else(|arg| { | ||
early_error( | ||
ErrorOutputType::default(), | ||
&format!("Argument {} is not valid Unicode: {:?}", i, arg), | ||
) | ||
}) | ||
}) | ||
.filter(|arg| { | ||
if arg == "--jit" { | ||
use_jit = true; | ||
false | ||
} else { | ||
true | ||
} | ||
}) | ||
.collect::<Vec<_>>(); | ||
if use_jit { | ||
args.push("-Cprefer-dynamic".to_string()); | ||
} | ||
rustc_driver::run_compiler( | ||
&args, | ||
&mut callbacks, | ||
None, | ||
None, | ||
Some(Box::new(move |_| { | ||
Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { | ||
config: rustc_codegen_cranelift::BackendConfig { | ||
use_jit, | ||
} | ||
}) | ||
})), | ||
) | ||
}); | ||
// The extra `\t` is necessary to align this label with the others. | ||
print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed()); | ||
std::process::exit(exit_code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.