From 8c6b959516f1041b826804ecf442aeb745c7b07a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 27 Dec 2023 13:43:44 +0000 Subject: Enable Patio-to-Wasm tests for wasm64 --- .../compiler/backends/wasm/PatioToWasm32Tests.java | 8 ++++++ .../compiler/backends/wasm/PatioToWasm64Tests.java | 8 ++++++ .../compiler/backends/wasm/PatioToWasmTests.java | 31 ++++++++++++++-------- 3 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasm32Tests.java create mode 100644 src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasm64Tests.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasm32Tests.java b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasm32Tests.java new file mode 100644 index 00000000..44626dca --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasm32Tests.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.backends.wasm; + +public class PatioToWasm32Tests extends PatioToWasmTests { + @Override + protected WasmTarget wasmTarget() { + return WasmTarget.WASM32; + } +} diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasm64Tests.java b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasm64Tests.java new file mode 100644 index 00000000..d73bf2c8 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasm64Tests.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.backends.wasm; + +public class PatioToWasm64Tests extends PatioToWasmTests { + @Override + protected WasmTarget wasmTarget() { + return WasmTarget.WASM64; + } +} diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java index d14cdedf..a239073d 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java @@ -3,6 +3,8 @@ package org.shedlang.compiler.backends.wasm; import org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormat; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmCall; import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmExpression; +import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmI32WrapI64; +import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmInstruction; import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmFuncName; import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmFunction; import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmImport; @@ -10,11 +12,12 @@ import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmImportDescr import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmFuncType; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType; import org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting; -import org.shedlang.compiler.patio.PatioExampleTests; import org.shedlang.compiler.patio.PatioCompilationUnit; +import org.shedlang.compiler.patio.PatioExampleTests; import org.shedlang.compiler.testing.ExecutionResult; import org.shedlang.compiler.testing.TestProcessRunner; import org.shedlang.compiler.util.Lists; +import org.shedlang.compiler.util.P; import java.io.FileOutputStream; import java.io.IOException; @@ -22,22 +25,27 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -public class PatioToWasmTests extends PatioExampleTests { +public abstract class PatioToWasmTests extends PatioExampleTests { @Override protected ExecutionResult run(PatioCompilationUnit patio) throws IOException, InterruptedException { - var wasmModule = PatioToWasm.generateCompilationUnit(patio, WasmTarget.WASM32); + var wasmModule = PatioToWasm.generateCompilationUnit(patio, wasmTarget()); wasmModule = WasmBackend.generateNativeRuntime(wasmModule); + var body = P.vector(new WasmCall(new WasmFuncName(FUNCTION_NAME))); + + if (wasmTarget() == WasmTarget.WASM64) { + body = body.plus(new WasmI32WrapI64()); + } + + body = body.plus(new WasmCall(new WasmFuncName("proc_exit"))); + wasmModule = wasmModule.addFunction(new WasmFunction( "_start", List.of(), List.of(), List.of(), - new WasmExpression(List.of( - new WasmCall(new WasmFuncName(FUNCTION_NAME)), - new WasmCall(new WasmFuncName("proc_exit")) - )) + new WasmExpression(body) )); wasmModule = wasmModule.addImport(new WasmImport( @@ -58,19 +66,20 @@ public class PatioToWasmTests extends PatioExampleTests { } var executablePath = workingDirectory.resolve("main.wasm"); - // TODO: also cover wasm64? - WasmBackend.WASM32.link( + new WasmBackend(wasmTarget()).link( List.of(objectPath), executablePath ); - WasmBinaryFormatTesting.validate(executablePath, WasmTarget.WASM32); + WasmBinaryFormatTesting.validate(executablePath, wasmTarget()); return TestProcessRunner.runCaptureOutput(Lists.concat( - WasmTesting.binaryRunner(WasmTarget.WASM32), + WasmTesting.binaryRunner(wasmTarget()), List.of( executablePath.toString() ) )); } + + protected abstract WasmTarget wasmTarget(); } -- cgit v1.2.3