From 4e22dc34a008313305a9479426257e687bda9078 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Tue, 28 May 2024 16:32:30 +0300 Subject: [PATCH 1/2] test: tx_kernel::get_inputs MASM compilation test --- hir/src/dataflow.rs | 4 + .../abi_transform_tx_kernel_get_inputs.hir | 834 ++++++++++++++++++ .../abi_transform_tx_kernel_get_inputs.wat | 629 +++++++++++++ tests/integration/src/compiler_test.rs | 66 ++ .../src/rust_masm_tests/abi_transform/mod.rs | 1 + .../abi_transform/tx_kernel.rs | 30 + 6 files changed, 1564 insertions(+) create mode 100644 tests/integration/expected/abi_transform_tx_kernel_get_inputs.hir create mode 100644 tests/integration/expected/abi_transform_tx_kernel_get_inputs.wat create mode 100644 tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs diff --git a/hir/src/dataflow.rs b/hir/src/dataflow.rs index 957abdb5f..7091f9ddf 100644 --- a/hir/src/dataflow.rs +++ b/hir/src/dataflow.rs @@ -578,6 +578,10 @@ impl DataFlowGraph { pub fn create_block_after(&mut self, block: Block) -> Block { let id = self.blocks.create(); let data = BlockData::new(id); + assert!( + self.blocks.get(block).is_some(), + "cannot insert a new block after {block}, it is not linked" + ); self.blocks.insert_after(id, block, data); id } diff --git a/tests/integration/expected/abi_transform_tx_kernel_get_inputs.hir b/tests/integration/expected/abi_transform_tx_kernel_get_inputs.hir new file mode 100644 index 000000000..cc895102a --- /dev/null +++ b/tests/integration/expected/abi_transform_tx_kernel_get_inputs.hir @@ -0,0 +1,834 @@ +(component + ;; Component Imports + (lower ((digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi canon) (param felt) (result i32 felt)))) (#miden:tx_kernel/note #get_inputs) + + ;; Modules + (module #abi_transform_tx_kernel_get_inputs + ;; Constants + (const (id 0) 0x00100000) + + ;; Global Variables + (global (export #__stack_pointer) (id 0) (type i32) (const 0)) + + ;; Functions + (func (export #entrypoint) (param i32) + (block 0 (param v0 i32) + (call #miden_sdk_tx_kernel::get_inputs v0) + (br (block 1))) + + (block 1 + (ret)) + ) + + (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_alloc_zeroed) (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)) + (let (v5 i1) (eq v4 0)) + (let (v6 i32) (cast v5)) + (let (v7 i1) (neq v6 0)) + (condbr v7 (block 2 v4) (block 3))) + + (block 1 (param v2 i32) + (ret v2)) + + (block 2 (param v9 i32) + (br (block 1 v9))) + + (block 3 + (let (v8 i32) (const.i32 0)) + (assert.eq 0 v8) + (br (block 2 v4))) + ) + + (func (export #wee_alloc::neighbors::Neighbors::remove) + (param i32) + (block 0 (param v0 i32) + (let (v1 i32) (const.i32 0)) + (let (v2 u32) (cast v0)) + (let (v3 (ptr i32)) (inttoptr v2)) + (let (v4 i32) (load v3)) + (let (v5 i32) (const.i32 2)) + (let (v6 i32) (band v4 v5)) + (let (v7 i1) (neq v6 0)) + (condbr v7 (block 2 v0 v4) (block 3))) + + (block 1 + (ret)) + + (block 2 (param v32 i32) (param v47 i32) + (let (v33 u32) (cast v32)) + (let (v34 u32) (add.checked v33 4)) + (let (v35 (ptr i32)) (inttoptr v34)) + (let (v36 i32) (load v35)) + (let (v37 i32) (const.i32 -4)) + (let (v38 i32) (band v36 v37)) + (let (v39 i1) (eq v38 0)) + (let (v40 i32) (cast v39)) + (let (v41 i1) (neq v40 0)) + (condbr v41 (block 5 v32 v36 v47) (block 6))) + + (block 3 + (let (v8 i32) (const.i32 -4)) + (let (v9 i32) (band v4 v8)) + (let (v10 i1) (eq v9 0)) + (let (v11 i32) (cast v10)) + (let (v12 i1) (neq v11 0)) + (condbr v12 (block 2 v0 v4) (block 4))) + + (block 4 + (let (v13 u32) (cast v9)) + (let (v14 u32) (add.checked v13 4)) + (let (v15 (ptr i32)) (inttoptr v14)) + (let (v16 i32) (load v15)) + (let (v17 i32) (const.i32 3)) + (let (v18 i32) (band v16 v17)) + (let (v19 u32) (cast v0)) + (let (v20 u32) (add.checked v19 4)) + (let (v21 (ptr i32)) (inttoptr v20)) + (let (v22 i32) (load v21)) + (let (v23 i32) (const.i32 -4)) + (let (v24 i32) (band v22 v23)) + (let (v25 i32) (bor v18 v24)) + (let (v26 u32) (cast v9)) + (let (v27 u32) (add.checked v26 4)) + (let (v28 (ptr i32)) (inttoptr v27)) + (store v28 v25) + (let (v29 u32) (cast v0)) + (let (v30 (ptr i32)) (inttoptr v29)) + (let (v31 i32) (load v30)) + (br (block 2 v0 v31))) + + (block 5 (param v60 i32) (param v61 i32) (param v67 i32) + (let (v62 i32) (const.i32 3)) + (let (v63 i32) (band v61 v62)) + (let (v64 u32) (cast v60)) + (let (v65 u32) (add.checked v64 4)) + (let (v66 (ptr i32)) (inttoptr v65)) + (store v66 v63) + (let (v68 i32) (const.i32 3)) + (let (v69 i32) (band v67 v68)) + (let (v70 u32) (cast v60)) + (let (v71 (ptr i32)) (inttoptr v70)) + (store v71 v69) + (br (block 1))) + + (block 6 + (let (v42 u32) (cast v38)) + (let (v43 (ptr i32)) (inttoptr v42)) + (let (v44 i32) (load v43)) + (let (v45 i32) (const.i32 3)) + (let (v46 i32) (band v44 v45)) + (let (v48 i32) (const.i32 -4)) + (let (v49 i32) (band v47 v48)) + (let (v50 i32) (bor v46 v49)) + (let (v51 u32) (cast v38)) + (let (v52 (ptr i32)) (inttoptr v51)) + (store v52 v50) + (let (v53 u32) (cast v32)) + (let (v54 u32) (add.checked v53 4)) + (let (v55 (ptr i32)) (inttoptr v54)) + (let (v56 i32) (load v55)) + (let (v57 u32) (cast v32)) + (let (v58 (ptr i32)) (inttoptr v57)) + (let (v59 i32) (load v58)) + (br (block 5 v32 v56 v59))) + ) + + (func (export #::new_cell_for_free_list) + (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 2)) + (let (v5 i32) (shl.wrapping v2 v4)) + (let (v6 i32) (const.i32 3)) + (let (v7 i32) (shl.wrapping v3 v6)) + (let (v8 i32) (const.i32 512)) + (let (v9 i32) (add.wrapping v7 v8)) + (let (v10 u32) (cast v5)) + (let (v11 u32) (cast v9)) + (let (v12 i1) (gt v10 v11)) + (let (v13 i32) (cast v12)) + (let (v14 i1) (neq v13 0)) + (let (v15 i32) (select v14 v5 v9)) + (let (v16 i32) (const.i32 65543)) + (let (v17 i32) (add.wrapping v15 v16)) + (let (v18 i32) (const.i32 16)) + (let (v19 u32) (cast v17)) + (let (v20 u32) (cast v18)) + (let (v21 u32) (shr.wrapping v19 v20)) + (let (v22 i32) (cast v21)) + (let (v23 u32) (cast v22)) + (let (v24 i32) (memory.grow v23)) + (let (v25 i32) (const.i32 -1)) + (let (v26 i1) (neq v24 v25)) + (let (v27 i32) (cast v26)) + (let (v28 i1) (neq v27 0)) + (condbr v28 (block 3) (block 4))) + + (block 1 + (ret)) + + (block 2 (param v45 i32) (param v46 i32) (param v50 i32) + (let (v47 u32) (cast v45)) + (let (v48 u32) (add.checked v47 4)) + (let (v49 (ptr i32)) (inttoptr v48)) + (store v49 v46) + (let (v51 u32) (cast v45)) + (let (v52 (ptr i32)) (inttoptr v51)) + (store v52 v50) + (br (block 1))) + + (block 3 + (let (v31 i32) (const.i32 16)) + (let (v32 i32) (shl.wrapping v24 v31)) + (let (v33 i64) (const.i64 0)) + (let (v34 u32) (cast v32)) + (let (v35 u32) (add.checked v34 4)) + (let (v36 (ptr i64)) (inttoptr v35)) + (store v36 v33) + (let (v37 i32) (const.i32 -65536)) + (let (v38 i32) (band v17 v37)) + (let (v39 i32) (add.wrapping v32 v38)) + (let (v40 i32) (const.i32 2)) + (let (v41 i32) (bor v39 v40)) + (let (v42 u32) (cast v32)) + (let (v43 (ptr i32)) (inttoptr v42)) + (store v43 v41) + (let (v44 i32) (const.i32 0)) + (br (block 2 v0 v32 v44))) + + (block 4 + (let (v29 i32) (const.i32 1)) + (let (v30 i32) (const.i32 0)) + (br (block 2 v0 v30 v29))) + ) + + (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 i32) (const.i32 -1)) + (let (v6 i32) (add.wrapping v1 v5)) + (let (v7 i32) (const.i32 0)) + (let (v8 i32) (const.i32 0)) + (let (v9 i32) (sub.wrapping v8 v1)) + (let (v10 i32) (const.i32 2)) + (let (v11 i32) (shl.wrapping v0 v10)) + (let (v12 u32) (cast v2)) + (let (v13 (ptr i32)) (inttoptr v12)) + (let (v14 i32) (load v13)) + (br (block 2 v14 v11 v9 v6 v2 v7))) + + (block 1 (param v3 i32)) + + (block 2 + (param v16 i32) + (param v181 i32) + (param v184 i32) + (param v187 i32) + (param v190 i32) + (param v209 i32) + (let (v17 i1) (eq v16 0)) + (let (v18 i32) (cast v17)) + (let (v19 i1) (neq v18 0)) + (condbr v19 (block 5 v209) (block 6))) + + (block 3 (param v15 i32)) + + (block 4 + (param v210 i32) + (param v211 i32) + (param v214 i32) + (param v215 i32) + (param v216 i32) + (param v217 i32) + (let (v212 u32) (cast v210)) + (let (v213 (ptr i32)) (inttoptr v212)) + (store v213 v211) + (br (block 2 v211 v214 v215 v216 v210 v217))) + + (block 5 (param v208 i32) + (ret v208)) + + (block 6 + (br (block 9 v16 v181 v184 v187 v190 v209))) + + (block 7 (param v200 i32) (param v201 i32) + (let (v202 i32) (const.i32 1)) + (let (v203 i32) (bor v201 v202)) + (let (v204 u32) (cast v200)) + (let (v205 (ptr i32)) (inttoptr v204)) + (store v205 v203) + (let (v206 i32) (const.i32 8)) + (let (v207 i32) (add.wrapping v200 v206)) + (br (block 5 v207))) + + (block 8 + (let (v191 i32) (const.i32 -3)) + (let (v192 i32) (band v127 v191)) + (let (v193 u32) (cast v108)) + (let (v194 (ptr i32)) (inttoptr v193)) + (store v194 v192) + (let (v195 u32) (cast v106)) + (let (v196 (ptr i32)) (inttoptr v195)) + (let (v197 i32) (load v196)) + (let (v198 i32) (const.i32 2)) + (let (v199 i32) (bor v197 v198)) + (br (block 7 v106 v199))) + + (block 9 + (param v20 i32) + (param v36 i32) + (param v45 i32) + (param v52 i32) + (param v55 i32) + (param v218 i32) + (let (v21 u32) (cast v20)) + (let (v22 u32) (add.checked v21 8)) + (let (v23 (ptr i32)) (inttoptr v22)) + (let (v24 i32) (load v23)) + (let (v25 i32) (const.i32 1)) + (let (v26 i32) (band v24 v25)) + (let (v27 i1) (neq v26 0)) + (condbr v27 (block 11) (block 12))) + + (block 10) + + (block 11 + (let (v136 i32) (const.i32 -2)) + (let (v137 i32) (band v24 v136)) + (let (v138 u32) (cast v20)) + (let (v139 u32) (add.checked v138 8)) + (let (v140 (ptr i32)) (inttoptr v139)) + (store v140 v137) + (let (v141 u32) (cast v20)) + (let (v142 u32) (add.checked v141 4)) + (let (v143 (ptr i32)) (inttoptr v142)) + (let (v144 i32) (load v143)) + (let (v145 i32) (const.i32 -4)) + (let (v146 i32) (band v144 v145)) + (let (v147 i1) (neq v146 0)) + (condbr v147 (block 22) (block 23))) + + (block 12 + (let (v28 u32) (cast v20)) + (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 i32) (const.i32 8)) + (let (v34 i32) (add.wrapping v20 v33)) + (let (v35 i32) (sub.wrapping v32 v34)) + (let (v37 u32) (cast v35)) + (let (v38 u32) (cast v36)) + (let (v39 i1) (lt v37 v38)) + (let (v40 i32) (cast v39)) + (let (v41 i1) (neq v40 0)) + (condbr v41 (block 4 v55 v24 v36 v45 v52 v218) (block 13))) + + (block 13 + (let (v42 i32) (const.i32 72)) + (let (v43 i32) (add.wrapping v34 v42)) + (let (v44 i32) (sub.wrapping v32 v36)) + (let (v46 i32) (band v44 v45)) + (let (v47 u32) (cast v43)) + (let (v48 u32) (cast v46)) + (let (v49 i1) (lte v47 v48)) + (let (v50 i32) (cast v49)) + (let (v51 i1) (neq v50 0)) + (condbr v51 (block 14) (block 15))) + + (block 14 + (let (v63 i32) (const.i32 0)) + (let (v64 i32) (const.i32 0)) + (let (v65 u32) (cast v46)) + (let (v66 (ptr i32)) (inttoptr v65)) + (store v66 v64) + (let (v67 i32) (const.i32 -8)) + (let (v68 i32) (add.wrapping v46 v67)) + (let (v69 i64) (const.i64 0)) + (let (v70 u32) (cast v68)) + (let (v71 (ptr i64)) (inttoptr v70)) + (store v71 v69) + (let (v72 u32) (cast v20)) + (let (v73 (ptr i32)) (inttoptr v72)) + (let (v74 i32) (load v73)) + (let (v75 i32) (const.i32 -4)) + (let (v76 i32) (band v74 v75)) + (let (v77 u32) (cast v68)) + (let (v78 (ptr i32)) (inttoptr v77)) + (store v78 v76) + (let (v79 u32) (cast v20)) + (let (v80 (ptr i32)) (inttoptr v79)) + (let (v81 i32) (load v80)) + (let (v82 i32) (const.i32 2)) + (let (v83 i32) (band v81 v82)) + (let (v84 i1) (neq v83 0)) + (condbr v84 (block 17 v68 v63 v20) (block 18))) + + (block 15 + (let (v53 i32) (band v52 v34)) + (let (v54 i1) (neq v53 0)) + (condbr v54 (block 4 v55 v24 v36 v45 v52 v218) (block 16))) + + (block 16 + (let (v56 i32) (const.i32 -4)) + (let (v57 i32) (band v24 v56)) + (let (v58 u32) (cast v55)) + (let (v59 (ptr i32)) (inttoptr v58)) + (store v59 v57) + (let (v60 u32) (cast v20)) + (let (v61 (ptr i32)) (inttoptr v60)) + (let (v62 i32) (load v61)) + (br (block 7 v20 v62))) + + (block 17 (param v106 i32) (param v107 i32) (param v108 i32) + (let (v109 i32) (bor v107 v108)) + (let (v110 u32) (cast v106)) + (let (v111 u32) (add.checked v110 4)) + (let (v112 (ptr i32)) (inttoptr v111)) + (store v112 v109) + (let (v113 u32) (cast v108)) + (let (v114 u32) (add.checked v113 8)) + (let (v115 (ptr i32)) (inttoptr v114)) + (let (v116 i32) (load v115)) + (let (v117 i32) (const.i32 -2)) + (let (v118 i32) (band v116 v117)) + (let (v119 u32) (cast v108)) + (let (v120 u32) (add.checked v119 8)) + (let (v121 (ptr i32)) (inttoptr v120)) + (store v121 v118) + (let (v122 u32) (cast v108)) + (let (v123 (ptr i32)) (inttoptr v122)) + (let (v124 i32) (load v123)) + (let (v125 i32) (const.i32 3)) + (let (v126 i32) (band v124 v125)) + (let (v127 i32) (bor v126 v106)) + (let (v128 u32) (cast v108)) + (let (v129 (ptr i32)) (inttoptr v128)) + (store v129 v127) + (let (v130 i32) (const.i32 2)) + (let (v131 i32) (band v124 v130)) + (let (v132 i1) (neq v131 0)) + (condbr v132 (block 8) (block 20))) + + (block 18 + (let (v85 i32) (const.i32 -4)) + (let (v86 i32) (band v81 v85)) + (let (v87 i1) (eq v86 0)) + (let (v88 i32) (cast v87)) + (let (v89 i1) (neq v88 0)) + (condbr v89 (block 17 v68 v63 v20) (block 19))) + + (block 19 + (let (v90 u32) (cast v86)) + (let (v91 u32) (add.checked v90 4)) + (let (v92 (ptr i32)) (inttoptr v91)) + (let (v93 i32) (load v92)) + (let (v94 i32) (const.i32 3)) + (let (v95 i32) (band v93 v94)) + (let (v96 i32) (bor v95 v68)) + (let (v97 u32) (cast v86)) + (let (v98 u32) (add.checked v97 4)) + (let (v99 (ptr i32)) (inttoptr v98)) + (store v99 v96) + (let (v100 u32) (cast v68)) + (let (v101 u32) (add.checked v100 4)) + (let (v102 (ptr i32)) (inttoptr v101)) + (let (v103 i32) (load v102)) + (let (v104 i32) (const.i32 3)) + (let (v105 i32) (band v103 v104)) + (br (block 17 v68 v105 v20))) + + (block 20 + (let (v133 u32) (cast v106)) + (let (v134 (ptr i32)) (inttoptr v133)) + (let (v135 i32) (load v134)) + (br (block 7 v106 v135))) + + (block 21 + (param v158 i32) + (param v168 i32) + (param v177 i32) + (param v183 i32) + (param v186 i32) + (param v189 i32) + (param v220 i32) + (call #wee_alloc::neighbors::Neighbors::remove v158) + (let (v159 u32) (cast v158)) + (let (v160 (ptr u8)) (inttoptr v159)) + (let (v161 u8) (load v160)) + (let (v162 i32) (zext v161)) + (let (v163 i32) (const.i32 2)) + (let (v164 i32) (band v162 v163)) + (let (v165 i1) (eq v164 0)) + (let (v166 i32) (cast v165)) + (let (v167 i1) (neq v166 0)) + (condbr v167 (block 24 v177 v168 v183 v186 v189 v220) (block 25))) + + (block 22 + (let (v149 i32) (const.i32 0)) + (let (v150 u32) (cast v146)) + (let (v151 (ptr u8)) (inttoptr v150)) + (let (v152 u8) (load v151)) + (let (v153 i32) (zext v152)) + (let (v154 i32) (const.i32 1)) + (let (v155 i32) (band v153 v154)) + (let (v156 i1) (neq v155 0)) + (let (v157 i32) (select v156 v149 v146)) + (br (block 21 v20 v157 v55 v36 v45 v52 v218))) + + (block 23 + (let (v148 i32) (const.i32 0)) + (br (block 21 v20 v148 v55 v36 v45 v52 v218))) + + (block 24 + (param v176 i32) + (param v178 i32) + (param v182 i32) + (param v185 i32) + (param v188 i32) + (param v219 i32) + (let (v179 u32) (cast v176)) + (let (v180 (ptr i32)) (inttoptr v179)) + (store v180 v178) + (br (block 9 v178 v182 v185 v188 v176 v219))) + + (block 25 + (let (v169 u32) (cast v168)) + (let (v170 (ptr i32)) (inttoptr v169)) + (let (v171 i32) (load v170)) + (let (v172 i32) (const.i32 2)) + (let (v173 i32) (bor v171 v172)) + (let (v174 u32) (cast v168)) + (let (v175 (ptr i32)) (inttoptr v174)) + (store v175 v173) + (br (block 24 v177 v168 v183 v186 v189 v220))) + ) + + (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 i32) (const.i32 1)) + (let (v10 i32) (const.i32 1)) + (let (v11 u32) (cast v1)) + (let (v12 u32) (cast v10)) + (let (v13 i1) (gt v11 v12)) + (let (v14 i32) (cast v13)) + (let (v15 i1) (neq v14 0)) + (let (v16 i32) (select v15 v1 v9)) + (let (v17 i1) (eq v2 0)) + (let (v18 i32) (cast v17)) + (let (v19 i1) (neq v18 0)) + (condbr v19 (block 2 v7 v16) (block 3))) + + (block 1 (param v3 i32) + (ret v3)) + + (block 2 (param v82 i32) (param v87 i32) + (let (v84 i32) (const.i32 16)) + (let (v85 i32) (add.wrapping v82 v84)) + (let (v86 (ptr i32)) (global.symbol #__stack_pointer)) + (store v86 v85) + (br (block 1 v87))) + + (block 3 + (let (v20 u32) (cast v0)) + (let (v21 (ptr i32)) (inttoptr v20)) + (let (v22 i32) (load v21)) + (let (v23 u32) (cast v7)) + (let (v24 u32) (add.checked v23 12)) + (let (v25 (ptr i32)) (inttoptr v24)) + (store v25 v22) + (let (v26 i32) (const.i32 3)) + (let (v27 i32) (add.wrapping v2 v26)) + (let (v28 i32) (const.i32 2)) + (let (v29 u32) (cast v27)) + (let (v30 u32) (cast v28)) + (let (v31 u32) (shr.wrapping v29 v30)) + (let (v32 i32) (cast v31)) + (let (v33 i32) (const.i32 12)) + (let (v34 i32) (add.wrapping v7 v33)) + (let (v35 i32) (call #wee_alloc::alloc_first_fit v32 v16 v34)) + (let (v36 i1) (eq v35 0)) + (let (v37 i32) (cast v36)) + (let (v38 i1) (neq v37 0)) + (condbr v38 (block 4) (block 5))) + + (block 4 + (call #::new_cell_for_free_list v7 v7 v32 v16) + (let (v45 u32) (cast v7)) + (let (v46 (ptr i32)) (inttoptr v45)) + (let (v47 i32) (load v46)) + (let (v48 i1) (eq v47 0)) + (let (v49 i32) (cast v48)) + (let (v50 i1) (neq v49 0)) + (condbr v50 (block 7) (block 8))) + + (block 5 + (let (v39 u32) (cast v7)) + (let (v40 u32) (add.checked v39 12)) + (let (v41 (ptr i32)) (inttoptr v40)) + (let (v42 i32) (load v41)) + (let (v43 u32) (cast v0)) + (let (v44 (ptr i32)) (inttoptr v43)) + (store v44 v42) + (br (block 2 v7 v35))) + + (block 6 (param v83 i32) + (let (v81 i32) (const.i32 0)) + (br (block 2 v83 v81))) + + (block 7 + (let (v57 u32) (cast v7)) + (let (v58 u32) (add.checked v57 4)) + (let (v59 (ptr i32)) (inttoptr v58)) + (let (v60 i32) (load v59)) + (let (v61 u32) (cast v7)) + (let (v62 u32) (add.checked v61 12)) + (let (v63 (ptr i32)) (inttoptr v62)) + (let (v64 i32) (load v63)) + (let (v65 u32) (cast v60)) + (let (v66 u32) (add.checked v65 8)) + (let (v67 (ptr i32)) (inttoptr v66)) + (store v67 v64) + (let (v68 u32) (cast v7)) + (let (v69 u32) (add.checked v68 12)) + (let (v70 (ptr i32)) (inttoptr v69)) + (store v70 v60) + (let (v71 i32) (const.i32 12)) + (let (v72 i32) (add.wrapping v7 v71)) + (let (v73 i32) (call #wee_alloc::alloc_first_fit v32 v16 v72)) + (let (v74 u32) (cast v7)) + (let (v75 u32) (add.checked v74 12)) + (let (v76 (ptr i32)) (inttoptr v75)) + (let (v77 i32) (load v76)) + (let (v78 u32) (cast v0)) + (let (v79 (ptr i32)) (inttoptr v78)) + (store v79 v77) + (let (v80 i1) (neq v73 0)) + (condbr v80 (block 2 v7 v73) (block 9))) + + (block 8 + (let (v51 u32) (cast v7)) + (let (v52 u32) (add.checked v51 12)) + (let (v53 (ptr i32)) (inttoptr v52)) + (let (v54 i32) (load v53)) + (let (v55 u32) (cast v0)) + (let (v56 (ptr i32)) (inttoptr v55)) + (store v56 v54) + (br (block 6 v7))) + + (block 9 + (br (block 6 v7))) + ) + + (func (export #miden_sdk_tx_kernel::get_inputs) + (param i32) + (block 0 (param v0 i32) + (let (v1 i32) (const.i32 0)) + (let (v2 i32) (global.load i32 (global.symbol #__stack_pointer))) + (let (v3 i32) (const.i32 16)) + (let (v4 i32) (sub.wrapping v2 v3)) + (let (v5 (ptr i32)) (global.symbol #__stack_pointer)) + (store v5 v4) + (let (v6 i32) (const.i32 4)) + (let (v7 i32) (add.wrapping v4 v6)) + (let (v8 i32) (const.i32 256)) + (let (v9 i32) (const.i32 0)) + (call #alloc::raw_vec::RawVec::try_allocate_in v7 v8 v9) + (let (v10 u32) (cast v4)) + (let (v11 u32) (add.checked v10 12)) + (let (v12 (ptr i32)) (inttoptr v11)) + (let (v13 i32) (load v12)) + (let (v14 u32) (cast v4)) + (let (v15 u32) (add.checked v14 8)) + (let (v16 (ptr i32)) (inttoptr v15)) + (let (v17 i32) (load v16)) + (let (v18 u32) (cast v4)) + (let (v19 u32) (add.checked v18 4)) + (let (v20 (ptr i32)) (inttoptr v19)) + (let (v21 i32) (load v20)) + (let (v22 i1) (eq v21 0)) + (let (v23 i32) (cast v22)) + (let (v24 i1) (neq v23 0)) + (condbr v24 (block 3) (block 4))) + + (block 1) + + (block 2 + (call #alloc::raw_vec::capacity_overflow) + (unreachable)) + + (block 3 + (let [(v28 i32) (v29 felt)] (call (#miden:tx_kernel/note #get_inputs) v13)) + (let (v30 i32) (const.i32 0)) + (let (v31 u32) (cast v0)) + (let (v32 u32) (add.checked v31 8)) + (let (v33 (ptr i32)) (inttoptr v32)) + (store v33 v30) + (let (v34 u32) (cast v0)) + (let (v35 u32) (add.checked v34 4)) + (let (v36 (ptr i32)) (inttoptr v35)) + (store v36 v13) + (let (v37 u32) (cast v0)) + (let (v38 (ptr i32)) (inttoptr v37)) + (store v38 v17) + (let (v39 i32) (const.i32 16)) + (let (v40 i32) (add.wrapping v4 v39)) + (let (v41 (ptr i32)) (global.symbol #__stack_pointer)) + (store v41 v40) + (ret)) + + (block 4 + (let (v25 i1) (eq v17 0)) + (let (v26 i32) (cast v25)) + (let (v27 i1) (neq v26 0)) + (condbr v27 (block 2) (block 5))) + + (block 5 + (call #alloc::alloc::handle_alloc_error v17 v13) + (unreachable)) + ) + + (func (export #alloc::raw_vec::RawVec::try_allocate_in) + (param i32) (param i32) (param i32) + (block 0 (param v0 i32) (param v1 i32) (param v2 i32) + (let (v3 i32) (const.i32 0)) + (let (v4 i1) (neq v1 0)) + (condbr v4 (block 3) (block 4))) + + (block 1 + (ret)) + + (block 2 (param v55 i32) (param v57 i32) + (let (v58 u32) (cast v55)) + (let (v59 (ptr i32)) (inttoptr v58)) + (store v59 v57) + (br (block 1))) + + (block 3 + (let (v10 i32) (const.i32 268435456)) + (let (v11 u32) (cast v1)) + (let (v12 u32) (cast v10)) + (let (v13 i1) (lt v11 v12)) + (let (v14 i32) (cast v13)) + (let (v15 i1) (neq v14 0)) + (condbr v15 (block 6) (block 7))) + + (block 4 + (let (v5 i64) (const.i64 34359738368)) + (let (v6 u32) (cast v0)) + (let (v7 u32) (add.checked v6 4)) + (let (v8 (ptr i64)) (inttoptr v7)) + (store v8 v5) + (let (v9 i32) (const.i32 0)) + (br (block 2 v0 v9))) + + (block 5 (param v56 i32) + (let (v54 i32) (const.i32 1)) + (br (block 2 v56 v54))) + + (block 6 + (let (v20 i32) (const.i32 3)) + (let (v21 i32) (shl.wrapping v1 v20)) + (let (v22 i1) (neq v2 0)) + (condbr v22 (block 9) (block 10))) + + (block 7 + (let (v16 i32) (const.i32 0)) + (let (v17 u32) (cast v0)) + (let (v18 u32) (add.checked v17 4)) + (let (v19 (ptr i32)) (inttoptr v18)) + (store v19 v16) + (br (block 5 v0))) + + (block 8 + (param v33 i32) + (param v37 i32) + (param v41 i32) + (param v46 i32) + (let (v34 i1) (eq v33 0)) + (let (v35 i32) (cast v34)) + (let (v36 i1) (neq v35 0)) + (condbr v36 (block 11) (block 12))) + + (block 9 + (let (v31 i32) (const.i32 8)) + (let (v32 i32) (call #__rust_alloc_zeroed v21 v31)) + (br (block 8 v32 v0 v1 v21))) + + (block 10 + (let (v23 i32) (const.i32 0)) + (let (v24 u32) (cast v23)) + (let (v25 u32) (add.checked v24 1048580)) + (let (v26 (ptr u8)) (inttoptr v25)) + (let (v27 u8) (load v26)) + (let (v28 i32) (zext v27)) + (let (v29 i32) (const.i32 8)) + (let (v30 i32) (call #__rust_alloc v21 v29)) + (br (block 8 v30 v0 v1 v21))) + + (block 11 + (let (v47 u32) (cast v37)) + (let (v48 u32) (add.checked v47 8)) + (let (v49 (ptr i32)) (inttoptr v48)) + (store v49 v46) + (let (v50 i32) (const.i32 8)) + (let (v51 u32) (cast v37)) + (let (v52 u32) (add.checked v51 4)) + (let (v53 (ptr i32)) (inttoptr v52)) + (store v53 v50) + (br (block 5 v37))) + + (block 12 + (let (v38 u32) (cast v37)) + (let (v39 u32) (add.checked v38 8)) + (let (v40 (ptr i32)) (inttoptr v39)) + (store v40 v33) + (let (v42 u32) (cast v37)) + (let (v43 u32) (add.checked v42 4)) + (let (v44 (ptr i32)) (inttoptr v43)) + (store v44 v41) + (let (v45 i32) (const.i32 0)) + (br (block 2 v37 v45))) + ) + + (func (export #alloc::alloc::handle_alloc_error) + (param i32) (param i32) + (block 0 (param v0 i32) (param v1 i32) + (unreachable)) + + (block 1) + ) + + (func (export #alloc::raw_vec::capacity_overflow) + + (block 0 + (unreachable)) + + (block 1) + ) + + ;; Imports + (func (import #miden:tx_kernel/note #get_inputs) + (param felt) (result i32 felt)) + ) + +) diff --git a/tests/integration/expected/abi_transform_tx_kernel_get_inputs.wat b/tests/integration/expected/abi_transform_tx_kernel_get_inputs.wat new file mode 100644 index 000000000..43a488090 --- /dev/null +++ b/tests/integration/expected/abi_transform_tx_kernel_get_inputs.wat @@ -0,0 +1,629 @@ +(module $abi_transform_tx_kernel_get_inputs.wasm + (type (;0;) (func (param i32) (result i32))) + (type (;1;) (func (param i32))) + (type (;2;) (func (param i32 i32) (result i32))) + (type (;3;) (func (param i32 i32 i32 i32))) + (type (;4;) (func (param i32 i32 i32) (result i32))) + (type (;5;) (func (param i32 i32 i32))) + (type (;6;) (func (param i32 i32))) + (type (;7;) (func)) + (import "miden:tx_kernel/note" "get_inputs<0x0000000000000000000000000000000000000000000000000000000000000000>" (func $miden_sdk_tx_kernel::externs::extern_note_get_inputs (;0;) (type 0))) + (func $entrypoint (;1;) (type 1) (param i32) + local.get 0 + call $miden_sdk_tx_kernel::get_inputs + ) + (func $__rust_alloc (;2;) (type 2) (param i32 i32) (result i32) + i32.const 1048576 + local.get 1 + local.get 0 + call $::alloc + ) + (func $__rust_alloc_zeroed (;3;) (type 2) (param i32 i32) (result i32) + block ;; label = @1 + i32.const 1048576 + local.get 1 + local.get 0 + call $::alloc + local.tee 1 + i32.eqz + br_if 0 (;@1;) + local.get 1 + i32.const 0 + local.get 0 + memory.fill + end + local.get 1 + ) + (func $wee_alloc::neighbors::Neighbors::remove (;4;) (type 1) (param i32) + (local i32 i32 i32) + block ;; label = @1 + local.get 0 + i32.load + local.tee 1 + i32.const 2 + i32.and + br_if 0 (;@1;) + local.get 1 + i32.const -4 + i32.and + local.tee 2 + i32.eqz + br_if 0 (;@1;) + local.get 2 + local.get 2 + i32.load offset=4 + i32.const 3 + i32.and + local.get 0 + i32.load offset=4 + i32.const -4 + i32.and + i32.or + i32.store offset=4 + local.get 0 + i32.load + local.set 1 + end + block ;; label = @1 + local.get 0 + i32.load offset=4 + local.tee 2 + i32.const -4 + i32.and + local.tee 3 + i32.eqz + br_if 0 (;@1;) + local.get 3 + local.get 3 + i32.load + i32.const 3 + i32.and + local.get 1 + i32.const -4 + i32.and + i32.or + i32.store + local.get 0 + i32.load offset=4 + local.set 2 + local.get 0 + i32.load + local.set 1 + end + local.get 0 + local.get 2 + i32.const 3 + i32.and + i32.store offset=4 + local.get 0 + local.get 1 + i32.const 3 + i32.and + i32.store + ) + (func $::new_cell_for_free_list (;5;) (type 3) (param i32 i32 i32 i32) + block ;; label = @1 + block ;; label = @2 + local.get 2 + i32.const 2 + i32.shl + local.tee 2 + local.get 3 + i32.const 3 + i32.shl + i32.const 512 + i32.add + local.tee 3 + local.get 2 + local.get 3 + i32.gt_u + select + i32.const 65543 + i32.add + local.tee 3 + i32.const 16 + i32.shr_u + memory.grow + local.tee 2 + i32.const -1 + i32.ne + br_if 0 (;@2;) + i32.const 1 + local.set 3 + i32.const 0 + local.set 2 + br 1 (;@1;) + end + local.get 2 + i32.const 16 + i32.shl + local.tee 2 + i64.const 0 + i64.store offset=4 align=4 + local.get 2 + local.get 2 + local.get 3 + i32.const -65536 + i32.and + i32.add + i32.const 2 + i32.or + i32.store + i32.const 0 + local.set 3 + end + local.get 0 + local.get 2 + i32.store offset=4 + local.get 0 + local.get 3 + i32.store + ) + (func $wee_alloc::alloc_first_fit (;6;) (type 4) (param i32 i32 i32) (result i32) + (local i32 i32 i32 i32 i32 i32) + local.get 1 + i32.const -1 + i32.add + local.set 3 + i32.const 0 + local.set 4 + i32.const 0 + local.get 1 + i32.sub + local.set 5 + local.get 0 + i32.const 2 + i32.shl + local.set 6 + local.get 2 + i32.load + local.set 0 + loop (result i32) ;; label = @1 + block ;; label = @2 + block ;; label = @3 + local.get 0 + i32.eqz + br_if 0 (;@3;) + local.get 0 + local.set 1 + block ;; label = @4 + block ;; label = @5 + loop ;; label = @6 + block ;; label = @7 + local.get 1 + i32.load offset=8 + local.tee 0 + i32.const 1 + i32.and + br_if 0 (;@7;) + local.get 1 + i32.load + i32.const -4 + i32.and + local.tee 7 + local.get 1 + i32.const 8 + i32.add + local.tee 8 + i32.sub + local.get 6 + i32.lt_u + br_if 5 (;@2;) + block ;; label = @8 + local.get 8 + i32.const 72 + i32.add + local.get 7 + local.get 6 + i32.sub + local.get 5 + i32.and + local.tee 7 + i32.le_u + br_if 0 (;@8;) + local.get 3 + local.get 8 + i32.and + br_if 6 (;@2;) + local.get 2 + local.get 0 + i32.const -4 + i32.and + i32.store + local.get 1 + i32.load + local.set 2 + local.get 1 + local.set 0 + br 4 (;@4;) + end + i32.const 0 + local.set 2 + local.get 7 + i32.const 0 + i32.store + local.get 7 + i32.const -8 + i32.add + local.tee 0 + i64.const 0 + i64.store align=4 + local.get 0 + local.get 1 + i32.load + i32.const -4 + i32.and + i32.store + block ;; label = @8 + local.get 1 + i32.load + local.tee 8 + i32.const 2 + i32.and + br_if 0 (;@8;) + local.get 8 + i32.const -4 + i32.and + local.tee 8 + i32.eqz + br_if 0 (;@8;) + local.get 8 + local.get 8 + i32.load offset=4 + i32.const 3 + i32.and + local.get 0 + i32.or + i32.store offset=4 + local.get 0 + i32.load offset=4 + i32.const 3 + i32.and + local.set 2 + end + local.get 0 + local.get 2 + local.get 1 + i32.or + i32.store offset=4 + local.get 1 + local.get 1 + i32.load offset=8 + i32.const -2 + i32.and + i32.store offset=8 + local.get 1 + local.get 1 + i32.load + local.tee 2 + i32.const 3 + i32.and + local.get 0 + i32.or + local.tee 8 + i32.store + local.get 2 + i32.const 2 + i32.and + br_if 2 (;@5;) + local.get 0 + i32.load + local.set 2 + br 3 (;@4;) + end + local.get 1 + local.get 0 + i32.const -2 + i32.and + i32.store offset=8 + block ;; label = @7 + block ;; label = @8 + local.get 1 + i32.load offset=4 + i32.const -4 + i32.and + local.tee 0 + br_if 0 (;@8;) + i32.const 0 + local.set 0 + br 1 (;@7;) + end + i32.const 0 + local.get 0 + local.get 0 + i32.load8_u + i32.const 1 + i32.and + select + local.set 0 + end + local.get 1 + call $wee_alloc::neighbors::Neighbors::remove + block ;; label = @7 + local.get 1 + i32.load8_u + i32.const 2 + i32.and + i32.eqz + br_if 0 (;@7;) + local.get 0 + local.get 0 + i32.load + i32.const 2 + i32.or + i32.store + end + local.get 2 + local.get 0 + i32.store + local.get 0 + local.set 1 + br 0 (;@6;) + end + end + local.get 1 + local.get 8 + i32.const -3 + i32.and + i32.store + local.get 0 + i32.load + i32.const 2 + i32.or + local.set 2 + end + local.get 0 + local.get 2 + i32.const 1 + i32.or + i32.store + local.get 0 + i32.const 8 + i32.add + local.set 4 + end + local.get 4 + return + end + local.get 2 + local.get 0 + i32.store + br 0 (;@1;) + end + ) + (func $::alloc (;7;) (type 4) (param i32 i32 i32) (result i32) + (local i32 i32) + global.get $__stack_pointer + i32.const 16 + i32.sub + local.tee 3 + global.set $__stack_pointer + local.get 1 + i32.const 1 + local.get 1 + i32.const 1 + i32.gt_u + select + local.set 1 + block ;; label = @1 + local.get 2 + i32.eqz + br_if 0 (;@1;) + local.get 3 + local.get 0 + i32.load + i32.store offset=12 + block ;; label = @2 + local.get 2 + i32.const 3 + i32.add + i32.const 2 + i32.shr_u + local.tee 4 + local.get 1 + local.get 3 + i32.const 12 + i32.add + call $wee_alloc::alloc_first_fit + local.tee 2 + i32.eqz + br_if 0 (;@2;) + local.get 0 + local.get 3 + i32.load offset=12 + i32.store + local.get 2 + local.set 1 + br 1 (;@1;) + end + local.get 3 + local.get 3 + local.get 4 + local.get 1 + call $::new_cell_for_free_list + block ;; label = @2 + block ;; label = @3 + local.get 3 + i32.load + i32.eqz + br_if 0 (;@3;) + local.get 0 + local.get 3 + i32.load offset=12 + i32.store + br 1 (;@2;) + end + local.get 3 + i32.load offset=4 + local.tee 2 + local.get 3 + i32.load offset=12 + i32.store offset=8 + local.get 3 + local.get 2 + i32.store offset=12 + local.get 4 + local.get 1 + local.get 3 + i32.const 12 + i32.add + call $wee_alloc::alloc_first_fit + local.set 1 + local.get 0 + local.get 3 + i32.load offset=12 + i32.store + local.get 1 + br_if 1 (;@1;) + end + i32.const 0 + local.set 1 + end + local.get 3 + i32.const 16 + i32.add + global.set $__stack_pointer + local.get 1 + ) + (func $miden_sdk_tx_kernel::get_inputs (;8;) (type 1) (param i32) + (local i32 i32 i32) + global.get $__stack_pointer + i32.const 16 + i32.sub + local.tee 1 + global.set $__stack_pointer + local.get 1 + i32.const 4 + i32.add + i32.const 256 + i32.const 0 + call $alloc::raw_vec::RawVec::try_allocate_in + local.get 1 + i32.load offset=12 + local.set 2 + local.get 1 + i32.load offset=8 + local.set 3 + block ;; label = @1 + block ;; label = @2 + local.get 1 + i32.load offset=4 + i32.eqz + br_if 0 (;@2;) + local.get 3 + i32.eqz + br_if 1 (;@1;) + local.get 3 + local.get 2 + call $alloc::alloc::handle_alloc_error + unreachable + end + local.get 2 + call $miden_sdk_tx_kernel::externs::extern_note_get_inputs + drop + local.get 0 + i32.const 0 + i32.store offset=8 + local.get 0 + local.get 2 + i32.store offset=4 + local.get 0 + local.get 3 + i32.store + local.get 1 + i32.const 16 + i32.add + global.set $__stack_pointer + return + end + call $alloc::raw_vec::capacity_overflow + unreachable + ) + (func $alloc::raw_vec::RawVec::try_allocate_in (;9;) (type 5) (param i32 i32 i32) + (local i32) + block ;; label = @1 + block ;; label = @2 + local.get 1 + br_if 0 (;@2;) + local.get 0 + i64.const 34359738368 + i64.store offset=4 align=4 + i32.const 0 + local.set 1 + br 1 (;@1;) + end + block ;; label = @2 + block ;; label = @3 + local.get 1 + i32.const 268435456 + i32.lt_u + br_if 0 (;@3;) + local.get 0 + i32.const 0 + i32.store offset=4 + br 1 (;@2;) + end + local.get 1 + i32.const 3 + i32.shl + local.set 3 + block ;; label = @3 + block ;; label = @4 + local.get 2 + br_if 0 (;@4;) + i32.const 0 + i32.load8_u offset=1048580 + drop + local.get 3 + i32.const 8 + call $__rust_alloc + local.set 2 + br 1 (;@3;) + end + local.get 3 + i32.const 8 + call $__rust_alloc_zeroed + local.set 2 + end + block ;; label = @3 + local.get 2 + i32.eqz + br_if 0 (;@3;) + local.get 0 + local.get 2 + i32.store offset=8 + local.get 0 + local.get 1 + i32.store offset=4 + i32.const 0 + local.set 1 + br 2 (;@1;) + end + local.get 0 + local.get 3 + i32.store offset=8 + local.get 0 + i32.const 8 + i32.store offset=4 + end + i32.const 1 + local.set 1 + end + local.get 0 + local.get 1 + i32.store + ) + (func $alloc::alloc::handle_alloc_error (;10;) (type 6) (param i32 i32) + unreachable + unreachable + ) + (func $alloc::raw_vec::capacity_overflow (;11;) (type 7) + unreachable + unreachable + ) + (table (;0;) 1 1 funcref) + (memory (;0;) 17) + (global $__stack_pointer (;0;) (mut i32) i32.const 1048576) + (export "memory" (memory 0)) + (export "entrypoint" (func $entrypoint)) +) \ No newline at end of file diff --git a/tests/integration/src/compiler_test.rs b/tests/integration/src/compiler_test.rs index 61ceb1500..05ae2add5 100644 --- a/tests/integration/src/compiler_test.rs +++ b/tests/integration/src/compiler_test.rs @@ -416,6 +416,72 @@ impl CompilerTest { Self::rust_source_cargo_lib(proj.root(), is_build_std, Some("entrypoint".to_string())) } + /// Set the Rust source code to compile with `miden-prelude` (stdlib + intrinsics) + pub fn rust_fn_body_with_sdk(name: &str, rust_source: &str, is_build_std: bool) -> Self { + let cwd = std::env::current_dir().unwrap(); + let miden_sdk_path = cwd.parent().unwrap().parent().unwrap().join("sdk").join("sdk"); + let miden_sdk_path_str = miden_sdk_path.to_str().unwrap(); + // dbg!(&miden_prelude_path); + let proj = project(name) + .file( + "Cargo.toml", + format!( + r#" + [package] + name = "{name}" + version = "0.0.1" + edition = "2015" + authors = [] + + [dependencies] + wee_alloc = {{ version = "0.4.5", default-features = false}} + miden-sdk = {{ path = "{miden_sdk_path_str}" }} + + [lib] + crate-type = ["cdylib"] + + [profile.release] + panic = "abort" + # optimize for size + opt-level = "z" + "# + ) + .as_str(), + ) + .file( + "src/lib.rs", + format!( + r#" + #![no_std] + #![no_main] + + #[panic_handler] + fn my_panic(_info: &core::panic::PanicInfo) -> ! {{ + loop {{}} + }} + + + #[global_allocator] + static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + + extern crate miden_sdk; + use miden_sdk::*; + + extern crate alloc; + use alloc::vec::Vec; + + #[no_mangle] + pub extern "C" fn entrypoint{} + "#, + rust_source + ) + .as_str(), + ) + .build(); + + Self::rust_source_cargo_lib(proj.root(), is_build_std, Some("entrypoint".to_string())) + } + /// Compare the compiled Wasm against the expected output pub fn expect_wasm(&self, expected_wat_file: expect_test::ExpectFile) { let wasm_bytes = self.wasm_bytes(); diff --git a/tests/integration/src/rust_masm_tests/abi_transform/mod.rs b/tests/integration/src/rust_masm_tests/abi_transform/mod.rs index d9366b9fb..c5b743a68 100644 --- a/tests/integration/src/rust_masm_tests/abi_transform/mod.rs +++ b/tests/integration/src/rust_masm_tests/abi_transform/mod.rs @@ -1 +1,2 @@ mod stdlib; +mod tx_kernel; diff --git a/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs b/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs new file mode 100644 index 000000000..db3d70c1b --- /dev/null +++ b/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs @@ -0,0 +1,30 @@ +use expect_test::expect_file; + +use crate::CompilerTest; + +#[test] +fn test_get_inputs() { + let main_fn = format!("() -> Vec {{ get_inputs() }}"); + let artifact_name = "abi_transform_tx_kernel_get_inputs"; + let mut test = CompilerTest::rust_fn_body_with_sdk(&artifact_name, &main_fn, true); + // Test expected compilation artifacts + test.expect_wasm(expect_file![format!("../../../expected/{artifact_name}.wat")]); + test.expect_ir(expect_file![format!("../../../expected/{artifact_name}.hir")]); + test.expect_masm(expect_file![format!("../../../expected/{artifact_name}.masm")]); + // let ir_masm = test.ir_masm_program(); + // let vm_program = test.vm_masm_program(); + + // Run the Rust and compiled MASM code against a bunch of random inputs and compare the results + // let res = + // TestRunner::default().run(&(any::<[u8; 32]>(), any::<[u8; 32]>()), move |(_a, _b)| { + // todo!("test against rust"); + // // run_masm_vs_rust(rs_out, &vm_program, ir_masm.clone(), &args) + // }); + // match res { + // Err(TestError::Fail(_, value)) => { + // panic!("Found minimal(shrinked) failing case: {:?}", value); + // } + // Ok(_) => (), + // _ => panic!("Unexpected test result: {:?}", res), + // } +} From d8d4bd00b95397962fe0e1f3fe1479f488449d55 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 3 Jun 2024 18:59:18 +0300 Subject: [PATCH 2/2] ignore the `get_inputs` MASM compilation test for now --- tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs b/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs index db3d70c1b..5c317cea9 100644 --- a/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs +++ b/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs @@ -2,6 +2,7 @@ use expect_test::expect_file; use crate::CompilerTest; +#[ignore = "until https://github.com/0xPolygonMiden/compiler/issues/200 is fixed"] #[test] fn test_get_inputs() { let main_fn = format!("() -> Vec {{ get_inputs() }}");