]> git.lizzy.rs Git - rust.git/blob - src/bin/cg_clif.rs
Merge pull request #1120 from bjorn3/lazy_jit
[rust.git] / src / bin / cg_clif.rs
1 #![feature(rustc_private)]
2
3 extern crate rustc_data_structures;
4 extern crate rustc_driver;
5 extern crate rustc_interface;
6 extern crate rustc_session;
7 extern crate rustc_target;
8
9 use rustc_data_structures::profiling::print_time_passes_entry;
10 use rustc_interface::interface;
11 use rustc_session::config::ErrorOutputType;
12 use rustc_session::early_error;
13 use rustc_target::spec::PanicStrategy;
14
15 #[derive(Default)]
16 pub struct CraneliftPassesCallbacks {
17     time_passes: bool,
18 }
19
20 impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
21     fn config(&mut self, config: &mut interface::Config) {
22         // If a --prints=... option has been given, we don't print the "total"
23         // time because it will mess up the --prints output. See #64339.
24         self.time_passes = config.opts.prints.is_empty()
25             && (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
26
27         config.opts.cg.panic = Some(PanicStrategy::Abort);
28         config.opts.debugging_opts.panic_abort_tests = true;
29         config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| {
30             std::env::current_exe()
31                 .unwrap()
32                 .parent()
33                 .unwrap()
34                 .parent()
35                 .unwrap()
36                 .to_owned()
37         }));
38     }
39 }
40
41 fn main() {
42     let start = std::time::Instant::now();
43     rustc_driver::init_rustc_env_logger();
44     let mut callbacks = CraneliftPassesCallbacks::default();
45     rustc_driver::install_ice_hook();
46     let exit_code = rustc_driver::catch_with_exit_code(|| {
47         let args = std::env::args_os()
48             .enumerate()
49             .map(|(i, arg)| {
50                 arg.into_string().unwrap_or_else(|arg| {
51                     early_error(
52                         ErrorOutputType::default(),
53                         &format!("Argument {} is not valid Unicode: {:?}", i, arg),
54                     )
55                 })
56             })
57             .collect::<Vec<_>>();
58         let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks);
59         run_compiler.set_make_codegen_backend(Some(Box::new(move |_| {
60             Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None })
61         })));
62         run_compiler.run()
63     });
64     // The extra `\t` is necessary to align this label with the others.
65     print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed());
66     std::process::exit(exit_code)
67 }