Skip to content

Implement type imports and exports #7330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix
  • Loading branch information
vouillon committed Mar 13, 2025
commit 7da566f8b6fab6b34fe0a7afeeba5c99f29d01cd
53 changes: 29 additions & 24 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@ void WasmBinaryReader::readTypes() {
if (!type.isRef()) {
throwError("unexpected exact prefix on non-reference type");
}
return builder.getTempRefType(
return typebuilder.getTempRefType(
type.getHeapType(), type.getNullability(), Exact);
}
return makeTypeNoExact(typeCode);
Expand Down Expand Up @@ -4459,30 +4459,35 @@ void WasmBinaryReader::readExports() {
throwError("duplicate export name");
}
ExternalKind kind = (ExternalKind)getU32LEB();
std::variant<Name, HeapType> value;
switch (kind) {
case ExternalKind::Function:
value = getFunctionName(getU32LEB());
break;
case ExternalKind::Table:
value = getTableName(getU32LEB());
break;
case ExternalKind::Memory:
value = getMemoryName(getU32LEB());
break;
case ExternalKind::Global:
value = getGlobalName(getU32LEB());
break;
case ExternalKind::Tag:
value = getTagName(getU32LEB());
break;
case ExternalKind::Type:
value = getHeapType();
break;
case ExternalKind::Invalid:
throwError("invalid export kind");
if (kind == ExternalKind::Type) {
auto curr = std::make_unique<TypeExport>();
curr->name = name;
auto* ex = wasm.addTypeExport(std::move(curr));
ex->heaptype = getHeapType();
} else {
std::variant<Name, HeapType> value;
switch (kind) {
case ExternalKind::Function:
value = getFunctionName(getU32LEB());
break;
case ExternalKind::Table:
value = getTableName(getU32LEB());
break;
case ExternalKind::Memory:
value = getMemoryName(getU32LEB());
break;
case ExternalKind::Global:
value = getGlobalName(getU32LEB());
break;
case ExternalKind::Tag:
value = getTagName(getU32LEB());
break;
case ExternalKind::Type:
case ExternalKind::Invalid:
throwError("invalid export kind");
}
wasm.addExport(new Export(name, kind, value));
}
wasm.addExport(new Export(name, kind, value));
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/binaryen.js/kitchen-sink.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Features.RelaxedSIMD: 4096
Features.ExtendedConst: 8192
Features.Strings: 16384
Features.MultiMemory: 32768
Features.All: 4194303
Features.All: 8388607
InvalidId: 0
BlockId: 1
IfId: 2
Expand Down
2 changes: 1 addition & 1 deletion test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ BinaryenFeatureMemory64: 2048
BinaryenFeatureRelaxedSIMD: 4096
BinaryenFeatureExtendedConst: 8192
BinaryenFeatureStrings: 16384
BinaryenFeatureAll: 4194303
BinaryenFeatureAll: 8388607
(f32.neg
(f32.const -33.61199951171875)
)
Expand Down