From 1e586f72afa17fc6a956f96c1b163c7a3ac6c2a1 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 12 Feb 2024 19:23:47 +0000 Subject: Remove reliance on exit code for Patio tests --- .../compiler/backends/llvm/PatioToLlvmTests.java | 26 +++++++++++----------- .../compiler/backends/wasm/PatioToWasmTests.java | 22 +----------------- 2 files changed, 14 insertions(+), 34 deletions(-) (limited to 'src/test/java/org/shedlang/compiler/backends') diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/PatioToLlvmTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/PatioToLlvmTests.java index 2873a855..802287ce 100644 --- a/src/test/java/org/shedlang/compiler/backends/llvm/PatioToLlvmTests.java +++ b/src/test/java/org/shedlang/compiler/backends/llvm/PatioToLlvmTests.java @@ -6,11 +6,11 @@ import org.shedlang.compiler.backends.llvm.ir.ast.LlvmBasicBlock; import org.shedlang.compiler.backends.llvm.ir.ast.LlvmFunctionDefinition; import org.shedlang.compiler.backends.llvm.ir.ast.instructions.LlvmCall; import org.shedlang.compiler.backends.llvm.ir.ast.instructions.LlvmReturn; -import org.shedlang.compiler.backends.llvm.ir.ast.instructions.LlvmTrunc; +import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmOperandInt; import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmVariableGlobal; -import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmVariableLocal; import org.shedlang.compiler.backends.llvm.ir.ast.types.LlvmTypes; import org.shedlang.compiler.backends.paths.PartialTargetPath; +import org.shedlang.compiler.filesystem.ShedCompilerFiles; import org.shedlang.compiler.patio.PatioCompilationUnit; import org.shedlang.compiler.patio.PatioExampleTests; import org.shedlang.compiler.testing.ExecutionResult; @@ -24,7 +24,7 @@ import java.util.Optional; public abstract class PatioToLlvmTests extends PatioExampleTests { @Override - protected ExecutionResult run(PatioCompilationUnit patio) throws IOException, InterruptedException { + protected ExecutionResult executeCompilationUnit(PatioCompilationUnit patio) throws IOException, InterruptedException { var llvmModuleResult = PatioToLlvm.generateCompilationUnit( patio, PatioToLlvmGlobalContext.empty(this.llvmTarget()) @@ -40,19 +40,13 @@ public abstract class PatioToLlvmTests extends PatioExampleTests { Optional.empty(), List.of( new LlvmCall( - new LlvmVariableLocal("exitCode"), - LlvmTypes.INT_64, + Optional.empty(), + LlvmTypes.VOID, new LlvmVariableGlobal(FUNCTION_NAME), List.of() - ), - new LlvmTrunc( - new LlvmVariableLocal("exitCode32"), - LlvmTypes.INT_64, - new LlvmVariableLocal("exitCode"), - LlvmTypes.INT_32 ) ), - new LlvmReturn(LlvmTypes.INT_32, new LlvmVariableLocal("exitCode32")) + new LlvmReturn(LlvmTypes.INT_32, new LlvmOperandInt(0)) ) ) )); @@ -69,7 +63,13 @@ public abstract class PatioToLlvmTests extends PatioExampleTests { var executablePath = workingDirectory.resolve("main"); LlvmBackend.forTarget(this.llvmTarget()).link( - List.of(objectFilePath), + List.of( + objectFilePath, + ShedCompilerFiles.getRoot() + .resolve("runtime/target") + .resolve(this.llvmTarget().targetName()) + .resolve("libpatio_test.a") + ), executablePath ); 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 d3a929e8..ed0380ea 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java @@ -3,14 +3,9 @@ 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; -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.PatioCompilationUnit; import org.shedlang.compiler.patio.PatioExampleTests; @@ -27,19 +22,13 @@ import java.util.List; public abstract class PatioToWasmTests extends PatioExampleTests { @Override - protected ExecutionResult run(PatioCompilationUnit patio) throws IOException, InterruptedException { + protected ExecutionResult executeCompilationUnit(PatioCompilationUnit patio) throws IOException, InterruptedException { 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(), @@ -48,15 +37,6 @@ public abstract class PatioToWasmTests extends PatioExampleTests { new WasmExpression(body) )); - 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"), "PatioToWasmTests"); -- cgit v1.2.3