diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-07 18:22:49 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-07 18:22:49 +0100 |
| commit | bbd0ad7fad36761f55555347b01a32887fc4a5f9 (patch) | |
| tree | 4f91676bba01b3aa85e9d8bf87b140f4ba3f8722 /src/test/java | |
| parent | 4123de472e0442cccd8fd01767e399dc05cc6b11 (diff) | |
Add int-sub instruction
Diffstat (limited to 'src/test/java')
4 files changed, 65 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCodeGenIntSubTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCodeGenIntSubTests.java new file mode 100644 index 00000000..dfde4836 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCodeGenIntSubTests.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 LlvmCodeGenIntSubTests { + @Test + public void intSubIsCompiledToSub(Snapshotter snapshotter) throws IOException { + var instruction = Instructions.intSub(); + 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/WasmCodeGenIntSubTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIntSubTests.java new file mode 100644 index 00000000..f394d823 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIntSubTests.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 WasmCodeGenIntSubTests { + @Test + public void intSubIsCompiledToI32Sub(Snapshotter snapshotter) throws IOException, InterruptedException { + var instruction = Instructions.intSub(); + 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 3f8398cc..c6046847 100644 --- a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java +++ b/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java @@ -103,6 +103,15 @@ public class InstructionSerializerTests { } @Test + public void canSerializeIntSub() { + var instruction = Instructions.intSub(); + + var string = serialize(instruction); + + assertThat(string, equalTo("(int-sub)")); + } + + @Test public void canSerializeLocalLoad() { var instruction = Instructions.localLoad("x"); 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 5b155878..6f769591 100644 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java +++ b/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java @@ -34,6 +34,10 @@ public class Instructions { return new IntNotEqualInstruction(Sources.NULL); } + public static Instruction intSub() { + return new IntSubInstruction(Sources.NULL); + } + public static Instruction localLoad(String name) { return new LocalLoadInstruction(name, Sources.NULL); } |
