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