github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v2/testdata/memory.wast (about) 1 ;; Test memory section structure 2 3 (module (memory 0)) 4 (module (memory 1)) 5 (module (memory 0 0)) 6 (module (memory 0 1)) 7 (module (memory 1 256)) 8 (module (memory 0 65536)) 9 10 (assert_invalid (module (memory 0) (memory 0)) "multiple memories") 11 (assert_invalid (module (memory (import "spectest" "memory") 0) (memory 0)) "multiple memories") 12 13 (module (memory (data)) (func (export "memsize") (result i32) (memory.size))) 14 (assert_return (invoke "memsize") (i32.const 0)) 15 (module (memory (data "")) (func (export "memsize") (result i32) (memory.size))) 16 (assert_return (invoke "memsize") (i32.const 0)) 17 (module (memory (data "x")) (func (export "memsize") (result i32) (memory.size))) 18 (assert_return (invoke "memsize") (i32.const 1)) 19 20 (assert_invalid (module (data (i32.const 0))) "unknown memory") 21 (assert_invalid (module (data (i32.const 0) "")) "unknown memory") 22 (assert_invalid (module (data (i32.const 0) "x")) "unknown memory") 23 24 (assert_invalid 25 (module (func (drop (f32.load (i32.const 0))))) 26 "unknown memory" 27 ) 28 (assert_invalid 29 (module (func (f32.store (i32.const 0) (f32.const 0)))) 30 "unknown memory" 31 ) 32 (assert_invalid 33 (module (func (drop (i32.load8_s (i32.const 0))))) 34 "unknown memory" 35 ) 36 (assert_invalid 37 (module (func (i32.store8 (i32.const 0) (i32.const 0)))) 38 "unknown memory" 39 ) 40 (assert_invalid 41 (module (func (drop (memory.size)))) 42 "unknown memory" 43 ) 44 (assert_invalid 45 (module (func (drop (memory.grow (i32.const 0))))) 46 "unknown memory" 47 ) 48 49 50 (assert_invalid 51 (module (memory 1 0)) 52 "size minimum must not be greater than maximum" 53 ) 54 (assert_invalid 55 (module (memory 65537)) 56 "memory size must be at most 65536 pages (4GiB)" 57 ) 58 (assert_invalid 59 (module (memory 2147483648)) 60 "memory size must be at most 65536 pages (4GiB)" 61 ) 62 (assert_invalid 63 (module (memory 4294967295)) 64 "memory size must be at most 65536 pages (4GiB)" 65 ) 66 (assert_invalid 67 (module (memory 0 65537)) 68 "memory size must be at most 65536 pages (4GiB)" 69 ) 70 (assert_invalid 71 (module (memory 0 2147483648)) 72 "memory size must be at most 65536 pages (4GiB)" 73 ) 74 (assert_invalid 75 (module (memory 0 4294967295)) 76 "memory size must be at most 65536 pages (4GiB)" 77 ) 78 79 (assert_malformed 80 (module quote "(memory 0x1_0000_0000)") 81 "i32 constant out of range" 82 ) 83 (assert_malformed 84 (module quote "(memory 0x1_0000_0000 0x1_0000_0000)") 85 "i32 constant out of range" 86 ) 87 (assert_malformed 88 (module quote "(memory 0 0x1_0000_0000)") 89 "i32 constant out of range" 90 ) 91 92 (module 93 (memory 1) 94 (data (i32.const 0) "ABC\a7D") (data (i32.const 20) "WASM") 95 96 ;; Data section 97 (func (export "data") (result i32) 98 (i32.and 99 (i32.and 100 (i32.and 101 (i32.eq (i32.load8_u (i32.const 0)) (i32.const 65)) 102 (i32.eq (i32.load8_u (i32.const 3)) (i32.const 167)) 103 ) 104 (i32.and 105 (i32.eq (i32.load8_u (i32.const 6)) (i32.const 0)) 106 (i32.eq (i32.load8_u (i32.const 19)) (i32.const 0)) 107 ) 108 ) 109 (i32.and 110 (i32.and 111 (i32.eq (i32.load8_u (i32.const 20)) (i32.const 87)) 112 (i32.eq (i32.load8_u (i32.const 23)) (i32.const 77)) 113 ) 114 (i32.and 115 (i32.eq (i32.load8_u (i32.const 24)) (i32.const 0)) 116 (i32.eq (i32.load8_u (i32.const 1023)) (i32.const 0)) 117 ) 118 ) 119 ) 120 ) 121 122 ;; Memory cast 123 (func (export "cast") (result f64) 124 (i64.store (i32.const 8) (i64.const -12345)) 125 (if 126 (f64.eq 127 (f64.load (i32.const 8)) 128 (f64.reinterpret_i64 (i64.const -12345)) 129 ) 130 (then (return (f64.const 0))) 131 ) 132 (i64.store align=1 (i32.const 9) (i64.const 0)) 133 (i32.store16 align=1 (i32.const 15) (i32.const 16453)) 134 (f64.load align=1 (i32.const 9)) 135 ) 136 137 ;; Sign and zero extending memory loads 138 (func (export "i32_load8_s") (param $i i32) (result i32) 139 (i32.store8 (i32.const 8) (local.get $i)) 140 (i32.load8_s (i32.const 8)) 141 ) 142 (func (export "i32_load8_u") (param $i i32) (result i32) 143 (i32.store8 (i32.const 8) (local.get $i)) 144 (i32.load8_u (i32.const 8)) 145 ) 146 (func (export "i32_load16_s") (param $i i32) (result i32) 147 (i32.store16 (i32.const 8) (local.get $i)) 148 (i32.load16_s (i32.const 8)) 149 ) 150 (func (export "i32_load16_u") (param $i i32) (result i32) 151 (i32.store16 (i32.const 8) (local.get $i)) 152 (i32.load16_u (i32.const 8)) 153 ) 154 (func (export "i64_load8_s") (param $i i64) (result i64) 155 (i64.store8 (i32.const 8) (local.get $i)) 156 (i64.load8_s (i32.const 8)) 157 ) 158 (func (export "i64_load8_u") (param $i i64) (result i64) 159 (i64.store8 (i32.const 8) (local.get $i)) 160 (i64.load8_u (i32.const 8)) 161 ) 162 (func (export "i64_load16_s") (param $i i64) (result i64) 163 (i64.store16 (i32.const 8) (local.get $i)) 164 (i64.load16_s (i32.const 8)) 165 ) 166 (func (export "i64_load16_u") (param $i i64) (result i64) 167 (i64.store16 (i32.const 8) (local.get $i)) 168 (i64.load16_u (i32.const 8)) 169 ) 170 (func (export "i64_load32_s") (param $i i64) (result i64) 171 (i64.store32 (i32.const 8) (local.get $i)) 172 (i64.load32_s (i32.const 8)) 173 ) 174 (func (export "i64_load32_u") (param $i i64) (result i64) 175 (i64.store32 (i32.const 8) (local.get $i)) 176 (i64.load32_u (i32.const 8)) 177 ) 178 ) 179 180 (assert_return (invoke "data") (i32.const 1)) 181 (assert_return (invoke "cast") (f64.const 42.0)) 182 183 (assert_return (invoke "i32_load8_s" (i32.const -1)) (i32.const -1)) 184 (assert_return (invoke "i32_load8_u" (i32.const -1)) (i32.const 255)) 185 (assert_return (invoke "i32_load16_s" (i32.const -1)) (i32.const -1)) 186 (assert_return (invoke "i32_load16_u" (i32.const -1)) (i32.const 65535)) 187 188 (assert_return (invoke "i32_load8_s" (i32.const 100)) (i32.const 100)) 189 (assert_return (invoke "i32_load8_u" (i32.const 200)) (i32.const 200)) 190 (assert_return (invoke "i32_load16_s" (i32.const 20000)) (i32.const 20000)) 191 (assert_return (invoke "i32_load16_u" (i32.const 40000)) (i32.const 40000)) 192 193 (assert_return (invoke "i32_load8_s" (i32.const 0xfedc6543)) (i32.const 0x43)) 194 (assert_return (invoke "i32_load8_s" (i32.const 0x3456cdef)) (i32.const 0xffffffef)) 195 (assert_return (invoke "i32_load8_u" (i32.const 0xfedc6543)) (i32.const 0x43)) 196 (assert_return (invoke "i32_load8_u" (i32.const 0x3456cdef)) (i32.const 0xef)) 197 (assert_return (invoke "i32_load16_s" (i32.const 0xfedc6543)) (i32.const 0x6543)) 198 (assert_return (invoke "i32_load16_s" (i32.const 0x3456cdef)) (i32.const 0xffffcdef)) 199 (assert_return (invoke "i32_load16_u" (i32.const 0xfedc6543)) (i32.const 0x6543)) 200 (assert_return (invoke "i32_load16_u" (i32.const 0x3456cdef)) (i32.const 0xcdef)) 201 202 (assert_return (invoke "i64_load8_s" (i64.const -1)) (i64.const -1)) 203 (assert_return (invoke "i64_load8_u" (i64.const -1)) (i64.const 255)) 204 (assert_return (invoke "i64_load16_s" (i64.const -1)) (i64.const -1)) 205 (assert_return (invoke "i64_load16_u" (i64.const -1)) (i64.const 65535)) 206 (assert_return (invoke "i64_load32_s" (i64.const -1)) (i64.const -1)) 207 (assert_return (invoke "i64_load32_u" (i64.const -1)) (i64.const 4294967295)) 208 209 (assert_return (invoke "i64_load8_s" (i64.const 100)) (i64.const 100)) 210 (assert_return (invoke "i64_load8_u" (i64.const 200)) (i64.const 200)) 211 (assert_return (invoke "i64_load16_s" (i64.const 20000)) (i64.const 20000)) 212 (assert_return (invoke "i64_load16_u" (i64.const 40000)) (i64.const 40000)) 213 (assert_return (invoke "i64_load32_s" (i64.const 20000)) (i64.const 20000)) 214 (assert_return (invoke "i64_load32_u" (i64.const 40000)) (i64.const 40000)) 215 216 (assert_return (invoke "i64_load8_s" (i64.const 0xfedcba9856346543)) (i64.const 0x43)) 217 (assert_return (invoke "i64_load8_s" (i64.const 0x3456436598bacdef)) (i64.const 0xffffffffffffffef)) 218 (assert_return (invoke "i64_load8_u" (i64.const 0xfedcba9856346543)) (i64.const 0x43)) 219 (assert_return (invoke "i64_load8_u" (i64.const 0x3456436598bacdef)) (i64.const 0xef)) 220 (assert_return (invoke "i64_load16_s" (i64.const 0xfedcba9856346543)) (i64.const 0x6543)) 221 (assert_return (invoke "i64_load16_s" (i64.const 0x3456436598bacdef)) (i64.const 0xffffffffffffcdef)) 222 (assert_return (invoke "i64_load16_u" (i64.const 0xfedcba9856346543)) (i64.const 0x6543)) 223 (assert_return (invoke "i64_load16_u" (i64.const 0x3456436598bacdef)) (i64.const 0xcdef)) 224 (assert_return (invoke "i64_load32_s" (i64.const 0xfedcba9856346543)) (i64.const 0x56346543)) 225 (assert_return (invoke "i64_load32_s" (i64.const 0x3456436598bacdef)) (i64.const 0xffffffff98bacdef)) 226 (assert_return (invoke "i64_load32_u" (i64.const 0xfedcba9856346543)) (i64.const 0x56346543)) 227 (assert_return (invoke "i64_load32_u" (i64.const 0x3456436598bacdef)) (i64.const 0x98bacdef)) 228 229 ;; Duplicate identifier errors 230 231 (assert_malformed (module quote 232 "(memory $foo 1)" 233 "(memory $foo 1)") 234 "duplicate memory") 235 (assert_malformed (module quote 236 "(import \"\" \"\" (memory $foo 1))" 237 "(memory $foo 1)") 238 "duplicate memory") 239 (assert_malformed (module quote 240 "(import \"\" \"\" (memory $foo 1))" 241 "(import \"\" \"\" (memory $foo 1))") 242 "duplicate memory")