summaryrefslogtreecommitdiff
path: root/src/ir
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir')
-rw-r--r--src/ir/type-updating.cpp73
1 files changed, 32 insertions, 41 deletions
diff --git a/src/ir/type-updating.cpp b/src/ir/type-updating.cpp
index ceb37300a..92ec97980 100644
--- a/src/ir/type-updating.cpp
+++ b/src/ir/type-updating.cpp
@@ -88,55 +88,47 @@ GlobalTypeRewriter::TypeMap GlobalTypeRewriter::rebuildTypes(
// Create the temporary heap types.
i = 0;
+ auto map = [&](HeapType type) -> HeapType {
+ if (auto it = typeIndices.find(type); it != typeIndices.end()) {
+ return typeBuilder[it->second];
+ }
+ return type;
+ };
for (auto [type, _] : typeIndices) {
- typeBuilder[i].setOpen(type.isOpen());
- typeBuilder[i].setShared(type.getShared());
- if (type.isSignature()) {
- auto sig = type.getSignature();
- TypeList newParams, newResults;
- for (auto t : sig.params) {
- newParams.push_back(getTempType(t));
+ typeBuilder[i].copy(type, map);
+ switch (type.getKind()) {
+ case HeapTypeKind::Func: {
+ auto newSig = HeapType(typeBuilder[i]).getSignature();
+ modifySignature(type, newSig);
+ typeBuilder[i] = newSig;
+ break;
}
- for (auto t : sig.results) {
- newResults.push_back(getTempType(t));
+ case HeapTypeKind::Struct: {
+ auto newStruct = HeapType(typeBuilder[i]).getStruct();
+ modifyStruct(type, newStruct);
+ typeBuilder[i] = newStruct;
+ break;
}
- Signature newSig(typeBuilder.getTempTupleType(newParams),
- typeBuilder.getTempTupleType(newResults));
- modifySignature(type, newSig);
- typeBuilder[i] = newSig;
- } else if (type.isStruct()) {
- auto struct_ = type.getStruct();
- // Start with a copy to get mutability/packing/etc.
- auto newStruct = struct_;
- for (auto& field : newStruct.fields) {
- field.type = getTempType(field.type);
+ case HeapTypeKind::Array: {
+ auto newArray = HeapType(typeBuilder[i]).getArray();
+ modifyArray(type, newArray);
+ typeBuilder[i] = newArray;
+ break;
}
- modifyStruct(type, newStruct);
- typeBuilder[i] = newStruct;
- } else if (type.isArray()) {
- auto array = type.getArray();
- // Start with a copy to get mutability/packing/etc.
- auto newArray = array;
- newArray.element.type = getTempType(newArray.element.type);
- modifyArray(type, newArray);
- typeBuilder[i] = newArray;
- } else {
- WASM_UNREACHABLE("bad type");
+ case HeapTypeKind::Cont:
+ WASM_UNREACHABLE("TODO: cont");
+ case HeapTypeKind::Basic:
+ WASM_UNREACHABLE("unexpected kind");
}
- // Apply a super, if there is one
if (auto super = getDeclaredSuperType(type)) {
- if (auto it = typeIndices.find(*super); it != typeIndices.end()) {
- assert(it->second < i);
- typeBuilder[i].subTypeOf(typeBuilder[it->second]);
- } else {
- typeBuilder[i].subTypeOf(*super);
- }
+ typeBuilder[i].subTypeOf(map(*super));
+ } else {
+ typeBuilder[i].subTypeOf(std::nullopt);
}
modifyTypeBuilderEntry(typeBuilder, i, type);
-
- i++;
+ ++i;
}
auto buildResults = typeBuilder.build();
@@ -316,8 +308,7 @@ Type GlobalTypeRewriter::getTempType(Type type) {
return type;
}
if (type.isTuple()) {
- auto& tuple = type.getTuple();
- auto newTuple = tuple;
+ auto newTuple = type.getTuple();
for (auto& t : newTuple) {
t = getTempType(t);
}