aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-28 00:08:15 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-28 00:08:15 +0000
commita35baa09222e3ce89fef37d15ebacd7e08efd525 (patch)
tree28195c5b9886741e633e3ec5f7bc4c6bcd5fdae0 /src
parent51a095edbac0cf722ae90ea6907410670d4544dd (diff)
Set target in LlvmCompiler
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java7
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java11
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/PatioToLlvmTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java2
4 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
index 89b48b5c..7404c8b1 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
@@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
-import static org.shedlang.compiler.backends.llvm.LlvmCompiler.compileLlvmModule;
import static org.shedlang.compiler.util.processes.ProcessRunner.runInheritIo;
public class LlvmBackend implements Backend {
@@ -58,6 +57,8 @@ public class LlvmBackend implements Backend {
TypeInfos typeInfos,
TargetDir targetDir
) throws IOException, InterruptedException {
+ var llvmCompiler = LlvmCompiler.forTarget(this.target);
+
var objectFilePaths = new ArrayList<Path>();
var globalContext = PatioToLlvmGlobalContext.EMPTY;
@@ -74,7 +75,7 @@ public class LlvmBackend implements Backend {
var llvmModule = llvmModuleResult.value();
globalContext = llvmModuleResult.context();
- var objectPath = compileLlvmModule(
+ var objectPath = llvmCompiler.compileLlvmModule(
llvmModule,
targetDir.namespace(namespace.namespaceName())
);
@@ -86,7 +87,7 @@ public class LlvmBackend implements Backend {
var linkInputs = new ArrayList<>(objectFilePaths);
var mainModule = this.generateMain(bin.mainNamespace(), typeInfos, globalContext);
- var mainObjectPath = compileLlvmModule(mainModule, targetDir.bin(bin.name()));
+ var mainObjectPath = llvmCompiler.compileLlvmModule(mainModule, targetDir.bin(bin.name()));
linkInputs.add(mainObjectPath);
link(linkInputs, targetDir.topLevel(bin.name()));
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java
index 0d8ab3cc..9dc6c5b6 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java
@@ -15,10 +15,17 @@ import java.util.List;
import static org.shedlang.compiler.util.processes.ProcessRunner.runInheritIo;
public class LlvmCompiler {
- private LlvmCompiler() {
+ public static LlvmCompiler forTarget(LlvmTarget target) {
+ return new LlvmCompiler(target);
}
- public static Path compileLlvmModule(
+ private final LlvmTarget target;
+
+ private LlvmCompiler(LlvmTarget target) {
+ this.target = target;
+ }
+
+ public Path compileLlvmModule(
LlvmModule llvmModule,
PartialTargetPath targetPath
) throws IOException, InterruptedException {
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 daf0209d..aa9cd007 100644
--- a/src/test/java/org/shedlang/compiler/backends/llvm/PatioToLlvmTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/llvm/PatioToLlvmTests.java
@@ -60,7 +60,8 @@ public abstract class PatioToLlvmTests extends PatioExampleTests {
Files.createDirectories(Path.of("tests-tmp"));
var workingDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "PatioToLlvmTests");
- var objectFilePath = LlvmCompiler.compileLlvmModule(
+ var llvmCompiler = LlvmCompiler.forTarget(this.llvmTarget());
+ var objectFilePath = llvmCompiler.compileLlvmModule(
llvmModule,
new PartialTargetPath(workingDirectory.resolve("main"))
);
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java
index 7476edbe..7f44f4cc 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java
@@ -9,8 +9,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
import static org.shedlang.compiler.backends.wasm.structure.WasmObjdump.objdump;