From f365095e567847620edfa6af6f72b5bc50f9537e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 21 Jun 2023 22:45:17 +0100 Subject: Support import of cuntions in WASM binary format --- .../structure/WasmBinaryFormatModuleTests.java | 25 ++++++++++++++++++++++ .../snapshots/WasmBinaryFormatModuleTests.snap | 5 +++++ 2 files changed, 30 insertions(+) (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 d53ffc62..ad63f317 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.imports.WasmImport; +import org.shedlang.compiler.backends.wasm.structure.ast.imports.WasmImportDescriptor; 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; @@ -42,6 +44,29 @@ public class WasmBinaryFormatModuleTests { expect.toMatchSnapshot(result); } + @Test + public void canSerializeModuleWithImports() throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addType(new WasmFuncType(List.of(), List.of())) + .addType(new WasmFuncType(List.of(WasmValueType.I32), List.of())) + .addImport(new WasmImport( + "ModuleName1", + "EntityName1", + "Identifier1", + new WasmImportDescriptor.Func(new WasmFuncType(List.of(), List.of())) + )) + .addImport(new WasmImport( + "ModuleName2", + "EntityName2", + "Identifier2", + new WasmImportDescriptor.Func(new WasmFuncType(List.of(WasmValueType.I32), List.of())) + )); + + var result = serializeModule(module); + + expect.toMatchSnapshot(result); + } + private String serializeModule(WasmModule module) throws IOException, InterruptedException { Files.createDirectories(Path.of("tests-tmp")); var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat"); 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 c205ed8e..ccd82568 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 @@ -3,6 +3,11 @@ module.wasm: file format wasm 0x1Section Details:Code Disassembly: ] +org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests.canSerializeModuleWithImports=[ +module.wasm: file format wasm 0x1Section Details:Type[2]: - type[0] () -> nil - type[1] (i32) -> nilImport[2]: - func[0] sig=0 <- ModuleName1.EntityName1 - func[1] sig=1 <- ModuleName2.EntityName2Code 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