// Builds ELF image from the module `Compilation`.
Builds ELF image from the module `Compilation`.
Builds ELF image from the module ` Compilation ` .
pub(crate) fn build_object(
    isa: &dyn TargetIsa,
    translation: &ModuleTranslation,
    funcs: &CompiledFunctions,
    dwarf_sections: Vec<DwarfSection>,
) -> Result<(Object, Vec<ObjectUnwindInfo>), anyhow::Error> {
    const CODE_SECTION_ALIGNMENT: u64 = 0x1000;
    assert_eq!(
        isa.triple().architecture.endianness(),
        Ok(target_lexicon::Endianness::Little)
    );
    let mut unwind_info = Vec::new();
    // Preserve function unwind info.
    unwind_info.extend(funcs.iter().filter_map(|(index, func)| {
        func.unwind_info
            .as_ref()
            .map(|info| ObjectUnwindInfo::Func(translation.module.func_index(index), info.clone()))
    }));
    let mut trampolines = PrimaryMap::with_capacity(translation.module.signatures.len());
    let mut cx = FunctionBuilderContext::new();
    // Build trampolines for every signature.
    for (i, native_sig) in translation.native_signatures.iter() {
        let func = build_trampoline(isa, &mut cx, native_sig, std::mem::size_of::<u128>())?;
        // Preserve trampoline function unwind info.
        if let Some(info) = &func.unwind_info {
            unwind_info.push(ObjectUnwindInfo::Trampoline(i, info.clone()))
        }
        trampolines.push(func);
    }
    let target = ObjectBuilderTarget::new(isa.triple().architecture)?;
    let mut builder = ObjectBuilder::new(target, &translation.module, funcs);
    builder
        .set_code_alignment(CODE_SECTION_ALIGNMENT)
        .set_trampolines(trampolines)
        .set_dwarf_sections(dwarf_sections);
    let obj = builder.build()?;
    Ok((obj, unwind_info))
}
pub ( crate ) fn build_object ( isa : & dyn TargetIsa , translation : & ModuleTranslation , funcs : & CompiledFunctions , dwarf_sections : Vec < DwarfSection > , ) -> Result < ( Object , Vec < ObjectUnwindInfo > ) , anyhow :: Error > { const CODE_SECTION_ALIGNMENT : u64 = 0x1000 ; assert_eq ! ( isa triple ( ) architecture endianness ( ) Ok ( target_lexicon Endianness Little ) ) ; let mut unwind_info = Vec :: new ( ) ; // Preserve function unwind info. unwind_info . extend ( funcs . iter ( ) . filter_map ( | ( index , func ) | { func . unwind_info . as_ref ( ) . map ( | info | ObjectUnwindInfo :: Func ( translation . module . func_index ( index ) , info . clone ( ) ) ) } ) ) ; let mut trampolines = PrimaryMap :: with_capacity ( translation . module . signatures . len ( ) ) ; let mut cx = FunctionBuilderContext :: new ( ) ; // Build trampolines for every signature. for ( i , native_sig ) in translation . native_signatures . iter ( ) { let func = build_trampoline ( isa , & mut cx , native_sig , std :: mem :: size_of :: < u128 > ( ) ) ? ; // Preserve trampoline function unwind info. if let Some ( info ) = & func . unwind_info { unwind_info . push ( ObjectUnwindInfo :: Trampoline ( i , info . clone ( ) ) ) } trampolines . push ( func ) ; } let target = ObjectBuilderTarget :: new ( isa . triple ( ) . architecture ) ? ; let mut builder = ObjectBuilder :: new ( target , & translation . module , funcs ) ; builder . set_code_alignment ( CODE_SECTION_ALIGNMENT ) . set_trampolines ( trampolines ) . set_dwarf_sections ( dwarf_sections ) ; let obj = builder . build ( ) ? ; Ok ( ( obj , unwind_info ) ) }
Builds ELF image from the module `Compilation`.
Builds ELF image from the module ` Compilation ` .
isa
&dyn TargetIsa
translation
&ModuleTranslation
funcs
&CompiledFunctions
dwarf_sections
Vec<DwarfSection>