aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-07 18:01:28 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-07 18:01:28 +0100
commit69ce0b822262c9ea5ae9cc4e89be0fa4498eaf25 (patch)
treefacd2ed40e3f4a001eee045bc809d57121b33b81 /src/test/java
parentdf888d6cce6a31e55eac4e21ccd496ce6023dfeb (diff)
Add int-ne instruction
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/LlvmCodeGenIntNotEqualTests.java28
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIntNotEqualTests.java24
-rw-r--r--src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java12
-rw-r--r--src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java12
4 files changed, 71 insertions, 5 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCodeGenIntNotEqualTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCodeGenIntNotEqualTests.java
new file mode 100644
index 00000000..b5759f61
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCodeGenIntNotEqualTests.java
@@ -0,0 +1,28 @@
+package org.shedlang.compiler.backends.llvm;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.shedlang.compiler.backends.llvm.ir.ast.LlvmIr;
+import org.shedlang.compiler.stackir.instructions.Instructions;
+import org.shedlang.compiler.testing.snapshots.SnapshotResolver;
+import org.shedlang.compiler.testing.snapshots.Snapshotter;
+
+import java.io.IOException;
+
+import static org.shedlang.compiler.backends.llvm.LlvmCodeGenTesting.serializeContext;
+
+@ExtendWith({SnapshotResolver.class})
+public class LlvmCodeGenIntNotEqualTests {
+ @Test
+ public void intNotEqualIsCompiledToComparison(Snapshotter snapshotter) throws IOException {
+ var instruction = Instructions.intNotEqual();
+ var context = LlvmCodeGenContext.EMPTY
+ .push(LlvmIr.variableLocal("a"))
+ .push(LlvmIr.variableLocal("b"))
+ .push(LlvmIr.variableLocal("c"));
+
+ var result = LlvmCodeGen.generateInstruction(instruction, context);
+
+ snapshotter.assertSnapshot(serializeContext(result));
+ }
+}
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIntNotEqualTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIntNotEqualTests.java
new file mode 100644
index 00000000..dc924eb9
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIntNotEqualTests.java
@@ -0,0 +1,24 @@
+package org.shedlang.compiler.backends.wasm;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.shedlang.compiler.stackir.instructions.Instructions;
+import org.shedlang.compiler.testing.snapshots.SnapshotResolver;
+import org.shedlang.compiler.testing.snapshots.Snapshotter;
+
+import java.io.IOException;
+
+import static org.shedlang.compiler.backends.wasm.WasmCodeGenTesting.objdumpContext;
+
+@ExtendWith({SnapshotResolver.class})
+public class WasmCodeGenIntNotEqualTests {
+ @Test
+ public void intNotEqualIsCompiledToI32Ne(Snapshotter snapshotter) throws IOException, InterruptedException {
+ var instruction = Instructions.intNotEqual();
+ var context = WasmCodeGenContext.EMPTY;
+
+ var result = WasmCodeGen.generateInstruction(instruction, context);
+
+ snapshotter.assertSnapshot(objdumpContext(result));
+ }
+}
diff --git a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java b/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java
index 10588ec1..a2d5065a 100644
--- a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java
+++ b/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java
@@ -74,13 +74,23 @@ public class InstructionSerializerTests {
assertThat(string, equalTo("(field-load \"Example/Lib\" \"x\")"));
}
+
@Test
public void canSerializeIntEquals() {
var instruction = Instructions.intEquals();
var string = serialize(instruction);
- assertThat(string, equalTo("(int-equals)"));
+ assertThat(string, equalTo("(int-eq)"));
+ }
+
+ @Test
+ public void canSerializeIntNotEqual() {
+ var instruction = Instructions.intNotEqual();
+
+ var string = serialize(instruction);
+
+ assertThat(string, equalTo("(int-ne)"));
}
@Test
diff --git a/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java b/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java
index a1630727..2b198617 100644
--- a/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java
+++ b/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java
@@ -22,6 +22,14 @@ public class Instructions {
return new FieldLoadInstruction(namespaceName, fieldName, Sources.NULL);
}
+ public static Instruction intEquals() {
+ return new IntEqualsInstruction(Sources.NULL);
+ }
+
+ public static Instruction intNotEqual() {
+ return new IntNotEqualInstruction(Sources.NULL);
+ }
+
public static Instruction localLoad(String name) {
return new LocalLoadInstruction(name, Sources.NULL);
}
@@ -61,8 +69,4 @@ public class Instructions {
public static Instruction return_() {
return new ReturnInstruction(Sources.NULL);
}
-
- public static Instruction intEquals() {
- return new IntEqualsInstruction(Sources.NULL);
- }
}