aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/backends
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-03-24 14:10:30 +0000
committerMichael Williamson <mike@zwobble.org>2024-03-24 14:10:30 +0000
commit04cf66d6b53121998b33889a5495aaef3925cdfd (patch)
tree71f827e2486627eb794c3f5b62e74ccab349d5ec /src/main/java/org/shedlang/compiler/backends
parentcb44def5d662e9ec15cf1d97d735c6deb129c302 (diff)
Use profiles when compiling
Diffstat (limited to 'src/main/java/org/shedlang/compiler/backends')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/Backend.java3
-rw-r--r--src/main/java/org/shedlang/compiler/backends/PatioBackends.java11
-rw-r--r--src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java7
-rw-r--r--src/main/java/org/shedlang/compiler/backends/ShidTextBackend.java3
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java15
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java15
6 files changed, 32 insertions, 22 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/Backend.java b/src/main/java/org/shedlang/compiler/backends/Backend.java
index 17b8400f..ddd57f8e 100644
--- a/src/main/java/org/shedlang/compiler/backends/Backend.java
+++ b/src/main/java/org/shedlang/compiler/backends/Backend.java
@@ -1,6 +1,7 @@
package org.shedlang.compiler.backends;
import org.shedlang.compiler.backends.paths.TargetDir;
+import org.shedlang.compiler.config.ProfileConfig;
import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.typechecker.TypeInfos;
@@ -13,7 +14,7 @@ public interface Backend {
void compile(
ProjectConfig config,
- String profileName,
+ ProfileConfig profileConfig,
List<ShidNamespace> namespaces,
TypeInfos typeInfos,
TargetDir targetDir
diff --git a/src/main/java/org/shedlang/compiler/backends/PatioBackends.java b/src/main/java/org/shedlang/compiler/backends/PatioBackends.java
index 8bdc15e0..bc90c6b4 100644
--- a/src/main/java/org/shedlang/compiler/backends/PatioBackends.java
+++ b/src/main/java/org/shedlang/compiler/backends/PatioBackends.java
@@ -1,6 +1,7 @@
package org.shedlang.compiler.backends;
import org.shedlang.compiler.config.BinConfig;
+import org.shedlang.compiler.config.ProfileConfig;
import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.patio.PatioCompilationUnit;
import org.shedlang.compiler.shid.ShidNamespace;
@@ -24,13 +25,13 @@ public class PatioBackends {
String binName,
PatioCompilationUnit patioCompilationUnit,
String mainFunctionName,
- String profileName
+ ProfileConfig profileConfig
) throws IOException, InterruptedException;
}
public static void compile(
ProjectConfig config,
- String profileName,
+ ProfileConfig profileConfig,
List<ShidNamespace> namespaces,
TypeInfos typeInfos,
PatioToTarget patioToTarget
@@ -49,12 +50,12 @@ public class PatioBackends {
}
for (var bin : config.bins()) {
- generateMain(profileName, bin, shidToPatioContext, patioToTarget);
+ generateMain(profileConfig, bin, shidToPatioContext, patioToTarget);
}
}
private static void generateMain(
- String profileName,
+ ProfileConfig profileConfig,
BinConfig binConfig,
ShidToPatioContext shidToPatioContext,
PatioToTarget patioToTarget
@@ -83,7 +84,7 @@ public class PatioBackends {
binConfig.name(),
patioCompilationUnit,
mainFunctionName,
- profileName
+ profileConfig
);
}
}
diff --git a/src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java b/src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java
index 929feac3..052408c0 100644
--- a/src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java
@@ -2,6 +2,7 @@ package org.shedlang.compiler.backends;
import org.shedlang.compiler.backends.paths.PartialTargetPath;
import org.shedlang.compiler.backends.paths.TargetDir;
+import org.shedlang.compiler.config.ProfileConfig;
import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.patio.PatioCompilationUnit;
import org.shedlang.compiler.patio.PatioSerializer;
@@ -26,14 +27,14 @@ public class PatioTextBackend implements Backend {
public void compile(
ProjectConfig config,
- String profileName,
+ ProfileConfig profileConfig,
List<ShidNamespace> namespaces,
TypeInfos typeInfos,
TargetDir targetDir
) throws IOException, InterruptedException {
PatioBackends.compile(
config,
- profileName,
+ profileConfig,
namespaces,
typeInfos,
new PatioToText(targetDir)
@@ -66,7 +67,7 @@ public class PatioTextBackend implements Backend {
String binName,
PatioCompilationUnit patioCompilationUnit,
String mainFunctionName,
- String profileName
+ ProfileConfig profileConfig
) throws IOException, InterruptedException {
serializeToDisk(
targetDir.bin(binName),
diff --git a/src/main/java/org/shedlang/compiler/backends/ShidTextBackend.java b/src/main/java/org/shedlang/compiler/backends/ShidTextBackend.java
index 36af4357..f34c18b2 100644
--- a/src/main/java/org/shedlang/compiler/backends/ShidTextBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/ShidTextBackend.java
@@ -1,6 +1,7 @@
package org.shedlang.compiler.backends;
import org.shedlang.compiler.backends.paths.TargetDir;
+import org.shedlang.compiler.config.ProfileConfig;
import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.shid.ShidSerializer;
@@ -19,7 +20,7 @@ public class ShidTextBackend implements Backend {
@Override
public void compile(
ProjectConfig config,
- String profileName,
+ ProfileConfig profileConfig,
List<ShidNamespace> namespaces,
TypeInfos typeInfos,
TargetDir targetDir
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 70430da7..bb951a9f 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
@@ -15,6 +15,8 @@ import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmVariableGlobal;
import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmVariableLocal;
import org.shedlang.compiler.backends.llvm.ir.ast.types.LlvmTypes;
import org.shedlang.compiler.backends.paths.TargetDir;
+import org.shedlang.compiler.config.GcConfig;
+import org.shedlang.compiler.config.ProfileConfig;
import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.filesystem.ShedCompilerFiles;
import org.shedlang.compiler.patio.PatioCompilationUnit;
@@ -54,14 +56,14 @@ public class LlvmBackend implements Backend {
@Override
public void compile(
ProjectConfig config,
- String profileName,
+ ProfileConfig profileConfig,
List<ShidNamespace> namespaces,
TypeInfos typeInfos,
TargetDir targetDir
) throws IOException, InterruptedException {
PatioBackends.compile(
config,
- profileName,
+ profileConfig,
namespaces,
typeInfos,
new PatioToBinary(
@@ -121,7 +123,7 @@ public class LlvmBackend implements Backend {
String binName,
PatioCompilationUnit patioCompilationUnit,
String mainFunctionName,
- String profileName
+ ProfileConfig profileConfig
) throws IOException, InterruptedException {
var linkInputs = new ArrayList<>(objectFilePaths);
@@ -133,15 +135,16 @@ public class LlvmBackend implements Backend {
var mainObjectPath = llvmCompiler.compileLlvmModule(mainModule, targetDir.bin(binName));
linkInputs.add(mainObjectPath);
- link(linkInputs, targetDir.topLevel(binName), profileName);
+ link(linkInputs, targetDir.topLevel(binName), profileConfig.gc().orElse(GcConfig.DEFAULT));
}
}
public void link(
List<Path> inputs,
Path outputPath,
- String profileName
+ GcConfig gcConfig
) throws ProcessError, InterruptedException {
+ // TODO: handle config for GC
var clangArgs = new ArrayList<String>();
clangArgs.add("clang");
@@ -154,7 +157,7 @@ public class LlvmBackend implements Backend {
var runtimeDir = ShedCompilerFiles.targetDir(
this.target.targetName(),
- profileName
+ gcConfig
);
clangArgs.add(runtimeDir.resolve("libpatio.a").toString());
clangArgs.add(runtimeDir.resolve("libshed.a").toString());
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 6069563f..3a7a4733 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
@@ -12,6 +12,8 @@ import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmExpres
import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmFuncName;
import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmFunction;
import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmModule;
+import org.shedlang.compiler.config.GcConfig;
+import org.shedlang.compiler.config.ProfileConfig;
import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.filesystem.ShedCompilerFiles;
import org.shedlang.compiler.patio.PatioCompilationUnit;
@@ -52,14 +54,14 @@ public class WasmBackend implements Backend {
@Override
public void compile(
ProjectConfig config,
- String profileName,
+ ProfileConfig profileConfig,
List<ShidNamespace> namespaces,
TypeInfos typeInfos,
TargetDir targetDir
) throws IOException, InterruptedException {
PatioBackends.compile(
config,
- profileName,
+ profileConfig,
namespaces,
typeInfos,
new PatioToWasmBinary(targetDir, P.vector())
@@ -101,7 +103,7 @@ public class WasmBackend implements Backend {
String binName,
PatioCompilationUnit patioCompilationUnit,
String mainFunctionName,
- String profileName
+ ProfileConfig profileConfig
) throws IOException, InterruptedException {
var linkInputs = new ArrayList<>(objectFilePaths);
@@ -110,7 +112,7 @@ public class WasmBackend implements Backend {
linkInputs.add(mainObjectPath);
var outputBinPath = targetDir.topLevel(binName + ".wasm");
- link(linkInputs, outputBinPath, profileName);
+ link(linkInputs, outputBinPath, profileConfig.gc().orElse(GcConfig.DEFAULT));
validate(outputBinPath);
}
}
@@ -118,8 +120,9 @@ public class WasmBackend implements Backend {
public void link(
List<Path> inputs,
Path outputPath,
- String profileName
+ GcConfig gcConfig
) throws ProcessError, InterruptedException {
+ // TODO: handle config for GC
var ldArgs = new ArrayList<String>();
ldArgs.add("wasm-ld-17");
@@ -134,7 +137,7 @@ public class WasmBackend implements Backend {
var runtimeDir = ShedCompilerFiles.targetDir(
this.target.targetName(),
- profileName
+ gcConfig
);
ldArgs.add(runtimeDir.resolve("libpatio.a").toString());
ldArgs.add(runtimeDir.resolve("libshed.a").toString());