diff options
| -rw-r--r-- | src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java | 67 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java | 72 |
2 files changed, 75 insertions, 64 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java b/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java index f8814ba7..c58e475c 100644 --- a/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java +++ b/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java @@ -2,72 +2,11 @@ package org.shedlang.compiler.backends.cranelift; import org.junit.jupiter.api.Disabled; import org.shedlang.compiler.backends.llvm.LlvmTarget; -import org.shedlang.compiler.backends.paths.PartialTargetPath; -import org.shedlang.compiler.patio.PatioCompilationUnit; -import org.shedlang.compiler.patio.PatioExampleTests; -import org.shedlang.compiler.patio.PatioFunctionDefinition; -import org.shedlang.compiler.patio.PatioVisibility; -import org.shedlang.compiler.patio.instructions.Patio; -import org.shedlang.compiler.patio.types.PatioTypes; -import org.shedlang.compiler.runtime.ShedRuntime; -import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.testing.ExecutionResult; -import org.shedlang.compiler.testing.TestProcessRunner; -import org.shedlang.compiler.util.Lists; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; @Disabled -public class PatioToCraneliftAmd64Tests extends PatioExampleTests { +public class PatioToCraneliftAmd64Tests extends PatioToCraneliftTests { @Override - protected ExecutionResult executeCompilationUnit(PatioCompilationUnit patio) throws IOException, InterruptedException { - var main = new PatioFunctionDefinition( - "main", - PatioVisibility.PUBLIC, - List.of(), - List.of(PatioTypes.INT32), - List.of( - Patio.call( - Optional.empty(), - FUNCTION_NAME, - List.of() - ), - Patio.return_(Patio.int32Const(0)) - ), - Sources.NULL - ); - - patio = new PatioCompilationUnit( - Lists.concat(patio.elements(), List.of(main)), - patio.source() - ); - - Files.createDirectories(Path.of("tests-tmp")); - var workingDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "PatioToCraneliftTests"); - - var backend = CraneliftBackend.AMD64; - var objectFilePath = backend.compileCompilationUnit( - patio, - new PartialTargetPath(workingDirectory.resolve("main")) - ); - - var executablePath = workingDirectory.resolve("main"); - - var runtime = ShedRuntime.defaultRuntime(LlvmTarget.AMD64.targetName()); - backend.link( - List.of( - objectFilePath, - runtime.dir().resolve("libpatio_test.a") - ), - executablePath, - runtime - ); - - return TestProcessRunner.runCaptureOutput(List.of(executablePath.toString())); - + protected LlvmTarget llvmTarget() { + return LlvmTarget.AMD64; } } diff --git a/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java b/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java new file mode 100644 index 00000000..10f33a5e --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java @@ -0,0 +1,72 @@ +package org.shedlang.compiler.backends.cranelift; + +import org.shedlang.compiler.backends.llvm.LlvmTarget; +import org.shedlang.compiler.backends.paths.PartialTargetPath; +import org.shedlang.compiler.patio.PatioCompilationUnit; +import org.shedlang.compiler.patio.PatioExampleTests; +import org.shedlang.compiler.patio.PatioFunctionDefinition; +import org.shedlang.compiler.patio.PatioVisibility; +import org.shedlang.compiler.patio.instructions.Patio; +import org.shedlang.compiler.patio.types.PatioTypes; +import org.shedlang.compiler.runtime.ShedRuntime; +import org.shedlang.compiler.sources.Sources; +import org.shedlang.compiler.testing.ExecutionResult; +import org.shedlang.compiler.testing.TestProcessRunner; +import org.shedlang.compiler.util.Lists; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; + +public abstract class PatioToCraneliftTests extends PatioExampleTests { + @Override + protected ExecutionResult executeCompilationUnit(PatioCompilationUnit patio) throws IOException, InterruptedException { + var main = new PatioFunctionDefinition( + "main", + PatioVisibility.PUBLIC, + List.of(), + List.of(PatioTypes.INT32), + List.of( + Patio.call( + Optional.empty(), + FUNCTION_NAME, + List.of() + ), + Patio.return_(Patio.int32Const(0)) + ), + Sources.NULL + ); + + patio = new PatioCompilationUnit( + Lists.concat(patio.elements(), List.of(main)), + patio.source() + ); + + Files.createDirectories(Path.of("tests-tmp")); + var workingDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "PatioToCraneliftTests"); + + var backend = CraneliftBackend.forTarget(this.llvmTarget()); + var objectFilePath = backend.compileCompilationUnit( + patio, + new PartialTargetPath(workingDirectory.resolve("main")) + ); + + var executablePath = workingDirectory.resolve("main"); + + var runtime = ShedRuntime.defaultRuntime(LlvmTarget.AMD64.targetName()); + backend.link( + List.of( + objectFilePath, + runtime.dir().resolve("libpatio_test.a") + ), + executablePath, + runtime + ); + + return TestProcessRunner.runCaptureOutput(List.of(executablePath.toString())); + } + + protected abstract LlvmTarget llvmTarget(); +} |
