wasm gc: export exception tag from module

This commit is contained in:
Alexey Andreev 2024-08-02 14:31:00 +02:00
parent e4fa6bd364
commit 7ba0a7fe7d
3 changed files with 23 additions and 3 deletions

View File

@ -107,6 +107,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
public WasmTag getExceptionTag() {
if (exceptionTag == null) {
exceptionTag = new WasmTag(functionTypes.of(null));
exceptionTag.setExportName("javaException");
module.tags.add(exceptionTag);
}
return exceptionTag;

View File

@ -17,8 +17,7 @@ package org.teavm.backend.wasm.model;
public class WasmTag extends WasmEntity {
private WasmFunctionType type;
WasmModule module;
int index;
private String exportName;
public WasmTag(WasmFunctionType type) {
this.type = type;
@ -28,6 +27,14 @@ public class WasmTag extends WasmEntity {
return type;
}
public String getExportName() {
return exportName;
}
public void setExportName(String exportName) {
this.exportName = exportName;
}
public int getIndex() {
return index;
}

View File

@ -48,6 +48,7 @@ public class WasmBinaryRenderer {
private static final int EXTERNAL_KIND_FUNCTION = 0;
private static final int EXTERNAL_KIND_MEMORY = 2;
private static final int EXTERNAL_KIND_TAG = 4;
private WasmBinaryWriter output;
private WasmBinaryVersion version;
@ -235,7 +236,11 @@ public class WasmBinaryRenderer {
.filter(function -> function.getExportName() != null)
.collect(Collectors.toList());
section.writeLEB(functions.size() + 1);
var tags = module.tags.stream()
.filter(tag -> tag.getExportName() != null)
.collect(Collectors.toList());
section.writeLEB(functions.size() + tags.size() + 1);
for (var function : functions) {
int functionIndex = module.functions.indexOf(function);
@ -244,6 +249,13 @@ public class WasmBinaryRenderer {
section.writeByte(EXTERNAL_KIND_FUNCTION);
section.writeLEB(functionIndex);
}
for (var tag : tags) {
var tagIndex = module.tags.indexOf(tag);
section.writeAsciiString(tag.getExportName());
section.writeByte(EXTERNAL_KIND_TAG);
section.writeLEB(tagIndex);
}
// We also need to export the memory to make it accessible
section.writeAsciiString("memory");