Move all code out of backend.rs

This commit is contained in:
bjorn3 2021-08-20 21:43:53 +02:00
parent 14617516f8
commit 47e4a62ac5
6 changed files with 20 additions and 24 deletions

View File

@ -6,8 +6,7 @@
use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer};
use gimli::{RunTimeEndian, SectionId};
use crate::backend::WriteDebugInfo;
use super::object::WriteDebugInfo;
use super::DebugContext;
impl DebugContext<'_> {

View File

@ -2,6 +2,7 @@
mod emit;
mod line_info;
mod object;
mod unwind;
use crate::prelude::*;

View File

@ -1,13 +1,9 @@
//! Abstraction around the object writing crate
use std::convert::{TryFrom, TryInto};
use rustc_data_structures::fx::FxHashMap;
use rustc_session::Session;
use cranelift_codegen::isa::TargetIsa;
use cranelift_module::FuncId;
use cranelift_object::{ObjectBuilder, ObjectModule, ObjectProduct};
use cranelift_object::ObjectProduct;
use object::write::{Relocation, StandardSegment};
use object::{RelocationEncoding, SectionKind};
@ -16,7 +12,7 @@
use crate::debuginfo::{DebugReloc, DebugRelocName};
pub(crate) trait WriteDebugInfo {
pub(super) trait WriteDebugInfo {
type SectionId: Copy;
fn add_debug_section(&mut self, name: SectionId, data: Vec<u8>) -> Self::SectionId;
@ -87,13 +83,3 @@ fn add_debug_reloc(
.unwrap();
}
}
pub(crate) fn make_module(sess: &Session, isa: Box<dyn TargetIsa>, name: String) -> ObjectModule {
let mut builder =
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
// Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size
// is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
// can easily double the amount of time necessary to perform linking.
builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false));
ObjectModule::new(builder)
}

View File

@ -8,7 +8,7 @@
use gimli::write::{Address, CieId, EhFrame, FrameTable, Section};
use gimli::RunTimeEndian;
use crate::backend::WriteDebugInfo;
use super::object::WriteDebugInfo;
pub(crate) struct UnwindContext {
endian: RunTimeEndian,

View File

@ -11,8 +11,10 @@
use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
use rustc_session::cgu_reuse_tracker::CguReuse;
use rustc_session::config::{DebugInfo, OutputType};
use rustc_session::Session;
use cranelift_object::ObjectModule;
use cranelift_codegen::isa::TargetIsa;
use cranelift_object::{ObjectBuilder, ObjectModule};
use crate::{prelude::*, BackendConfig};
@ -24,6 +26,16 @@ fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) {
}
}
fn make_module(sess: &Session, isa: Box<dyn TargetIsa>, name: String) -> ObjectModule {
let mut builder =
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
// Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size
// is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
// can easily double the amount of time necessary to perform linking.
builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false));
ObjectModule::new(builder)
}
fn emit_module(
tcx: TyCtxt<'_>,
backend_config: &BackendConfig,
@ -105,7 +117,7 @@ fn module_codegen(
let mono_items = cgu.items_in_deterministic_order(tcx);
let isa = crate::build_isa(tcx.sess, &backend_config);
let mut module = crate::backend::make_module(tcx.sess, isa, cgu_name.as_str().to_string());
let mut module = make_module(tcx.sess, isa, cgu_name.as_str().to_string());
let mut cx = crate::CodegenCx::new(
tcx,
@ -228,8 +240,7 @@ pub(crate) fn run_aot(
tcx.sess.abort_if_errors();
let isa = crate::build_isa(tcx.sess, &backend_config);
let mut allocator_module =
crate::backend::make_module(tcx.sess, isa, "allocator_shim".to_string());
let mut allocator_module = make_module(tcx.sess, isa, "allocator_shim".to_string());
assert_eq!(pointer_ty(tcx), allocator_module.target_config().pointer_type());
let mut allocator_unwind_context = UnwindContext::new(tcx, allocator_module.isa(), true);
let created_alloc_shim =

View File

@ -45,7 +45,6 @@
mod allocator;
mod analyze;
mod archive;
mod backend;
mod base;
mod cast;
mod codegen_i128;