mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-31 12:24:10 -08:00
WASM: fix bugs in support of 0xC binary version
This commit is contained in:
parent
386c703459
commit
b4916ee4e7
|
@ -155,12 +155,11 @@ public class WasmBinaryRenderer {
|
||||||
private void renderFunctions(WasmModule module) {
|
private void renderFunctions(WasmModule module) {
|
||||||
WasmBinaryWriter section = new WasmBinaryWriter();
|
WasmBinaryWriter section = new WasmBinaryWriter();
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
List<WasmFunction> functions = module.getFunctions().values().stream()
|
List<WasmFunction> functions = module.getFunctions().values().stream()
|
||||||
.filter(function -> function.getImportName() == null)
|
.filter(function -> function.getImportName() == null)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
for (WasmFunction function : functions) {
|
for (WasmFunction function : functions) {
|
||||||
functionIndexes.put(function.getName(), index++);
|
functionIndexes.put(function.getName(), functionIndexes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
section.writeLEB(functions.size());
|
section.writeLEB(functions.size());
|
||||||
|
@ -187,9 +186,8 @@ public class WasmBinaryRenderer {
|
||||||
} else {
|
} else {
|
||||||
section.writeByte(1);
|
section.writeByte(1);
|
||||||
section.writeByte(0x20);
|
section.writeByte(0x20);
|
||||||
section.writeByte(1);
|
section.writeByte(0);
|
||||||
section.writeLEB(functionIndexes.size());
|
section.writeLEB(functionIndexes.size());
|
||||||
//section.writeLEB(functionIndexes.size());
|
|
||||||
}
|
}
|
||||||
writeSection(SECTION_TABLE, "table", section.getData());
|
writeSection(SECTION_TABLE, "table", section.getData());
|
||||||
}
|
}
|
||||||
|
@ -320,6 +318,9 @@ public class WasmBinaryRenderer {
|
||||||
for (WasmExpression part : function.getBody()) {
|
for (WasmExpression part : function.getBody()) {
|
||||||
part.acceptVisitor(visitor);
|
part.acceptVisitor(visitor);
|
||||||
}
|
}
|
||||||
|
if (version == WasmBinaryVersion.V_0xC) {
|
||||||
|
code.writeByte(0x0F);
|
||||||
|
}
|
||||||
|
|
||||||
return code.getData();
|
return code.getData();
|
||||||
}
|
}
|
||||||
|
@ -333,7 +334,15 @@ public class WasmBinaryRenderer {
|
||||||
|
|
||||||
section.writeLEB(module.getSegments().size());
|
section.writeLEB(module.getSegments().size());
|
||||||
for (WasmMemorySegment segment : module.getSegments()) {
|
for (WasmMemorySegment segment : module.getSegments()) {
|
||||||
section.writeLEB(segment.getOffset());
|
if (version == WasmBinaryVersion.V_0xB) {
|
||||||
|
section.writeLEB(segment.getOffset());
|
||||||
|
} else {
|
||||||
|
section.writeByte(0);
|
||||||
|
section.writeByte(0x10);
|
||||||
|
section.writeLEB(segment.getOffset());
|
||||||
|
section.writeByte(0xF);
|
||||||
|
}
|
||||||
|
|
||||||
section.writeLEB(segment.getLength());
|
section.writeLEB(segment.getLength());
|
||||||
int chunkSize = 65536;
|
int chunkSize = 65536;
|
||||||
for (int i = 0; i < segment.getLength(); i += chunkSize) {
|
for (int i = 0; i < segment.getLength(); i += chunkSize) {
|
||||||
|
|
|
@ -107,10 +107,10 @@ public final class TeaVMRunner {
|
||||||
.withLongOpt("classpath")
|
.withLongOpt("classpath")
|
||||||
.create('p'));
|
.create('p'));
|
||||||
options.addOption(OptionBuilder
|
options.addOption(OptionBuilder
|
||||||
.withArgName("wasm-version")
|
.withLongOpt("wasm-version")
|
||||||
|
.withArgName("version")
|
||||||
.hasArg()
|
.hasArg()
|
||||||
.withDescription("WebAssembly binary version (11, 12)")
|
.withDescription("WebAssembly binary version (11, 12)")
|
||||||
.withLongOpt("version")
|
|
||||||
.create());
|
.create());
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user