|
17 | 17 |
|
18 | 18 | ;; CHECK: (type $0 (func)) |
19 | 19 |
|
| 20 | + ;; CHECK: (global $global (ref string) (string.const "foo")) |
| 21 | + (global $global (ref string) (string.const "foo")) |
| 22 | + |
20 | 23 | ;; CHECK: (global $"string.const_\"bar\"" (ref string) (string.const "bar")) |
21 | 24 |
|
22 | 25 | ;; CHECK: (global $"string.const_\"other\"" (ref string) (string.const "other")) |
23 | 26 |
|
24 | | - ;; CHECK: (global $global (ref string) (string.const "foo")) |
25 | | - (global $global (ref string) (string.const "foo")) |
26 | | - |
27 | 27 | ;; CHECK: (global $global2 stringref (global.get $"string.const_\"bar\"")) |
28 | 28 | ;; LOWER: (type $0 (array (mut i16))) |
29 | 29 |
|
|
45 | 45 |
|
46 | 46 | ;; LOWER: (type $9 (func (param externref i32 i32) (result (ref extern)))) |
47 | 47 |
|
48 | | - ;; LOWER: (import "string.const" "0" (global $"string.const_\"bar\"" (ref extern))) |
| 48 | + ;; LOWER: (import "string.const" "0" (global $global (ref extern))) |
49 | 49 |
|
50 | | - ;; LOWER: (import "string.const" "1" (global $"string.const_\"other\"" (ref extern))) |
| 50 | + ;; LOWER: (import "string.const" "1" (global $"string.const_\"bar\"" (ref extern))) |
51 | 51 |
|
52 | | - ;; LOWER: (import "string.const" "2" (global $global (ref extern))) |
| 52 | + ;; LOWER: (import "string.const" "2" (global $"string.const_\"other\"" (ref extern))) |
53 | 53 |
|
54 | 54 | ;; LOWER: (import "wasm:js-string" "fromCharCodeArray" (func $fromCharCodeArray (type $3) (param (ref null $0) i32 i32) (result (ref extern)))) |
55 | 55 |
|
|
165 | 165 |
|
166 | 166 | ;; LOWER: (type $8 (func (param externref i32 i32) (result (ref extern)))) |
167 | 167 |
|
| 168 | + ;; LOWER: (import "string.const" "0" (global $global1 (ref extern))) |
| 169 | + |
| 170 | + ;; LOWER: (import "string.const" "1" (global $global4 (ref extern))) |
| 171 | + |
168 | 172 | ;; LOWER: (import "a" "b" (global $import (ref extern))) |
169 | 173 | (import "a" "b" (global $import (ref string))) |
170 | 174 |
|
171 | 175 | ;; CHECK: (global $global1 (ref string) (string.const "foo")) |
172 | 176 | (global $global1 (ref string) (string.const "foo")) |
173 | 177 |
|
174 | | - ;; CHECK: (global $global2 (ref string) (global.get $global1)) |
175 | | - ;; LOWER: (import "string.const" "0" (global $global1 (ref extern))) |
176 | | - |
177 | | - ;; LOWER: (import "string.const" "1" (global $global4 (ref extern))) |
| 178 | + ;; CHECK: (global $global4 (ref string) (string.const "bar")) |
178 | 179 |
|
| 180 | + ;; CHECK: (global $global2 (ref string) (global.get $global1)) |
179 | 181 | ;; LOWER: (import "wasm:js-string" "fromCharCodeArray" (func $fromCharCodeArray (type $2) (param (ref null $0) i32 i32) (result (ref extern)))) |
180 | 182 |
|
181 | 183 | ;; LOWER: (import "wasm:js-string" "fromCodePoint" (func $fromCodePoint (type $3) (param i32) (result (ref extern)))) |
|
201 | 203 | ;; LOWER: (global $global3 (ref extern) (global.get $global1)) |
202 | 204 | (global $global3 (ref string) (string.const "foo")) |
203 | 205 |
|
204 | | - ;; CHECK: (global $global4 (ref string) (string.const "bar")) |
205 | 206 | (global $global4 (ref string) (string.const "bar")) |
206 | 207 |
|
207 | 208 | ;; CHECK: (global $global5 (ref string) (global.get $global4)) |
|
279 | 280 | ) |
280 | 281 | ) |
281 | 282 | ) |
| 283 | + |
| 284 | +;; A module where a string (in this case the empty string) appears twice, so we |
| 285 | +;; will use a single global for both. The first use of the string appears in a |
| 286 | +;; nested position, inside a struct constructor, so we cannot use that one as |
| 287 | +;; our defining global, but there is an appropriate global after it. We must be |
| 288 | +;; careful to then sort the globals, as $string must then appear before $struct. |
| 289 | +(module |
| 290 | + ;; CHECK: (type $struct (struct (field stringref))) |
| 291 | + ;; LOWER: (type $0 (array (mut i16))) |
| 292 | + |
| 293 | + ;; LOWER: (type $struct (struct (field externref))) |
| 294 | + (type $struct (struct (field stringref))) |
| 295 | + |
| 296 | + ;; CHECK: (global $string (ref string) (string.const "")) |
| 297 | + |
| 298 | + ;; CHECK: (global $struct (ref $struct) (struct.new $struct |
| 299 | + ;; CHECK-NEXT: (global.get $string) |
| 300 | + ;; CHECK-NEXT: )) |
| 301 | + ;; LOWER: (type $2 (func (param externref externref) (result i32))) |
| 302 | + |
| 303 | + ;; LOWER: (type $3 (func (param (ref null $0) i32 i32) (result (ref extern)))) |
| 304 | + |
| 305 | + ;; LOWER: (type $4 (func (param i32) (result (ref extern)))) |
| 306 | + |
| 307 | + ;; LOWER: (type $5 (func (param externref externref) (result (ref extern)))) |
| 308 | + |
| 309 | + ;; LOWER: (type $6 (func (param externref (ref null $0) i32) (result i32))) |
| 310 | + |
| 311 | + ;; LOWER: (type $7 (func (param externref) (result i32))) |
| 312 | + |
| 313 | + ;; LOWER: (type $8 (func (param externref i32) (result i32))) |
| 314 | + |
| 315 | + ;; LOWER: (type $9 (func (param externref i32 i32) (result (ref extern)))) |
| 316 | + |
| 317 | + ;; LOWER: (import "string.const" "0" (global $string (ref extern))) |
| 318 | + |
| 319 | + ;; LOWER: (import "wasm:js-string" "fromCharCodeArray" (func $fromCharCodeArray (type $3) (param (ref null $0) i32 i32) (result (ref extern)))) |
| 320 | + |
| 321 | + ;; LOWER: (import "wasm:js-string" "fromCodePoint" (func $fromCodePoint (type $4) (param i32) (result (ref extern)))) |
| 322 | + |
| 323 | + ;; LOWER: (import "wasm:js-string" "concat" (func $concat (type $5) (param externref externref) (result (ref extern)))) |
| 324 | + |
| 325 | + ;; LOWER: (import "wasm:js-string" "intoCharCodeArray" (func $intoCharCodeArray (type $6) (param externref (ref null $0) i32) (result i32))) |
| 326 | + |
| 327 | + ;; LOWER: (import "wasm:js-string" "equals" (func $equals (type $2) (param externref externref) (result i32))) |
| 328 | + |
| 329 | + ;; LOWER: (import "wasm:js-string" "compare" (func $compare (type $2) (param externref externref) (result i32))) |
| 330 | + |
| 331 | + ;; LOWER: (import "wasm:js-string" "length" (func $length (type $7) (param externref) (result i32))) |
| 332 | + |
| 333 | + ;; LOWER: (import "wasm:js-string" "charCodeAt" (func $charCodeAt (type $8) (param externref i32) (result i32))) |
| 334 | + |
| 335 | + ;; LOWER: (import "wasm:js-string" "substring" (func $substring (type $9) (param externref i32 i32) (result (ref extern)))) |
| 336 | + |
| 337 | + ;; LOWER: (global $struct (ref $struct) (struct.new $struct |
| 338 | + ;; LOWER-NEXT: (global.get $string) |
| 339 | + ;; LOWER-NEXT: )) |
| 340 | + (global $struct (ref $struct) (struct.new $struct |
| 341 | + (string.const "") |
| 342 | + )) |
| 343 | + |
| 344 | + (global $string (ref string) (string.const "")) |
| 345 | +) |
| 346 | + |
0 commit comments