wasmer_compiler_cranelift/
lib.rs

1//! A WebAssembly `Compiler` implementation using Cranelift.
2//!
3//! Cranelift is a fast IR generator created by Mozilla for usage in
4//! Firefox as a next JS compiler generator.
5//!
6//! Compared to LLVM, Cranelift is a bit faster and made entirely in Rust.
7#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
8#![warn(unused_import_braces)]
9#![allow(clippy::new_without_default, clippy::new_without_default)]
10#![warn(
11    clippy::float_arithmetic,
12    clippy::mut_mut,
13    clippy::nonminimal_bool,
14    clippy::map_unwrap_or,
15    clippy::print_stdout,
16    clippy::unicode_not_nfc,
17    clippy::use_self
18)]
19#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
20
21#[cfg(not(feature = "std"))]
22#[macro_use]
23extern crate alloc as std;
24#[cfg(feature = "std")]
25#[macro_use]
26extern crate std;
27
28#[cfg(not(feature = "std"))]
29use hashbrown::{
30    HashMap, hash_map,
31    hash_map::Entry::{Occupied, Vacant},
32};
33#[cfg(feature = "std")]
34use std::collections::{
35    HashMap, hash_map,
36    hash_map::Entry::{Occupied, Vacant},
37};
38
39mod address_map;
40mod compiler;
41mod config;
42mod debug;
43#[cfg(feature = "unwind")]
44mod dwarf;
45mod func_environ;
46mod heap;
47mod table;
48mod trampoline;
49mod translator;
50
51use cranelift_codegen::ir::TrapCode;
52
53pub use crate::compiler::CraneliftCompiler;
54pub use crate::config::{Cranelift, CraneliftOptLevel};
55pub use crate::debug::{ModuleInfoMemoryOffset, ModuleInfoVmctxInfo, ValueLabelsRanges};
56pub use crate::trampoline::make_trampoline_function_call;
57
58/// Version number of this crate.
59pub const VERSION: &str = env!("CARGO_PKG_VERSION");
60
61/// Offset applied to user-defined trap codes to avoid colliding with
62/// Cranelift-reserved values.
63const TRAP_USER_OFFSET: u8 = 32;
64
65/// Trap reported when an indirect call targets a null function reference.
66#[allow(clippy::identity_op, reason = "for clarity")]
67pub const TRAP_INDIRECT_CALL_TO_NULL: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 0);
68/// Trap reported when an indirect call signature does not match.
69pub const TRAP_BAD_SIGNATURE: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 1);
70/// Trap reported when a table access goes out of bounds.
71pub const TRAP_TABLE_OUT_OF_BOUNDS: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 2);
72/// Trap reported when a heap access violates alignment guarantees.
73pub const TRAP_HEAP_MISALIGNED: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 3);
74/// Trap reported when unreachable code is executed.
75pub const TRAP_UNREACHABLE: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 4);
76/// Trap reported when a null reference is observed.
77pub const TRAP_NULL_REFERENCE: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 5);
78/// Trap reported when a null i31 reference is observed.
79pub const TRAP_NULL_I31_REF: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 6);
80/// Trap reported for interrupts (not currently supported).
81pub const TRAP_INTERRUPT: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 7);