diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-04-08 21:26:20 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-04-14 14:57:04 +0200 |
| commit | ba8e610b269f90287aad1b5db0520bfd3118612e (patch) | |
| tree | 585e9062140e8a4338b94fe7fd1befe838dbe062 | |
| parent | d9e9fedfe579b0062645e3be06284a9246228b8e (diff) | |
| download | rust-ba8e610b269f90287aad1b5db0520bfd3118612e.tar.gz rust-ba8e610b269f90287aad1b5db0520bfd3118612e.zip | |
Inline driver::codegen_crate
| -rw-r--r-- | src/driver/aot.rs | 2 | ||||
| -rw-r--r-- | src/driver/jit.rs | 8 | ||||
| -rw-r--r-- | src/driver/mod.rs | 34 | ||||
| -rw-r--r-- | src/lib.rs | 12 |
4 files changed, 20 insertions, 36 deletions
diff --git a/src/driver/aot.rs b/src/driver/aot.rs index fc1dd558603..f1d30ba4bdc 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -152,7 +152,7 @@ fn module_codegen( codegen_result } -pub(super) fn run_aot( +pub(crate) fn run_aot( tcx: TyCtxt<'_>, backend_config: BackendConfig, metadata: EncodedMetadata, diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 13cfad8df2e..bcc7a494499 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -20,9 +20,13 @@ thread_local! { pub static CURRENT_MODULE: RefCell<Option<JITModule>> = RefCell::new(None); } -pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { +pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { if !tcx.sess.opts.output_types.should_codegen() { - tcx.sess.fatal("JIT mode doesn't work with `cargo check`."); + tcx.sess.fatal("JIT mode doesn't work with `cargo check`"); + } + + if !tcx.sess.crate_types().contains(&rustc_session::config::CrateType::Executable) { + tcx.sess.fatal("can't jit non-executable crate"); } let imported_symbols = load_imported_symbols_for_jit(tcx); diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 27fd7a2f2d8..8dde9992b35 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -1,43 +1,13 @@ //! Drivers are responsible for calling [`codegen_mono_item`] and performing any further actions //! like JIT executing or writing object files. -use std::any::Any; - -use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; use crate::prelude::*; -use crate::CodegenMode; -mod aot; +pub(crate) mod aot; #[cfg(feature = "jit")] -mod jit; - -pub(crate) fn codegen_crate( - tcx: TyCtxt<'_>, - metadata: EncodedMetadata, - need_metadata_module: bool, - backend_config: crate::BackendConfig, -) -> Box<dyn Any> { - tcx.sess.abort_if_errors(); - - match backend_config.codegen_mode { - CodegenMode::Aot => aot::run_aot(tcx, backend_config, metadata, need_metadata_module), - CodegenMode::Jit | CodegenMode::JitLazy => { - let is_executable = - tcx.sess.crate_types().contains(&rustc_session::config::CrateType::Executable); - if !is_executable { - tcx.sess.fatal("can't jit non-executable crate"); - } - - #[cfg(feature = "jit")] - let _: ! = jit::run_jit(tcx, backend_config); - - #[cfg(not(feature = "jit"))] - tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift"); - } - } -} +pub(crate) mod jit; fn predefine_mono_items<'tcx>( tcx: TyCtxt<'tcx>, diff --git a/src/lib.rs b/src/lib.rs index 1afd35af352..e15d21a123d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,13 +177,23 @@ impl CodegenBackend for CraneliftCodegenBackend { metadata: EncodedMetadata, need_metadata_module: bool, ) -> Box<dyn Any> { + tcx.sess.abort_if_errors(); let config = if let Some(config) = self.config.clone() { config } else { BackendConfig::from_opts(&tcx.sess.opts.cg.llvm_args) .unwrap_or_else(|err| tcx.sess.fatal(&err)) }; - driver::codegen_crate(tcx, metadata, need_metadata_module, config) + match config.codegen_mode { + CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module), + CodegenMode::Jit | CodegenMode::JitLazy => { + #[cfg(feature = "jit")] + let _: ! = driver::jit::run_jit(tcx, config); + + #[cfg(not(feature = "jit"))] + tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift"); + } + } } fn join_codegen( |
