Skip to content

Commit 84ace4a

Browse files
authored
PrintBoundary: Handle types for all externable things (#8739)
The old code gave memories, tables, and tags, a null Type as a placeholder. But that actually crashes in printing. This adds a proper type for each.
1 parent 17a9078 commit 84ace4a

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

src/passes/PrintBoundary.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,20 @@ struct PrintBoundary : public Pass {
135135
switch (kind) {
136136
case ExternalKind::Function:
137137
return getTypes(wasm.getFunction(name)->type);
138-
break;
139138
case ExternalKind::Table:
140-
break;
139+
return getTypes(wasm.getTable(name)->type);
141140
case ExternalKind::Memory:
142-
break;
141+
return getTypes(wasm.getMemory(name)->addressType);
143142
case ExternalKind::Global:
144143
return getTypes(wasm.getGlobal(name)->type);
145144
case ExternalKind::Tag:
146-
break;
145+
// Wrap it in a Type so that getTypes can handle it. That will print the
146+
// params and results as we expect.
147+
return getTypes(Type(wasm.getTag(name)->type, NonNullable));
147148
case ExternalKind::Invalid:
148-
WASM_UNREACHABLE("invalid ExternalKind");
149+
break;
149150
}
150-
return {};
151+
WASM_UNREACHABLE("invalid ExternalKind");
151152
}
152153

153154
json::Value::Ref getKindName(ExternalKind kind) {

test/lit/passes/print-boundary.wast

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55

66
(import "module2" "other" (func $bar (result i32 f32)))
77

8+
(memory $mem 10 20)
9+
10+
(table 10 20 funcref)
11+
12+
(tag $e (param i32))
13+
814
(global $g (mut i32) (i32.const 42))
915

1016
(export "one" (func $one))
1117

18+
(export "m" (memory $mem))
19+
20+
(export "tab" (table 0))
21+
22+
(export "tag" (tag $e))
23+
1224
(export "glob" (global $g))
1325

1426
(func $one (param $x (ref $struct)) (result i32 i32 i32)
@@ -64,9 +76,31 @@
6476
;; CHECK-NEXT: }
6577
;; CHECK-NEXT: },
6678
;; CHECK-NEXT: {
79+
;; CHECK-NEXT: "name": "m",
80+
;; CHECK-NEXT: "kind": "memory",
81+
;; CHECK-NEXT: "type": "i32"
82+
;; CHECK-NEXT: },
83+
;; CHECK-NEXT: {
84+
;; CHECK-NEXT: "name": "tab",
85+
;; CHECK-NEXT: "kind": "table",
86+
;; CHECK-NEXT: "type": "funcref"
87+
;; CHECK-NEXT: },
88+
;; CHECK-NEXT: {
89+
;; CHECK-NEXT: "name": "tag",
90+
;; CHECK-NEXT: "kind": "tag",
91+
;; CHECK-NEXT: "type": {
92+
;; CHECK-NEXT: "params": [
93+
;; CHECK-NEXT: "i32"
94+
;; CHECK-NEXT: ],
95+
;; CHECK-NEXT: "results": [
96+
;; CHECK-NEXT: ]
97+
;; CHECK-NEXT: }
98+
;; CHECK-NEXT: },
99+
;; CHECK-NEXT: {
67100
;; CHECK-NEXT: "name": "glob",
68101
;; CHECK-NEXT: "kind": "global",
69102
;; CHECK-NEXT: "type": "i32"
70103
;; CHECK-NEXT: }
71104
;; CHECK-NEXT: ]
72105
;; CHECK-NEXT: }
106+

0 commit comments

Comments
 (0)