Move global_asm into CodegenCx
This commit is contained in:
parent
548c46fe9d
commit
35701d8caa
@ -112,21 +112,11 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
|
||||
|
||||
let module = new_module(tcx, cgu_name.as_str().to_string());
|
||||
|
||||
let mut global_asm = Vec::new();
|
||||
let mut cx = crate::CodegenCx::new(tcx, module, tcx.sess.opts.debuginfo != DebugInfo::None);
|
||||
super::codegen_mono_items(&mut cx, &mut global_asm, mono_items);
|
||||
let (mut module, debug, mut unwind_context) = tcx.sess.time("finalize CodegenCx", || cx.finalize());
|
||||
super::codegen_mono_items(&mut cx, mono_items);
|
||||
let (mut module, global_asm, debug, mut unwind_context) = tcx.sess.time("finalize CodegenCx", || cx.finalize());
|
||||
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context);
|
||||
|
||||
let global_asm = global_asm.into_iter().map(|hir_id| {
|
||||
let item = tcx.hir().expect_item(hir_id);
|
||||
if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind {
|
||||
asm.as_str().to_string()
|
||||
} else {
|
||||
bug!("Expected GlobalAsm found {:?}", item);
|
||||
}
|
||||
}).collect::<Vec<String>>().join("\n");
|
||||
|
||||
let codegen_result = emit_module(
|
||||
tcx,
|
||||
cgu.name().as_str().to_string(),
|
||||
|
@ -54,15 +54,13 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
|
||||
|
||||
let mut cx = crate::CodegenCx::new(tcx, jit_module, false);
|
||||
|
||||
let (mut jit_module, _debug, mut unwind_context) = super::time(tcx, "codegen mono items", || {
|
||||
let mut global_asm = Vec::new();
|
||||
super::codegen_mono_items(&mut cx, &mut global_asm, mono_items);
|
||||
for hir_id in global_asm {
|
||||
let item = tcx.hir().expect_item(hir_id);
|
||||
tcx.sess.span_err(item.span, "Global asm is not supported in JIT mode");
|
||||
}
|
||||
let (mut jit_module, global_asm, _debug, mut unwind_context) = super::time(tcx, "codegen mono items", || {
|
||||
super::codegen_mono_items(&mut cx, mono_items);
|
||||
tcx.sess.time("finalize CodegenCx", || cx.finalize())
|
||||
});
|
||||
if !global_asm.is_empty() {
|
||||
tcx.sess.fatal("Global asm is not supported in JIT mode");
|
||||
}
|
||||
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, &mut unwind_context);
|
||||
crate::allocator::codegen(tcx, &mut jit_module, &mut unwind_context);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::any::Any;
|
||||
|
||||
use rustc_hir::HirId;
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
|
||||
|
||||
@ -32,7 +31,6 @@ pub(crate) fn codegen_crate(
|
||||
|
||||
fn codegen_mono_items<'tcx>(
|
||||
cx: &mut crate::CodegenCx<'tcx, impl Backend + 'static>,
|
||||
global_asm: &mut Vec<HirId>,
|
||||
mono_items: Vec<(MonoItem<'tcx>, (RLinkage, Visibility))>,
|
||||
) {
|
||||
cx.tcx.sess.time("predefine functions", || {
|
||||
@ -51,13 +49,12 @@ fn codegen_mono_items<'tcx>(
|
||||
|
||||
for (mono_item, (linkage, visibility)) in mono_items {
|
||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
||||
trans_mono_item(cx, global_asm, mono_item, linkage);
|
||||
trans_mono_item(cx, mono_item, linkage);
|
||||
}
|
||||
}
|
||||
|
||||
fn trans_mono_item<'tcx, B: Backend + 'static>(
|
||||
cx: &mut crate::CodegenCx<'tcx, B>,
|
||||
global_asm: &mut Vec<HirId>,
|
||||
mono_item: MonoItem<'tcx>,
|
||||
linkage: Linkage,
|
||||
) {
|
||||
@ -94,7 +91,13 @@ fn trans_mono_item<'tcx, B: Backend + 'static>(
|
||||
crate::constant::codegen_static(&mut cx.constants_cx, def_id);
|
||||
}
|
||||
MonoItem::GlobalAsm(hir_id) => {
|
||||
global_asm.push(hir_id);
|
||||
let item = tcx.hir().expect_item(hir_id);
|
||||
if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind {
|
||||
cx.global_asm.push_str(&*asm.as_str());
|
||||
cx.global_asm.push_str("\n\n");
|
||||
} else {
|
||||
bug!("Expected GlobalAsm found {:?}", item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +123,7 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
|
||||
struct CodegenCx<'tcx, B: Backend + 'static> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
module: Module<B>,
|
||||
global_asm: String,
|
||||
constants_cx: ConstantCx,
|
||||
cached_context: Context,
|
||||
vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
|
||||
@ -148,6 +149,7 @@ impl<'tcx, B: Backend + 'static> CodegenCx<'tcx, B> {
|
||||
CodegenCx {
|
||||
tcx,
|
||||
module,
|
||||
global_asm: String::new(),
|
||||
constants_cx: ConstantCx::default(),
|
||||
cached_context: Context::new(),
|
||||
vtables: FxHashMap::default(),
|
||||
@ -156,9 +158,9 @@ impl<'tcx, B: Backend + 'static> CodegenCx<'tcx, B> {
|
||||
}
|
||||
}
|
||||
|
||||
fn finalize(mut self) -> (Module<B>, Option<DebugContext<'tcx>>, UnwindContext<'tcx>) {
|
||||
fn finalize(mut self) -> (Module<B>, String, Option<DebugContext<'tcx>>, UnwindContext<'tcx>) {
|
||||
self.constants_cx.finalize(self.tcx, &mut self.module);
|
||||
(self.module, self.debug_context, self.unwind_context)
|
||||
(self.module, self.global_asm, self.debug_context, self.unwind_context)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user