diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-11 23:01:47 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-11 23:01:47 +0100 |
| commit | 594488a5ac0edef9074ed8957c65137cee453e37 (patch) | |
| tree | 0993364f84748b5c14bb639fb47b01c5e7b4bca5 /src/main/java | |
| parent | f1fcbace22b971efe9234152ae677081b127e7cc (diff) | |
Compile push-bool instruction to LLVM IR
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java | 23 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompilerContext.java | 28 |
2 files changed, 44 insertions, 7 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java index 8921ad8d..be5dbf8c 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java @@ -1,37 +1,48 @@ package org.shedlang.compiler.backends.llvm; +import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmOperandInt; import org.shedlang.compiler.stackir.instructions.*; import org.shedlang.compiler.types.NamespaceName; import java.util.List; public class LlvmCompiler { - public void compileNamespace(NamespaceName namespaceName, List<Instruction> instructions) { + public static void compileNamespace(NamespaceName namespaceName, List<Instruction> instructions) { } - public void compileInstruction(Instruction instruction) { - switch (instruction) { + public static LlvmCompilerContext compileInstruction(Instruction instruction, LlvmCompilerContext context) { + return switch (instruction) { case CallInstruction callInstruction -> { + throw new UnsupportedOperationException("TODO"); } case DefineFunctionInstruction defineFunctionInstruction -> { + throw new UnsupportedOperationException("TODO"); } case DiscardInstruction discardInstruction -> { + throw new UnsupportedOperationException("TODO"); } case LocalLoadInstruction localLoadInstruction -> { + throw new UnsupportedOperationException("TODO"); } case LocalStoreInstruction localStoreInstruction -> { + throw new UnsupportedOperationException("TODO"); } case ModuleExportInstruction moduleExportInstruction -> { + throw new UnsupportedOperationException("TODO"); } - case PushBoolInstruction pushBoolInstruction -> { - } + case PushBoolInstruction pushBool -> + context.push(new LlvmOperandInt(pushBool.value() ? 1 : 0)); + case PushIntInstruction pushIntInstruction -> { + throw new UnsupportedOperationException("TODO"); } case PushStringInstruction pushStringInstruction -> { + throw new UnsupportedOperationException("TODO"); } case PushUnitInstruction pushUnitInstruction -> { + throw new UnsupportedOperationException("TODO"); } - } + }; } } diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompilerContext.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompilerContext.java index 924b9091..6d917e49 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompilerContext.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompilerContext.java @@ -1,4 +1,30 @@ package org.shedlang.compiler.backends.llvm; -public class LlvmCompilerContext { +import org.pcollections.Empty; +import org.pcollections.PVector; +import org.shedlang.compiler.backends.llvm.ir.ast.instructions.LlvmInstruction; +import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmOperand; + +public record LlvmCompilerContext( + PVector<LlvmOperand> stack, + PVector<LlvmInstruction> instructions +) { + public static LlvmCompilerContext EMPTY = new LlvmCompilerContext( + Empty.vector(), + Empty.vector() + ); + + public LlvmCompilerContext addInstruction(LlvmInstruction instruction) { + return new LlvmCompilerContext( + stack, + instructions.plus(instruction) + ); + } + + public LlvmCompilerContext push(LlvmOperand operand) { + return new LlvmCompilerContext( + stack.plus(operand), + instructions + ); + } } |
