From cfbdb4b8873a218519ac74d59195615edcd3e88a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 29 Jul 2023 10:46:34 +0100 Subject: Rename Patio instruction alloc to alloc-heap --- .../compiler/backends/llvm/LlvmPatioCodeGen.java | 6 +++--- .../compiler/backends/wasm/WasmPatioCodeGen.java | 6 +++--- .../shedlang/compiler/patio/PatioCodeGenClosures.java | 2 +- .../org/shedlang/compiler/patio/ast/PatioSerializer.java | 8 ++++---- .../compiler/patio/ast/instructions/PatioAlloc.java | 16 ---------------- .../compiler/patio/ast/instructions/PatioAllocHeap.java | 16 ++++++++++++++++ .../patio/ast/instructions/PatioInstruction.java | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAlloc.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocHeap.java (limited to 'src/main/java') 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 8b3d4a4b..8ba153de 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java @@ -179,12 +179,12 @@ public class LlvmPatioCodeGen { FunctionContext context ) { return switch (patioInstruction) { - case PatioAlloc patioAlloc -> { - var sizeResult = sizeOf(patioDataLayoutToLlvmType(patioAlloc.layout()), context); + case PatioAllocHeap patioAllocHeap -> { + var sizeResult = sizeOf(patioDataLayoutToLlvmType(patioAllocHeap.layout()), context); var size = sizeResult.value; context = sizeResult.context; - var targetResult = context.addPatioLocalToLlvmLocal(patioAlloc.target()); + var targetResult = context.addPatioLocalToLlvmLocal(patioAllocHeap.target()); var target = targetResult.value; context = targetResult.context; 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 529a2198..d559ece4 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmPatioCodeGen.java @@ -120,11 +120,11 @@ public class WasmPatioCodeGen { Context context ) { return switch (patioInstruction) { - case PatioAlloc patioAlloc -> { + case PatioAllocHeap patioAllocHeap -> { context = context - .addInstruction(new WasmI32Const(sizeOf(patioAlloc.layout()))) + .addInstruction(new WasmI32Const(sizeOf(patioAllocHeap.layout()))) .addInstruction(new WasmCall(new WasmFuncName(ALLOC_NAME))) - .addInstruction(new WasmLocalSet(context.wasmLocalIndex(patioAlloc.target()))); + .addInstruction(new WasmLocalSet(context.wasmLocalIndex(patioAllocHeap.target()))); yield context; } diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java index 8c9c242e..c0cb41ea 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java @@ -105,7 +105,7 @@ class PatioCodeGenClosures { var closurePointer = closurePointerResult.value(); context = closurePointerResult.context(); - context = context.addInstruction(new PatioAlloc(closurePointer, layout, source)); + context = context.addInstruction(new PatioAllocHeap(closurePointer, layout, source)); context = context.addInstruction(new PatioMemoryStore( closurePointer, 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 d0826348..e5cf29b1 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java @@ -138,11 +138,11 @@ public class PatioSerializer { private static Tree instructionToTree(PatioInstruction instruction) { return switch (instruction) { - case PatioAlloc alloc -> + case PatioAllocHeap allocHeap -> treeList( - treeIdentifier("alloc"), - operandToTree(alloc.target()), - dataLayoutToTree(alloc.layout()) + treeIdentifier("alloc-heap"), + operandToTree(allocHeap.target()), + dataLayoutToTree(allocHeap.layout()) ); case PatioBoolToInt boolToInt -> diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAlloc.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAlloc.java deleted file mode 100644 index dd5bde56..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAlloc.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.sources.Source; - -/** - * Allocate space for the given data layout, and store the pointer to the - * allocated memory in the target local. - */ -public record PatioAlloc( - PatioLocalRef target, - PatioDataLayout layout, - Source source -) implements PatioInstruction { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocHeap.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocHeap.java new file mode 100644 index 00000000..aee64781 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocHeap.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.PatioDataLayout; +import org.shedlang.compiler.sources.Source; + +/** + * Allocate space on the heap for the given data layout, and store the pointer + * to the allocated memory in the target local. + */ +public record PatioAllocHeap( + PatioLocalRef target, + PatioDataLayout layout, + 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 3dcc516e..cd3fb874 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 PatioAlloc, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioReturn { +public sealed interface PatioInstruction permits PatioAllocHeap, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioReturn { Source source(); } -- cgit v1.2.3