Skip to main content

sf_nano_core/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3#![warn(unreachable_pub)]
4
5extern crate alloc;
6
7#[cfg(any(sf_has_std, test))]
8extern crate std;
9
10#[cfg(all(test, feature = "memprof"))]
11#[global_allocator]
12static TEST_ALLOCATOR: tracked_alloc::TrackingAllocator<std::alloc::System> =
13    tracked_alloc::TrackingAllocator::new(std::alloc::System);
14
15pub(crate) mod collections;
16// At least one execution engine has to be compiled in; a crate that can parse
17// and validate Wasm but not run it is not a useful build. Whether the engine
18// you asked for can exist on this ISA is a separate question, answered in
19// build.rs (`require_supported_isa`) before any of this compiles.
20#[cfg(not(any(sf_jit, sf_interp)))]
21compile_error!(
22    "sf-nano-core needs at least one execution engine: enable the `jit` feature, \
23     the `interp` feature, or both (the default)."
24);
25
26mod config;
27pub(crate) mod constants;
28mod error;
29pub(crate) mod module;
30pub(crate) mod op_decoder;
31pub(crate) mod opcodes;
32pub(crate) mod utils;
33mod value;
34pub mod value_type;
35pub(crate) mod vm;
36
37#[cfg(sf_wasi_host)]
38pub mod wasi;
39
40// Public re-exports for ergonomic API
41pub use config::{Config, ConfigError};
42pub use constants::WASM_PAGE_SIZE;
43pub use error::WasmError;
44pub use module::type_defs::FunctionType;
45pub use module::Module;
46pub use utils::limits::Limits;
47pub use vm::engine::{Engine, Tier};
48pub use vm::entities::{Caller, HostFn};
49pub use vm::imports::{Extern, Import};
50pub use vm::instance::{Func, Instance, InstanceInstantiationError, RuntimeWorld};
51// Diagnostics expose owned data, never instance bodies or instruction enums.
52#[cfg(sf_interp)]
53pub use vm::interpreter::InterpreterStats;
54#[cfg(sf_jit)]
55pub use vm::jit::arch::active_native_backend_name;
56// Compile statistics belong to the JIT *engine*, so they carry its name.
57// "Native" is this tree's word for the ISA, which is a different axis --
58// see `Engine` versus `active_native_backend_name`.
59pub use value::{RefValue, Value};
60#[cfg(sf_jit)]
61pub use vm::jit::build::{jit_stats_snapshot, JitStatsSnapshot};
62pub use vm::link::{InstanceId, WorldAccess};
63pub use vm::memory::{MemoryView, MemoryViewMut};
64pub use vm::tag::TagIdentity;
65
66#[inline]
67pub const fn target_has_simd() -> bool {
68    cfg!(sf_has_simd)
69}