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