diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-29 13:47:17 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-29 13:47:17 +0100 |
| commit | 5f03ac4ca00595c34f34a8415c653ce6f489c8c8 (patch) | |
| tree | 9666ff648c40403a48fef10dc2cbb722520a9346 /src/main/java | |
| parent | 2d55c4ae5cb7704dc9ac6b2ed431b344e351ed39 (diff) | |
Add Patio alloc-stack instruction
Diffstat (limited to 'src/main/java')
5 files changed, 32 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java index 8ba153de..96866b50 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java @@ -198,6 +198,10 @@ public class LlvmPatioCodeGen { )); } + case PatioAllocStack patioAllocStack -> { + throw new UnsupportedOperationException(); + } + case PatioBoolToInt patioBoolToInt -> { var targetResult = context.addPatioLocalToLlvmLocal(patioBoolToInt.target()); var target = targetResult.value; diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGen.java b/src/main/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGen.java index d559ece4..f7b5d8c8 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGen.java @@ -129,6 +129,10 @@ public class WasmPatioCodeGen { yield context; } + case PatioAllocStack patioAllocStack -> { + throw new UnsupportedOperationException(); + } + case PatioBoolToInt patioBoolToInt -> generateOperandToPatioLocal( patioBoolToInt.target(), diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java index e5cf29b1..74165bdc 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java @@ -145,6 +145,13 @@ public class PatioSerializer { dataLayoutToTree(allocHeap.layout()) ); + case PatioAllocStack allocStack -> + treeList( + treeIdentifier("alloc-stack"), + operandToTree(allocStack.target()), + typeToTree(allocStack.type()) + ); + case PatioBoolToInt boolToInt -> treeList( treeIdentifier("bool-to-int"), diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocStack.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocStack.java new file mode 100644 index 00000000..e94accd1 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocStack.java @@ -0,0 +1,16 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; +import org.shedlang.compiler.patio.ast.types.PatioType; +import org.shedlang.compiler.sources.Source; + +/** + * Allocate space on the stack for the given type, and store the pointer + * to the allocated memory in the target local. + */ +public record PatioAllocStack( + PatioLocalRef target, + PatioType type, + Source source +) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java index cd3fb874..a61613ff 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java @@ -2,6 +2,6 @@ package org.shedlang.compiler.patio.ast.instructions; import org.shedlang.compiler.sources.Source; -public sealed interface PatioInstruction permits PatioAllocHeap, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioReturn { +public sealed interface PatioInstruction permits PatioAllocHeap, PatioAllocStack, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioReturn { Source source(); } |
