From 62f55dc669ce263656228ad7bf96a800ddb9abe3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 20 Dec 2023 16:46:28 +0000 Subject: Rename WasmPatioCodeGen to PatioToWasm --- .../compiler/backends/wasm/PatioToWasmTests.java | 75 ++++++++++++++++++++++ .../backends/wasm/WasmPatioCodeGenTests.java | 75 ---------------------- 2 files changed, 75 insertions(+), 75 deletions(-) create mode 100644 src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java delete mode 100644 src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGenTests.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java new file mode 100644 index 00000000..a8687230 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java @@ -0,0 +1,75 @@ +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.modules.WasmFuncName; +import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmFunction; +import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmImport; +import org.shedlang.compiler.backends.wasm.structure.ast.modules.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.backends.wasm.structure.binary.WasmBinaryFormatTesting; +import org.shedlang.compiler.patio.PatioExampleTests; +import org.shedlang.compiler.patio.ast.PatioCompilationUnit; +import org.shedlang.compiler.testing.ExecutionResult; +import org.shedlang.compiler.testing.TestProcessRunner; +import org.shedlang.compiler.util.Lists; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +public class PatioToWasmTests extends PatioExampleTests { + @Override + protected ExecutionResult run(PatioCompilationUnit patio) throws IOException, InterruptedException { + var wasmModule = PatioToWasm.generateCompilationUnit(patio); + + wasmModule = WasmBackend.generateNativeRuntime(wasmModule); + + 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")) + )) + )); + + wasmModule = wasmModule.addImport(new WasmImport( + "wasi_snapshot_preview1", + "proc_exit", + new WasmImportDescriptor.Func("proc_exit", new WasmFuncType( + List.of(WasmValueType.I32), + List.of() + )) + )); + + Files.createDirectories(Path.of("tests-tmp")); + var workingDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmPatioCodeGen"); + + var objectPath = workingDirectory.resolve("main.o"); + try (var outputStream = new FileOutputStream(objectPath.toFile())) { + WasmBinaryFormat.serializeModule(wasmModule, outputStream); + } + + var executablePath = workingDirectory.resolve("main.wasm"); + WasmBackend.link( + List.of(objectPath), + executablePath + ); + + WasmBinaryFormatTesting.validate(executablePath); + + return TestProcessRunner.runCaptureOutput(Lists.concat( + WasmTesting.BINARY_RUNNER, + List.of( + executablePath.toString() + ) + )); + } +} diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGenTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGenTests.java deleted file mode 100644 index f7f8b47a..00000000 --- a/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGenTests.java +++ /dev/null @@ -1,75 +0,0 @@ -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.modules.WasmFuncName; -import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmFunction; -import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmImport; -import org.shedlang.compiler.backends.wasm.structure.ast.modules.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.backends.wasm.structure.binary.WasmBinaryFormatTesting; -import org.shedlang.compiler.patio.PatioExampleTests; -import org.shedlang.compiler.patio.ast.PatioCompilationUnit; -import org.shedlang.compiler.testing.ExecutionResult; -import org.shedlang.compiler.testing.TestProcessRunner; -import org.shedlang.compiler.util.Lists; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; - -public class WasmPatioCodeGenTests extends PatioExampleTests { - @Override - protected ExecutionResult run(PatioCompilationUnit patio) throws IOException, InterruptedException { - var wasmModule = WasmPatioCodeGen.generateCompilationUnit(patio); - - wasmModule = WasmBackend.generateNativeRuntime(wasmModule); - - 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")) - )) - )); - - wasmModule = wasmModule.addImport(new WasmImport( - "wasi_snapshot_preview1", - "proc_exit", - new WasmImportDescriptor.Func("proc_exit", new WasmFuncType( - List.of(WasmValueType.I32), - List.of() - )) - )); - - Files.createDirectories(Path.of("tests-tmp")); - var workingDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmPatioCodeGen"); - - var objectPath = workingDirectory.resolve("main.o"); - try (var outputStream = new FileOutputStream(objectPath.toFile())) { - WasmBinaryFormat.serializeModule(wasmModule, outputStream); - } - - var executablePath = workingDirectory.resolve("main.wasm"); - WasmBackend.link( - List.of(objectPath), - executablePath - ); - - WasmBinaryFormatTesting.validate(executablePath); - - return TestProcessRunner.runCaptureOutput(Lists.concat( - WasmTesting.BINARY_RUNNER, - List.of( - executablePath.toString() - ) - )); - } -} -- cgit v1.2.3