midenc_frontend_wasm/
lib.rs1#![deny(warnings)]
5#![deny(missing_docs)]
6#![deny(rustdoc::broken_intra_doc_links)]
7#![allow(dead_code)]
9#![feature(iterator_try_collect)]
10
11extern crate alloc;
12
13mod callable;
14mod code_translator;
15mod component;
16mod config;
17mod error;
18mod intrinsics;
19mod miden_abi;
20mod module;
21mod ssa;
22mod translation_utils;
23
24use alloc::rc::Rc;
25
26use component::build_ir::translate_component;
27use error::WasmResult;
28use midenc_hir::{dialects::builtin, Context};
29use module::build_ir::translate_module_as_component;
30use wasmparser::WasmFeatures;
31
32pub use self::{config::*, error::WasmError};
33
34pub struct FrontendOutput {
36 pub component: builtin::ComponentRef,
38 pub account_component_metadata_bytes: Option<Vec<u8>>,
40}
41
42pub fn translate(
45 wasm: &[u8],
46 config: &WasmTranslationConfig,
47 context: Rc<Context>,
48) -> WasmResult<FrontendOutput> {
49 if wasm[4..8] == [0x01, 0x00, 0x00, 0x00] {
50 let component = translate_module_as_component(wasm, config, context)?;
53 Ok(FrontendOutput {
54 component,
55 account_component_metadata_bytes: None,
56 })
57 } else {
58 translate_component(wasm, config, context)
59 }
60}
61
62pub(crate) fn supported_features() -> WasmFeatures {
64 WasmFeatures::BULK_MEMORY
65 | WasmFeatures::FLOATS
66 | WasmFeatures::FUNCTION_REFERENCES
67 | WasmFeatures::MULTI_VALUE
68 | WasmFeatures::MUTABLE_GLOBAL
69 | WasmFeatures::SATURATING_FLOAT_TO_INT
70 | WasmFeatures::SIGN_EXTENSION
71 | WasmFeatures::TAIL_CALL
72 | WasmFeatures::WIDE_ARITHMETIC
73}
74
75pub(crate) fn supported_component_model_features() -> WasmFeatures {
78 supported_features() | WasmFeatures::COMPONENT_MODEL
79}