1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
(module
(memory 0)
(start $start)
(type $0 (func))
(type $0-dupe (func))
(type $1 (func (param i32)))
(type $1-dupe (func (param i32)))
(type $2 (func (param i32) (result i32)))
(type $2-dupe (func (param i32) (result i32)))
(type $2-thrupe (func (param i32) (result i32)))
(export "memory" (memory $0))
(export "exported" $exported)
(export "other1" $other1)
(export "other2" $other2)
(table 1 1 funcref)
(elem (i32.const 0) $called_indirect)
(func $start (type $0)
(call $called0)
)
(func $called0 (type $0)
(call $called1)
)
(func $called1 (type $0)
(nop)
)
(func $called_indirect (type $0)
(nop)
)
(func $exported (type $0-dupe)
(call $called2)
)
(func $called2 (type $0-dupe)
(call $called2)
(call $called3)
)
(func $called3 (type $0-dupe)
(call $called4)
)
(func $called4 (type $0-dupe)
(call $called3)
)
(func $remove0 (type $0-dupe)
(call $remove1)
)
(func $remove1 (type $0-dupe)
(nop)
)
(func $remove2 (type $0-dupe)
(call $remove2)
)
(func $remove3 (type $0)
(call $remove4)
)
(func $remove4 (type $0)
(call $remove3)
)
(func $other1 (param i32) (type $1)
(call_indirect (type $0) (i32.const 0))
(call_indirect (type $0) (i32.const 0))
(call_indirect (type $0-dupe) (i32.const 0))
(call_indirect (type $0-dupe) (i32.const 0))
(call_indirect (type $1) (i32.const 0) (i32.const 0))
(call_indirect (type $1-dupe) (i32.const 0) (i32.const 0))
(drop (call_indirect (type $2) (i32.const 0) (i32.const 0)))
(drop (call_indirect (type $2-dupe) (i32.const 0) (i32.const 0)))
(drop (call_indirect (type $2-thrupe) (i32.const 0) (i32.const 0)))
)
(func $other2 (param i32) (type $1-dupe)
(unreachable)
)
)
(module ;; remove the table and memory
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 0 funcref))
)
(module ;; also when not imported
(memory 256)
(table 1 funcref)
)
(module ;; but not when exported
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 1 funcref))
(export "mem" (memory 0))
(export "tab" (table 0))
)
(module ;; and not when there are segments
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 1 funcref))
(data (i32.const 1) "hello, world!")
(elem (i32.const 0) $waka)
(func $waka)
)
(module ;; and not when used
(type $0 (func))
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 0 funcref))
(export "user" $user)
(func $user
(drop (i32.load (i32.const 0)))
(call_indirect (type $0) (i32.const 0))
)
)
(module ;; more use checks
(memory $0 (shared 23 256))
(export "user" $user)
(func $user
(i32.store (i32.const 0) (i32.const 0))
)
)
(module ;; more use checks
(memory $0 (shared 23 256))
(export "user" $user)
(func $user (result i32)
(i32.atomic.rmw.add (i32.const 0) (i32.const 0))
)
)
(module ;; more use checks
(memory $0 (shared 23 256))
(export "user" $user)
(func $user (result i32)
(i32.atomic.rmw8.cmpxchg_u (i32.const 0) (i32.const 0) (i32.const 0))
)
)
(module ;; more use checks
(memory $0 (shared 23 256))
(export "user" $user)
(func $user
(local $0 i32)
(local $1 i64)
(drop
(i32.wait
(local.get $0)
(local.get $0)
(local.get $1)
)
)
)
)
(module ;; more use checks
(memory $0 (shared 23 256))
(export "user" $user)
(func $user (result i32)
(wake (i32.const 0) (i32.const 0))
)
)
(module ;; more use checks
(memory $0 23 256)
(export "user" $user)
(func $user (result i32)
(grow_memory (i32.const 0))
)
)
(module ;; more use checks
(import "env" "memory" (memory $0 256))
(export "user" $user)
(func $user (result i32)
(grow_memory (i32.const 0))
)
)
(module ;; more use checks
(memory $0 23 256)
(export "user" $user)
(func $user (result i32)
(current_memory)
)
)
(module
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 0 funcref))
(import "env" "memoryBase" (global $memoryBase i32)) ;; used in init
(import "env" "tableBase" (global $tableBase i32)) ;; used in init
(data (global.get $memoryBase) "hello, world!")
(elem (global.get $tableBase) $waka)
(func $waka) ;; used in table
)
(module ;; one is exported, and one->two->int global, whose init->imported
(import "env" "imported" (global $imported i32))
(import "env" "forgetme" (global $forgetme i32))
(import "env" "_puts" (func $_puts (param i32) (result i32)))
(import "env" "forget_puts" (func $forget_puts (param i32) (result i32)))
(global $int (mut i32) (global.get $imported))
(global $set (mut i32) (i32.const 100))
(global $forglobal.get (mut i32) (i32.const 500))
(global $exp_glob i32 (i32.const 600))
(export "one" (func $one))
(export "three" (func $three))
(export "exp_glob" (global $exp_glob))
(start $starter)
(func $one (result i32)
(call $two)
)
(func $two (result i32)
(global.get $int)
)
(func $three
(call $four)
)
(func $four
(global.set $set (i32.const 200))
(drop (call $_puts (i32.const 300)))
)
(func $forget_implemented
(nop)
)
(func $starter
(nop)
)
)
(module ;; empty start being removed
(start $starter)
(func $starter
(nop)
)
)
(module ;; non-empty start being kept
(start $starter)
(func $starter
(drop (i32.const 0))
)
)
(module ;; the function stays but the table can be removed
(type $0 (func (param f64) (result f64)))
(table 6 6 funcref)
(func $0 (; 0 ;) (type $0) (param $var$0 f64) (result f64)
(if (result f64)
(f64.eq
(f64.const 1)
(f64.const 1)
)
(f64.const 1)
(f64.const 0)
)
)
)
(module ;; the function keeps the table alive
(type $0 (func (param f64) (result f64)))
(table 6 6 funcref)
(func $0 (; 0 ;) (type $0) (param $var$0 f64) (result f64)
(if (result f64)
(f64.eq
(f64.const 1)
(f64.const 1)
)
(call_indirect (type $0) (f64.const 1) (i32.const 0))
(f64.const 0)
)
)
)
(module ;; the table is imported - we can't remove it
(type $0 (func (param f64) (result f64)))
(import "env" "table" (table 6 6 funcref))
(elem (i32.const 0) $0)
(func $0 (; 0 ;) (type $0) (param $var$0 f64) (result f64)
(if (result f64)
(f64.eq
(f64.const 1)
(f64.const 1)
)
(f64.const 1)
(f64.const 0)
)
)
)
|