aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-03-29 09:40:06 +0100
committerMichael Williamson <mike@zwobble.org>2026-03-29 09:40:06 +0100
commit957410553cb0ebdcfb00b933f893735be3c7e681 (patch)
treeb0d8a251fac48f1e29f4c38756c4409d25a525ce /src
parent05bd9a969a89c070d683928727fece4ab9eaa490 (diff)
Load target ISA in patio-to-cranelift
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java22
-rw-r--r--src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java5
2 files changed, 21 insertions, 6 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java b/src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java
index 97d0a156..d66f9a92 100644
--- a/src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java
@@ -18,7 +18,19 @@ import java.util.List;
import static org.shedlang.compiler.util.processes.ProcessRunner.runInheritIo;
public class CraneliftBackend {
- public static Path compileCompilationUnit(
+ public static final CraneliftBackend AMD64 = forTarget(LlvmTarget.AMD64);
+
+ public static CraneliftBackend forTarget(LlvmTarget target) {
+ return new CraneliftBackend(target);
+ }
+
+ private final LlvmTarget target;
+
+ private CraneliftBackend(LlvmTarget target) {
+ this.target = target;
+ }
+
+ public Path compileCompilationUnit(
PatioCompilationUnit patio,
PartialTargetPath partialTargetPath
) throws IOException, InterruptedException {
@@ -32,19 +44,21 @@ public class CraneliftBackend {
runInheritIo(List.of(
ShedCompilerFiles.getRoot().resolve("patio-to-cranelift/target/debug/patio-to-cranelift").toString(),
- patioPath.toString()
+ patioPath.toString(),
+ "--target",
+ this.target.targetTriple()
));
var objectFilePath = partialTargetPath.withExtension(".o");
return objectFilePath;
}
- public static void link(
+ public void link(
List<Path> inputs,
Path outputPath,
ShedRuntime shedRuntime
) throws ProcessError, InterruptedException {
// TODO: extract linking if it's not specific to LLVM.
- LlvmBackend.forTarget(LlvmTarget.AMD64).link(inputs, outputPath, shedRuntime);
+ LlvmBackend.forTarget(this.target).link(inputs, outputPath, shedRuntime);
}
}
diff --git a/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java b/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java
index ff9b1d82..58e7a2c4 100644
--- a/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftTests.java
@@ -21,7 +21,8 @@ public class PatioToCraneliftTests extends PatioExampleTests {
Files.createDirectories(Path.of("tests-tmp"));
var workingDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "PatioToCraneliftTests");
- var objectFilePath = CraneliftBackend.compileCompilationUnit(
+ var backend = CraneliftBackend.AMD64;
+ var objectFilePath = backend.compileCompilationUnit(
patio,
new PartialTargetPath(workingDirectory.resolve("main"))
);
@@ -29,7 +30,7 @@ public class PatioToCraneliftTests extends PatioExampleTests {
var executablePath = workingDirectory.resolve("main");
var runtime = ShedRuntime.defaultRuntime(LlvmTarget.AMD64.targetName());
- CraneliftBackend.link(
+ backend.link(
List.of(
objectFilePath,
runtime.dir().resolve("libpatio_test.a")