mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
wasm gc: export exception tag from module
This commit is contained in:
parent
e4fa6bd364
commit
7ba0a7fe7d
|
@ -107,6 +107,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
|
||||||
public WasmTag getExceptionTag() {
|
public WasmTag getExceptionTag() {
|
||||||
if (exceptionTag == null) {
|
if (exceptionTag == null) {
|
||||||
exceptionTag = new WasmTag(functionTypes.of(null));
|
exceptionTag = new WasmTag(functionTypes.of(null));
|
||||||
|
exceptionTag.setExportName("javaException");
|
||||||
module.tags.add(exceptionTag);
|
module.tags.add(exceptionTag);
|
||||||
}
|
}
|
||||||
return exceptionTag;
|
return exceptionTag;
|
||||||
|
|
|
@ -17,8 +17,7 @@ package org.teavm.backend.wasm.model;
|
||||||
|
|
||||||
public class WasmTag extends WasmEntity {
|
public class WasmTag extends WasmEntity {
|
||||||
private WasmFunctionType type;
|
private WasmFunctionType type;
|
||||||
WasmModule module;
|
private String exportName;
|
||||||
int index;
|
|
||||||
|
|
||||||
public WasmTag(WasmFunctionType type) {
|
public WasmTag(WasmFunctionType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -28,6 +27,14 @@ public class WasmTag extends WasmEntity {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExportName() {
|
||||||
|
return exportName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExportName(String exportName) {
|
||||||
|
this.exportName = exportName;
|
||||||
|
}
|
||||||
|
|
||||||
public int getIndex() {
|
public int getIndex() {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class WasmBinaryRenderer {
|
||||||
|
|
||||||
private static final int EXTERNAL_KIND_FUNCTION = 0;
|
private static final int EXTERNAL_KIND_FUNCTION = 0;
|
||||||
private static final int EXTERNAL_KIND_MEMORY = 2;
|
private static final int EXTERNAL_KIND_MEMORY = 2;
|
||||||
|
private static final int EXTERNAL_KIND_TAG = 4;
|
||||||
|
|
||||||
private WasmBinaryWriter output;
|
private WasmBinaryWriter output;
|
||||||
private WasmBinaryVersion version;
|
private WasmBinaryVersion version;
|
||||||
|
@ -235,7 +236,11 @@ public class WasmBinaryRenderer {
|
||||||
.filter(function -> function.getExportName() != null)
|
.filter(function -> function.getExportName() != null)
|
||||||
.collect(Collectors.toList());
|
.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) {
|
for (var function : functions) {
|
||||||
int functionIndex = module.functions.indexOf(function);
|
int functionIndex = module.functions.indexOf(function);
|
||||||
|
|
||||||
|
@ -244,6 +249,13 @@ public class WasmBinaryRenderer {
|
||||||
section.writeByte(EXTERNAL_KIND_FUNCTION);
|
section.writeByte(EXTERNAL_KIND_FUNCTION);
|
||||||
section.writeLEB(functionIndex);
|
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
|
// We also need to export the memory to make it accessible
|
||||||
section.writeAsciiString("memory");
|
section.writeAsciiString("memory");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user