aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-11 23:04:18 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-11 23:04:18 +0100
commit04dff356a4323d2b22f0916ffe6931a31f75bb77 (patch)
treedced7bdf651dcfb900ef1a163d89627edf38d9bc
parent5564950ec34d3be47b9e39d3c8cdf58c0b38af1d (diff)
Compile push-int instruction to LLVM IR
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java6
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/LlvmCompilerPushIntTests.java23
2 files changed, 26 insertions, 3 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 710e9c7f..b311b41d 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java
@@ -34,9 +34,9 @@ public class LlvmCompiler {
case PushBoolInstruction pushBool ->
context.push(new LlvmOperandInt(pushBool.value() ? 1 : 0));
- case PushIntInstruction pushIntInstruction -> {
- throw new UnsupportedOperationException("TODO");
- }
+ case PushIntInstruction pushInt ->
+ context.push(new LlvmOperandInt(pushInt.value().longValueExact()));
+
case PushStringInstruction pushStringInstruction -> {
throw new UnsupportedOperationException("TODO");
}
diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCompilerPushIntTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCompilerPushIntTests.java
new file mode 100644
index 00000000..983a1661
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCompilerPushIntTests.java
@@ -0,0 +1,23 @@
+package org.shedlang.compiler.backends.llvm;
+
+import org.junit.jupiter.api.Test;
+import org.shedlang.compiler.stackir.instructions.Instructions;
+
+import static org.shedlang.compiler.backends.llvm.ir.ast.LlvmIrMatchers.isLlvmOperandInt;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.isSequence;
+
+public class LlvmCompilerPushIntTests {
+ // TODO: handle larger ints
+
+ @Test
+ public void pushIntIsCompiledToOperandInStack() {
+ var instruction = Instructions.pushInt(42);
+ var context = LlvmCompilerContext.EMPTY;
+
+ var result = LlvmCompiler.compileInstruction(instruction, context);
+
+ assertThat(result.instructions(), isSequence());
+ assertThat(result.stack(), isSequence(isLlvmOperandInt(42)));
+ }
+}