Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 37 additions & 31 deletions src/wasm/wasm-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct TypePrinter {
std::ostream& print(const Field& field);
std::ostream& print(const Signature& sig);
std::ostream& print(const Continuation& cont);
std::ostream& print(const Struct& struct_,
std::ostream& print(HeapType type,
const std::unordered_map<Index, Name>& fieldNames);
std::ostream& print(const Array& array);
};
Expand Down Expand Up @@ -1656,9 +1656,9 @@ std::ostream& TypePrinter::print(Type type) {
} else if (type.isRef()) {
auto heapType = type.getHeapType();
if (type.isNullable() && heapType.isBasic() && !heapType.isShared()) {
if (type.isExact()) {
os << "(exact ";
}
// if (type.isExact()) {
// os << "(exact ";
// }
// Print shorthands for certain basic heap types.
switch (heapType.getBasic(Unshared)) {
case HeapType::ext:
Expand Down Expand Up @@ -1707,22 +1707,22 @@ std::ostream& TypePrinter::print(Type type) {
os << "nullexnref";
break;
}
if (type.isExact()) {
os << ')';
}
// if (type.isExact()) {
// os << ')';
// }
return os;
}
os << "(ref ";
if (type.isNullable()) {
os << "null ";
}
if (type.isExact()) {
os << "(exact ";
}
// if (type.isExact()) {
// os << "(exact ";
// }
printHeapTypeName(heapType);
if (type.isExact()) {
os << ')';
}
// if (type.isExact()) {
// os << ')';
// }
os << ')';
} else {
WASM_UNREACHABLE("unexpected type");
Expand Down Expand Up @@ -1813,22 +1813,22 @@ std::ostream& TypePrinter::print(HeapType type) {
if (type.isShared()) {
os << "(shared ";
}
if (auto desc = type.getDescribedType()) {
os << "(describes ";
printHeapTypeName(*desc);
os << ' ';
}
if (auto desc = type.getDescriptorType()) {
os << "(descriptor ";
printHeapTypeName(*desc);
os << ' ';
}
// if (auto desc = type.getDescribedType()) {
// os << "(describes ";
// printHeapTypeName(*desc);
// os << ' ';
// }
// if (auto desc = type.getDescriptorType()) {
// os << "(descriptor ";
// printHeapTypeName(*desc);
// os << ' ';
// }
switch (type.getKind()) {
case HeapTypeKind::Func:
print(type.getSignature());
break;
case HeapTypeKind::Struct:
print(type.getStruct(), names.fieldNames);
print(type, names.fieldNames);
break;
case HeapTypeKind::Array:
print(type.getArray());
Expand All @@ -1839,12 +1839,12 @@ std::ostream& TypePrinter::print(HeapType type) {
case HeapTypeKind::Basic:
WASM_UNREACHABLE("unexpected kind");
}
if (type.getDescriptorType()) {
os << ')';
}
if (type.getDescribedType()) {
os << ')';
}
// if (type.getDescriptorType()) {
// os << ')';
// }
// if (type.getDescribedType()) {
// os << ')';
// }
if (type.isShared()) {
os << ')';
}
Expand Down Expand Up @@ -1914,9 +1914,15 @@ std::ostream& TypePrinter::print(const Continuation& continuation) {
}

std::ostream&
TypePrinter::print(const Struct& struct_,
TypePrinter::print(HeapType type,
const std::unordered_map<Index, Name>& fieldNames) {
const auto& struct_ = type.getStruct();
os << "(struct";
if (auto desc = type.getDescriptorType()) {
os << " (field $vtable ";
print(Type(*desc, NonNullable));
os << ')';
}
for (Index i = 0; i < struct_.fields.size(); ++i) {
// TODO: move this to the function for printing fields.
os << " (field ";
Expand Down
Loading