From a4d0595b70aab0cc71a6f4721654a961190f5180 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 25 Jun 2023 13:56:22 +0100 Subject: Support init funcs in WASM binary format --- .../structure/WasmBinaryFormatModuleTests.java | 33 ++++++++++++++++++++++ 1 file changed, 33 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 58c39b85..bab17edd 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,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmExpression; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmI32Const; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmI64Const; +import org.shedlang.compiler.backends.wasm.structure.ast.linking.WasmInitFunc; import org.shedlang.compiler.backends.wasm.structure.ast.modules.*; import org.shedlang.compiler.backends.wasm.structure.ast.types.*; import org.shedlang.compiler.testing.ProcessRunner; @@ -269,6 +270,38 @@ public class WasmBinaryFormatModuleTests { snapshotter.assertSnapshot(result); } + @Test + public void canSerializeModuleWithInitFuncs(Snapshotter snapshotter) throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addFunction(new WasmFunction( + "f1", + List.of(), + List.of(), + List.of(), + new WasmExpression(List.of()) + )) + .addFunction(new WasmFunction( + "f2", + List.of(), + List.of(), + List.of(), + new WasmExpression(List.of()) + )) + .addFunction(new WasmFunction( + "f3", + List.of(), + List.of(), + List.of(), + new WasmExpression(List.of()) + )) + .addInitFunc(new WasmInitFunc(0, new WasmFuncIndex(2))) + .addInitFunc(new WasmInitFunc(4, new WasmFuncIndex(0))); + + var result = serializeModule(module); + + snapshotter.assertSnapshot(result); + } + private String serializeModule(WasmModule module) throws IOException, InterruptedException { Files.createDirectories(Path.of("tests-tmp")); var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat"); -- cgit v1.2.3