aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-22 11:32:38 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-22 11:32:38 +0100
commite2a87d4a022edfa7a7f552af9117c1ac1669cf32 (patch)
tree982f7a4a230fefe42fdf40b0db9f6ccac4d07a14 /src/main/java
parente9da20124cc757f7db4b31b7cbd6e3457013693a (diff)
Add stubbed llvm-patio backend
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/Backends.java3
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java39
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java10
3 files changed, 47 insertions, 5 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/Backends.java b/src/main/java/org/shedlang/compiler/backends/Backends.java
index f0a75510..02a3e60d 100644
--- a/src/main/java/org/shedlang/compiler/backends/Backends.java
+++ b/src/main/java/org/shedlang/compiler/backends/Backends.java
@@ -9,7 +9,8 @@ public class Backends {
}
public static final OrderedPMap<String, Backend> BACKENDS = OrderedPMap.<String, Backend>empty()
- .plus("llvm", new LlvmBackend())
+ .plus("llvm", LlvmBackend.DIRECT)
+ .plus("llvm-patio", LlvmBackend.PATIO)
.plus("wasm", WasmBackend.DIRECT)
.plus("wasm-patio", WasmBackend.PATIO);
}
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 0dead3ac..97cbbf17 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
@@ -5,6 +5,8 @@ import org.shedlang.compiler.backends.llvm.ir.LlvmIrSerializer;
import org.shedlang.compiler.backends.llvm.ir.ast.LlvmModule;
import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.filesystem.ShedCompilerFiles;
+import org.shedlang.compiler.patio.PatioCodeGen;
+import org.shedlang.compiler.patio.PatioCodeGenContext;
import org.shedlang.compiler.stackir.StackIrNamespace;
import org.shedlang.compiler.typechecker.TypeInfo;
@@ -20,6 +22,38 @@ import java.util.List;
import static org.shedlang.compiler.backends.ProcessRunner.runInheritIo;
public class LlvmBackend implements Backend {
+ public static final LlvmBackend DIRECT = new LlvmBackend(new CodeGen() {
+ @Override
+ public LlvmModule generateNamespace(StackIrNamespace stackIrNamespace, TypeInfo typeInfo) {
+ return LlvmCodeGen.generateNamespace(stackIrNamespace, typeInfo);
+ }
+ });
+
+ public static final LlvmBackend PATIO = new LlvmBackend(new CodeGen() {
+ @Override
+ public LlvmModule generateNamespace(StackIrNamespace stackIrNamespace, TypeInfo typeInfo) {
+ var patioCompilationUnit = PatioCodeGen.generateNamespace(
+ stackIrNamespace,
+ PatioCodeGenContext.forTypeInfo(typeInfo)
+ );
+
+ return LlvmPatioCodeGen.generateCompilationUnit(patioCompilationUnit);
+ }
+ });
+
+ interface CodeGen {
+ LlvmModule generateNamespace(
+ StackIrNamespace stackIrNamespace,
+ TypeInfo typeInfo
+ );
+ }
+
+ private final CodeGen codeGen;
+
+ private LlvmBackend(CodeGen codeGen) {
+ this.codeGen = codeGen;
+ }
+
@Override
public void compile(
ProjectConfig config,
@@ -29,10 +63,7 @@ public class LlvmBackend implements Backend {
) throws IOException, InterruptedException {
var objectFilePaths = new ArrayList<Path>();
for (var namespace : namespaces) {
- var llvmModule = LlvmCodeGen.generateNamespace(
- namespace,
- typeInfo
- );
+ var llvmModule = this.codeGen.generateNamespace(namespace, typeInfo);
var objectPath = compileLlvmModule(
llvmModule,
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java
new file mode 100644
index 00000000..76b6a1b9
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java
@@ -0,0 +1,10 @@
+package org.shedlang.compiler.backends.llvm;
+
+import org.shedlang.compiler.backends.llvm.ir.ast.LlvmModule;
+import org.shedlang.compiler.patio.ast.PatioCompilationUnit;
+
+public class LlvmPatioCodeGen {
+ public static LlvmModule generateCompilationUnit(PatioCompilationUnit patioCompilationUnit) {
+ throw new UnsupportedOperationException();
+ }
+}