1 //! Top-level lib.rs for `cranelift_module`. 2 3 #![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] 4 #![warn(unused_import_braces)] 5 #![cfg_attr(feature = "std", deny(unstable_features))] 6 #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] 7 #![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))] 8 #![cfg_attr( 9 feature = "cargo-clippy", 10 warn( 11 clippy::float_arithmetic, 12 clippy::mut_mut, 13 clippy::nonminimal_bool, 14 clippy::map_unwrap_or, 15 clippy::clippy::print_stdout, 16 clippy::unicode_not_nfc, 17 clippy::use_self 18 ) 19 )] 20 #![no_std] 21 22 #[cfg(not(feature = "std"))] 23 #[macro_use] 24 extern crate alloc as std; 25 #[cfg(feature = "std")] 26 #[macro_use] 27 extern crate std; 28 29 #[cfg(not(feature = "std"))] 30 use hashbrown::{hash_map, HashMap}; 31 use std::borrow::ToOwned; 32 use std::boxed::Box; 33 #[cfg(feature = "std")] 34 use std::collections::{hash_map, HashMap}; 35 use std::string::String; 36 37 use cranelift_codegen::ir; 38 39 mod data_context; 40 mod module; 41 mod traps; 42 43 pub use crate::data_context::{DataContext, DataDescription, Init}; 44 pub use crate::module::{ 45 DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleCompiledFunction, ModuleDeclarations, 46 ModuleError, ModuleResult, RelocRecord, 47 }; 48 pub use crate::traps::TrapSite; 49 50 /// Version number of this crate. 51 pub const VERSION: &str = env!("CARGO_PKG_VERSION"); 52 53 /// Default names for `ir::LibCall`s. A function by this name is imported into the object as 54 /// part of the translation of a `ir::ExternalName::LibCall` variant. 55 pub fn default_libcall_names() -> Box<dyn Fn(ir::LibCall) -> String + Send + Sync> { 56 Box::new(move |libcall| match libcall { 57 ir::LibCall::Probestack => "__cranelift_probestack".to_owned(), 58 ir::LibCall::UdivI64 => "__udivdi3".to_owned(), 59 ir::LibCall::SdivI64 => "__divdi3".to_owned(), 60 ir::LibCall::UremI64 => "__umoddi3".to_owned(), 61 ir::LibCall::SremI64 => "__moddi3".to_owned(), 62 ir::LibCall::IshlI64 => "__ashldi3".to_owned(), 63 ir::LibCall::UshrI64 => "__lshrdi3".to_owned(), 64 ir::LibCall::SshrI64 => "__ashrdi3".to_owned(), 65 ir::LibCall::CeilF32 => "ceilf".to_owned(), 66 ir::LibCall::CeilF64 => "ceil".to_owned(), 67 ir::LibCall::FloorF32 => "floorf".to_owned(), 68 ir::LibCall::FloorF64 => "floor".to_owned(), 69 ir::LibCall::TruncF32 => "truncf".to_owned(), 70 ir::LibCall::TruncF64 => "trunc".to_owned(), 71 ir::LibCall::NearestF32 => "nearbyintf".to_owned(), 72 ir::LibCall::NearestF64 => "nearbyint".to_owned(), 73 ir::LibCall::Memcpy => "memcpy".to_owned(), 74 ir::LibCall::Memset => "memset".to_owned(), 75 ir::LibCall::Memmove => "memmove".to_owned(), 76 77 ir::LibCall::ElfTlsGetAddr => "__tls_get_addr".to_owned(), 78 }) 79 } 80