From 8e069d9ddfd8c34f742d1dc4301a0fa5a76c16f6 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 28 Jan 2024 19:41:00 +0000 Subject: Introduce PatioDataPtrValue --- .../backends/llvm/codegen/PatioToLlvm.java | 20 ++++++++++------ .../compiler/backends/wasm/PatioToWasm.java | 27 ++++++++++++++-------- 2 files changed, 30 insertions(+), 17 deletions(-) (limited to 'src/main/java/org/shedlang/compiler/backends') 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 -> -- cgit v1.2.3