From 8c89d5efde54b9d6a73c9695f79563d1b03f45a2 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 15 Feb 2024 18:01:07 +0200 Subject: [PATCH 1/2] chore: update `cargo-component` to v0.7.0, use `wee_alloc` in Wasm components and Miden SDK tests. The panic handler and global allocator is now set in the `lib.rs` file of each component crate. Before, the `cargo-component-bindings` was not built correctly for `no_std` and was linking the stdlib allocator. The Rust bindings for the WIT are now generated in the `src` directory of the component crate, instead of the `target/.../bindings` directory. The Wasm `bulk-memory` proposal is enabled via `RUSTFLAGS` so that `memcpy` function import is replaced with Wasm `memory.copy` op. --- tests/integration/src/compiler_test.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/src/compiler_test.rs b/tests/integration/src/compiler_test.rs index 6055d42cb..3897a2bf1 100644 --- a/tests/integration/src/compiler_test.rs +++ b/tests/integration/src/compiler_test.rs @@ -69,6 +69,8 @@ impl CompilerTest { let mut cargo_build_cmd = Command::new("cargo"); // Enable Wasm bulk-memory proposal (uses Wasm `memory.copy` op instead of `memcpy` import) cargo_build_cmd.env("RUSTFLAGS", "-C target-feature=+bulk-memory"); + // Enable Wasm bulk-memory proposal (uses Wasm `memory.copy` op instead of `memcpy` import) + cargo_build_cmd.env("RUSTFLAGS", "-C target-feature=+bulk-memory"); cargo_build_cmd .arg("component") .arg("build") From 1960cfd59f1c2b27d2c27e17728c662e1a1462eb Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Fri, 15 Mar 2024 00:14:29 -0400 Subject: [PATCH 2/2] chore: add Wasm component translation support to the integration tests; --- Cargo.lock | 1 + frontend-wasm/tests/test_rust_comp.rs | 4 +- hir-type/src/lib.rs | 18 + hir/src/component/interface.rs | 33 +- hir/src/component/mod.rs | 92 +- hir/src/ident.rs | 2 +- tests/integration/Cargo.toml | 5 +- .../components/add_wasm_component.hir | 913 +++++++++++++++++ .../components/add_wasm_component.wat | 8 +- .../components/inc_wasm_component.hir | 916 ++++++++++++++++++ .../components/inc_wasm_component.wat | 8 +- tests/integration/expected/fib.hir | 2 +- tests/integration/expected/fib.masm | 6 +- tests/integration/src/compiler_test.rs | 180 ++-- .../src/rust_masm_tests/components.rs | 70 +- tests/integration/src/rust_masm_tests/sdk.rs | 21 +- tests/rust-apps-wasm/add-comp/src/bindings.rs | 8 +- tests/rust-apps-wasm/add-comp/src/lib.rs | 2 +- tests/rust-apps-wasm/add-comp/wit/add.wit | 6 +- tests/rust-apps-wasm/inc-comp/src/bindings.rs | 8 +- tests/rust-apps-wasm/inc-comp/src/lib.rs | 3 +- tests/rust-apps-wasm/inc-comp/wit/inc.wit | 6 +- 22 files changed, 2159 insertions(+), 153 deletions(-) create mode 100644 tests/integration/expected/components/add_wasm_component.hir create mode 100644 tests/integration/expected/components/inc_wasm_component.hir diff --git a/Cargo.lock b/Cargo.lock index aee06de47..f4770b661 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2747,6 +2747,7 @@ version = "0.1.0" dependencies = [ "cargo_metadata", "concat-idents", + "derive_more", "expect-test", "miden-assembly", "miden-codegen-masm", diff --git a/frontend-wasm/tests/test_rust_comp.rs b/frontend-wasm/tests/test_rust_comp.rs index cfb5b6b96..7c8d872dd 100644 --- a/frontend-wasm/tests/test_rust_comp.rs +++ b/frontend-wasm/tests/test_rust_comp.rs @@ -28,7 +28,7 @@ fn rust_array() { test.expect_wasm(expect_file!["./expected/array.wat"]); test.expect_ir(expect_file!["./expected/array.hir"]); assert!( - test.hir.unwrap().segments().last().unwrap().is_readonly(), + test.hir.unwrap().unwrap_program().segments().last().unwrap().is_readonly(), "data segment should be readonly" ); } @@ -39,7 +39,7 @@ fn rust_static_mut() { test.expect_wasm(expect_file!["./expected/static_mut.wat"]); test.expect_ir(expect_file!["./expected/static_mut.hir"]); assert!( - !test.hir.unwrap().segments().last().unwrap().is_readonly(), + !test.hir.unwrap().unwrap_program().segments().last().unwrap().is_readonly(), "data segment should be mutable" ); } diff --git a/hir-type/src/lib.rs b/hir-type/src/lib.rs index 96af02ab8..01c9dffa0 100644 --- a/hir-type/src/lib.rs +++ b/hir-type/src/lib.rs @@ -635,6 +635,24 @@ pub struct LiftedFunctionType { /// The results returned by this function pub results: Vec, } +impl fmt::Display for LiftedFunctionType { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use core::fmt::Write; + + f.write_str("(func")?; + for ty in self.params.iter() { + write!(f, " (param {ty})")?; + } + if !self.results.is_empty() { + f.write_str(" (result")?; + for ty in self.results.iter() { + write!(f, " {ty}")?; + } + f.write_char(')')?; + } + f.write_char(')') + } +} /// This error is raised when parsing an [AddressSpace] #[derive(Debug)] diff --git a/hir/src/component/interface.rs b/hir/src/component/interface.rs index 9e87faf1d..0ffc6bed4 100644 --- a/hir/src/component/interface.rs +++ b/hir/src/component/interface.rs @@ -1,8 +1,12 @@ +use core::fmt; + use miden_hir_symbol::Symbol; +use crate::formatter::PrettyPrint; + /// A fully-qualified identifier for the interface being imported, e.g. /// `namespace::package/interface@version` -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct InterfaceIdent { /// A fully-qualified identifier for the interface being imported, e.g. /// `namespace::package/interface@version` @@ -19,8 +23,14 @@ impl InterfaceIdent { } } +impl fmt::Display for InterfaceIdent { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "\"{}\"", self.full_name.as_str().escape_default()) + } +} + /// An identifier for a function in an interface -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct InterfaceFunctionIdent { /// An interface identifier for the interface being imported (e.g. /// `namespace::package/interface@version`) @@ -39,3 +49,22 @@ impl InterfaceFunctionIdent { } } } + +impl fmt::Display for InterfaceFunctionIdent { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.pretty_print(f) + } +} +impl PrettyPrint for InterfaceFunctionIdent { + fn render(&self) -> crate::formatter::Document { + use crate::formatter::*; + + flatten( + const_text("(") + + display(self.interface) + + const_text(" ") + + text(format!("#{}", self.function)) + + const_text(")"), + ) + } +} diff --git a/hir/src/component/mod.rs b/hir/src/component/mod.rs index 6e6527f96..ac3d25f1b 100644 --- a/hir/src/component/mod.rs +++ b/hir/src/component/mod.rs @@ -1,9 +1,10 @@ +use alloc::collections::BTreeMap; use core::ops::{Deref, DerefMut}; -use std::collections::BTreeMap; use intrusive_collections::RBTree; use miden_core::crypto::hash::RpoDigest; +use self::formatter::PrettyPrint; use super::*; mod interface; @@ -19,6 +20,14 @@ pub enum FunctionInvocationMethod { #[default] Exec, } +impl fmt::Display for FunctionInvocationMethod { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::Call => f.write_str("call"), + Self::Exec => f.write_str("exec"), + } + } +} /// A component import #[derive(Debug)] @@ -32,6 +41,32 @@ pub struct ComponentImport { /// The MAST root hash of the function to be used in codegen pub digest: RpoDigest, } +impl fmt::Display for ComponentImport { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.pretty_print(f) + } +} +impl formatter::PrettyPrint for ComponentImport { + fn render(&self) -> formatter::Document { + use crate::formatter::*; + + const_text("(") + + const_text("import") + + const_text(" ") + + display(self.digest) + + const_text(" ") + + const_text("(") + + display(self.invoke_method) + + const_text(")") + + const_text(" ") + + const_text("(") + + const_text("type") + + const_text(" ") + + text(format!("{}", &self.function_ty)) + + const_text(")") + + const_text(")") + } +} /// The name of a exported function #[derive(Debug, Ord, PartialEq, PartialOrd, Eq, Hash, derive_more::From, derive_more::Into)] @@ -99,6 +134,61 @@ impl Component { } } +impl fmt::Display for Component { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.pretty_print(f) + } +} + +impl formatter::PrettyPrint for Component { + fn render(&self) -> formatter::Document { + use crate::formatter::*; + + let imports = self + .imports + .iter() + .map(|(id, import)| { + const_text("(") + + const_text("lower") + + const_text(" ") + + import.render() + + const_text(" ") + + id.render() + + const_text(")") + }) + .reduce(|acc, doc| acc + nl() + doc) + .map(|doc| const_text(";; Component Imports") + nl() + doc) + .unwrap_or(Document::Empty); + + let modules = self + .modules + .iter() + .map(PrettyPrint::render) + .reduce(|acc, doc| acc + nl() + doc) + .map(|doc| const_text(";; Modules") + nl() + doc) + .unwrap_or(Document::Empty); + + let body = vec![imports, modules].into_iter().filter(|section| !section.is_empty()).fold( + nl(), + |a, b| { + if matches!(a, Document::Newline) { + indent(4, a + b) + } else { + a + nl() + indent(4, nl() + b) + } + }, + ); + + let header = const_text("(") + const_text("component") + const_text(" "); + + if body.is_empty() { + header + const_text(")") + nl() + } else { + header + body + nl() + const_text(")") + nl() + } + } +} + /// This struct provides an ergonomic way to construct a [Component] in an imperative fashion. /// /// Simply create the builder, add/build one or more modules, then call `link` to obtain a diff --git a/hir/src/ident.rs b/hir/src/ident.rs index f5b4a5114..20e4d29fc 100644 --- a/hir/src/ident.rs +++ b/hir/src/ident.rs @@ -54,7 +54,7 @@ impl PrettyPrint for FunctionIdent { fn render(&self) -> formatter::Document { use crate::formatter::*; - flatten(display(self.module) + const_text("::") + display(self.function)) + flatten(const_text("(") + display(self.module) + const_text(" ") + display(self.function)) } } impl PartialOrd for FunctionIdent { diff --git a/tests/integration/Cargo.toml b/tests/integration/Cargo.toml index 0c492060c..acbbda4a7 100644 --- a/tests/integration/Cargo.toml +++ b/tests/integration/Cargo.toml @@ -22,11 +22,12 @@ miden-stdlib.workspace = true miden-diagnostics.workspace = true midenc-session.workspace = true expect-test = "1.4.1" -miden-integration-tests-rust-fib = {path = "../rust-apps/fib"} +miden-integration-tests-rust-fib = { path = "../rust-apps/fib" } wasmprinter = "0.2.63" sha2 = "0.10" -rustc-demangle = {version = "0.1.19", features = ["std"]} +rustc-demangle = { version = "0.1.19", features = ["std"] } cargo_metadata = "0.18" +derive_more.workspace = true [dev-dependencies] miden-core.workspace = true diff --git a/tests/integration/expected/components/add_wasm_component.hir b/tests/integration/expected/components/add_wasm_component.hir new file mode 100644 index 000000000..065903368 --- /dev/null +++ b/tests/integration/expected/components/add_wasm_component.hir @@ -0,0 +1,913 @@ +(component + ;; Modules + (module #add_wasm_component.wasm + ;; Constants + (const (id 0) 0x00100000) + + ;; Global Variables + (global (export #__stack_pointer) (id 0) (type i32) (const 0)) + + ;; Functions + (func (export #__wasm_call_ctors) + (block 0 + (br (block 1))) + + (block 1 + (ret)) + ) + + (func (export #miden:add-package/add-interface@1.0.0#add) + (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) + (call #wit_bindgen::rt::run_ctors_once) + (let (v3 i32) (add.wrapping v1 v0)) + (br (block 1 v3))) + + (block 1 (param v2 i32) + (ret v2)) + ) + + (func (export #__rust_alloc) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) + (let (v3 i32) (const.i32 1048576)) + (let (v4 i32) (call #::alloc v3 v1 v0)) + (br (block 1 v4))) + + (block 1 (param v2 i32) + (ret v2)) + ) + + (func (export #__rust_realloc) + (param i32) (param i32) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) + (let (v5 i32) (const.i32 0)) + (let (v6 i32) (const.i32 1048576)) + (let (v7 i32) (call #::alloc v6 v2 v3)) + (let (v8 i1) (eq v7 0)) + (let (v9 i32) (cast v8)) + (let (v10 i1) (neq v9 0)) + (condbr v10 (block 2 v7) (block 3))) + + (block 1 (param v4 i32) + (ret v4)) + + (block 2 (param v22 i32) + (br (block 1 v22))) + + (block 3 + (let (v11 u32) (cast v1)) + (let (v12 u32) (cast v3)) + (let (v13 i1) (lt v11 v12)) + (let (v14 i32) (cast v13)) + (let (v15 i1) (neq v14 0)) + (let (v16 i32) (select v15 v1 v3)) + (let (v17 u32) (cast v7)) + (let (v18 (ptr u8)) (inttoptr v17)) + (let (v19 u32) (cast v0)) + (let (v20 (ptr u8)) (inttoptr v19)) + (memcpy v20 v18 v16) + (let (v21 i32) (const.i32 1048576)) + (call #::dealloc v21 v0 v2 v1) + (br (block 2 v7))) + ) + + (func (export #wee_alloc::alloc_first_fit) + (param i32) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) + (let (v4 i32) (const.i32 0)) + (let (v5 u32) (cast v2)) + (let (v6 (ptr i32)) (inttoptr v5)) + (let (v7 i32) (load v6)) + (let (v8 i1) (eq v7 0)) + (let (v9 i32) (cast v8)) + (let (v10 i1) (neq v9 0)) + (condbr v10 (block 2) (block 3))) + + (block 1 (param v3 i32) + (ret v3)) + + (block 2 + (let (v288 i32) (const.i32 0)) + (br (block 1 v288))) + + (block 3 + (let (v11 i32) (const.i32 -1)) + (let (v12 i32) (add.wrapping v1 v11)) + (let (v13 i32) (const.i32 0)) + (let (v14 i32) (sub.wrapping v13 v1)) + (let (v15 i32) (const.i32 2)) + (let (v16 i32) (shl.wrapping v0 v15)) + (br (block 4 v7 v2 v16 v14 v12))) + + (block 4 + (param v17 i32) + (param v139 i32) + (param v149 i32) + (param v163 i32) + (param v175 i32) + (let (v18 i32) (const.i32 8)) + (let (v19 i32) (add.wrapping v17 v18)) + (let (v20 u32) (cast v17)) + (let (v21 u32) (add.checked v20 8)) + (let (v22 (ptr i32)) (inttoptr v21)) + (let (v23 i32) (load v22)) + (let (v24 i32) (const.i32 1)) + (let (v25 i32) (band v23 v24)) + (let (v26 i1) (neq v25 0)) + (condbr v26 (block 7) (block 8))) + + (block 5 + (br (block 2))) + + (block 6 + (param v140 i32) + (param v146 i32) + (param v148 i32) + (param v162 i32) + (param v174 i32) + (param v182 i32) + (param v183 i32) + (let (v141 u32) (cast v140)) + (let (v142 (ptr i32)) (inttoptr v141)) + (let (v143 i32) (load v142)) + (let (v144 i32) (const.i32 -4)) + (let (v145 i32) (band v143 v144)) + (let (v147 i32) (sub.wrapping v145 v146)) + (let (v154 u32) (cast v147)) + (let (v155 u32) (cast v148)) + (let (v156 i1) (lt v154 v155)) + (let (v157 i32) (cast v156)) + (let (v158 i1) (neq v157 0)) + (condbr v158 (block 21 v182 v183 v148 v162 v174) (block 22))) + + (block 7 + (br (block 9 v19 v23 v17 v139 v149 v163 v175))) + + (block 8 + (br (block 6 v17 v19 v149 v163 v175 v139 v23))) + + (block 9 + (param v27 i32) + (param v28 i32) + (param v33 i32) + (param v125 i32) + (param v152 i32) + (param v166 i32) + (param v178 i32) + (let (v29 i32) (const.i32 -2)) + (let (v30 i32) (band v28 v29)) + (let (v31 u32) (cast v27)) + (let (v32 (ptr i32)) (inttoptr v31)) + (store v32 v30) + (let (v34 u32) (cast v33)) + (let (v35 u32) (add.checked v34 4)) + (let (v36 (ptr i32)) (inttoptr v35)) + (let (v37 i32) (load v36)) + (let (v38 i32) (const.i32 -4)) + (let (v39 i32) (band v37 v38)) + (let (v40 u32) (cast v39)) + (let (v41 (ptr i32)) (inttoptr v40)) + (let (v42 i32) (load v41)) + (let (v43 u32) (cast v33)) + (let (v44 (ptr i32)) (inttoptr v43)) + (let (v45 i32) (load v44)) + (let (v46 i32) (const.i32 -4)) + (let (v47 i32) (band v45 v46)) + (let (v48 i1) (neq v47 0)) + (condbr v48 (block 13) (block 14))) + + (block 10 + (br (block 6 v127 v131 v150 v164 v176 v123 v135))) + + (block 11 + (param v97 i32) + (param v98 i32) + (param v104 i32) + (param v114 i32) + (param v124 i32) + (param v151 i32) + (param v165 i32) + (param v177 i32) + (let (v99 i32) (const.i32 3)) + (let (v100 i32) (band v98 v99)) + (let (v101 u32) (cast v97)) + (let (v102 u32) (add.checked v101 4)) + (let (v103 (ptr i32)) (inttoptr v102)) + (store v103 v100) + (let (v105 i32) (const.i32 3)) + (let (v106 i32) (band v104 v105)) + (let (v107 u32) (cast v97)) + (let (v108 (ptr i32)) (inttoptr v107)) + (store v108 v106) + (let (v109 i32) (const.i32 2)) + (let (v110 i32) (band v104 v109)) + (let (v111 i1) (eq v110 0)) + (let (v112 i32) (cast v111)) + (let (v113 i1) (neq v112 0)) + (condbr v113 (block 18 v124 v114 v151 v165 v177) (block 19))) + + (block 12 + (param v81 i32) + (param v82 i32) + (param v85 i32) + (param v89 i32) + (param v115 i32) + (param v126 i32) + (param v153 i32) + (param v167 i32) + (param v179 i32) + (let (v83 i32) (const.i32 3)) + (let (v84 i32) (band v82 v83)) + (let (v86 i32) (bor v84 v85)) + (let (v87 u32) (cast v81)) + (let (v88 (ptr i32)) (inttoptr v87)) + (store v88 v86) + (let (v90 u32) (cast v89)) + (let (v91 u32) (add.checked v90 4)) + (let (v92 (ptr i32)) (inttoptr v91)) + (let (v93 i32) (load v92)) + (let (v94 u32) (cast v89)) + (let (v95 (ptr i32)) (inttoptr v94)) + (let (v96 i32) (load v95)) + (br (block 11 v89 v93 v96 v115 v126 v153 v167 v179))) + + (block 13 + (let (v49 i32) (const.i32 2)) + (let (v50 i32) (band v45 v49)) + (let (v51 i1) (eq v50 0)) + (let (v52 i32) (cast v51)) + (let (v53 i1) (neq v52 0)) + (condbr v53 (block 15) (block 16))) + + (block 14 + (br (block 12 v39 v42 v47 v33 v39 v125 v152 v166 v178))) + + (block 15 + (let (v54 u32) (cast v47)) + (let (v55 u32) (add.checked v54 4)) + (let (v56 (ptr i32)) (inttoptr v55)) + (let (v57 i32) (load v56)) + (let (v58 i32) (const.i32 3)) + (let (v59 i32) (band v57 v58)) + (let (v60 i32) (bor v59 v39)) + (let (v61 u32) (cast v47)) + (let (v62 u32) (add.checked v61 4)) + (let (v63 (ptr i32)) (inttoptr v62)) + (store v63 v60) + (let (v64 u32) (cast v33)) + (let (v65 (ptr i32)) (inttoptr v64)) + (let (v66 i32) (load v65)) + (let (v67 u32) (cast v33)) + (let (v68 u32) (add.checked v67 4)) + (let (v69 (ptr i32)) (inttoptr v68)) + (let (v70 i32) (load v69)) + (let (v71 i32) (const.i32 -4)) + (let (v72 i32) (band v70 v71)) + (let (v73 i1) (eq v72 0)) + (let (v74 i32) (cast v73)) + (let (v75 i1) (neq v74 0)) + (condbr v75 (block 11 v33 v70 v66 v39 v125 v152 v166 v178) (block 17))) + + (block 16 + (br (block 12 v39 v42 v47 v33 v39 v125 v152 v166 v178))) + + (block 17 + (let (v76 i32) (const.i32 -4)) + (let (v77 i32) (band v66 v76)) + (let (v78 u32) (cast v72)) + (let (v79 (ptr i32)) (inttoptr v78)) + (let (v80 i32) (load v79)) + (br (block 12 v72 v80 v77 v33 v39 v125 v152 v166 v178))) + + (block 18 + (param v123 i32) + (param v127 i32) + (param v150 i32) + (param v164 i32) + (param v176 i32) + (let (v128 u32) (cast v123)) + (let (v129 (ptr i32)) (inttoptr v128)) + (store v129 v127) + (let (v130 i32) (const.i32 8)) + (let (v131 i32) (add.wrapping v127 v130)) + (let (v132 u32) (cast v127)) + (let (v133 u32) (add.checked v132 8)) + (let (v134 (ptr i32)) (inttoptr v133)) + (let (v135 i32) (load v134)) + (let (v136 i32) (const.i32 1)) + (let (v137 i32) (band v135 v136)) + (let (v138 i1) (neq v137 0)) + (condbr v138 (block 9 v131 v135 v127 v123 v150 v164 v176) (block 20))) + + (block 19 + (let (v116 u32) (cast v114)) + (let (v117 (ptr i32)) (inttoptr v116)) + (let (v118 i32) (load v117)) + (let (v119 i32) (const.i32 2)) + (let (v120 i32) (bor v118 v119)) + (let (v121 u32) (cast v114)) + (let (v122 (ptr i32)) (inttoptr v121)) + (store v122 v120) + (br (block 18 v124 v114 v151 v165 v177))) + + (block 20 + (br (block 10))) + + (block 21 + (param v280 i32) + (param v281 i32) + (param v285 i32) + (param v286 i32) + (param v287 i32) + (let (v282 u32) (cast v280)) + (let (v283 (ptr i32)) (inttoptr v282)) + (store v283 v281) + (let (v284 i1) (neq v281 0)) + (condbr v284 (block 4 v281 v280 v285 v286 v287) (block 32))) + + (block 22 + (let (v159 i32) (const.i32 72)) + (let (v160 i32) (add.wrapping v146 v159)) + (let (v161 i32) (sub.wrapping v145 v148)) + (let (v168 i32) (band v161 v162)) + (let (v169 u32) (cast v160)) + (let (v170 u32) (cast v168)) + (let (v171 i1) (lte v169 v170)) + (let (v172 i32) (cast v171)) + (let (v173 i1) (neq v172 0)) + (condbr v173 (block 24) (block 25))) + + (block 23 (param v272 i32) (param v273 i32) + (let (v274 i32) (const.i32 1)) + (let (v275 i32) (bor v273 v274)) + (let (v276 u32) (cast v272)) + (let (v277 (ptr i32)) (inttoptr v276)) + (store v277 v275) + (let (v278 i32) (const.i32 8)) + (let (v279 i32) (add.wrapping v272 v278)) + (ret v279)) + + (block 24 + (let (v191 i32) (const.i32 0)) + (let (v192 i32) (const.i32 0)) + (let (v193 u32) (cast v168)) + (let (v194 (ptr i32)) (inttoptr v193)) + (store v194 v192) + (let (v195 i32) (const.i32 -8)) + (let (v196 i32) (add.wrapping v168 v195)) + (let (v197 i64) (const.i64 0)) + (let (v198 u32) (cast v196)) + (let (v199 (ptr i64)) (inttoptr v198)) + (store v199 v197) + (let (v200 u32) (cast v140)) + (let (v201 (ptr i32)) (inttoptr v200)) + (let (v202 i32) (load v201)) + (let (v203 i32) (const.i32 -4)) + (let (v204 i32) (band v202 v203)) + (let (v205 u32) (cast v196)) + (let (v206 (ptr i32)) (inttoptr v205)) + (store v206 v204) + (let (v207 u32) (cast v140)) + (let (v208 (ptr i32)) (inttoptr v207)) + (let (v209 i32) (load v208)) + (let (v210 i32) (const.i32 -4)) + (let (v211 i32) (band v209 v210)) + (let (v212 i1) (eq v211 0)) + (let (v213 i32) (cast v212)) + (let (v214 i1) (neq v213 0)) + (condbr v214 (block 27 v196 v191 v140 v146) (block 28))) + + (block 25 + (let (v180 i32) (band v174 v146)) + (let (v181 i1) (neq v180 0)) + (condbr v181 (block 21 v182 v183 v148 v162 v174) (block 26))) + + (block 26 + (let (v184 i32) (const.i32 -4)) + (let (v185 i32) (band v183 v184)) + (let (v186 u32) (cast v182)) + (let (v187 (ptr i32)) (inttoptr v186)) + (store v187 v185) + (let (v188 u32) (cast v140)) + (let (v189 (ptr i32)) (inttoptr v188)) + (let (v190 i32) (load v189)) + (br (block 23 v140 v190))) + + (block 27 + (param v234 i32) + (param v235 i32) + (param v236 i32) + (param v241 i32) + (let (v237 i32) (bor v235 v236)) + (let (v238 u32) (cast v234)) + (let (v239 u32) (add.checked v238 4)) + (let (v240 (ptr i32)) (inttoptr v239)) + (store v240 v237) + (let (v242 u32) (cast v241)) + (let (v243 (ptr i32)) (inttoptr v242)) + (let (v244 i32) (load v243)) + (let (v245 i32) (const.i32 -2)) + (let (v246 i32) (band v244 v245)) + (let (v247 u32) (cast v241)) + (let (v248 (ptr i32)) (inttoptr v247)) + (store v248 v246) + (let (v249 u32) (cast v236)) + (let (v250 (ptr i32)) (inttoptr v249)) + (let (v251 i32) (load v250)) + (let (v252 i32) (const.i32 3)) + (let (v253 i32) (band v251 v252)) + (let (v254 i32) (bor v253 v234)) + (let (v255 u32) (cast v236)) + (let (v256 (ptr i32)) (inttoptr v255)) + (store v256 v254) + (let (v257 i32) (const.i32 2)) + (let (v258 i32) (band v251 v257)) + (let (v259 i1) (neq v258 0)) + (condbr v259 (block 30) (block 31))) + + (block 28 + (let (v215 i32) (const.i32 2)) + (let (v216 i32) (band v209 v215)) + (let (v217 i1) (neq v216 0)) + (condbr v217 (block 27 v196 v191 v140 v146) (block 29))) + + (block 29 + (let (v218 u32) (cast v211)) + (let (v219 u32) (add.checked v218 4)) + (let (v220 (ptr i32)) (inttoptr v219)) + (let (v221 i32) (load v220)) + (let (v222 i32) (const.i32 3)) + (let (v223 i32) (band v221 v222)) + (let (v224 i32) (bor v223 v196)) + (let (v225 u32) (cast v211)) + (let (v226 u32) (add.checked v225 4)) + (let (v227 (ptr i32)) (inttoptr v226)) + (store v227 v224) + (let (v228 u32) (cast v196)) + (let (v229 u32) (add.checked v228 4)) + (let (v230 (ptr i32)) (inttoptr v229)) + (let (v231 i32) (load v230)) + (let (v232 i32) (const.i32 3)) + (let (v233 i32) (band v231 v232)) + (br (block 27 v196 v233 v140 v146))) + + (block 30 + (let (v263 i32) (const.i32 -3)) + (let (v264 i32) (band v254 v263)) + (let (v265 u32) (cast v236)) + (let (v266 (ptr i32)) (inttoptr v265)) + (store v266 v264) + (let (v267 u32) (cast v234)) + (let (v268 (ptr i32)) (inttoptr v267)) + (let (v269 i32) (load v268)) + (let (v270 i32) (const.i32 2)) + (let (v271 i32) (bor v269 v270)) + (br (block 23 v234 v271))) + + (block 31 + (let (v260 u32) (cast v234)) + (let (v261 (ptr i32)) (inttoptr v260)) + (let (v262 i32) (load v261)) + (br (block 23 v234 v262))) + + (block 32 + (br (block 5))) + ) + + (func (export #::alloc) + (param i32) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) + (let (v4 i32) (const.i32 0)) + (let (v5 i32) (global.load i32 (global.symbol #__stack_pointer))) + (let (v6 i32) (const.i32 16)) + (let (v7 i32) (sub.wrapping v5 v6)) + (let (v8 (ptr i32)) (global.symbol #__stack_pointer)) + (store v8 v7) + (let (v9 i1) (neq v2 0)) + (condbr v9 (block 3) (block 4))) + + (block 1 (param v3 i32) + (ret v3)) + + (block 2 (param v87 i32) (param v91 i32) + (let (v88 i32) (const.i32 16)) + (let (v89 i32) (add.wrapping v87 v88)) + (let (v90 (ptr i32)) (global.symbol #__stack_pointer)) + (store v90 v89) + (br (block 1 v91))) + + (block 3 + (let (v10 u32) (cast v0)) + (let (v11 (ptr i32)) (inttoptr v10)) + (let (v12 i32) (load v11)) + (let (v13 u32) (cast v7)) + (let (v14 u32) (add.checked v13 12)) + (let (v15 (ptr i32)) (inttoptr v14)) + (store v15 v12) + (let (v16 i32) (const.i32 3)) + (let (v17 i32) (add.wrapping v2 v16)) + (let (v18 i32) (const.i32 2)) + (let (v19 u32) (cast v17)) + (let (v20 u32) (cast v18)) + (let (v21 u32) (shr.wrapping v19 v20)) + (let (v22 i32) (cast v21)) + (let (v23 i32) (const.i32 12)) + (let (v24 i32) (add.wrapping v7 v23)) + (let (v25 i32) (call #wee_alloc::alloc_first_fit v22 v1 v24)) + (let (v26 i1) (neq v25 0)) + (condbr v26 (block 5 v0 v7 v25) (block 6))) + + (block 4 + (br (block 2 v7 v1))) + + (block 5 (param v79 i32) (param v80 i32) (param v92 i32) + (let (v81 u32) (cast v80)) + (let (v82 u32) (add.checked v81 12)) + (let (v83 (ptr i32)) (inttoptr v82)) + (let (v84 i32) (load v83)) + (let (v85 u32) (cast v79)) + (let (v86 (ptr i32)) (inttoptr v85)) + (store v86 v84) + (br (block 2 v80 v92))) + + (block 6 + (let (v27 i32) (const.i32 -4)) + (let (v28 i32) (band v17 v27)) + (let (v29 i32) (const.i32 3)) + (let (v30 i32) (shl.wrapping v1 v29)) + (let (v31 i32) (const.i32 512)) + (let (v32 i32) (add.wrapping v30 v31)) + (let (v33 u32) (cast v28)) + (let (v34 u32) (cast v32)) + (let (v35 i1) (gt v33 v34)) + (let (v36 i32) (cast v35)) + (let (v37 i1) (neq v36 0)) + (let (v38 i32) (select v37 v28 v32)) + (let (v39 i32) (const.i32 65543)) + (let (v40 i32) (add.wrapping v38 v39)) + (let (v41 i32) (const.i32 16)) + (let (v42 u32) (cast v40)) + (let (v43 u32) (cast v41)) + (let (v44 u32) (shr.wrapping v42 v43)) + (let (v45 i32) (cast v44)) + (let (v46 u32) (cast v45)) + (let (v47 i32) (memory.grow v46)) + (let (v48 i32) (const.i32 -1)) + (let (v49 i1) (neq v47 v48)) + (let (v50 i32) (cast v49)) + (let (v51 i1) (neq v50 0)) + (condbr v51 (block 7) (block 8))) + + (block 7 + (let (v53 i32) (const.i32 16)) + (let (v54 i32) (shl.wrapping v47 v53)) + (let (v55 i32) (const.i32 0)) + (let (v56 u32) (cast v54)) + (let (v57 u32) (add.checked v56 4)) + (let (v58 (ptr i32)) (inttoptr v57)) + (store v58 v55) + (let (v59 u32) (cast v7)) + (let (v60 u32) (add.checked v59 12)) + (let (v61 (ptr i32)) (inttoptr v60)) + (let (v62 i32) (load v61)) + (let (v63 u32) (cast v54)) + (let (v64 u32) (add.checked v63 8)) + (let (v65 (ptr i32)) (inttoptr v64)) + (store v65 v62) + (let (v66 i32) (const.i32 -65536)) + (let (v67 i32) (band v40 v66)) + (let (v68 i32) (add.wrapping v54 v67)) + (let (v69 i32) (const.i32 2)) + (let (v70 i32) (bor v68 v69)) + (let (v71 u32) (cast v54)) + (let (v72 (ptr i32)) (inttoptr v71)) + (store v72 v70) + (let (v73 u32) (cast v7)) + (let (v74 u32) (add.checked v73 12)) + (let (v75 (ptr i32)) (inttoptr v74)) + (store v75 v54) + (let (v76 i32) (const.i32 12)) + (let (v77 i32) (add.wrapping v7 v76)) + (let (v78 i32) (call #wee_alloc::alloc_first_fit v22 v1 v77)) + (br (block 5 v0 v7 v78))) + + (block 8 + (let (v52 i32) (const.i32 0)) + (br (block 5 v0 v7 v52))) + ) + + (func (export #::dealloc) + (param i32) (param i32) (param i32) (param i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) + (let (v4 i32) (const.i32 0)) + (let (v5 i1) (eq v1 0)) + (let (v6 i32) (cast v5)) + (let (v7 i1) (neq v6 0)) + (condbr v7 (block 2) (block 3))) + + (block 1 + (ret)) + + (block 2 + (br (block 1))) + + (block 3 + (let (v8 i1) (eq v3 0)) + (let (v9 i32) (cast v8)) + (let (v10 i1) (neq v9 0)) + (condbr v10 (block 2) (block 4))) + + (block 4 + (let (v11 u32) (cast v0)) + (let (v12 (ptr i32)) (inttoptr v11)) + (let (v13 i32) (load v12)) + (let (v14 i32) (const.i32 0)) + (let (v15 u32) (cast v1)) + (let (v16 (ptr i32)) (inttoptr v15)) + (store v16 v14) + (let (v17 i32) (const.i32 -8)) + (let (v18 i32) (add.wrapping v1 v17)) + (let (v19 u32) (cast v18)) + (let (v20 (ptr i32)) (inttoptr v19)) + (let (v21 i32) (load v20)) + (let (v22 i32) (const.i32 -2)) + (let (v23 i32) (band v21 v22)) + (let (v24 u32) (cast v18)) + (let (v25 (ptr i32)) (inttoptr v24)) + (store v25 v23) + (let (v26 i32) (const.i32 4)) + (let (v27 i32) (add.wrapping v18 v26)) + (let (v28 u32) (cast v27)) + (let (v29 (ptr i32)) (inttoptr v28)) + (let (v30 i32) (load v29)) + (let (v31 i32) (const.i32 -4)) + (let (v32 i32) (band v30 v31)) + (let (v33 i1) (eq v32 0)) + (let (v34 i32) (cast v33)) + (let (v35 i1) (neq v34 0)) + (condbr v35 (block 10 v21 v1 v18 v13 v0) (block 11))) + + (block 5 (param v159 i32) (param v165 i32) + (let (v167 u32) (cast v159)) + (let (v168 (ptr i32)) (inttoptr v167)) + (store v168 v165) + (br (block 2))) + + (block 6 + (param v155 i32) + (param v156 i32) + (param v164 i32) + (param v166 i32) + (let (v157 u32) (cast v155)) + (let (v158 (ptr i32)) (inttoptr v157)) + (store v158 v156) + (br (block 5 v164 v166))) + + (block 7 (param v151 i32) (param v160 i32) + (br (block 5 v160 v151))) + + (block 8 + (let (v129 u32) (cast v46)) + (let (v130 (ptr u8)) (inttoptr v129)) + (let (v131 u8) (load v130)) + (let (v132 i32) (zext v131)) + (let (v133 i32) (const.i32 1)) + (let (v134 i32) (band v132 v133)) + (let (v135 i1) (neq v134 0)) + (condbr v135 (block 6 v136 v154 v163 v145) (block 22))) + + (block 9 + (let (v55 i32) (const.i32 -4)) + (let (v56 i32) (band v21 v55)) + (let (v57 i1) (neq v56 0)) + (condbr v57 (block 17) (block 18))) + + (block 10 + (param v44 i32) + (param v136 i32) + (param v145 i32) + (param v154 i32) + (param v163 i32) + (let (v45 i32) (const.i32 -4)) + (let (v46 i32) (band v44 v45)) + (let (v47 i1) (eq v46 0)) + (let (v48 i32) (cast v47)) + (let (v49 i1) (neq v48 0)) + (condbr v49 (block 6 v136 v154 v163 v145) (block 13))) + + (block 11 + (let (v36 u32) (cast v32)) + (let (v37 (ptr i32)) (inttoptr v36)) + (let (v38 i32) (load v37)) + (let (v39 i32) (const.i32 1)) + (let (v40 i32) (band v38 v39)) + (let (v41 i1) (eq v40 0)) + (let (v42 i32) (cast v41)) + (let (v43 i1) (neq v42 0)) + (condbr v43 (block 9) (block 12))) + + (block 12 + (br (block 10 v21 v1 v18 v13 v0))) + + (block 13 + (let (v50 i32) (const.i32 2)) + (let (v51 i32) (band v44 v50)) + (let (v52 i1) (eq v51 0)) + (let (v53 i32) (cast v52)) + (let (v54 i1) (neq v53 0)) + (condbr v54 (block 8) (block 14))) + + (block 14 + (br (block 6 v136 v154 v163 v145))) + + (block 15 + (param v103 i32) + (param v104 i32) + (param v109 i32) + (param v110 i32) + (param v120 i32) + (param v152 i32) + (param v161 i32) + (let (v105 i32) (const.i32 3)) + (let (v106 i32) (band v104 v105)) + (let (v107 u32) (cast v103)) + (let (v108 (ptr i32)) (inttoptr v107)) + (store v108 v106) + (let (v111 i32) (const.i32 3)) + (let (v112 i32) (band v110 v111)) + (let (v113 u32) (cast v109)) + (let (v114 (ptr i32)) (inttoptr v113)) + (store v114 v112) + (let (v115 i32) (const.i32 2)) + (let (v116 i32) (band v110 v115)) + (let (v117 i1) (eq v116 0)) + (let (v118 i32) (cast v117)) + (let (v119 i1) (neq v118 0)) + (condbr v119 (block 7 v152 v161) (block 21))) + + (block 16 + (param v85 i32) + (param v86 i32) + (param v89 i32) + (param v95 i32) + (param v99 i32) + (param v121 i32) + (param v153 i32) + (param v162 i32) + (let (v87 i32) (const.i32 -4)) + (let (v88 i32) (band v86 v87)) + (let (v90 i32) (const.i32 3)) + (let (v91 i32) (band v89 v90)) + (let (v92 i32) (bor v88 v91)) + (let (v93 u32) (cast v85)) + (let (v94 (ptr i32)) (inttoptr v93)) + (store v94 v92) + (let (v96 u32) (cast v95)) + (let (v97 (ptr i32)) (inttoptr v96)) + (let (v98 i32) (load v97)) + (let (v100 u32) (cast v99)) + (let (v101 (ptr i32)) (inttoptr v100)) + (let (v102 i32) (load v101)) + (br (block 15 v95 v98 v99 v102 v121 v153 v162))) + + (block 17 + (let (v58 i32) (const.i32 2)) + (let (v59 i32) (band v21 v58)) + (let (v60 i1) (neq v59 0)) + (condbr v60 (block 16 v32 v23 v38 v27 v18 v32 v13 v0) (block 19))) + + (block 18 + (br (block 16 v32 v23 v38 v27 v18 v32 v13 v0))) + + (block 19 + (let (v61 u32) (cast v56)) + (let (v62 u32) (add.checked v61 4)) + (let (v63 (ptr i32)) (inttoptr v62)) + (let (v64 i32) (load v63)) + (let (v65 i32) (const.i32 3)) + (let (v66 i32) (band v64 v65)) + (let (v67 i32) (bor v66 v32)) + (let (v68 u32) (cast v56)) + (let (v69 u32) (add.checked v68 4)) + (let (v70 (ptr i32)) (inttoptr v69)) + (store v70 v67) + (let (v71 u32) (cast v18)) + (let (v72 (ptr i32)) (inttoptr v71)) + (let (v73 i32) (load v72)) + (let (v74 u32) (cast v27)) + (let (v75 (ptr i32)) (inttoptr v74)) + (let (v76 i32) (load v75)) + (let (v77 i32) (const.i32 -4)) + (let (v78 i32) (band v76 v77)) + (let (v79 i1) (eq v78 0)) + (let (v80 i32) (cast v79)) + (let (v81 i1) (neq v80 0)) + (condbr v81 (block 15 v27 v76 v18 v73 v32 v13 v0) (block 20))) + + (block 20 + (let (v82 u32) (cast v78)) + (let (v83 (ptr i32)) (inttoptr v82)) + (let (v84 i32) (load v83)) + (br (block 16 v78 v73 v84 v27 v18 v32 v13 v0))) + + (block 21 + (let (v122 u32) (cast v120)) + (let (v123 (ptr i32)) (inttoptr v122)) + (let (v124 i32) (load v123)) + (let (v125 i32) (const.i32 2)) + (let (v126 i32) (bor v124 v125)) + (let (v127 u32) (cast v120)) + (let (v128 (ptr i32)) (inttoptr v127)) + (store v128 v126) + (br (block 7 v152 v161))) + + (block 22 + (let (v137 u32) (cast v46)) + (let (v138 u32) (add.checked v137 8)) + (let (v139 (ptr i32)) (inttoptr v138)) + (let (v140 i32) (load v139)) + (let (v141 i32) (const.i32 -4)) + (let (v142 i32) (band v140 v141)) + (let (v143 u32) (cast v136)) + (let (v144 (ptr i32)) (inttoptr v143)) + (store v144 v142) + (let (v146 i32) (const.i32 1)) + (let (v147 i32) (bor v145 v146)) + (let (v148 u32) (cast v46)) + (let (v149 u32) (add.checked v148 8)) + (let (v150 (ptr i32)) (inttoptr v149)) + (store v150 v147) + (br (block 7 v154 v163))) + ) + + (func (export #wit_bindgen::rt::run_ctors_once) + (block 0 + (let (v0 i32) (const.i32 0)) + (let (v1 u32) (cast v0)) + (let (v2 u32) (add.checked v1 1048581)) + (let (v3 (ptr u8)) (inttoptr v2)) + (let (v4 u8) (load v3)) + (let (v5 i32) (zext v4)) + (let (v6 i1) (neq v5 0)) + (condbr v6 (block 2) (block 3))) + + (block 1 + (ret)) + + (block 2 + (br (block 1))) + + (block 3 + (call #__wasm_call_ctors) + (let (v7 i32) (const.i32 0)) + (let (v8 i32) (const.i32 1)) + (let (v9 u8) (trunc v8)) + (let (v10 u32) (cast v7)) + (let (v11 u32) (add.checked v10 1048581)) + (let (v12 (ptr u8)) (inttoptr v11)) + (store v12 v9) + (br (block 2))) + ) + + (func (export #cabi_realloc) + (param i32) (param i32) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) + (let (v5 i1) (neq v1 0)) + (condbr v5 (block 4) (block 5))) + + (block 1 (param v4 i32) + (ret v4)) + + (block 2 (param v19 i32) + (br (block 1 v19))) + + (block 3 (param v17 i32) + (let (v18 i1) (neq v17 0)) + (condbr v18 (block 2 v17) (block 7))) + + (block 4 + (let (v16 i32) (call #__rust_realloc v0 v1 v2 v3)) + (br (block 3 v16))) + + (block 5 + (let (v6 i1) (eq v3 0)) + (let (v7 i32) (cast v6)) + (let (v8 i1) (neq v7 0)) + (condbr v8 (block 2 v2) (block 6))) + + (block 6 + (let (v9 i32) (const.i32 0)) + (let (v10 u32) (cast v9)) + (let (v11 u32) (add.checked v10 1048580)) + (let (v12 (ptr u8)) (inttoptr v11)) + (let (v13 u8) (load v12)) + (let (v14 i32) (zext v13)) + (let (v15 i32) (call #__rust_alloc v3 v2)) + (br (block 3 v15))) + + (block 7 + (unreachable)) + ) + ) + +) diff --git a/tests/integration/expected/components/add_wasm_component.wat b/tests/integration/expected/components/add_wasm_component.wat index 7e7c06a0b..c9358ef50 100644 --- a/tests/integration/expected/components/add_wasm_component.wat +++ b/tests/integration/expected/components/add_wasm_component.wat @@ -6,7 +6,7 @@ (type (;3;) (func (param i32 i32 i32) (result i32))) (type (;4;) (func (param i32 i32 i32 i32))) (func $__wasm_call_ctors (;0;) (type 0)) - (func $miden:add/add@1.0.0#add (;1;) (type 1) (param i32 i32) (result i32) + (func $miden:add-package/add-interface@1.0.0#add (;1;) (type 1) (param i32 i32) (result i32) call $wit_bindgen::rt::run_ctors_once local.get 1 local.get 0 @@ -671,14 +671,14 @@ (memory (;0;) 17) (global $__stack_pointer (;0;) (mut i32) i32.const 1048576) (export "memory" (memory 0)) - (export "miden:add/add@1.0.0#add" (func $miden:add/add@1.0.0#add)) + (export "miden:add-package/add-interface@1.0.0#add" (func $miden:add-package/add-interface@1.0.0#add)) (export "cabi_realloc" (func $cabi_realloc)) ) (core instance (;0;) (instantiate 0)) (alias core export 0 "memory" (core memory (;0;))) (alias core export 0 "cabi_realloc" (core func (;0;))) (type (;0;) (func (param "a" u32) (param "b" u32) (result u32))) - (alias core export 0 "miden:add/add@1.0.0#add" (core func (;1;))) + (alias core export 0 "miden:add-package/add-interface@1.0.0#add" (core func (;1;))) (func (;0;) (type 0) (canon lift (core func 1))) (component (;0;) (type (;0;) (func (param "a" u32) (param "b" u32) (result u32))) @@ -690,5 +690,5 @@ (with "import-func-add" (func 0)) ) ) - (export (;1;) "miden:add/add@1.0.0" (instance 0)) + (export (;1;) "miden:add-package/add-interface@1.0.0" (instance 0)) ) \ No newline at end of file diff --git a/tests/integration/expected/components/inc_wasm_component.hir b/tests/integration/expected/components/inc_wasm_component.hir new file mode 100644 index 000000000..2ef0dfc6a --- /dev/null +++ b/tests/integration/expected/components/inc_wasm_component.hir @@ -0,0 +1,916 @@ +(component + ;; Component Imports + (lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (call) (type (func (param u32) (param u32) (result u32)))) (#inc_wasm_component.wasm #inc_wasm_component::bindings::miden::add_package::add_interface::add::wit_import) + + ;; Modules + (module #inc_wasm_component.wasm + ;; Constants + (const (id 0) 0x00100000) + + ;; Global Variables + (global (export #__stack_pointer) (id 0) (type i32) (const 0)) + + ;; Functions + (func (export #__wasm_call_ctors) + (block 0 + (br (block 1))) + + (block 1 + (ret)) + ) + + (func (export #inc) (param i32) (result i32) + (block 0 (param v0 i32) + (call #wit_bindgen::rt::run_ctors_once) + (let (v2 i32) (const.i32 1)) + (let (v3 i32) (call #inc_wasm_component::bindings::miden::add_package::add_interface::add::wit_import v0 v2)) + (br (block 1 v3))) + + (block 1 (param v1 i32) + (ret v1)) + ) + + (func (export #__rust_alloc) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) + (let (v3 i32) (const.i32 1048576)) + (let (v4 i32) (call #::alloc v3 v1 v0)) + (br (block 1 v4))) + + (block 1 (param v2 i32) + (ret v2)) + ) + + (func (export #__rust_realloc) + (param i32) (param i32) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) + (let (v5 i32) (const.i32 0)) + (let (v6 i32) (const.i32 1048576)) + (let (v7 i32) (call #::alloc v6 v2 v3)) + (let (v8 i1) (eq v7 0)) + (let (v9 i32) (cast v8)) + (let (v10 i1) (neq v9 0)) + (condbr v10 (block 2 v7) (block 3))) + + (block 1 (param v4 i32) + (ret v4)) + + (block 2 (param v22 i32) + (br (block 1 v22))) + + (block 3 + (let (v11 u32) (cast v1)) + (let (v12 u32) (cast v3)) + (let (v13 i1) (lt v11 v12)) + (let (v14 i32) (cast v13)) + (let (v15 i1) (neq v14 0)) + (let (v16 i32) (select v15 v1 v3)) + (let (v17 u32) (cast v7)) + (let (v18 (ptr u8)) (inttoptr v17)) + (let (v19 u32) (cast v0)) + (let (v20 (ptr u8)) (inttoptr v19)) + (memcpy v20 v18 v16) + (let (v21 i32) (const.i32 1048576)) + (call #::dealloc v21 v0 v2 v1) + (br (block 2 v7))) + ) + + (func (export #wee_alloc::alloc_first_fit) + (param i32) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) + (let (v4 i32) (const.i32 0)) + (let (v5 u32) (cast v2)) + (let (v6 (ptr i32)) (inttoptr v5)) + (let (v7 i32) (load v6)) + (let (v8 i1) (eq v7 0)) + (let (v9 i32) (cast v8)) + (let (v10 i1) (neq v9 0)) + (condbr v10 (block 2) (block 3))) + + (block 1 (param v3 i32) + (ret v3)) + + (block 2 + (let (v288 i32) (const.i32 0)) + (br (block 1 v288))) + + (block 3 + (let (v11 i32) (const.i32 -1)) + (let (v12 i32) (add.wrapping v1 v11)) + (let (v13 i32) (const.i32 0)) + (let (v14 i32) (sub.wrapping v13 v1)) + (let (v15 i32) (const.i32 2)) + (let (v16 i32) (shl.wrapping v0 v15)) + (br (block 4 v7 v2 v16 v14 v12))) + + (block 4 + (param v17 i32) + (param v139 i32) + (param v149 i32) + (param v163 i32) + (param v175 i32) + (let (v18 i32) (const.i32 8)) + (let (v19 i32) (add.wrapping v17 v18)) + (let (v20 u32) (cast v17)) + (let (v21 u32) (add.checked v20 8)) + (let (v22 (ptr i32)) (inttoptr v21)) + (let (v23 i32) (load v22)) + (let (v24 i32) (const.i32 1)) + (let (v25 i32) (band v23 v24)) + (let (v26 i1) (neq v25 0)) + (condbr v26 (block 7) (block 8))) + + (block 5 + (br (block 2))) + + (block 6 + (param v140 i32) + (param v146 i32) + (param v148 i32) + (param v162 i32) + (param v174 i32) + (param v182 i32) + (param v183 i32) + (let (v141 u32) (cast v140)) + (let (v142 (ptr i32)) (inttoptr v141)) + (let (v143 i32) (load v142)) + (let (v144 i32) (const.i32 -4)) + (let (v145 i32) (band v143 v144)) + (let (v147 i32) (sub.wrapping v145 v146)) + (let (v154 u32) (cast v147)) + (let (v155 u32) (cast v148)) + (let (v156 i1) (lt v154 v155)) + (let (v157 i32) (cast v156)) + (let (v158 i1) (neq v157 0)) + (condbr v158 (block 21 v182 v183 v148 v162 v174) (block 22))) + + (block 7 + (br (block 9 v19 v23 v17 v139 v149 v163 v175))) + + (block 8 + (br (block 6 v17 v19 v149 v163 v175 v139 v23))) + + (block 9 + (param v27 i32) + (param v28 i32) + (param v33 i32) + (param v125 i32) + (param v152 i32) + (param v166 i32) + (param v178 i32) + (let (v29 i32) (const.i32 -2)) + (let (v30 i32) (band v28 v29)) + (let (v31 u32) (cast v27)) + (let (v32 (ptr i32)) (inttoptr v31)) + (store v32 v30) + (let (v34 u32) (cast v33)) + (let (v35 u32) (add.checked v34 4)) + (let (v36 (ptr i32)) (inttoptr v35)) + (let (v37 i32) (load v36)) + (let (v38 i32) (const.i32 -4)) + (let (v39 i32) (band v37 v38)) + (let (v40 u32) (cast v39)) + (let (v41 (ptr i32)) (inttoptr v40)) + (let (v42 i32) (load v41)) + (let (v43 u32) (cast v33)) + (let (v44 (ptr i32)) (inttoptr v43)) + (let (v45 i32) (load v44)) + (let (v46 i32) (const.i32 -4)) + (let (v47 i32) (band v45 v46)) + (let (v48 i1) (neq v47 0)) + (condbr v48 (block 13) (block 14))) + + (block 10 + (br (block 6 v127 v131 v150 v164 v176 v123 v135))) + + (block 11 + (param v97 i32) + (param v98 i32) + (param v104 i32) + (param v114 i32) + (param v124 i32) + (param v151 i32) + (param v165 i32) + (param v177 i32) + (let (v99 i32) (const.i32 3)) + (let (v100 i32) (band v98 v99)) + (let (v101 u32) (cast v97)) + (let (v102 u32) (add.checked v101 4)) + (let (v103 (ptr i32)) (inttoptr v102)) + (store v103 v100) + (let (v105 i32) (const.i32 3)) + (let (v106 i32) (band v104 v105)) + (let (v107 u32) (cast v97)) + (let (v108 (ptr i32)) (inttoptr v107)) + (store v108 v106) + (let (v109 i32) (const.i32 2)) + (let (v110 i32) (band v104 v109)) + (let (v111 i1) (eq v110 0)) + (let (v112 i32) (cast v111)) + (let (v113 i1) (neq v112 0)) + (condbr v113 (block 18 v124 v114 v151 v165 v177) (block 19))) + + (block 12 + (param v81 i32) + (param v82 i32) + (param v85 i32) + (param v89 i32) + (param v115 i32) + (param v126 i32) + (param v153 i32) + (param v167 i32) + (param v179 i32) + (let (v83 i32) (const.i32 3)) + (let (v84 i32) (band v82 v83)) + (let (v86 i32) (bor v84 v85)) + (let (v87 u32) (cast v81)) + (let (v88 (ptr i32)) (inttoptr v87)) + (store v88 v86) + (let (v90 u32) (cast v89)) + (let (v91 u32) (add.checked v90 4)) + (let (v92 (ptr i32)) (inttoptr v91)) + (let (v93 i32) (load v92)) + (let (v94 u32) (cast v89)) + (let (v95 (ptr i32)) (inttoptr v94)) + (let (v96 i32) (load v95)) + (br (block 11 v89 v93 v96 v115 v126 v153 v167 v179))) + + (block 13 + (let (v49 i32) (const.i32 2)) + (let (v50 i32) (band v45 v49)) + (let (v51 i1) (eq v50 0)) + (let (v52 i32) (cast v51)) + (let (v53 i1) (neq v52 0)) + (condbr v53 (block 15) (block 16))) + + (block 14 + (br (block 12 v39 v42 v47 v33 v39 v125 v152 v166 v178))) + + (block 15 + (let (v54 u32) (cast v47)) + (let (v55 u32) (add.checked v54 4)) + (let (v56 (ptr i32)) (inttoptr v55)) + (let (v57 i32) (load v56)) + (let (v58 i32) (const.i32 3)) + (let (v59 i32) (band v57 v58)) + (let (v60 i32) (bor v59 v39)) + (let (v61 u32) (cast v47)) + (let (v62 u32) (add.checked v61 4)) + (let (v63 (ptr i32)) (inttoptr v62)) + (store v63 v60) + (let (v64 u32) (cast v33)) + (let (v65 (ptr i32)) (inttoptr v64)) + (let (v66 i32) (load v65)) + (let (v67 u32) (cast v33)) + (let (v68 u32) (add.checked v67 4)) + (let (v69 (ptr i32)) (inttoptr v68)) + (let (v70 i32) (load v69)) + (let (v71 i32) (const.i32 -4)) + (let (v72 i32) (band v70 v71)) + (let (v73 i1) (eq v72 0)) + (let (v74 i32) (cast v73)) + (let (v75 i1) (neq v74 0)) + (condbr v75 (block 11 v33 v70 v66 v39 v125 v152 v166 v178) (block 17))) + + (block 16 + (br (block 12 v39 v42 v47 v33 v39 v125 v152 v166 v178))) + + (block 17 + (let (v76 i32) (const.i32 -4)) + (let (v77 i32) (band v66 v76)) + (let (v78 u32) (cast v72)) + (let (v79 (ptr i32)) (inttoptr v78)) + (let (v80 i32) (load v79)) + (br (block 12 v72 v80 v77 v33 v39 v125 v152 v166 v178))) + + (block 18 + (param v123 i32) + (param v127 i32) + (param v150 i32) + (param v164 i32) + (param v176 i32) + (let (v128 u32) (cast v123)) + (let (v129 (ptr i32)) (inttoptr v128)) + (store v129 v127) + (let (v130 i32) (const.i32 8)) + (let (v131 i32) (add.wrapping v127 v130)) + (let (v132 u32) (cast v127)) + (let (v133 u32) (add.checked v132 8)) + (let (v134 (ptr i32)) (inttoptr v133)) + (let (v135 i32) (load v134)) + (let (v136 i32) (const.i32 1)) + (let (v137 i32) (band v135 v136)) + (let (v138 i1) (neq v137 0)) + (condbr v138 (block 9 v131 v135 v127 v123 v150 v164 v176) (block 20))) + + (block 19 + (let (v116 u32) (cast v114)) + (let (v117 (ptr i32)) (inttoptr v116)) + (let (v118 i32) (load v117)) + (let (v119 i32) (const.i32 2)) + (let (v120 i32) (bor v118 v119)) + (let (v121 u32) (cast v114)) + (let (v122 (ptr i32)) (inttoptr v121)) + (store v122 v120) + (br (block 18 v124 v114 v151 v165 v177))) + + (block 20 + (br (block 10))) + + (block 21 + (param v280 i32) + (param v281 i32) + (param v285 i32) + (param v286 i32) + (param v287 i32) + (let (v282 u32) (cast v280)) + (let (v283 (ptr i32)) (inttoptr v282)) + (store v283 v281) + (let (v284 i1) (neq v281 0)) + (condbr v284 (block 4 v281 v280 v285 v286 v287) (block 32))) + + (block 22 + (let (v159 i32) (const.i32 72)) + (let (v160 i32) (add.wrapping v146 v159)) + (let (v161 i32) (sub.wrapping v145 v148)) + (let (v168 i32) (band v161 v162)) + (let (v169 u32) (cast v160)) + (let (v170 u32) (cast v168)) + (let (v171 i1) (lte v169 v170)) + (let (v172 i32) (cast v171)) + (let (v173 i1) (neq v172 0)) + (condbr v173 (block 24) (block 25))) + + (block 23 (param v272 i32) (param v273 i32) + (let (v274 i32) (const.i32 1)) + (let (v275 i32) (bor v273 v274)) + (let (v276 u32) (cast v272)) + (let (v277 (ptr i32)) (inttoptr v276)) + (store v277 v275) + (let (v278 i32) (const.i32 8)) + (let (v279 i32) (add.wrapping v272 v278)) + (ret v279)) + + (block 24 + (let (v191 i32) (const.i32 0)) + (let (v192 i32) (const.i32 0)) + (let (v193 u32) (cast v168)) + (let (v194 (ptr i32)) (inttoptr v193)) + (store v194 v192) + (let (v195 i32) (const.i32 -8)) + (let (v196 i32) (add.wrapping v168 v195)) + (let (v197 i64) (const.i64 0)) + (let (v198 u32) (cast v196)) + (let (v199 (ptr i64)) (inttoptr v198)) + (store v199 v197) + (let (v200 u32) (cast v140)) + (let (v201 (ptr i32)) (inttoptr v200)) + (let (v202 i32) (load v201)) + (let (v203 i32) (const.i32 -4)) + (let (v204 i32) (band v202 v203)) + (let (v205 u32) (cast v196)) + (let (v206 (ptr i32)) (inttoptr v205)) + (store v206 v204) + (let (v207 u32) (cast v140)) + (let (v208 (ptr i32)) (inttoptr v207)) + (let (v209 i32) (load v208)) + (let (v210 i32) (const.i32 -4)) + (let (v211 i32) (band v209 v210)) + (let (v212 i1) (eq v211 0)) + (let (v213 i32) (cast v212)) + (let (v214 i1) (neq v213 0)) + (condbr v214 (block 27 v196 v191 v140 v146) (block 28))) + + (block 25 + (let (v180 i32) (band v174 v146)) + (let (v181 i1) (neq v180 0)) + (condbr v181 (block 21 v182 v183 v148 v162 v174) (block 26))) + + (block 26 + (let (v184 i32) (const.i32 -4)) + (let (v185 i32) (band v183 v184)) + (let (v186 u32) (cast v182)) + (let (v187 (ptr i32)) (inttoptr v186)) + (store v187 v185) + (let (v188 u32) (cast v140)) + (let (v189 (ptr i32)) (inttoptr v188)) + (let (v190 i32) (load v189)) + (br (block 23 v140 v190))) + + (block 27 + (param v234 i32) + (param v235 i32) + (param v236 i32) + (param v241 i32) + (let (v237 i32) (bor v235 v236)) + (let (v238 u32) (cast v234)) + (let (v239 u32) (add.checked v238 4)) + (let (v240 (ptr i32)) (inttoptr v239)) + (store v240 v237) + (let (v242 u32) (cast v241)) + (let (v243 (ptr i32)) (inttoptr v242)) + (let (v244 i32) (load v243)) + (let (v245 i32) (const.i32 -2)) + (let (v246 i32) (band v244 v245)) + (let (v247 u32) (cast v241)) + (let (v248 (ptr i32)) (inttoptr v247)) + (store v248 v246) + (let (v249 u32) (cast v236)) + (let (v250 (ptr i32)) (inttoptr v249)) + (let (v251 i32) (load v250)) + (let (v252 i32) (const.i32 3)) + (let (v253 i32) (band v251 v252)) + (let (v254 i32) (bor v253 v234)) + (let (v255 u32) (cast v236)) + (let (v256 (ptr i32)) (inttoptr v255)) + (store v256 v254) + (let (v257 i32) (const.i32 2)) + (let (v258 i32) (band v251 v257)) + (let (v259 i1) (neq v258 0)) + (condbr v259 (block 30) (block 31))) + + (block 28 + (let (v215 i32) (const.i32 2)) + (let (v216 i32) (band v209 v215)) + (let (v217 i1) (neq v216 0)) + (condbr v217 (block 27 v196 v191 v140 v146) (block 29))) + + (block 29 + (let (v218 u32) (cast v211)) + (let (v219 u32) (add.checked v218 4)) + (let (v220 (ptr i32)) (inttoptr v219)) + (let (v221 i32) (load v220)) + (let (v222 i32) (const.i32 3)) + (let (v223 i32) (band v221 v222)) + (let (v224 i32) (bor v223 v196)) + (let (v225 u32) (cast v211)) + (let (v226 u32) (add.checked v225 4)) + (let (v227 (ptr i32)) (inttoptr v226)) + (store v227 v224) + (let (v228 u32) (cast v196)) + (let (v229 u32) (add.checked v228 4)) + (let (v230 (ptr i32)) (inttoptr v229)) + (let (v231 i32) (load v230)) + (let (v232 i32) (const.i32 3)) + (let (v233 i32) (band v231 v232)) + (br (block 27 v196 v233 v140 v146))) + + (block 30 + (let (v263 i32) (const.i32 -3)) + (let (v264 i32) (band v254 v263)) + (let (v265 u32) (cast v236)) + (let (v266 (ptr i32)) (inttoptr v265)) + (store v266 v264) + (let (v267 u32) (cast v234)) + (let (v268 (ptr i32)) (inttoptr v267)) + (let (v269 i32) (load v268)) + (let (v270 i32) (const.i32 2)) + (let (v271 i32) (bor v269 v270)) + (br (block 23 v234 v271))) + + (block 31 + (let (v260 u32) (cast v234)) + (let (v261 (ptr i32)) (inttoptr v260)) + (let (v262 i32) (load v261)) + (br (block 23 v234 v262))) + + (block 32 + (br (block 5))) + ) + + (func (export #::alloc) + (param i32) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) + (let (v4 i32) (const.i32 0)) + (let (v5 i32) (global.load i32 (global.symbol #__stack_pointer))) + (let (v6 i32) (const.i32 16)) + (let (v7 i32) (sub.wrapping v5 v6)) + (let (v8 (ptr i32)) (global.symbol #__stack_pointer)) + (store v8 v7) + (let (v9 i1) (neq v2 0)) + (condbr v9 (block 3) (block 4))) + + (block 1 (param v3 i32) + (ret v3)) + + (block 2 (param v87 i32) (param v91 i32) + (let (v88 i32) (const.i32 16)) + (let (v89 i32) (add.wrapping v87 v88)) + (let (v90 (ptr i32)) (global.symbol #__stack_pointer)) + (store v90 v89) + (br (block 1 v91))) + + (block 3 + (let (v10 u32) (cast v0)) + (let (v11 (ptr i32)) (inttoptr v10)) + (let (v12 i32) (load v11)) + (let (v13 u32) (cast v7)) + (let (v14 u32) (add.checked v13 12)) + (let (v15 (ptr i32)) (inttoptr v14)) + (store v15 v12) + (let (v16 i32) (const.i32 3)) + (let (v17 i32) (add.wrapping v2 v16)) + (let (v18 i32) (const.i32 2)) + (let (v19 u32) (cast v17)) + (let (v20 u32) (cast v18)) + (let (v21 u32) (shr.wrapping v19 v20)) + (let (v22 i32) (cast v21)) + (let (v23 i32) (const.i32 12)) + (let (v24 i32) (add.wrapping v7 v23)) + (let (v25 i32) (call #wee_alloc::alloc_first_fit v22 v1 v24)) + (let (v26 i1) (neq v25 0)) + (condbr v26 (block 5 v0 v7 v25) (block 6))) + + (block 4 + (br (block 2 v7 v1))) + + (block 5 (param v79 i32) (param v80 i32) (param v92 i32) + (let (v81 u32) (cast v80)) + (let (v82 u32) (add.checked v81 12)) + (let (v83 (ptr i32)) (inttoptr v82)) + (let (v84 i32) (load v83)) + (let (v85 u32) (cast v79)) + (let (v86 (ptr i32)) (inttoptr v85)) + (store v86 v84) + (br (block 2 v80 v92))) + + (block 6 + (let (v27 i32) (const.i32 -4)) + (let (v28 i32) (band v17 v27)) + (let (v29 i32) (const.i32 3)) + (let (v30 i32) (shl.wrapping v1 v29)) + (let (v31 i32) (const.i32 512)) + (let (v32 i32) (add.wrapping v30 v31)) + (let (v33 u32) (cast v28)) + (let (v34 u32) (cast v32)) + (let (v35 i1) (gt v33 v34)) + (let (v36 i32) (cast v35)) + (let (v37 i1) (neq v36 0)) + (let (v38 i32) (select v37 v28 v32)) + (let (v39 i32) (const.i32 65543)) + (let (v40 i32) (add.wrapping v38 v39)) + (let (v41 i32) (const.i32 16)) + (let (v42 u32) (cast v40)) + (let (v43 u32) (cast v41)) + (let (v44 u32) (shr.wrapping v42 v43)) + (let (v45 i32) (cast v44)) + (let (v46 u32) (cast v45)) + (let (v47 i32) (memory.grow v46)) + (let (v48 i32) (const.i32 -1)) + (let (v49 i1) (neq v47 v48)) + (let (v50 i32) (cast v49)) + (let (v51 i1) (neq v50 0)) + (condbr v51 (block 7) (block 8))) + + (block 7 + (let (v53 i32) (const.i32 16)) + (let (v54 i32) (shl.wrapping v47 v53)) + (let (v55 i32) (const.i32 0)) + (let (v56 u32) (cast v54)) + (let (v57 u32) (add.checked v56 4)) + (let (v58 (ptr i32)) (inttoptr v57)) + (store v58 v55) + (let (v59 u32) (cast v7)) + (let (v60 u32) (add.checked v59 12)) + (let (v61 (ptr i32)) (inttoptr v60)) + (let (v62 i32) (load v61)) + (let (v63 u32) (cast v54)) + (let (v64 u32) (add.checked v63 8)) + (let (v65 (ptr i32)) (inttoptr v64)) + (store v65 v62) + (let (v66 i32) (const.i32 -65536)) + (let (v67 i32) (band v40 v66)) + (let (v68 i32) (add.wrapping v54 v67)) + (let (v69 i32) (const.i32 2)) + (let (v70 i32) (bor v68 v69)) + (let (v71 u32) (cast v54)) + (let (v72 (ptr i32)) (inttoptr v71)) + (store v72 v70) + (let (v73 u32) (cast v7)) + (let (v74 u32) (add.checked v73 12)) + (let (v75 (ptr i32)) (inttoptr v74)) + (store v75 v54) + (let (v76 i32) (const.i32 12)) + (let (v77 i32) (add.wrapping v7 v76)) + (let (v78 i32) (call #wee_alloc::alloc_first_fit v22 v1 v77)) + (br (block 5 v0 v7 v78))) + + (block 8 + (let (v52 i32) (const.i32 0)) + (br (block 5 v0 v7 v52))) + ) + + (func (export #::dealloc) + (param i32) (param i32) (param i32) (param i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) + (let (v4 i32) (const.i32 0)) + (let (v5 i1) (eq v1 0)) + (let (v6 i32) (cast v5)) + (let (v7 i1) (neq v6 0)) + (condbr v7 (block 2) (block 3))) + + (block 1 + (ret)) + + (block 2 + (br (block 1))) + + (block 3 + (let (v8 i1) (eq v3 0)) + (let (v9 i32) (cast v8)) + (let (v10 i1) (neq v9 0)) + (condbr v10 (block 2) (block 4))) + + (block 4 + (let (v11 u32) (cast v0)) + (let (v12 (ptr i32)) (inttoptr v11)) + (let (v13 i32) (load v12)) + (let (v14 i32) (const.i32 0)) + (let (v15 u32) (cast v1)) + (let (v16 (ptr i32)) (inttoptr v15)) + (store v16 v14) + (let (v17 i32) (const.i32 -8)) + (let (v18 i32) (add.wrapping v1 v17)) + (let (v19 u32) (cast v18)) + (let (v20 (ptr i32)) (inttoptr v19)) + (let (v21 i32) (load v20)) + (let (v22 i32) (const.i32 -2)) + (let (v23 i32) (band v21 v22)) + (let (v24 u32) (cast v18)) + (let (v25 (ptr i32)) (inttoptr v24)) + (store v25 v23) + (let (v26 i32) (const.i32 4)) + (let (v27 i32) (add.wrapping v18 v26)) + (let (v28 u32) (cast v27)) + (let (v29 (ptr i32)) (inttoptr v28)) + (let (v30 i32) (load v29)) + (let (v31 i32) (const.i32 -4)) + (let (v32 i32) (band v30 v31)) + (let (v33 i1) (eq v32 0)) + (let (v34 i32) (cast v33)) + (let (v35 i1) (neq v34 0)) + (condbr v35 (block 10 v21 v1 v18 v13 v0) (block 11))) + + (block 5 (param v159 i32) (param v165 i32) + (let (v167 u32) (cast v159)) + (let (v168 (ptr i32)) (inttoptr v167)) + (store v168 v165) + (br (block 2))) + + (block 6 + (param v155 i32) + (param v156 i32) + (param v164 i32) + (param v166 i32) + (let (v157 u32) (cast v155)) + (let (v158 (ptr i32)) (inttoptr v157)) + (store v158 v156) + (br (block 5 v164 v166))) + + (block 7 (param v151 i32) (param v160 i32) + (br (block 5 v160 v151))) + + (block 8 + (let (v129 u32) (cast v46)) + (let (v130 (ptr u8)) (inttoptr v129)) + (let (v131 u8) (load v130)) + (let (v132 i32) (zext v131)) + (let (v133 i32) (const.i32 1)) + (let (v134 i32) (band v132 v133)) + (let (v135 i1) (neq v134 0)) + (condbr v135 (block 6 v136 v154 v163 v145) (block 22))) + + (block 9 + (let (v55 i32) (const.i32 -4)) + (let (v56 i32) (band v21 v55)) + (let (v57 i1) (neq v56 0)) + (condbr v57 (block 17) (block 18))) + + (block 10 + (param v44 i32) + (param v136 i32) + (param v145 i32) + (param v154 i32) + (param v163 i32) + (let (v45 i32) (const.i32 -4)) + (let (v46 i32) (band v44 v45)) + (let (v47 i1) (eq v46 0)) + (let (v48 i32) (cast v47)) + (let (v49 i1) (neq v48 0)) + (condbr v49 (block 6 v136 v154 v163 v145) (block 13))) + + (block 11 + (let (v36 u32) (cast v32)) + (let (v37 (ptr i32)) (inttoptr v36)) + (let (v38 i32) (load v37)) + (let (v39 i32) (const.i32 1)) + (let (v40 i32) (band v38 v39)) + (let (v41 i1) (eq v40 0)) + (let (v42 i32) (cast v41)) + (let (v43 i1) (neq v42 0)) + (condbr v43 (block 9) (block 12))) + + (block 12 + (br (block 10 v21 v1 v18 v13 v0))) + + (block 13 + (let (v50 i32) (const.i32 2)) + (let (v51 i32) (band v44 v50)) + (let (v52 i1) (eq v51 0)) + (let (v53 i32) (cast v52)) + (let (v54 i1) (neq v53 0)) + (condbr v54 (block 8) (block 14))) + + (block 14 + (br (block 6 v136 v154 v163 v145))) + + (block 15 + (param v103 i32) + (param v104 i32) + (param v109 i32) + (param v110 i32) + (param v120 i32) + (param v152 i32) + (param v161 i32) + (let (v105 i32) (const.i32 3)) + (let (v106 i32) (band v104 v105)) + (let (v107 u32) (cast v103)) + (let (v108 (ptr i32)) (inttoptr v107)) + (store v108 v106) + (let (v111 i32) (const.i32 3)) + (let (v112 i32) (band v110 v111)) + (let (v113 u32) (cast v109)) + (let (v114 (ptr i32)) (inttoptr v113)) + (store v114 v112) + (let (v115 i32) (const.i32 2)) + (let (v116 i32) (band v110 v115)) + (let (v117 i1) (eq v116 0)) + (let (v118 i32) (cast v117)) + (let (v119 i1) (neq v118 0)) + (condbr v119 (block 7 v152 v161) (block 21))) + + (block 16 + (param v85 i32) + (param v86 i32) + (param v89 i32) + (param v95 i32) + (param v99 i32) + (param v121 i32) + (param v153 i32) + (param v162 i32) + (let (v87 i32) (const.i32 -4)) + (let (v88 i32) (band v86 v87)) + (let (v90 i32) (const.i32 3)) + (let (v91 i32) (band v89 v90)) + (let (v92 i32) (bor v88 v91)) + (let (v93 u32) (cast v85)) + (let (v94 (ptr i32)) (inttoptr v93)) + (store v94 v92) + (let (v96 u32) (cast v95)) + (let (v97 (ptr i32)) (inttoptr v96)) + (let (v98 i32) (load v97)) + (let (v100 u32) (cast v99)) + (let (v101 (ptr i32)) (inttoptr v100)) + (let (v102 i32) (load v101)) + (br (block 15 v95 v98 v99 v102 v121 v153 v162))) + + (block 17 + (let (v58 i32) (const.i32 2)) + (let (v59 i32) (band v21 v58)) + (let (v60 i1) (neq v59 0)) + (condbr v60 (block 16 v32 v23 v38 v27 v18 v32 v13 v0) (block 19))) + + (block 18 + (br (block 16 v32 v23 v38 v27 v18 v32 v13 v0))) + + (block 19 + (let (v61 u32) (cast v56)) + (let (v62 u32) (add.checked v61 4)) + (let (v63 (ptr i32)) (inttoptr v62)) + (let (v64 i32) (load v63)) + (let (v65 i32) (const.i32 3)) + (let (v66 i32) (band v64 v65)) + (let (v67 i32) (bor v66 v32)) + (let (v68 u32) (cast v56)) + (let (v69 u32) (add.checked v68 4)) + (let (v70 (ptr i32)) (inttoptr v69)) + (store v70 v67) + (let (v71 u32) (cast v18)) + (let (v72 (ptr i32)) (inttoptr v71)) + (let (v73 i32) (load v72)) + (let (v74 u32) (cast v27)) + (let (v75 (ptr i32)) (inttoptr v74)) + (let (v76 i32) (load v75)) + (let (v77 i32) (const.i32 -4)) + (let (v78 i32) (band v76 v77)) + (let (v79 i1) (eq v78 0)) + (let (v80 i32) (cast v79)) + (let (v81 i1) (neq v80 0)) + (condbr v81 (block 15 v27 v76 v18 v73 v32 v13 v0) (block 20))) + + (block 20 + (let (v82 u32) (cast v78)) + (let (v83 (ptr i32)) (inttoptr v82)) + (let (v84 i32) (load v83)) + (br (block 16 v78 v73 v84 v27 v18 v32 v13 v0))) + + (block 21 + (let (v122 u32) (cast v120)) + (let (v123 (ptr i32)) (inttoptr v122)) + (let (v124 i32) (load v123)) + (let (v125 i32) (const.i32 2)) + (let (v126 i32) (bor v124 v125)) + (let (v127 u32) (cast v120)) + (let (v128 (ptr i32)) (inttoptr v127)) + (store v128 v126) + (br (block 7 v152 v161))) + + (block 22 + (let (v137 u32) (cast v46)) + (let (v138 u32) (add.checked v137 8)) + (let (v139 (ptr i32)) (inttoptr v138)) + (let (v140 i32) (load v139)) + (let (v141 i32) (const.i32 -4)) + (let (v142 i32) (band v140 v141)) + (let (v143 u32) (cast v136)) + (let (v144 (ptr i32)) (inttoptr v143)) + (store v144 v142) + (let (v146 i32) (const.i32 1)) + (let (v147 i32) (bor v145 v146)) + (let (v148 u32) (cast v46)) + (let (v149 u32) (add.checked v148 8)) + (let (v150 (ptr i32)) (inttoptr v149)) + (store v150 v147) + (br (block 7 v154 v163))) + ) + + (func (export #wit_bindgen::rt::run_ctors_once) + (block 0 + (let (v0 i32) (const.i32 0)) + (let (v1 u32) (cast v0)) + (let (v2 u32) (add.checked v1 1048581)) + (let (v3 (ptr u8)) (inttoptr v2)) + (let (v4 u8) (load v3)) + (let (v5 i32) (zext v4)) + (let (v6 i1) (neq v5 0)) + (condbr v6 (block 2) (block 3))) + + (block 1 + (ret)) + + (block 2 + (br (block 1))) + + (block 3 + (call #__wasm_call_ctors) + (let (v7 i32) (const.i32 0)) + (let (v8 i32) (const.i32 1)) + (let (v9 u8) (trunc v8)) + (let (v10 u32) (cast v7)) + (let (v11 u32) (add.checked v10 1048581)) + (let (v12 (ptr u8)) (inttoptr v11)) + (store v12 v9) + (br (block 2))) + ) + + (func (export #cabi_realloc) + (param i32) (param i32) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) + (let (v5 i1) (neq v1 0)) + (condbr v5 (block 4) (block 5))) + + (block 1 (param v4 i32) + (ret v4)) + + (block 2 (param v19 i32) + (br (block 1 v19))) + + (block 3 (param v17 i32) + (let (v18 i1) (neq v17 0)) + (condbr v18 (block 2 v17) (block 7))) + + (block 4 + (let (v16 i32) (call #__rust_realloc v0 v1 v2 v3)) + (br (block 3 v16))) + + (block 5 + (let (v6 i1) (eq v3 0)) + (let (v7 i32) (cast v6)) + (let (v8 i1) (neq v7 0)) + (condbr v8 (block 2 v2) (block 6))) + + (block 6 + (let (v9 i32) (const.i32 0)) + (let (v10 u32) (cast v9)) + (let (v11 u32) (add.checked v10 1048580)) + (let (v12 (ptr u8)) (inttoptr v11)) + (let (v13 u8) (load v12)) + (let (v14 i32) (zext v13)) + (let (v15 i32) (call #__rust_alloc v3 v2)) + (br (block 3 v15))) + + (block 7 + (unreachable)) + ) + ) + +) diff --git a/tests/integration/expected/components/inc_wasm_component.wat b/tests/integration/expected/components/inc_wasm_component.wat index 07c879dba..48063992f 100644 --- a/tests/integration/expected/components/inc_wasm_component.wat +++ b/tests/integration/expected/components/inc_wasm_component.wat @@ -5,7 +5,7 @@ (export (;0;) "add" (func (type 0))) ) ) - (import "miden:add/add@1.0.0" (instance (;0;) (type 0))) + (import "miden:add-package/add-interface@1.0.0" (instance (;0;) (type 0))) (core module (;0;) (type (;0;) (func (param i32 i32) (result i32))) (type (;1;) (func)) @@ -13,13 +13,13 @@ (type (;3;) (func (param i32 i32 i32 i32) (result i32))) (type (;4;) (func (param i32 i32 i32) (result i32))) (type (;5;) (func (param i32 i32 i32 i32))) - (import "miden:add/add@1.0.0" "add" (func $inc_wasm_component::bindings::miden::add::add::add::wit_import (;0;) (type 0))) + (import "miden:add-package/add-interface@1.0.0" "add" (func $inc_wasm_component::bindings::miden::add_package::add_interface::add::wit_import (;0;) (type 0))) (func $__wasm_call_ctors (;1;) (type 1)) (func $inc (;2;) (type 2) (param i32) (result i32) call $wit_bindgen::rt::run_ctors_once local.get 0 i32.const 1 - call $inc_wasm_component::bindings::miden::add::add::add::wit_import + call $inc_wasm_component::bindings::miden::add_package::add_interface::add::wit_import ) (func $__rust_alloc (;3;) (type 0) (param i32 i32) (result i32) i32.const 1048576 @@ -689,7 +689,7 @@ (export "add" (func 0)) ) (core instance (;1;) (instantiate 0 - (with "miden:add/add@1.0.0" (instance 0)) + (with "miden:add-package/add-interface@1.0.0" (instance 0)) ) ) (alias core export 1 "memory" (core memory (;0;))) diff --git a/tests/integration/expected/fib.hir b/tests/integration/expected/fib.hir index 3cc933f50..b28549c44 100644 --- a/tests/integration/expected/fib.hir +++ b/tests/integration/expected/fib.hir @@ -1,4 +1,4 @@ -(module #noname +(module #miden_integration_tests_rust_fib_wasm ;; Constants (const (id 0) 0x00100000) diff --git a/tests/integration/expected/fib.masm b/tests/integration/expected/fib.masm index 77378bb31..801a8e8c9 100644 --- a/tests/integration/expected/fib.masm +++ b/tests/integration/expected/fib.masm @@ -653,7 +653,7 @@ export.load_dw end end -mod noname +mod miden_integration_tests_rust_fib_wasm export.fib push.0 @@ -689,8 +689,8 @@ end program -use noname +use miden_integration_tests_rust_fib_wasm begin - exec.noname::fib + exec.miden_integration_tests_rust_fib_wasm::fib end diff --git a/tests/integration/src/compiler_test.rs b/tests/integration/src/compiler_test.rs index 3897a2bf1..f6cbd0273 100644 --- a/tests/integration/src/compiler_test.rs +++ b/tests/integration/src/compiler_test.rs @@ -14,7 +14,7 @@ use miden_diagnostics::{ term::termcolor::ColorChoice, CodeMap, DefaultEmitter, DiagnosticsConfig, DiagnosticsHandler, Emitter, NullEmitter, SourceSpan, Verbosity, }; -use miden_frontend_wasm::{translate_module, WasmTranslationConfig}; +use miden_frontend_wasm::{translate_component, translate_module, WasmTranslationConfig}; use miden_hir::{ pass::{AnalysisManager, RewritePass, RewriteSet}, FunctionIdent, Ident, ModuleRewritePassAdapter, ProgramBuilder, Symbol, @@ -28,8 +28,10 @@ pub enum CompilerTestSource { cargo_project_folder_name: String, artifact_name: String, }, - // Wasm(String), - // Ir(String), + RustCargoComponent { + cargo_project_folder_name: String, + artifact_name: String, + }, } impl CompilerTestSource { @@ -39,14 +41,42 @@ impl CompilerTestSource { cargo_project_folder_name: _, artifact_name, } => artifact_name.clone(), + CompilerTestSource::RustCargoComponent { + cargo_project_folder_name: _, + artifact_name, + } => artifact_name.clone(), _ => panic!("Not a Rust Cargo project"), } } } +#[derive(derive_more::From)] +pub enum HirArtifact { + Program(Box), + Component(Box), +} + +impl HirArtifact { + pub fn unwrap_program(&self) -> &miden_hir::Program { + match self { + Self::Program(program) => program, + _ => panic!("attempted to unwrap a program, but had a component"), + } + } + + pub fn unwrap_component(&self) -> &miden_hir::Component { + match self { + Self::Component(program) => program, + _ => panic!("attempted to unwrap a component, but had a program"), + } + } +} + /// Compile to different stages (e.g. Wasm, IR, MASM) and compare the results against expected /// output pub struct CompilerTest { + /// The Wasm translation configuration + pub config: WasmTranslationConfig, /// The compiler session pub session: Session, /// The source code used to compile the test @@ -56,21 +86,22 @@ pub struct CompilerTest { /// The compiled Wasm component/module pub wasm_bytes: Vec, /// The compiled IR - pub hir: Option>, + pub hir: Option, /// The compiled MASM pub ir_masm: Option>, } impl CompilerTest { /// Compile the Wasm component from a Rust Cargo project using cargo-component - pub fn rust_source_cargo_component(cargo_project_folder: &str) -> Self { + pub fn rust_source_cargo_component( + cargo_project_folder: &str, + config: WasmTranslationConfig, + ) -> Self { let manifest_path = format!("../rust-apps-wasm/{}/Cargo.toml", cargo_project_folder); // dbg!(&pwd); let mut cargo_build_cmd = Command::new("cargo"); // Enable Wasm bulk-memory proposal (uses Wasm `memory.copy` op instead of `memcpy` import) cargo_build_cmd.env("RUSTFLAGS", "-C target-feature=+bulk-memory"); - // Enable Wasm bulk-memory proposal (uses Wasm `memory.copy` op instead of `memcpy` import) - cargo_build_cmd.env("RUSTFLAGS", "-C target-feature=+bulk-memory"); cargo_build_cmd .arg("component") .arg("build") @@ -128,8 +159,9 @@ impl CompilerTest { let wasm_comp_path = &wasm_artifacts.first().unwrap(); let artifact_name = wasm_comp_path.file_stem().unwrap().to_str().unwrap().to_string(); Self { + config, session: default_session(), - source: CompilerTestSource::RustCargo { + source: CompilerTestSource::RustCargoComponent { cargo_project_folder_name: cargo_project_folder.to_string(), artifact_name, }, @@ -187,10 +219,14 @@ impl CompilerTest { let session = default_session(); let entrypoint = FunctionIdent { - module: Ident::new(Symbol::intern("noname"), SourceSpan::default()), + module: Ident::new(Symbol::intern(artifact_name), SourceSpan::default()), function: Ident::new(Symbol::intern(entrypoint.to_string()), SourceSpan::default()), }; CompilerTest { + config: WasmTranslationConfig { + override_name: Some(artifact_name.to_string().into()), + ..Default::default() + }, session, source: CompilerTestSource::RustCargo { cargo_project_folder_name: cargo_project_folder.to_string(), @@ -208,6 +244,10 @@ impl CompilerTest { let wasm_bytes = compile_rust_file(rust_source); let session = default_session(); CompilerTest { + config: WasmTranslationConfig { + override_name: Some("noname".into()), + ..Default::default() + }, session, source: CompilerTestSource::Rust(rust_source.to_string()), wasm_bytes, @@ -248,6 +288,10 @@ impl CompilerTest { }; CompilerTest { + config: WasmTranslationConfig { + override_name: Some("noname".into()), + ..Default::default() + }, session, source: CompilerTestSource::Rust(rust_source.to_string()), wasm_bytes, @@ -264,35 +308,74 @@ impl CompilerTest { expected_wat_file.assert_eq(&wat); } + fn wasm_to_ir(&self) -> HirArtifact { + match &self.source { + CompilerTestSource::RustCargoComponent { .. } => { + // Wasm component is expected + let ir_component = + translate_component(&self.wasm_bytes, &self.config, &self.session.diagnostics) + .expect("Failed to translate Wasm to IR component"); + Box::new(ir_component).into() + } + _ => { + // Wasm module is expected + use miden_hir_transform as transforms; + let mut ir_module = + translate_module(&self.wasm_bytes, &self.config, &self.session.diagnostics) + .expect("Failed to translate Wasm to IR module"); + + let mut analyses = AnalysisManager::new(); + let mut rewrites = RewriteSet::default(); + rewrites.push(ModuleRewritePassAdapter::new(transforms::SplitCriticalEdges)); + rewrites.push(ModuleRewritePassAdapter::new(transforms::Treeify)); + rewrites.push(ModuleRewritePassAdapter::new(transforms::InlineBlocks)); + rewrites + .apply(&mut ir_module, &mut analyses, &self.session) + .expect("Failed to apply rewrites"); + + let mut builder = ProgramBuilder::new(&self.session.diagnostics) + .with_module(Box::new(ir_module)) + .unwrap(); + if let Some(entrypoint) = self.entrypoint.as_ref() { + builder = builder.with_entrypoint(entrypoint.clone()); + } + let hir_program = builder.link().expect("Failed to link IR program"); + hir_program.into() + } + } + } + + /// Get the compiled IR, compiling the Wasm if it has not been compiled yet + pub fn hir(&mut self) -> &HirArtifact { + if self.hir.is_none() { + self.hir = Some(self.wasm_to_ir()); + } + self.hir.as_ref().unwrap() + } + /// Compare the compiled IR against the expected output pub fn expect_ir(&mut self, expected_hir_file: expect_test::ExpectFile) { - let hir_program = if let Some(hir) = self.hir.as_ref() { - hir - } else { - let hir_module = wasm_to_ir(&self.wasm_bytes, &self.session); - let mut builder = ProgramBuilder::new(&self.session.diagnostics) - .with_module(hir_module.into()) - .unwrap(); - if let Some(entrypoint) = self.entrypoint.as_ref() { - builder = builder.with_entrypoint(entrypoint.clone()); + match self.hir() { + HirArtifact::Program(hir_program) => { + // Program does not implement pretty printer yet, use the first module + let ir_module = demangle( + &hir_program + .modules() + .iter() + .take(1) + .collect::>() + .first() + .expect("no module in IR program") + .to_string() + .as_str(), + ); + expected_hir_file.assert_eq(&ir_module); } - let hir_program = builder.link().expect("Failed to link IR program"); - self.hir = Some(hir_program); - self.hir.as_ref().unwrap() - }; - // Program does not implement pretty printer yet, use the first module - let ir_module = demangle( - &hir_program - .modules() - .iter() - .take(1) - .collect::>() - .first() - .expect("no module in IR program") - .to_string() - .as_str(), - ); - expected_hir_file.assert_eq(&ir_module); + HirArtifact::Component(hir_component) => { + let ir_component = demangle(&hir_component.to_string()); + expected_hir_file.assert_eq(&ir_component); + } + } } /// Compare the compiled MASM against the expected output @@ -335,7 +418,12 @@ impl CompilerTest { if self.ir_masm.is_none() { let mut compiler = MasmCompiler::new(&self.session); let hir = self.hir.take().expect("IR is not compiled"); - let ir_masm = compiler.compile(hir).unwrap(); + let ir_masm = match hir { + HirArtifact::Program(hir_program) => compiler.compile(hir_program).unwrap(), + HirArtifact::Component(_hir_component) => { + todo!("Component to MASM compilation is not implemented yet") + } + }; let frozen = ir_masm.freeze(); self.ir_masm = Some(frozen); } @@ -433,23 +521,3 @@ fn hash_string(inputs: &str) -> String { let hash = ::digest(inputs.as_bytes()); format!("{:x}", hash) } - -fn wasm_to_ir(wasm_bytes: &[u8], session: &Session) -> miden_hir::Module { - use miden_hir_transform as transforms; - let config = WasmTranslationConfig { - override_name: Some("noname".into()), - ..Default::default() - }; - let mut ir_module = translate_module(wasm_bytes, &config, &session.diagnostics) - .expect("Failed to translate Wasm to IR module"); - - let mut analyses = AnalysisManager::new(); - let mut rewrites = RewriteSet::default(); - rewrites.push(ModuleRewritePassAdapter::new(transforms::SplitCriticalEdges)); - rewrites.push(ModuleRewritePassAdapter::new(transforms::Treeify)); - rewrites.push(ModuleRewritePassAdapter::new(transforms::InlineBlocks)); - rewrites - .apply(&mut ir_module, &mut analyses, session) - .expect("Failed to apply rewrites"); - ir_module -} diff --git a/tests/integration/src/rust_masm_tests/components.rs b/tests/integration/src/rust_masm_tests/components.rs index 57a51655b..77a39488c 100644 --- a/tests/integration/src/rust_masm_tests/components.rs +++ b/tests/integration/src/rust_masm_tests/components.rs @@ -1,31 +1,13 @@ -use crate::compiler_test::default_session; -use crate::CompilerTest; use expect_test::expect_file; use miden_core::crypto::hash::RpoDigest; -use miden_frontend_wasm::translate_component; -use miden_frontend_wasm::ExportMetadata; -use miden_frontend_wasm::ImportMetadata; -use miden_frontend_wasm::WasmTranslationConfig; -use miden_hir::InterfaceFunctionIdent; -use miden_hir::InterfaceIdent; -use miden_hir::LiftedFunctionType; -use miden_hir::Symbol; -use miden_hir::Type; +use miden_frontend_wasm::{ExportMetadata, ImportMetadata, WasmTranslationConfig}; +use miden_hir::{InterfaceFunctionIdent, InterfaceIdent, LiftedFunctionType, Symbol, Type}; + +use crate::CompilerTest; #[test] fn wcm_add() { // Has no imports - let test = CompilerTest::rust_source_cargo_component("add-comp"); - let artifact_name = test.source.artifact_name(); - test.expect_wasm(expect_file![format!( - "../../expected/components/{artifact_name}.wat" - )]); - // test.expect_wit_bind(expect_file![format!( - // "../../expected/components/bindings/{artifact_name}_bindings.rs" - // )]); - let wasm_bytes = test.wasm_bytes; - - let session = default_session(); let export_metadata = [( Symbol::intern("add").into(), ExportMetadata { @@ -38,28 +20,20 @@ fn wcm_add() { export_metadata, ..Default::default() }; - let component = translate_component(&wasm_bytes, &config, &session.diagnostics) - .expect("Failed to translate Wasm to IR module"); - assert!(!component.modules().is_empty()); + let mut test = CompilerTest::rust_source_cargo_component("add-comp", config); + let artifact_name = test.source.artifact_name(); + test.expect_wasm(expect_file![format!("../../expected/components/{artifact_name}.wat")]); + test.expect_ir(expect_file![format!("../../expected/components/{artifact_name}.hir")]); } #[test] fn wcm_inc() { // Imports an add component used in the above test - let test = CompilerTest::rust_source_cargo_component("inc-comp"); - let artifact_name = test.source.artifact_name(); - test.expect_wasm(expect_file![format!( - "../../expected/components/{artifact_name}.wat" - )]); - // test.expect_wit_bind(expect_file![format!( - // "../../expected/components/bindings/{artifact_name}_bindings.rs" - // )]); - let wasm_bytes = test.wasm_bytes; - - let session = default_session(); let interface_function_ident = InterfaceFunctionIdent { - interface: InterfaceIdent::from_full_ident("miden:add/add@1.0.0".to_string()), + interface: InterfaceIdent::from_full_ident( + "miden:add-package/add-interface@1.0.0".to_string(), + ), function: Symbol::intern("add"), }; let import_metadata = [( @@ -84,19 +58,24 @@ fn wcm_inc() { export_metadata, ..Default::default() }; - let ir = translate_component(&wasm_bytes, &config, &session.diagnostics) - .expect("Failed to translate Wasm to IR module"); - assert!(!ir.modules().is_empty()); + let mut test = CompilerTest::rust_source_cargo_component("inc-comp", config); + let artifact_name = test.source.artifact_name(); + test.expect_wasm(expect_file![format!("../../expected/components/{artifact_name}.wat")]); + test.expect_ir(expect_file![format!("../../expected/components/{artifact_name}.hir")]); + + let ir_component = test.hir().unwrap_component(); + + assert!(!ir_component.modules().is_empty()); let export_name_sym = Symbol::intern("inc"); - let export = ir.exports().get(&export_name_sym.into()).unwrap(); + let export = ir_component.exports().get(&export_name_sym.into()).unwrap(); assert_eq!(export.function.function.as_symbol(), export_name_sym); let expected_export_func_ty = LiftedFunctionType { params: vec![Type::U32], results: vec![Type::U32], }; assert_eq!(export.function_ty, expected_export_func_ty); - let module = ir.modules().front().get().unwrap(); + let module = ir_component.modules().front().get().unwrap(); dbg!(&module.imports()); let import_info = module.imports(); let function_id = import_info @@ -110,11 +89,8 @@ fn wcm_inc() { .clone(); assert_eq!(function_id.module, module.name); // assert_eq!(function_id.function, interface_function_ident.function); - let component_import = ir.imports().get(&function_id).unwrap(); - assert_eq!( - component_import.interface_function, - interface_function_ident - ); + let component_import = ir_component.imports().get(&function_id).unwrap(); + assert_eq!(component_import.interface_function, interface_function_ident); assert!(!component_import.function_ty.params.is_empty()); let expected_import_func_ty = LiftedFunctionType { params: vec![Type::U32, Type::U32], diff --git a/tests/integration/src/rust_masm_tests/sdk.rs b/tests/integration/src/rust_masm_tests/sdk.rs index c47748a3e..d00023bef 100644 --- a/tests/integration/src/rust_masm_tests/sdk.rs +++ b/tests/integration/src/rust_masm_tests/sdk.rs @@ -1,29 +1,24 @@ -use crate::CompilerTest; use expect_test::expect_file; +use crate::CompilerTest; + #[test] fn sdk() { - let test = CompilerTest::rust_source_cargo_component("sdk/sdk"); + let test = CompilerTest::rust_source_cargo_component("sdk/sdk", Default::default()); let artifact_name = test.source.artifact_name(); - test.expect_wasm(expect_file![format!( - "../../expected/sdk_basic_wallet/{artifact_name}.wat" - )]); + test.expect_wasm(expect_file![format!("../../expected/sdk_basic_wallet/{artifact_name}.wat")]); } #[test] fn sdk_basic_wallet() { - let test = CompilerTest::rust_source_cargo_component("sdk/basic-wallet"); + let test = CompilerTest::rust_source_cargo_component("sdk/basic-wallet", Default::default()); let artifact_name = test.source.artifact_name(); - test.expect_wasm(expect_file![format!( - "../../expected/sdk_basic_wallet/{artifact_name}.wat" - )]); + test.expect_wasm(expect_file![format!("../../expected/sdk_basic_wallet/{artifact_name}.wat")]); } #[test] fn sdk_basic_wallet_p2id_note() { - let test = CompilerTest::rust_source_cargo_component("sdk/p2id-note"); + let test = CompilerTest::rust_source_cargo_component("sdk/p2id-note", Default::default()); let artifact_name = test.source.artifact_name(); - test.expect_wasm(expect_file![format!( - "../../expected/sdk_basic_wallet/{artifact_name}.wat" - )]); + test.expect_wasm(expect_file![format!("../../expected/sdk_basic_wallet/{artifact_name}.wat")]); } diff --git a/tests/rust-apps-wasm/add-comp/src/bindings.rs b/tests/rust-apps-wasm/add-comp/src/bindings.rs index 3ca31dc0d..b5ca7dd6d 100644 --- a/tests/rust-apps-wasm/add-comp/src/bindings.rs +++ b/tests/rust-apps-wasm/add-comp/src/bindings.rs @@ -1,10 +1,10 @@ // Generated by `wit-bindgen` 0.16.0. DO NOT EDIT! pub mod exports { pub mod miden { - pub mod add { + pub mod add_package { #[allow(clippy::all)] - pub mod add { + pub mod add_interface { #[used] #[doc(hidden)] #[cfg(target_arch = "wasm32")] @@ -12,7 +12,7 @@ pub mod exports { const _: () = { #[doc(hidden)] - #[export_name = "miden:add/add@1.0.0#add"] + #[export_name = "miden:add-package/add-interface@1.0.0#add"] #[allow(non_snake_case)] unsafe extern "C" fn __export_add(arg0: i32,arg1: i32,) -> i32 { #[allow(unused_imports)] @@ -50,7 +50,7 @@ pub mod exports { #[cfg(target_arch = "wasm32")] #[link_section = "component-type:add-world"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 273] = [3, 0, 9, 97, 100, 100, 45, 119, 111, 114, 108, 100, 0, 97, 115, 109, 13, 0, 1, 0, 7, 49, 1, 65, 2, 1, 66, 2, 1, 64, 2, 1, 97, 121, 1, 98, 121, 0, 121, 4, 0, 3, 97, 100, 100, 1, 0, 4, 1, 19, 109, 105, 100, 101, 110, 58, 97, 100, 100, 47, 97, 100, 100, 64, 49, 46, 48, 46, 48, 5, 0, 11, 9, 1, 0, 3, 97, 100, 100, 3, 0, 0, 7, 82, 1, 65, 2, 1, 65, 2, 1, 66, 2, 1, 64, 2, 1, 97, 121, 1, 98, 121, 0, 121, 4, 0, 3, 97, 100, 100, 1, 0, 4, 1, 19, 109, 105, 100, 101, 110, 58, 97, 100, 100, 47, 97, 100, 100, 64, 49, 46, 48, 46, 48, 5, 0, 4, 1, 25, 109, 105, 100, 101, 110, 58, 97, 100, 100, 47, 97, 100, 100, 45, 119, 111, 114, 108, 100, 64, 49, 46, 48, 46, 48, 4, 0, 11, 15, 1, 0, 9, 97, 100, 100, 45, 119, 111, 114, 108, 100, 3, 2, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 327] = [3, 0, 9, 97, 100, 100, 45, 119, 111, 114, 108, 100, 0, 97, 115, 109, 13, 0, 1, 0, 7, 67, 1, 65, 2, 1, 66, 2, 1, 64, 2, 1, 97, 121, 1, 98, 121, 0, 121, 4, 0, 3, 97, 100, 100, 1, 0, 4, 1, 37, 109, 105, 100, 101, 110, 58, 97, 100, 100, 45, 112, 97, 99, 107, 97, 103, 101, 47, 97, 100, 100, 45, 105, 110, 116, 101, 114, 102, 97, 99, 101, 64, 49, 46, 48, 46, 48, 5, 0, 11, 19, 1, 0, 13, 97, 100, 100, 45, 105, 110, 116, 101, 114, 102, 97, 99, 101, 3, 0, 0, 7, 108, 1, 65, 2, 1, 65, 2, 1, 66, 2, 1, 64, 2, 1, 97, 121, 1, 98, 121, 0, 121, 4, 0, 3, 97, 100, 100, 1, 0, 4, 1, 37, 109, 105, 100, 101, 110, 58, 97, 100, 100, 45, 112, 97, 99, 107, 97, 103, 101, 47, 97, 100, 100, 45, 105, 110, 116, 101, 114, 102, 97, 99, 101, 64, 49, 46, 48, 46, 48, 5, 0, 4, 1, 33, 109, 105, 100, 101, 110, 58, 97, 100, 100, 45, 112, 97, 99, 107, 97, 103, 101, 47, 97, 100, 100, 45, 119, 111, 114, 108, 100, 64, 49, 46, 48, 46, 48, 4, 0, 11, 15, 1, 0, 9, 97, 100, 100, 45, 119, 111, 114, 108, 100, 3, 2, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; #[inline(never)] #[doc(hidden)] diff --git a/tests/rust-apps-wasm/add-comp/src/lib.rs b/tests/rust-apps-wasm/add-comp/src/lib.rs index efaacdcf2..d7b0625f6 100644 --- a/tests/rust-apps-wasm/add-comp/src/lib.rs +++ b/tests/rust-apps-wasm/add-comp/src/lib.rs @@ -10,7 +10,7 @@ fn my_panic(_info: &core::panic::PanicInfo) -> ! { mod bindings; -use crate::bindings::exports::miden::add::add::Guest; +use crate::bindings::exports::miden::add_package::add_interface::Guest; struct Component; diff --git a/tests/rust-apps-wasm/add-comp/wit/add.wit b/tests/rust-apps-wasm/add-comp/wit/add.wit index 58515f715..b4dca0330 100644 --- a/tests/rust-apps-wasm/add-comp/wit/add.wit +++ b/tests/rust-apps-wasm/add-comp/wit/add.wit @@ -1,9 +1,9 @@ -package miden:add@1.0.0; +package miden:add-package@1.0.0; -interface add { +interface add-interface { add: func(a: u32, b: u32) -> u32; } world add-world { - export add; + export add-interface; } diff --git a/tests/rust-apps-wasm/inc-comp/src/bindings.rs b/tests/rust-apps-wasm/inc-comp/src/bindings.rs index f2d746c01..c235308e5 100644 --- a/tests/rust-apps-wasm/inc-comp/src/bindings.rs +++ b/tests/rust-apps-wasm/inc-comp/src/bindings.rs @@ -31,10 +31,10 @@ pub trait Guest { fn inc(a: u32,) -> u32; } pub mod miden { - pub mod add { + pub mod add_package { #[allow(clippy::all)] - pub mod add { + pub mod add_interface { #[used] #[doc(hidden)] #[cfg(target_arch = "wasm32")] @@ -47,7 +47,7 @@ pub mod miden { unsafe { #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "miden:add/add@1.0.0")] + #[link(wasm_import_module = "miden:add-package/add-interface@1.0.0")] extern "C" { #[link_name = "add"] fn wit_import(_: i32, _: i32, ) -> i32; @@ -68,7 +68,7 @@ pub mod miden { #[cfg(target_arch = "wasm32")] #[link_section = "component-type:inc"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 209] = [3, 0, 3, 105, 110, 99, 0, 97, 115, 109, 13, 0, 1, 0, 7, 92, 1, 65, 2, 1, 65, 4, 1, 66, 2, 1, 64, 2, 1, 97, 121, 1, 98, 121, 0, 121, 4, 0, 3, 97, 100, 100, 1, 0, 3, 1, 19, 109, 105, 100, 101, 110, 58, 97, 100, 100, 47, 97, 100, 100, 64, 49, 46, 48, 46, 48, 5, 0, 1, 64, 1, 1, 97, 121, 0, 121, 4, 0, 3, 105, 110, 99, 1, 1, 4, 1, 19, 109, 105, 100, 101, 110, 58, 105, 110, 99, 47, 105, 110, 99, 64, 49, 46, 48, 46, 48, 4, 0, 11, 9, 1, 0, 3, 105, 110, 99, 3, 0, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 235] = [3, 0, 3, 105, 110, 99, 0, 97, 115, 109, 13, 0, 1, 0, 7, 118, 1, 65, 2, 1, 65, 4, 1, 66, 2, 1, 64, 2, 1, 97, 121, 1, 98, 121, 0, 121, 4, 0, 3, 97, 100, 100, 1, 0, 3, 1, 37, 109, 105, 100, 101, 110, 58, 97, 100, 100, 45, 112, 97, 99, 107, 97, 103, 101, 47, 97, 100, 100, 45, 105, 110, 116, 101, 114, 102, 97, 99, 101, 64, 49, 46, 48, 46, 48, 5, 0, 1, 64, 1, 1, 97, 121, 0, 121, 4, 0, 3, 105, 110, 99, 1, 1, 4, 1, 27, 109, 105, 100, 101, 110, 58, 105, 110, 99, 45, 112, 97, 99, 107, 97, 103, 101, 47, 105, 110, 99, 64, 49, 46, 48, 46, 48, 4, 0, 11, 9, 1, 0, 3, 105, 110, 99, 3, 0, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; #[inline(never)] #[doc(hidden)] diff --git a/tests/rust-apps-wasm/inc-comp/src/lib.rs b/tests/rust-apps-wasm/inc-comp/src/lib.rs index 496cf71fb..78070e7ad 100644 --- a/tests/rust-apps-wasm/inc-comp/src/lib.rs +++ b/tests/rust-apps-wasm/inc-comp/src/lib.rs @@ -10,8 +10,7 @@ fn my_panic(_info: &core::panic::PanicInfo) -> ! { mod bindings; -use crate::bindings::miden::add::add::add; -use crate::bindings::Guest; +use crate::bindings::{miden::add_package::add_interface::add, Guest}; struct Component; diff --git a/tests/rust-apps-wasm/inc-comp/wit/inc.wit b/tests/rust-apps-wasm/inc-comp/wit/inc.wit index 213543895..b63637af8 100644 --- a/tests/rust-apps-wasm/inc-comp/wit/inc.wit +++ b/tests/rust-apps-wasm/inc-comp/wit/inc.wit @@ -1,8 +1,8 @@ -package miden:inc@1.0.0; +package miden:inc-package@1.0.0; -use miden:add/add@1.0.0; +use miden:add-package/add-interface@1.0.0; world inc { - import add; + import add-interface; export inc: func(a: u32) -> u32; }