From 7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 4 May 2023 16:44:09 -0700 Subject: [NFC] Refactor each of ArrayNewSeg and ArrayInit into subclasses for Data/Elem (#5692) ArrayNewSeg => ArrayNewSegData, ArrayNewSegElem ArrayInit => ArrayInitData, ArrayInitElem Basically we remove the opcode and use the class type to differentiate them. This adds some code but it makes the representation simpler and more compact in memory, and it will help with #5690 --- src/passes/Print.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 650a17203..76fd53759 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2265,21 +2265,20 @@ struct PrintExpressionContents o << ' '; TypeNamePrinter(o, wasm).print(curr->type.getHeapType()); } - void visitArrayNewSeg(ArrayNewSeg* curr) { + void visitArrayNewData(ArrayNewData* curr) { if (printUnreachableReplacement(curr)) { return; } - printMedium(o, "array.new_"); - switch (curr->op) { - case NewData: - printMedium(o, "data"); - break; - case NewElem: - printMedium(o, "elem"); - break; - default: - WASM_UNREACHABLE("unexpected op"); + printMedium(o, "array.new_data"); + o << ' '; + TypeNamePrinter(o, wasm).print(curr->type.getHeapType()); + o << " $" << curr->segment; + } + void visitArrayNewElem(ArrayNewElem* curr) { + if (printUnreachableReplacement(curr)) { + return; } + printMedium(o, "array.new_elem"); o << ' '; TypeNamePrinter(o, wasm).print(curr->type.getHeapType()); o << " $" << curr->segment; @@ -2333,20 +2332,19 @@ struct PrintExpressionContents printMedium(o, "array.fill "); TypeNamePrinter(o, wasm).print(curr->ref->type.getHeapType()); } - void visitArrayInit(ArrayInit* curr) { + void visitArrayInitData(ArrayInitData* curr) { if (printUnreachableOrNullReplacement(curr->ref)) { return; } - switch (curr->op) { - case InitData: - printMedium(o, "array.init_data "); - break; - case InitElem: - printMedium(o, "array.init_elem "); - break; - default: - WASM_UNREACHABLE("unexpected op"); + printMedium(o, "array.init_data "); + TypeNamePrinter(o, wasm).print(curr->ref->type.getHeapType()); + o << " $" << curr->segment; + } + void visitArrayInitElem(ArrayInitElem* curr) { + if (printUnreachableOrNullReplacement(curr->ref)) { + return; } + printMedium(o, "array.init_elem "); TypeNamePrinter(o, wasm).print(curr->ref->type.getHeapType()); o << " $" << curr->segment; } @@ -2915,7 +2913,10 @@ struct PrintSExpression : public UnifiedExpressionVisitor { void visitArrayNew(ArrayNew* curr) { maybePrintUnreachableReplacement(curr, curr->type); } - void visitArrayNewSeg(ArrayNewSeg* curr) { + void visitArrayNewData(ArrayNewData* curr) { + maybePrintUnreachableReplacement(curr, curr->type); + } + void visitArrayNewElem(ArrayNewElem* curr) { maybePrintUnreachableReplacement(curr, curr->type); } void visitArrayNewFixed(ArrayNewFixed* curr) { -- cgit v1.2.3