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)]
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))]
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;
45#[cfg(feature = "unwind")]
46mod eh;
47mod func_environ;
48mod heap;
49mod table;
50mod trampoline;
51mod translator;
52
53use cranelift_codegen::ir::TrapCode;
54
55pub use crate::compiler::CraneliftCompiler;
56pub use crate::config::{Cranelift, CraneliftCallbacks, CraneliftOptLevel};
57pub use crate::debug::{ModuleInfoMemoryOffset, ModuleInfoVmctxInfo, ValueLabelsRanges};
58pub use crate::trampoline::make_trampoline_function_call;
59
60/// Version number of this crate.
61pub const VERSION: &str = env!("CARGO_PKG_VERSION");
62
63/// Offset applied to user-defined trap codes to avoid colliding with
64/// Cranelift-reserved values.
65const TRAP_USER_OFFSET: u8 = 32;
66
67/// Trap reported when an indirect call targets a null function reference.
68#[allow(clippy::identity_op, reason = "for clarity")]
69pub const TRAP_INDIRECT_CALL_TO_NULL: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 0);
70/// Trap reported when an indirect call signature does not match.
71pub const TRAP_BAD_SIGNATURE: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 1);
72/// Trap reported when a table access goes out of bounds.
73pub const TRAP_TABLE_OUT_OF_BOUNDS: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 2);
74/// Trap reported when a heap access violates alignment guarantees.
75pub const TRAP_HEAP_MISALIGNED: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 3);
76/// Trap reported when unreachable code is executed.
77pub const TRAP_UNREACHABLE: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 4);
78/// Trap reported when a null reference is observed.
79pub const TRAP_NULL_REFERENCE: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 5);
80/// Trap reported when a null i31 reference is observed.
81pub const TRAP_NULL_I31_REF: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 6);
82/// Trap reported for interrupts (not currently supported).
83pub const TRAP_INTERRUPT: TrapCode = TrapCode::unwrap_user(TRAP_USER_OFFSET + 7);