summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp49
-rw-r--r--src/wasm/wasm-binary.cpp4
2 files changed, 41 insertions, 12 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index abea90117..fee59ce3b 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2510,9 +2510,22 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
visitExpression(curr);
}
// Module-level visitors
+ void printSupertypeOr(HeapType curr, std::string noSuper) {
+ HeapType super;
+ if (curr.getSuperType(super)) {
+ TypeNamePrinter(o, currModule).print(super);
+ } else {
+ o << noSuper;
+ }
+ }
+
void handleSignature(HeapType curr, Name name = Name()) {
Signature sig = curr.getSignature();
- o << "(func";
+ if (!name.is() && getTypeSystem() == TypeSystem::Nominal) {
+ o << "(func_subtype";
+ } else {
+ o << "(func";
+ }
if (name.is()) {
o << " $" << name;
}
@@ -2538,6 +2551,10 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
}
o << ')';
}
+ if (!name.is() && getTypeSystem() == TypeSystem::Nominal) {
+ o << ' ';
+ printSupertypeOr(curr, "func");
+ }
o << ")";
}
void handleFieldBody(const Field& field) {
@@ -2560,13 +2577,25 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
}
}
void handleArray(HeapType curr) {
- o << "(array ";
+ if (getTypeSystem() == TypeSystem::Nominal) {
+ o << "(array_subtype ";
+ } else {
+ o << "(array ";
+ }
handleFieldBody(curr.getArray().element);
+ if (getTypeSystem() == TypeSystem::Nominal) {
+ o << ' ';
+ printSupertypeOr(curr, "data");
+ }
o << ')';
}
void handleStruct(HeapType curr) {
const auto& fields = curr.getStruct().fields;
- o << "(struct ";
+ if (getTypeSystem() == TypeSystem::Nominal) {
+ o << "(struct_subtype ";
+ } else {
+ o << "(struct ";
+ }
auto sep = "";
for (Index i = 0; i < fields.size(); i++) {
o << sep << "(field ";
@@ -2579,9 +2608,13 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
o << ')';
sep = " ";
}
+ if (getTypeSystem() == TypeSystem::Nominal) {
+ o << ' ';
+ printSupertypeOr(curr, "data");
+ }
o << ')';
}
- void handleHeapType(HeapType type, Module* module) {
+ void handleHeapType(HeapType type) {
if (type.isSignature()) {
handleSignature(type);
} else if (type.isArray()) {
@@ -2591,12 +2624,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
} else {
o << type;
}
- HeapType super;
- if (type.getSuperType(super)) {
- o << " (extends ";
- TypeNamePrinter(o, module).print(super);
- o << ')';
- }
}
void visitExport(Export* curr) {
o << '(';
@@ -2981,7 +3008,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
printMedium(o, "type") << ' ';
TypeNamePrinter(o, curr).print(type);
o << ' ';
- handleHeapType(type, curr);
+ handleHeapType(type);
o << ")" << maybeNewLine;
}
ModuleUtils::iterImportedMemories(
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 70bc738f6..e2dacdf70 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -219,11 +219,11 @@ void WasmBinaryWriter::writeTypes() {
return;
}
BYN_TRACE("== writeTypes\n");
- bool nominal = getTypeSystem() == TypeSystem::Nominal;
auto start = startSection(BinaryConsts::Section::Type);
o << U32LEB(types.size());
for (Index i = 0; i < types.size(); ++i) {
auto type = types[i];
+ bool nominal = type.isNominal() || getTypeSystem() == TypeSystem::Nominal;
BYN_TRACE("write " << type << std::endl);
if (type.isSignature()) {
o << S32LEB(nominal ? BinaryConsts::EncodedType::FuncExtending
@@ -1959,6 +1959,8 @@ void WasmBinaryBuilder::readTypes() {
if (form == BinaryConsts::EncodedType::FuncExtending ||
form == BinaryConsts::EncodedType::StructExtending ||
form == BinaryConsts::EncodedType::ArrayExtending) {
+ // TODO: Let the new nominal types coexist with equirecursive types
+ // builder[i].setNominal();
auto superIndex = getS64LEB(); // TODO: Actually s33
if (superIndex >= 0) {
if (size_t(superIndex) >= numTypes) {