diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-20 18:33:14 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-20 18:33:14 +0100 |
| commit | 07f659df1466934fb129df8145cc1a3565dd55e2 (patch) | |
| tree | 466065f3d03db49f8d4883a1d30b17f67c3141d6 /src/main/java | |
| parent | 89f5a082b37c59d81e0561a863cb69622502eb62 (diff) | |
Separate target directory by backend
Diffstat (limited to 'src/main/java')
5 files changed, 32 insertions, 8 deletions
diff --git a/src/main/java/org/shedlang/compiler/ShedCompiler.java b/src/main/java/org/shedlang/compiler/ShedCompiler.java index ebf97bdc..3aedc946 100644 --- a/src/main/java/org/shedlang/compiler/ShedCompiler.java +++ b/src/main/java/org/shedlang/compiler/ShedCompiler.java @@ -70,7 +70,7 @@ public class ShedCompiler { namespaces.put(namespaceName, instructions); } - backend.compile(config, namespaces, typeCheckerContext.toTypeInfo()); + backend.compile(config, namespaces, typeCheckerContext.toTypeInfo(), config.targetDir().resolve(backend.name())); } private List<Path> collectSourceFilePaths(Path sourceRoot) throws IOException { diff --git a/src/main/java/org/shedlang/compiler/backends/Backend.java b/src/main/java/org/shedlang/compiler/backends/Backend.java index aaf73bf9..54abde81 100644 --- a/src/main/java/org/shedlang/compiler/backends/Backend.java +++ b/src/main/java/org/shedlang/compiler/backends/Backend.java @@ -6,6 +6,7 @@ import org.shedlang.compiler.typechecker.TypeInfo; import org.shedlang.compiler.types.NamespaceName; import java.io.IOException; +import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -13,6 +14,9 @@ public interface Backend { void compile( ProjectConfig config, Map<NamespaceName, List<Instruction>> namespaces, - TypeInfo typeInfo + TypeInfo typeInfo, + Path targetDir ) throws IOException; + + String name(); } diff --git a/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java b/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java index ed980e77..88cfa631 100644 --- a/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java @@ -6,6 +6,7 @@ import org.shedlang.compiler.stackir.instructions.Instruction; import org.shedlang.compiler.typechecker.TypeInfo; import org.shedlang.compiler.types.NamespaceName; +import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -13,7 +14,8 @@ public class GenerateInstructionsBackend implements Backend { public void compile( ProjectConfig config, Map<NamespaceName, List<Instruction>> namespaces, - TypeInfo typeInfo + TypeInfo typeInfo, + Path targetDir ) { System.out.println("main: " + config.main()); @@ -31,4 +33,9 @@ public class GenerateInstructionsBackend implements Backend { System.out.println(); } } + + @Override + public String name() { + return "generate-instructions"; + } } 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 f26de6dd..49b55160 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java @@ -24,7 +24,8 @@ public class LlvmBackend implements Backend { public void compile( ProjectConfig config, Map<NamespaceName, List<Instruction>> namespaces, - TypeInfo typeInfo + TypeInfo typeInfo, + Path targetDir ) throws IOException { var objectFilePaths = new ArrayList<Path>(); for (var namespace : namespaces.entrySet()) { @@ -35,20 +36,20 @@ public class LlvmBackend implements Backend { typeInfo ); - var objectPath = compileLlvmModule(llvmModule, config.targetDir().resolve("namespaces"), String.join("_", namespaceName.parts())); + var objectPath = compileLlvmModule(llvmModule, targetDir.resolve("namespaces"), String.join("_", namespaceName.parts())); objectFilePaths.add(objectPath); } for (var bin : config.bins()) { var mainModule = LlvmCompiler.compileMain(config.main(), typeInfo); - var objectPath = compileLlvmModule(mainModule, config.targetDir().resolve("bins"), bin.name()); + var objectPath = compileLlvmModule(mainModule, targetDir.resolve("bins"), bin.name()); objectFilePaths.add(objectPath); var gccArgs = new ArrayList<String>(); gccArgs.add("gcc"); gccArgs.add("-o"); - gccArgs.add(config.targetDir().resolve(bin.name()).toString()); + gccArgs.add(targetDir.resolve(bin.name()).toString()); for (var objectFilePath : objectFilePaths) { gccArgs.add(objectFilePath.toString()); @@ -60,6 +61,11 @@ public class LlvmBackend implements Backend { } } + @Override + public String name() { + return "llvm"; + } + private static Path compileLlvmModule( LlvmModule llvmModule, Path workingDirectory, diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java index 85541f6e..89ca9189 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java @@ -7,6 +7,7 @@ import org.shedlang.compiler.typechecker.TypeInfo; import org.shedlang.compiler.types.NamespaceName; import java.io.IOException; +import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -15,8 +16,14 @@ public class WasmBackend implements Backend { public void compile( ProjectConfig config, Map<NamespaceName, List<Instruction>> namespaces, - TypeInfo typeInfo + TypeInfo typeInfo, + Path targetDir ) throws IOException { } + + @Override + public String name() { + return "wasm"; + } } |
