Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ba8e610

Browse files
committed
Inline driver::codegen_crate
1 parent d9e9fed commit ba8e610

File tree

4 files changed

+20
-36
lines changed

4 files changed

+20
-36
lines changed

src/driver/aot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn module_codegen(
152152
codegen_result
153153
}
154154

155-
pub(super) fn run_aot(
155+
pub(crate) fn run_aot(
156156
tcx: TyCtxt<'_>,
157157
backend_config: BackendConfig,
158158
metadata: EncodedMetadata,

src/driver/jit.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ thread_local! {
2020
pub static CURRENT_MODULE: RefCell<Option<JITModule>> = RefCell::new(None);
2121
}
2222

23-
pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
23+
pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
2424
if !tcx.sess.opts.output_types.should_codegen() {
25-
tcx.sess.fatal("JIT mode doesn't work with `cargo check`.");
25+
tcx.sess.fatal("JIT mode doesn't work with `cargo check`");
26+
}
27+
28+
if !tcx.sess.crate_types().contains(&rustc_session::config::CrateType::Executable) {
29+
tcx.sess.fatal("can't jit non-executable crate");
2630
}
2731

2832
let imported_symbols = load_imported_symbols_for_jit(tcx);

src/driver/mod.rs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,13 @@
11
//! Drivers are responsible for calling [`codegen_mono_item`] and performing any further actions
22
//! like JIT executing or writing object files.
33
4-
use std::any::Any;
5-
6-
use rustc_middle::middle::cstore::EncodedMetadata;
74
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
85

96
use crate::prelude::*;
10-
use crate::CodegenMode;
117

12-
mod aot;
8+
pub(crate) mod aot;
139
#[cfg(feature = "jit")]
14-
mod jit;
15-
16-
pub(crate) fn codegen_crate(
17-
tcx: TyCtxt<'_>,
18-
metadata: EncodedMetadata,
19-
need_metadata_module: bool,
20-
backend_config: crate::BackendConfig,
21-
) -> Box<dyn Any> {
22-
tcx.sess.abort_if_errors();
23-
24-
match backend_config.codegen_mode {
25-
CodegenMode::Aot => aot::run_aot(tcx, backend_config, metadata, need_metadata_module),
26-
CodegenMode::Jit | CodegenMode::JitLazy => {
27-
let is_executable =
28-
tcx.sess.crate_types().contains(&rustc_session::config::CrateType::Executable);
29-
if !is_executable {
30-
tcx.sess.fatal("can't jit non-executable crate");
31-
}
32-
33-
#[cfg(feature = "jit")]
34-
let _: ! = jit::run_jit(tcx, backend_config);
35-
36-
#[cfg(not(feature = "jit"))]
37-
tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift");
38-
}
39-
}
40-
}
10+
pub(crate) mod jit;
4111

4212
fn predefine_mono_items<'tcx>(
4313
tcx: TyCtxt<'tcx>,

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,23 @@ impl CodegenBackend for CraneliftCodegenBackend {
177177
metadata: EncodedMetadata,
178178
need_metadata_module: bool,
179179
) -> Box<dyn Any> {
180+
tcx.sess.abort_if_errors();
180181
let config = if let Some(config) = self.config.clone() {
181182
config
182183
} else {
183184
BackendConfig::from_opts(&tcx.sess.opts.cg.llvm_args)
184185
.unwrap_or_else(|err| tcx.sess.fatal(&err))
185186
};
186-
driver::codegen_crate(tcx, metadata, need_metadata_module, config)
187+
match config.codegen_mode {
188+
CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module),
189+
CodegenMode::Jit | CodegenMode::JitLazy => {
190+
#[cfg(feature = "jit")]
191+
let _: ! = driver::jit::run_jit(tcx, config);
192+
193+
#[cfg(not(feature = "jit"))]
194+
tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift");
195+
}
196+
}
187197
}
188198

189199
fn join_codegen(

0 commit comments

Comments
 (0)