-
Notifications
You must be signed in to change notification settings - Fork 758
/
Copy pathPrint.cpp
3577 lines (3412 loc) · 90.5 KB
/
Print.cpp
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2016 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// Print out text in s-expression format
//
#include <algorithm>
#include <ir/iteration.h>
#include <ir/module-utils.h>
#include <ir/table-utils.h>
#include <ir/utils.h>
#include <pass.h>
#include <pretty_printing.h>
#include <support/string.h>
#include <wasm-stack.h>
#include <wasm-type-printing.h>
#include <wasm.h>
namespace wasm {
struct PrintSExpression;
static std::ostream& printExpression(Expression* expression,
std::ostream& o,
bool minify = false,
bool full = false,
Module* wasm = nullptr);
static std::ostream&
printStackInst(StackInst* inst, std::ostream& o, Function* func = nullptr);
static std::ostream& printStackIR(StackIR* ir, PrintSExpression&);
namespace {
bool isFullForced() {
if (getenv("BINARYEN_PRINT_FULL")) {
return std::stoi(getenv("BINARYEN_PRINT_FULL")) != 0;
}
return false;
}
std::ostream& printMemoryName(Name name, std::ostream& o, Module* wasm) {
if (!wasm || wasm->memories.size() > 1) {
o << ' ';
name.print(o);
}
return o;
}
std::ostream& printLocal(Index index, Function* func, std::ostream& o) {
Name name;
if (func) {
name = func->getLocalNameOrDefault(index);
}
if (!name) {
name = Name::fromInt(index);
}
return name.print(o);
}
// Print a name from the type section, if available. Otherwise print the type
// normally.
void printTypeOrName(Type type, std::ostream& o, Module* wasm) {
if (type.isRef() && wasm) {
auto heapType = type.getHeapType();
auto iter = wasm->typeNames.find(heapType);
if (iter != wasm->typeNames.end()) {
o << iter->second.name;
if (type.isNullable()) {
o << " null";
}
return;
}
}
// No luck with a name, just print the test as best we can.
o << type;
}
} // anonymous namespace
// Printing "unreachable" as a instruction prefix type is not valid in wasm text
// format. Print something else to make it pass.
static Type forceConcrete(Type type) {
return type.isConcrete() ? type : Type::i32;
}
struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
std::ostream& o;
unsigned indent = 0;
bool minify;
const char* maybeSpace;
const char* maybeNewLine;
// Whether to not elide nodes in output when possible (like implicit blocks)
// and to emit types.
bool full = false;
// If present, it contains StackIR that we will print.
std::optional<ModuleStackIR> moduleStackIR;
Module* currModule = nullptr;
Function* currFunction = nullptr;
// Keep track of the last printed debug location to avoid printing
// repeated debug locations for children. nullopt means that we have
// not yet printed any debug location, or that we last printed an
// annotation indicating that the expression had no associated
// debug location.
std::optional<Function::DebugLocation> lastPrintedLocation;
bool debugInfo;
// Used to print delegate's depth argument when it throws to the caller
int controlFlowDepth = 0;
std::vector<HeapType> heapTypes;
std::unordered_map<Signature, HeapType> signatureTypes;
// Track the print indent so that we can see when it changes. That affects how
// we print debug annotations. In particular, we don't want to print repeated
// debug locations for children, like this:
//
// ;;@ file.cpp:20:4
// (block
// ;; no need to annotate here; children have the parent's location by
// ;; default anyhow
// (nop)
//
// But we do want to print an annotation even if it repeats if it is not a
// child:
//
// ;;@ file.cpp:20:4
// (block)
// ;;@ file.cpp:20:4 - this is clearer to annotate, to avoid confusion with
// the case where there is no debug info on the nop
// (nop)
//
unsigned lastPrintIndent = 0;
// Print type names by saved name or index if we have a module, or otherwise
// by generating minimalist names. TODO: Handle conflicts between
// user-provided names and the fallback indexed names.
struct TypePrinter : TypeNameGeneratorBase<TypePrinter> {
PrintSExpression& parent;
DefaultTypeNameGenerator fallback;
std::unordered_map<HeapType, TypeNames> fallbackNames;
TypePrinter(PrintSExpression& parent, const std::vector<HeapType>& types)
: parent(parent) {
if (!parent.currModule) {
return;
}
std::unordered_set<Name> usedNames;
for (auto& [_, names] : parent.currModule->typeNames) {
usedNames.insert(names.name);
}
size_t i = 0;
// Use indices for any remaining type names, skipping any that are already
// used.
for (auto type : types) {
if (parent.currModule->typeNames.count(type)) {
++i;
continue;
}
Name name;
do {
name = std::to_string(i++);
} while (usedNames.count(name));
fallbackNames[type] = {name, {}};
}
}
TypeNames getNames(HeapType type) {
if (parent.currModule) {
if (auto it = parent.currModule->typeNames.find(type);
it != parent.currModule->typeNames.end()) {
return it->second;
}
// In principle we should always have at least a fallback name for every
// type in the module, so this lookup should never fail. In practice,
// though, the `printExpression` variants deliberately avoid walking the
// module to find unnamed types so they can be safely used in a
// function-parallel context. That means we can have a module but not
// have generated the fallback names, so this lookup can fail, in which
// case we generate a name on demand.
if (auto it = fallbackNames.find(type); it != fallbackNames.end()) {
return it->second;
}
}
return fallback.getNames(type);
}
Name getName(HeapType type) { return getNames(type).name; }
} typePrinter;
PrintSExpression(std::ostream& o) : o(o), typePrinter(*this, heapTypes) {
setMinify(false);
if (!full) {
full = isFullForced();
}
}
void setModule(Module* module);
std::ostream& printType(Type type) { return o << typePrinter(type); }
std::ostream& printHeapType(HeapType type) {
if (type.isBasic()) {
return o << type;
}
return typePrinter.getNames(type).name.print(o);
}
std::ostream& printPrefixedTypes(const char* prefix, Type type);
std::ostream& printResultType(Type type) {
return printPrefixedTypes("result", type);
}
std::ostream& printParamType(Type type) {
return printPrefixedTypes("param", type);
}
std::ostream& printBlockType(Signature sig) {
assert(sig.params == Type::none);
if (sig.results == Type::none) {
return o;
}
if (sig.results.isTuple()) {
if (auto it = signatureTypes.find(sig); it != signatureTypes.end()) {
o << "(type ";
printHeapType(it->second);
o << ") ";
}
}
printResultType(sig.results);
return o;
}
void
printDebugLocation(const std::optional<Function::DebugLocation>& location);
void printDebugLocation(Expression* curr);
// Prints debug info for a delimiter in an expression.
void printDebugDelimiterLocation(Expression* curr, Index i);
void printExpressionContents(Expression* curr);
void visit(Expression* curr) {
printDebugLocation(curr);
UnifiedExpressionVisitor<PrintSExpression>::visit(curr);
}
void setMinify(bool minify_) {
minify = minify_;
maybeSpace = minify ? "" : " ";
maybeNewLine = minify ? "" : "\n";
}
void setFull(bool full_) { full = full_; }
void generateStackIR(const PassOptions& options) {
moduleStackIR.emplace(*currModule, options);
}
void setDebugInfo(bool debugInfo_) { debugInfo = debugInfo_; }
void incIndent();
void decIndent();
void printFullLine(Expression* expression);
// loop, if, and try can contain implicit blocks. But they are not needed to
// be printed in some cases.
void maybePrintImplicitBlock(Expression* curr);
// Generic visitor, overridden only when necessary.
void visitExpression(Expression* curr);
void visitBlock(Block* curr);
void visitIf(If* curr);
void visitLoop(Loop* curr);
void visitTry(Try* curr);
void visitTryTable(TryTable* curr);
void visitResume(Resume* curr);
bool maybePrintUnreachableReplacement(Expression* curr, Type type);
bool maybePrintUnreachableOrNullReplacement(Expression* curr, Type type);
void visitCallRef(CallRef* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->target->type)) {
visitExpression(curr);
}
}
void visitRefCast(RefCast* curr) {
if (!maybePrintUnreachableReplacement(curr, curr->type)) {
visitExpression(curr);
}
}
void visitStructNew(StructNew* curr) {
if (!maybePrintUnreachableReplacement(curr, curr->type)) {
visitExpression(curr);
}
}
void visitStructSet(StructSet* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->ref->type)) {
visitExpression(curr);
}
}
void visitStructGet(StructGet* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->ref->type)) {
visitExpression(curr);
}
}
void visitArrayNew(ArrayNew* curr) {
if (!maybePrintUnreachableReplacement(curr, curr->type)) {
visitExpression(curr);
}
}
void visitArrayNewData(ArrayNewData* curr) {
if (!maybePrintUnreachableReplacement(curr, curr->type)) {
visitExpression(curr);
}
}
void visitArrayNewElem(ArrayNewElem* curr) {
if (!maybePrintUnreachableReplacement(curr, curr->type)) {
visitExpression(curr);
}
}
void visitArrayNewFixed(ArrayNewFixed* curr) {
if (!maybePrintUnreachableReplacement(curr, curr->type)) {
visitExpression(curr);
}
}
void visitArraySet(ArraySet* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->ref->type)) {
visitExpression(curr);
}
}
void visitArrayGet(ArrayGet* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->ref->type)) {
visitExpression(curr);
}
}
void visitArrayCopy(ArrayCopy* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->srcRef->type) &&
!maybePrintUnreachableOrNullReplacement(curr, curr->destRef->type)) {
visitExpression(curr);
}
}
void visitArrayFill(ArrayFill* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->ref->type)) {
visitExpression(curr);
}
}
void visitArrayInitData(ArrayInitData* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->ref->type)) {
visitExpression(curr);
}
}
void visitArrayInitElem(ArrayInitElem* curr) {
if (!maybePrintUnreachableOrNullReplacement(curr, curr->ref->type)) {
visitExpression(curr);
}
}
// Module-level visitors
void handleSignature(HeapType curr, Name name = Name());
void visitExport(Export* curr);
void emitImportHeader(Importable* curr);
void visitGlobal(Global* curr);
void emitGlobalType(Global* curr);
void visitImportedGlobal(Global* curr);
void visitDefinedGlobal(Global* curr);
void visitFunction(Function* curr);
void visitImportedFunction(Function* curr);
void visitDefinedFunction(Function* curr);
void visitTag(Tag* curr);
void visitImportedTag(Tag* curr);
void visitDefinedTag(Tag* curr);
void printTableHeader(Table* curr);
void visitTable(Table* curr);
void visitElementSegment(ElementSegment* curr);
void printMemoryHeader(Memory* curr);
void visitMemory(Memory* curr);
void visitDataSegment(DataSegment* curr);
void printDylinkSection(const std::unique_ptr<DylinkSection>& dylinkSection);
void visitModule(Module* curr);
};
// Prints the internal contents of an expression: everything but
// the children.
struct PrintExpressionContents
: public OverriddenVisitor<PrintExpressionContents> {
PrintSExpression& parent;
Module* wasm = nullptr;
Function* currFunction = nullptr;
std::ostream& o;
FeatureSet features;
PrintExpressionContents(PrintSExpression& parent)
: parent(parent), wasm(parent.currModule),
currFunction(parent.currFunction), o(parent.o),
features(wasm ? wasm->features : FeatureSet::All) {}
std::ostream& printType(Type type) { return parent.printType(type); }
std::ostream& printHeapType(HeapType type) {
return parent.printHeapType(type);
}
std::ostream& printResultType(Type type) {
return parent.printResultType(type);
}
std::ostream& printParamType(Type type) {
return parent.printParamType(type);
}
std::ostream& printBlockType(Signature sig) {
return parent.printBlockType(sig);
}
void visitBlock(Block* curr) {
printMedium(o, "block");
if (curr->name.is()) {
o << ' ';
curr->name.print(o);
}
if (curr->type.isConcrete()) {
o << ' ';
printBlockType(Signature(Type::none, curr->type));
}
}
void visitIf(If* curr) {
printMedium(o, "if");
if (curr->type.isConcrete()) {
o << ' ';
printBlockType(Signature(Type::none, curr->type));
}
}
void visitLoop(Loop* curr) {
printMedium(o, "loop");
if (curr->name.is()) {
o << ' ';
curr->name.print(o);
}
if (curr->type.isConcrete()) {
o << ' ';
printBlockType(Signature(Type::none, curr->type));
}
}
void visitBreak(Break* curr) {
if (curr->condition) {
printMedium(o, "br_if ");
} else {
printMedium(o, "br ");
}
curr->name.print(o);
}
void visitSwitch(Switch* curr) {
printMedium(o, "br_table");
for (auto& t : curr->targets) {
o << ' ';
t.print(o);
}
o << ' ';
curr->default_.print(o);
}
void visitCall(Call* curr) {
if (curr->isReturn) {
printMedium(o, "return_call ");
} else {
printMedium(o, "call ");
}
curr->target.print(o);
}
void visitCallIndirect(CallIndirect* curr) {
if (curr->isReturn) {
printMedium(o, "return_call_indirect ");
} else {
printMedium(o, "call_indirect ");
}
if (features.hasReferenceTypes()) {
curr->table.print(o);
o << ' ';
}
o << '(';
printMinor(o, "type ");
printHeapType(curr->heapType);
o << ')';
}
void visitLocalGet(LocalGet* curr) {
printMedium(o, "local.get ");
printLocal(curr->index, currFunction, o);
}
void visitLocalSet(LocalSet* curr) {
if (curr->isTee()) {
printMedium(o, "local.tee ");
} else {
printMedium(o, "local.set ");
}
printLocal(curr->index, currFunction, o);
}
void visitGlobalGet(GlobalGet* curr) {
printMedium(o, "global.get ");
curr->name.print(o);
}
void visitGlobalSet(GlobalSet* curr) {
printMedium(o, "global.set ");
curr->name.print(o);
}
void visitLoad(Load* curr) {
prepareColor(o) << forceConcrete(curr->type);
if (curr->isAtomic) {
o << ".atomic";
}
o << ".load";
if (curr->type != Type::unreachable &&
curr->bytes < curr->type.getByteSize()) {
if (curr->bytes == 1) {
o << '8';
} else if (curr->bytes == 2) {
o << "16";
} else if (curr->bytes == 4) {
o << "32";
} else {
abort();
}
o << (curr->signed_ ? "_s" : "_u");
}
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
if (curr->offset) {
o << " offset=" << curr->offset;
}
if (curr->align != curr->bytes) {
o << " align=" << curr->align;
}
}
void visitStore(Store* curr) {
prepareColor(o) << forceConcrete(curr->valueType);
if (curr->isAtomic) {
o << ".atomic";
}
o << ".store";
if (curr->bytes < 4 || (curr->valueType == Type::i64 && curr->bytes < 8)) {
if (curr->bytes == 1) {
o << '8';
} else if (curr->bytes == 2) {
o << "16";
} else if (curr->bytes == 4) {
o << "32";
} else {
abort();
}
}
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
if (curr->offset) {
o << " offset=" << curr->offset;
}
if (curr->align != curr->bytes) {
o << " align=" << curr->align;
}
}
static void printRMWSize(std::ostream& o, Type type, uint8_t bytes) {
prepareColor(o) << forceConcrete(type) << ".atomic.rmw";
if (type != Type::unreachable && bytes != type.getByteSize()) {
if (bytes == 1) {
o << '8';
} else if (bytes == 2) {
o << "16";
} else if (bytes == 4) {
o << "32";
} else {
WASM_UNREACHABLE("invalid RMW byte length");
}
}
o << '.';
}
void visitAtomicRMW(AtomicRMW* curr) {
prepareColor(o);
printRMWSize(o, curr->type, curr->bytes);
switch (curr->op) {
case RMWAdd:
o << "add";
break;
case RMWSub:
o << "sub";
break;
case RMWAnd:
o << "and";
break;
case RMWOr:
o << "or";
break;
case RMWXor:
o << "xor";
break;
case RMWXchg:
o << "xchg";
break;
}
if (curr->type != Type::unreachable &&
curr->bytes != curr->type.getByteSize()) {
o << "_u";
}
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
if (curr->offset) {
o << " offset=" << curr->offset;
}
}
void visitAtomicCmpxchg(AtomicCmpxchg* curr) {
prepareColor(o);
printRMWSize(o, curr->type, curr->bytes);
o << "cmpxchg";
if (curr->type != Type::unreachable &&
curr->bytes != curr->type.getByteSize()) {
o << "_u";
}
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
if (curr->offset) {
o << " offset=" << curr->offset;
}
}
void visitAtomicWait(AtomicWait* curr) {
prepareColor(o);
Type type = forceConcrete(curr->expectedType);
assert(type == Type::i32 || type == Type::i64);
o << "memory.atomic.wait" << (type == Type::i32 ? "32" : "64");
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
if (curr->offset) {
o << " offset=" << curr->offset;
}
}
void visitAtomicNotify(AtomicNotify* curr) {
printMedium(o, "memory.atomic.notify");
printMemoryName(curr->memory, o, wasm);
if (curr->offset) {
o << " offset=" << curr->offset;
}
}
void visitAtomicFence(AtomicFence* curr) { printMedium(o, "atomic.fence"); }
void visitSIMDExtract(SIMDExtract* curr) {
prepareColor(o);
switch (curr->op) {
case ExtractLaneSVecI8x16:
o << "i8x16.extract_lane_s";
break;
case ExtractLaneUVecI8x16:
o << "i8x16.extract_lane_u";
break;
case ExtractLaneSVecI16x8:
o << "i16x8.extract_lane_s";
break;
case ExtractLaneUVecI16x8:
o << "i16x8.extract_lane_u";
break;
case ExtractLaneVecI32x4:
o << "i32x4.extract_lane";
break;
case ExtractLaneVecI64x2:
o << "i64x2.extract_lane";
break;
case ExtractLaneVecF32x4:
o << "f32x4.extract_lane";
break;
case ExtractLaneVecF64x2:
o << "f64x2.extract_lane";
break;
}
restoreNormalColor(o);
o << " " << int(curr->index);
}
void visitSIMDReplace(SIMDReplace* curr) {
prepareColor(o);
switch (curr->op) {
case ReplaceLaneVecI8x16:
o << "i8x16.replace_lane";
break;
case ReplaceLaneVecI16x8:
o << "i16x8.replace_lane";
break;
case ReplaceLaneVecI32x4:
o << "i32x4.replace_lane";
break;
case ReplaceLaneVecI64x2:
o << "i64x2.replace_lane";
break;
case ReplaceLaneVecF32x4:
o << "f32x4.replace_lane";
break;
case ReplaceLaneVecF64x2:
o << "f64x2.replace_lane";
break;
}
restoreNormalColor(o);
o << " " << int(curr->index);
}
void visitSIMDShuffle(SIMDShuffle* curr) {
prepareColor(o);
o << "i8x16.shuffle";
restoreNormalColor(o);
for (uint8_t mask_index : curr->mask) {
o << " " << std::to_string(mask_index);
}
}
void visitSIMDTernary(SIMDTernary* curr) {
prepareColor(o);
switch (curr->op) {
case Bitselect:
o << "v128.bitselect";
break;
case LaneselectI8x16:
o << "i8x16.laneselect";
break;
case LaneselectI16x8:
o << "i16x8.laneselect";
break;
case LaneselectI32x4:
o << "i32x4.laneselect";
break;
case LaneselectI64x2:
o << "i64x2.laneselect";
break;
case RelaxedFmaVecF32x4:
o << "f32x4.relaxed_fma";
break;
case RelaxedFmsVecF32x4:
o << "f32x4.relaxed_fms";
break;
case RelaxedFmaVecF64x2:
o << "f64x2.relaxed_fma";
break;
case RelaxedFmsVecF64x2:
o << "f64x2.relaxed_fms";
break;
case DotI8x16I7x16AddSToVecI32x4:
o << "i32x4.dot_i8x16_i7x16_add_s";
break;
}
restoreNormalColor(o);
}
void visitSIMDShift(SIMDShift* curr) {
prepareColor(o);
switch (curr->op) {
case ShlVecI8x16:
o << "i8x16.shl";
break;
case ShrSVecI8x16:
o << "i8x16.shr_s";
break;
case ShrUVecI8x16:
o << "i8x16.shr_u";
break;
case ShlVecI16x8:
o << "i16x8.shl";
break;
case ShrSVecI16x8:
o << "i16x8.shr_s";
break;
case ShrUVecI16x8:
o << "i16x8.shr_u";
break;
case ShlVecI32x4:
o << "i32x4.shl";
break;
case ShrSVecI32x4:
o << "i32x4.shr_s";
break;
case ShrUVecI32x4:
o << "i32x4.shr_u";
break;
case ShlVecI64x2:
o << "i64x2.shl";
break;
case ShrSVecI64x2:
o << "i64x2.shr_s";
break;
case ShrUVecI64x2:
o << "i64x2.shr_u";
break;
}
restoreNormalColor(o);
}
void visitSIMDLoad(SIMDLoad* curr) {
prepareColor(o);
switch (curr->op) {
case Load8SplatVec128:
o << "v128.load8_splat";
break;
case Load16SplatVec128:
o << "v128.load16_splat";
break;
case Load32SplatVec128:
o << "v128.load32_splat";
break;
case Load64SplatVec128:
o << "v128.load64_splat";
break;
case Load8x8SVec128:
o << "v128.load8x8_s";
break;
case Load8x8UVec128:
o << "v128.load8x8_u";
break;
case Load16x4SVec128:
o << "v128.load16x4_s";
break;
case Load16x4UVec128:
o << "v128.load16x4_u";
break;
case Load32x2SVec128:
o << "v128.load32x2_s";
break;
case Load32x2UVec128:
o << "v128.load32x2_u";
break;
case Load32ZeroVec128:
o << "v128.load32_zero";
break;
case Load64ZeroVec128:
o << "v128.load64_zero";
break;
}
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
if (curr->offset) {
o << " offset=" << curr->offset;
}
if (curr->align != curr->getMemBytes()) {
o << " align=" << curr->align;
}
}
void visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
prepareColor(o);
switch (curr->op) {
case Load8LaneVec128:
o << "v128.load8_lane";
break;
case Load16LaneVec128:
o << "v128.load16_lane";
break;
case Load32LaneVec128:
o << "v128.load32_lane";
break;
case Load64LaneVec128:
o << "v128.load64_lane";
break;
case Store8LaneVec128:
o << "v128.store8_lane";
break;
case Store16LaneVec128:
o << "v128.store16_lane";
break;
case Store32LaneVec128:
o << "v128.store32_lane";
break;
case Store64LaneVec128:
o << "v128.store64_lane";
break;
}
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
if (curr->offset) {
o << " offset=" << curr->offset;
}
if (curr->align != curr->getMemBytes()) {
o << " align=" << curr->align;
}
o << " " << int(curr->index);
}
void visitMemoryInit(MemoryInit* curr) {
prepareColor(o);
o << "memory.init";
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
o << ' ';
curr->segment.print(o);
}
void visitDataDrop(DataDrop* curr) {
prepareColor(o);
o << "data.drop";
restoreNormalColor(o);
o << ' ';
curr->segment.print(o);
}
void visitMemoryCopy(MemoryCopy* curr) {
prepareColor(o);
o << "memory.copy";
restoreNormalColor(o);
printMemoryName(curr->destMemory, o, wasm);
printMemoryName(curr->sourceMemory, o, wasm);
}
void visitMemoryFill(MemoryFill* curr) {
prepareColor(o);
o << "memory.fill";
restoreNormalColor(o);
printMemoryName(curr->memory, o, wasm);
}
void visitConst(Const* curr) {
o << curr->value.type << ".const " << curr->value;
}
void visitUnary(Unary* curr) {
prepareColor(o);
switch (curr->op) {
case ClzInt32:
o << "i32.clz";
break;
case CtzInt32:
o << "i32.ctz";
break;
case PopcntInt32:
o << "i32.popcnt";
break;
case EqZInt32:
o << "i32.eqz";
break;
case ClzInt64:
o << "i64.clz";
break;
case CtzInt64:
o << "i64.ctz";
break;
case PopcntInt64:
o << "i64.popcnt";
break;
case EqZInt64:
o << "i64.eqz";
break;
case NegFloat32:
o << "f32.neg";
break;
case AbsFloat32:
o << "f32.abs";
break;
case CeilFloat32:
o << "f32.ceil";
break;
case FloorFloat32:
o << "f32.floor";
break;
case TruncFloat32:
o << "f32.trunc";
break;
case NearestFloat32:
o << "f32.nearest";
break;
case SqrtFloat32:
o << "f32.sqrt";
break;
case NegFloat64:
o << "f64.neg";
break;
case AbsFloat64:
o << "f64.abs";
break;
case CeilFloat64:
o << "f64.ceil";
break;
case FloorFloat64:
o << "f64.floor";
break;
case TruncFloat64:
o << "f64.trunc";
break;
case NearestFloat64:
o << "f64.nearest";
break;
case SqrtFloat64:
o << "f64.sqrt";
break;
case ExtendSInt32:
o << "i64.extend_i32_s";
break;
case ExtendUInt32:
o << "i64.extend_i32_u";
break;
case WrapInt64:
o << "i32.wrap_i64";