1 //! Top-level lib.rs for `cranelift_module`.
2
3 #![deny(missing_docs)]
4 #![no_std]
5
6 #[cfg(not(feature = "std"))]
7 #[macro_use]
8 extern crate alloc as std;
9 #[cfg(feature = "std")]
10 #[macro_use]
11 extern crate std;
12
13 #[cfg(not(feature = "std"))]
14 use hashbrown::{HashMap, hash_map};
15 use std::borrow::ToOwned;
16 use std::boxed::Box;
17 #[cfg(feature = "std")]
18 use std::collections::{HashMap, hash_map};
19 use std::string::String;
20
21 use cranelift_codegen::ir;
22
23 mod data_context;
24 mod module;
25 mod traps;
26
27 pub use crate::data_context::{DataDescription, Init};
28 pub use crate::module::{
29 DataDeclaration, DataId, FuncId, FuncOrDataId, FunctionDeclaration, Linkage, Module,
30 ModuleDeclarations, ModuleError, ModuleReloc, ModuleRelocTarget, ModuleResult,
31 };
32 pub use crate::traps::TrapSite;
33
34 /// Version number of this crate.
35 pub const VERSION: &str = env!("CARGO_PKG_VERSION");
36
37 /// Default names for [ir::LibCall]s. A function by this name is imported into the object as
38 /// part of the translation of a [ir::ExternalName::LibCall] variant.
default_libcall_names() -> Box<dyn Fn(ir::LibCall) -> String + Send + Sync>39 pub fn default_libcall_names() -> Box<dyn Fn(ir::LibCall) -> String + Send + Sync> {
40 Box::new(move |libcall| match libcall {
41 ir::LibCall::Probestack => "__cranelift_probestack".to_owned(),
42 ir::LibCall::CeilF32 => "ceilf".to_owned(),
43 ir::LibCall::CeilF64 => "ceil".to_owned(),
44 ir::LibCall::FloorF32 => "floorf".to_owned(),
45 ir::LibCall::FloorF64 => "floor".to_owned(),
46 ir::LibCall::TruncF32 => "truncf".to_owned(),
47 ir::LibCall::TruncF64 => "trunc".to_owned(),
48 ir::LibCall::NearestF32 => "nearbyintf".to_owned(),
49 ir::LibCall::NearestF64 => "nearbyint".to_owned(),
50 ir::LibCall::FmaF32 => "fmaf".to_owned(),
51 ir::LibCall::FmaF64 => "fma".to_owned(),
52 ir::LibCall::Memcpy => "memcpy".to_owned(),
53 ir::LibCall::Memset => "memset".to_owned(),
54 ir::LibCall::Memmove => "memmove".to_owned(),
55 ir::LibCall::Memcmp => "memcmp".to_owned(),
56
57 ir::LibCall::ElfTlsGetAddr => "__tls_get_addr".to_owned(),
58 ir::LibCall::ElfTlsGetOffset => "__tls_get_offset".to_owned(),
59 ir::LibCall::X86Pshufb => "__cranelift_x86_pshufb".to_owned(),
60 })
61 }
62