From 126533bf5210d1bf311628a18af6e46f765c922e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 21 Jun 2023 21:27:31 +0100 Subject: Add binary encoding of WASM type section --- .../wasm/structure/WasmBinaryFormatModuleTests.java | 20 ++++++++++++++++++-- .../snapshots/WasmBinaryFormatModuleTests.snap | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java index 5ddad366..d53ffc62 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java @@ -5,6 +5,8 @@ import au.com.origin.snapshots.junit5.SnapshotExtension; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.backends.wasm.structure.ast.WasmModule; +import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmFuncType; +import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType; import org.shedlang.compiler.testing.ProcessRunner; import java.io.FileOutputStream; @@ -19,8 +21,21 @@ public class WasmBinaryFormatModuleTests { @Test public void canSerializeEmptyModule() throws IOException, InterruptedException { - var module = WasmModule.builder() - .build(); + var module = WasmModule.EMPTY; + + var result = serializeModule(module); + + expect.toMatchSnapshot(result); + } + + @Test + public void canSerializeModuleWithTypes() throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addType(new WasmFuncType(List.of(), List.of())) + .addType(new WasmFuncType( + List.of(WasmValueType.I32, WasmValueType.I64), + List.of(WasmValueType.F32, WasmValueType.F64) + )); var result = serializeModule(module); @@ -31,6 +46,7 @@ public class WasmBinaryFormatModuleTests { Files.createDirectories(Path.of("tests-tmp")); var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat"); var modulePath = temporaryDirectory.resolve("module.wasm"); + System.out.println(modulePath); try (var outputStream = new FileOutputStream(modulePath.toFile())) { WasmBinaryFormat.serializeModule(module, outputStream); diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/snapshots/WasmBinaryFormatModuleTests.snap b/src/test/java/org/shedlang/compiler/backends/wasm/structure/snapshots/WasmBinaryFormatModuleTests.snap index 370ab0d6..c205ed8e 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/snapshots/WasmBinaryFormatModuleTests.snap +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/snapshots/WasmBinaryFormatModuleTests.snap @@ -1,3 +1,8 @@ org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests.canSerializeEmptyModule=[ module.wasm: file format wasm 0x1Section Details:Code Disassembly: +] + + +org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests.canSerializeModuleWithTypes=[ +module.wasm: file format wasm 0x1Section Details:Type[2]: - type[0] () -> nil - type[1] (i32, i64) -> (f32, f64)Code Disassembly: ] \ No newline at end of file -- cgit v1.2.3