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::{DataDescription, Init}; 44 pub use crate::module::{ 45 DataDeclaration, DataId, FuncId, FuncOrDataId, FunctionDeclaration, Linkage, Module, 46 ModuleDeclarations, ModuleError, ModuleExtName, ModuleReloc, ModuleResult, 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::CeilF32 => "ceilf".to_owned(), 59 ir::LibCall::CeilF64 => "ceil".to_owned(), 60 ir::LibCall::FloorF32 => "floorf".to_owned(), 61 ir::LibCall::FloorF64 => "floor".to_owned(), 62 ir::LibCall::TruncF32 => "truncf".to_owned(), 63 ir::LibCall::TruncF64 => "trunc".to_owned(), 64 ir::LibCall::NearestF32 => "nearbyintf".to_owned(), 65 ir::LibCall::NearestF64 => "nearbyint".to_owned(), 66 ir::LibCall::FmaF32 => "fmaf".to_owned(), 67 ir::LibCall::FmaF64 => "fma".to_owned(), 68 ir::LibCall::Memcpy => "memcpy".to_owned(), 69 ir::LibCall::Memset => "memset".to_owned(), 70 ir::LibCall::Memmove => "memmove".to_owned(), 71 ir::LibCall::Memcmp => "memcmp".to_owned(), 72 73 ir::LibCall::ElfTlsGetAddr => "__tls_get_addr".to_owned(), 74 ir::LibCall::ElfTlsGetOffset => "__tls_get_offset".to_owned(), 75 ir::LibCall::X86Pshufb => "__cranelift_x86_pshufb".to_owned(), 76 }) 77 } 78