aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/backends
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-21 16:22:34 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-21 16:23:14 +0100
commit0fe26c78dd1f7127654cb2dfaef8f5caeebd7e73 (patch)
treebd20bfc0915adecadf585cfedc6f40fabf8b915a /src/main/java/org/shedlang/compiler/backends
parentf12f949dda91f596c8ec401375e48cef584218c2 (diff)
Support wasm-patio backend in CLI
Diffstat (limited to 'src/main/java/org/shedlang/compiler/backends')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/Backends.java3
-rw-r--r--src/main/java/org/shedlang/compiler/backends/PatioBackend.java8
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java39
3 files changed, 39 insertions, 11 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/Backends.java b/src/main/java/org/shedlang/compiler/backends/Backends.java
index 93801fbc..f0a75510 100644
--- a/src/main/java/org/shedlang/compiler/backends/Backends.java
+++ b/src/main/java/org/shedlang/compiler/backends/Backends.java
@@ -10,5 +10,6 @@ public class Backends {
public static final OrderedPMap<String, Backend> BACKENDS = OrderedPMap.<String, Backend>empty()
.plus("llvm", new LlvmBackend())
- .plus("wasm", new WasmBackend());
+ .plus("wasm", WasmBackend.DIRECT)
+ .plus("wasm-patio", WasmBackend.PATIO);
}
diff --git a/src/main/java/org/shedlang/compiler/backends/PatioBackend.java b/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
index 9e8e5560..682bf79f 100644
--- a/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
@@ -22,14 +22,10 @@ public class PatioBackend implements Backend {
var context = PatioCodeGenContext.forTypeInfo(typeInfo);
for (var namespace : namespaces) {
- var namespaceName = namespace.namespaceName();
- var instructions = namespace.instructions();
-
- System.out.println(namespaceName);
+ System.out.println(namespace.namespaceName());
var compilationUnit = PatioCodeGen.generateNamespace(
- namespaceName,
- instructions,
+ namespace,
context
);
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 d127525e..65d6068f 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
@@ -5,6 +5,8 @@ import org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormat;
import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmModule;
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;
@@ -18,6 +20,38 @@ import java.util.List;
import static org.shedlang.compiler.backends.ProcessRunner.runInheritIo;
public class WasmBackend implements Backend {
+ public static final WasmBackend DIRECT = new WasmBackend(new CodeGen() {
+ @Override
+ public WasmModule generateNamespace(StackIrNamespace stackIrNamespace, TypeInfo typeInfo) {
+ return WasmCodeGen.generateNamespace(stackIrNamespace, typeInfo);
+ }
+ });
+
+ public static final WasmBackend PATIO = new WasmBackend(new CodeGen() {
+ @Override
+ public WasmModule generateNamespace(StackIrNamespace stackIrNamespace, TypeInfo typeInfo) {
+ var patioCompilationUnit = PatioCodeGen.generateNamespace(
+ stackIrNamespace,
+ PatioCodeGenContext.forTypeInfo(typeInfo)
+ );
+
+ return WasmPatioCodeGen.generateCompilationUnit(patioCompilationUnit);
+ }
+ });
+
+ interface CodeGen {
+ WasmModule generateNamespace(
+ StackIrNamespace stackIrNamespace,
+ TypeInfo typeInfo
+ );
+ }
+
+ private final CodeGen codeGen;
+
+ private WasmBackend(CodeGen codeGen) {
+ this.codeGen = codeGen;
+ }
+
@Override
public void compile(
ProjectConfig config,
@@ -27,10 +61,7 @@ public class WasmBackend implements Backend {
) throws IOException, InterruptedException {
var objectFilePaths = new ArrayList<Path>();
for (var namespace : namespaces) {
- var wasmModule = WasmCodeGen.generateNamespace(
- namespace,
- typeInfo
- );
+ var wasmModule = this.codeGen.generateNamespace(namespace, typeInfo);
var objectPath = writeObjectFile(
wasmModule,