aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/backends
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-01-28 19:41:00 +0000
committerMichael Williamson <mike@zwobble.org>2024-01-28 19:41:00 +0000
commit8e069d9ddfd8c34f742d1dc4301a0fa5a76c16f6 (patch)
tree85ada8031cac9ead1aaf89cfc98ab4c48e6dc14e /src/main/java/org/shedlang/compiler/backends
parentefbf3709697f1a94bbbed83563e0d7225e79e0fa (diff)
Introduce PatioDataPtrValue
Diffstat (limited to 'src/main/java/org/shedlang/compiler/backends')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java20
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java27
2 files changed, 30 insertions, 17 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java
index 962fb62e..726418e1 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java
@@ -15,10 +15,7 @@ import org.shedlang.compiler.patio.*;
import org.shedlang.compiler.patio.instructions.*;
import org.shedlang.compiler.patio.operands.*;
import org.shedlang.compiler.patio.types.*;
-import org.shedlang.compiler.patio.values.PatioIntValue;
-import org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf;
-import org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf;
-import org.shedlang.compiler.patio.values.PatioIntValueLiteral;
+import org.shedlang.compiler.patio.values.*;
import org.shedlang.compiler.util.Lazy;
import org.shedlang.compiler.util.Lists;
import org.shedlang.compiler.util.P;
@@ -1099,7 +1096,7 @@ public class PatioToLlvm {
new LlvmOperandInt(patioByteConst.value());
case PatioDataPtrConst patioDataPtrConst ->
- new LlvmVariableGlobal(patioDataPtrConst.name());
+ patioDataPtrValueToLlvmOperand(patioDataPtrConst.value());
case PatioFunctionPtrConst patioFunctionPtrConst ->
new LlvmVariableGlobal(patioFunctionPtrConst.name());
@@ -1123,12 +1120,21 @@ public class PatioToLlvm {
};
}
+ private static LlvmOperand patioDataPtrValueToLlvmOperand(
+ PatioDataPtrValue dataPtrValue
+ ) {
+ return switch (dataPtrValue) {
+ case PatioDataPtrValueDataElement dataElement ->
+ new LlvmVariableGlobal(dataElement.name());
+ };
+ }
+
private static LlvmOperand patioIntValueToLlvmOperand(
- PatioIntValue patioIntConst,
+ PatioIntValue intValue,
PatioType patioDestinationType,
LlvmTarget target
) {
- return switch (patioIntConst) {
+ return switch (intValue) {
case PatioIntValueByteOffsetOf byteOffsetOf ->
offsetOf(
byteOffsetOf.layout(),
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java
index 0dec70ab..67404151 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java
@@ -12,10 +12,7 @@ import org.shedlang.compiler.patio.*;
import org.shedlang.compiler.patio.instructions.*;
import org.shedlang.compiler.patio.operands.*;
import org.shedlang.compiler.patio.types.*;
-import org.shedlang.compiler.patio.values.PatioIntValue;
-import org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf;
-import org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf;
-import org.shedlang.compiler.patio.values.PatioIntValueLiteral;
+import org.shedlang.compiler.patio.values.*;
import org.shedlang.compiler.util.Lists;
import org.shedlang.compiler.util.P;
@@ -541,13 +538,11 @@ public class PatioToWasm {
case PatioByteConst patioByteConst ->
context.addInstruction(new WasmI32Const(Byte.toUnsignedInt(patioByteConst.value())));
- case PatioDataPtrConst patioDataPtrConst -> {
- var wasmMemoryAddress = new WasmMemoryAddress(patioDataPtrConst.name());
- yield context.addInstruction(new WasmMemoryAddressConst(
- context.target.indexType(),
- wasmMemoryAddress
+ case PatioDataPtrConst patioDataPtrConst ->
+ context.addInstruction(generateDataPtrValue(
+ patioDataPtrConst.value(),
+ context.target
));
- }
case PatioFunctionPtrConst patioFunctionPtrConst -> {
var wasmFuncName = new WasmFuncName(patioFunctionPtrConst.name());
@@ -579,6 +574,18 @@ public class PatioToWasm {
};
}
+ private static WasmInstruction generateDataPtrValue(PatioDataPtrValue value, WasmTarget target) {
+ return switch (value) {
+ case PatioDataPtrValueDataElement dataElement -> {
+ var wasmMemoryAddress = new WasmMemoryAddress(dataElement.name());
+ yield new WasmMemoryAddressConst(
+ target.indexType(),
+ wasmMemoryAddress
+ );
+ }
+ };
+ }
+
private static int generateIntValue(PatioIntValue value, WasmTarget target) {
return switch (value) {
case PatioIntValueByteOffsetOf byteOffsetOf ->