Backed out changeset 88fbb17e3c20 (bug 1865637) for causing animation related mochite...
[gecko.git] / js / src / wasm / WasmDump.cpp
blob2af9ebece2aa388b8958853513988f744a9ccc5f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "wasm/WasmDump.h"
9 #include <cinttypes>
11 using namespace js;
12 using namespace js::wasm;
14 #ifdef DEBUG
16 void wasm::Dump(ValType type) {
17 Fprinter out(stdout);
18 wasm::Dump(type, out);
21 void wasm::Dump(ValType type, GenericPrinter& out) {
22 Dump(type.storageType(), out);
25 void wasm::Dump(StorageType type) {
26 Fprinter out(stdout);
27 wasm::Dump(type, out);
30 void wasm::Dump(StorageType type, GenericPrinter& out) {
31 const char* literal = nullptr;
32 switch (type.kind()) {
33 case StorageType::I8:
34 literal = "i8";
35 break;
36 case StorageType::I16:
37 literal = "i16";
38 break;
39 case StorageType::I32:
40 literal = "i32";
41 break;
42 case StorageType::I64:
43 literal = "i64";
44 break;
45 case StorageType::V128:
46 literal = "v128";
47 break;
48 case StorageType::F32:
49 literal = "f32";
50 break;
51 case StorageType::F64:
52 literal = "f64";
53 break;
54 case StorageType::Ref:
55 return Dump(type.refType(), out);
57 out.put(literal);
60 void wasm::Dump(RefType type) {
61 Fprinter out(stdout);
62 wasm::Dump(type, out);
65 void wasm::Dump(RefType type, GenericPrinter& out) {
66 if (type.isNullable() && !type.isTypeRef()) {
67 const char* literal = nullptr;
68 switch (type.kind()) {
69 case RefType::Func:
70 literal = "funcref";
71 break;
72 case RefType::Extern:
73 literal = "externref";
74 break;
75 case RefType::Any:
76 literal = "anyref";
77 break;
78 case RefType::NoFunc:
79 literal = "nullfuncref";
80 break;
81 case RefType::NoExtern:
82 literal = "nullexternref";
83 break;
84 case RefType::None:
85 literal = "nullref";
86 break;
87 case RefType::Eq:
88 literal = "eqref";
89 break;
90 case RefType::I31:
91 literal = "i31ref";
92 break;
93 case RefType::Struct:
94 literal = "structref";
95 break;
96 case RefType::Array:
97 literal = "arrayref";
98 break;
99 case RefType::Exn:
100 literal = "exnref";
101 break;
102 case RefType::TypeRef: {
103 MOZ_CRASH("type ref should not be possible here");
106 out.put(literal);
107 return;
110 // Emit the full reference type with heap type
111 const char* heapType = nullptr;
112 switch (type.kind()) {
113 case RefType::Func:
114 heapType = "func";
115 break;
116 case RefType::Extern:
117 heapType = "extern";
118 break;
119 case RefType::Any:
120 heapType = "any";
121 break;
122 case RefType::NoFunc:
123 heapType = "nofunc";
124 break;
125 case RefType::NoExtern:
126 heapType = "noextern";
127 break;
128 case RefType::None:
129 heapType = "none";
130 break;
131 case RefType::Eq:
132 heapType = "eq";
133 break;
134 case RefType::I31:
135 heapType = "eq";
136 break;
137 case RefType::Struct:
138 heapType = "struct";
139 break;
140 case RefType::Array:
141 heapType = "array";
142 break;
143 case RefType::Exn:
144 heapType = "exn";
145 break;
146 case RefType::TypeRef: {
147 uintptr_t typeAddress = (uintptr_t)type.typeDef();
148 out.printf("(ref %s0x%" PRIxPTR ")", type.isNullable() ? "null " : "",
149 typeAddress);
150 return;
153 out.printf("(ref %s%s)", type.isNullable() ? "null " : "", heapType);
156 void wasm::Dump(const FuncType& funcType) {
157 Fprinter fileOut(stdout);
158 IndentedPrinter out(fileOut);
159 wasm::Dump(funcType, out);
162 void wasm::Dump(const FuncType& funcType, IndentedPrinter& out) {
163 out.printf("(func\n");
165 IndentedPrinter::AutoIndent innerIndent(out);
166 for (ValType arg : funcType.args()) {
167 out.printf("(param ");
168 Dump(arg, out);
169 out.printf(")\n");
171 for (ValType result : funcType.results()) {
172 out.printf("(result ");
173 Dump(result, out);
174 out.printf(")\n");
177 out.printf(")\n");
180 void wasm::Dump(const StructType& structType) {
181 Fprinter fileOut(stdout);
182 IndentedPrinter out(fileOut);
183 wasm::Dump(structType, out);
186 void wasm::Dump(const StructType& structType, IndentedPrinter& out) {
187 out.printf("(struct\n");
189 IndentedPrinter::AutoIndent innerIndent(out);
190 for (const StructField& field : structType.fields_) {
191 out.printf("(field ");
192 if (field.isMutable) {
193 out.printf("(mut ");
195 Dump(field.type, out);
196 if (field.isMutable) {
197 out.printf(")");
199 out.printf(")\n");
202 out.printf(")\n");
205 void wasm::Dump(const ArrayType& arrayType) {
206 Fprinter fileOut(stdout);
207 IndentedPrinter out(fileOut);
208 wasm::Dump(arrayType, out);
211 void wasm::Dump(const ArrayType& arrayType, IndentedPrinter& out) {
212 out.printf("(array ");
213 if (arrayType.isMutable_) {
214 out.printf("(mut ");
216 Dump(arrayType.elementType_, out);
217 if (arrayType.isMutable_) {
218 out.printf(")");
220 out.printf(")\n");
223 void wasm::Dump(const TypeDef& typeDef) {
224 Fprinter fileOut(stdout);
225 IndentedPrinter out(fileOut);
226 wasm::Dump(typeDef, out);
229 void wasm::Dump(const TypeDef& typeDef, IndentedPrinter& out) {
230 out.printf("(type 0x%" PRIxPTR "\n", (uintptr_t)&typeDef);
233 IndentedPrinter::AutoIndent innerIndent(out);
234 out.printf("final=%u\n", typeDef.isFinal() ? 1 : 0);
235 out.printf("subtypingDepth=%u\n", typeDef.subTypingDepth());
236 if (typeDef.superTypeDef()) {
237 out.printf("superType=0x%" PRIxPTR "\n",
238 (uintptr_t)typeDef.superTypeDef());
240 switch (typeDef.kind()) {
241 case TypeDefKind::Func:
242 Dump(typeDef.funcType(), out);
243 break;
244 case TypeDefKind::Struct:
245 Dump(typeDef.structType(), out);
246 break;
247 case TypeDefKind::Array:
248 Dump(typeDef.arrayType(), out);
249 break;
250 case TypeDefKind::None:
251 out.printf("(none)\n");
252 break;
256 out.printf(")\n");
259 void wasm::Dump(const RecGroup& recGroup) {
260 Fprinter fileOut(stdout);
261 IndentedPrinter out(fileOut);
262 wasm::Dump(recGroup, out);
265 void wasm::Dump(const RecGroup& recGroup, IndentedPrinter& out) {
266 out.printf("(rec\n");
268 IndentedPrinter::AutoIndent innerIndent(out);
269 for (uint32_t typeIndex = 0; typeIndex < recGroup.numTypes(); typeIndex++) {
270 Dump(recGroup.type(typeIndex), out);
273 out.printf(")\n");
276 void wasm::Dump(const TypeContext& typeContext) {
277 Fprinter fileOut(stdout);
278 IndentedPrinter out(fileOut);
279 wasm::Dump(typeContext, out);
282 void wasm::Dump(const TypeContext& typeContext, IndentedPrinter& out) {
283 out.printf("(types\n");
285 IndentedPrinter::AutoIndent innerIndent(out);
286 for (const SharedRecGroup& recGroup : typeContext.groups()) {
287 Dump(*recGroup, out);
290 out.printf(")\n");
293 #endif // DEBUG