summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-12-10 15:25:23 -0800
committerGitHub <noreply@github.com>2020-12-10 15:25:23 -0800
commitc93da3de39a4592abc6cddbed30b5c7074069a24 (patch)
tree265bcd421a97a21d58493f65eb29f252bf3a6001 /src/passes/Print.cpp
parent57a9e77add02dc1d874fdbfee2c61cae8c0eefa1 (diff)
downloadbinaryen-c93da3de39a4592abc6cddbed30b5c7074069a24.tar.gz
binaryen-c93da3de39a4592abc6cddbed30b5c7074069a24.tar.bz2
binaryen-c93da3de39a4592abc6cddbed30b5c7074069a24.zip
[GC] Add Array operations (#3436)
array.new/get/set/len - pretty straightforward after structs and all the infrastructure for them. Also fixes validation of the unnecessary heapType param in the text and binary formats in structs as well as arrays. Fixes printing of packed types in type names, which emitted i32 for them. That broke when we emitted the same name for an array of i8 and i32 as in the new testing here. Also fix a bug in Field::operator< which was wrong for packed types; again, this was easy to notice with the new testing.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp78
1 files changed, 59 insertions, 19 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 0577c7c02..694b1b118 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -104,6 +104,23 @@ static void printTypeName(std::ostream& os, Type type) {
WASM_UNREACHABLE("unsupported print type");
}
+static void printFieldName(std::ostream& os, const Field& field) {
+ if (field.mutable_) {
+ os << "mut:";
+ }
+ if (field.type == Type::i32 && field.packedType != Field::not_packed) {
+ if (field.packedType == Field::i8) {
+ os << "i8";
+ } else if (field.packedType == Field::i16) {
+ os << "i16";
+ } else {
+ WASM_UNREACHABLE("invalid packed type");
+ }
+ } else {
+ printTypeName(os, field.type);
+ }
+}
+
static void printHeapTypeName(std::ostream& os, HeapType type, bool first) {
if (type.isBasic()) {
os << type;
@@ -128,19 +145,12 @@ static void printHeapTypeName(std::ostream& os, HeapType type, bool first) {
for (auto& field : struct_.fields) {
os << sep;
sep = "_";
- if (field.mutable_) {
- os << "mut:";
- }
- printTypeName(os, field.type);
+ printFieldName(os, field);
}
os << "}";
} else if (type.isArray()) {
os << "[";
- auto element = type.getArray().element;
- if (element.mutable_) {
- os << "mut:";
- }
- printTypeName(os, element.type);
+ printFieldName(os, type.getArray().element);
os << "]";
} else {
os << type;
@@ -1732,18 +1742,33 @@ struct PrintExpressionContents
o << curr->index;
}
void visitArrayNew(ArrayNew* curr) {
- WASM_UNREACHABLE("TODO (gc): array.new");
+ printMedium(o, "array.new_");
+ if (curr->isWithDefault()) {
+ o << "default_";
+ }
+ o << "with_rtt ";
+ printHeapTypeName(o, curr->rtt->type.getRtt().heapType);
}
void visitArrayGet(ArrayGet* curr) {
- WASM_UNREACHABLE("TODO (gc): array.get");
+ const auto& element = curr->ref->type.getHeapType().getArray().element;
+ if (element.type == Type::i32 && element.packedType != Field::not_packed) {
+ if (curr->signed_) {
+ printMedium(o, "array.get_s ");
+ } else {
+ printMedium(o, "array.get_u ");
+ }
+ } else {
+ printMedium(o, "array.get ");
+ }
+ printHeapTypeName(o, curr->ref->type.getHeapType());
}
void visitArraySet(ArraySet* curr) {
- printMedium(o, "array.set");
- WASM_UNREACHABLE("TODO (gc): array.set");
+ printMedium(o, "array.set ");
+ printHeapTypeName(o, curr->ref->type.getHeapType());
}
void visitArrayLen(ArrayLen* curr) {
- printMedium(o, "array.len");
- WASM_UNREACHABLE("TODO (gc): array.len");
+ printMedium(o, "array.len ");
+ printHeapTypeName(o, curr->ref->type.getHeapType());
}
};
@@ -2421,22 +2446,37 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
void visitArrayNew(ArrayNew* curr) {
o << '(';
PrintExpressionContents(currFunction, o).visit(curr);
- WASM_UNREACHABLE("TODO (gc): array.new");
+ incIndent();
+ printFullLine(curr->rtt);
+ printFullLine(curr->size);
+ if (curr->init) {
+ printFullLine(curr->init);
+ }
+ decIndent();
}
void visitArrayGet(ArrayGet* curr) {
o << '(';
PrintExpressionContents(currFunction, o).visit(curr);
- WASM_UNREACHABLE("TODO (gc): array.get");
+ incIndent();
+ printFullLine(curr->ref);
+ printFullLine(curr->index);
+ decIndent();
}
void visitArraySet(ArraySet* curr) {
o << '(';
PrintExpressionContents(currFunction, o).visit(curr);
- WASM_UNREACHABLE("TODO (gc): array.set");
+ incIndent();
+ printFullLine(curr->ref);
+ printFullLine(curr->index);
+ printFullLine(curr->value);
+ decIndent();
}
void visitArrayLen(ArrayLen* curr) {
o << '(';
PrintExpressionContents(currFunction, o).visit(curr);
- WASM_UNREACHABLE("TODO (gc): array.len");
+ incIndent();
+ printFullLine(curr->ref);
+ decIndent();
}
// Module-level visitors
void handleSignature(Signature curr, Name name = Name()) {