aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-14 23:04:25 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-14 23:05:18 +0100
commit8b4e7af45f229fcce74cd380cc64399bc1d03384 (patch)
treee03d6cf5cf9f3b3ba65894dbd3042530a8770056 /src/test/java/org
parenteeef2f1636e2fc96c0018532d1e6945ee97c43c6 (diff)
Support if instructions in WASM backend
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIfTests.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIfTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIfTests.java
new file mode 100644
index 00000000..82c034a5
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIfTests.java
@@ -0,0 +1,34 @@
+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 java.util.List;
+
+import static org.shedlang.compiler.backends.wasm.WasmCodeGenTesting.objdumpContext;
+
+@ExtendWith({SnapshotResolver.class})
+public class WasmCodeGenIfTests {
+ @Test
+ public void ifIsCompiledToWasmIf(Snapshotter snapshotter) throws IOException, InterruptedException {
+ var instruction = Instructions.if_(
+ List.of(
+ Instructions.pushInt(1),
+ Instructions.pushInt(2)
+ ),
+ List.of(
+ Instructions.pushInt(101),
+ Instructions.pushInt(102)
+ )
+ );
+ var context = WasmCodeGenContext.EMPTY;
+
+ var result = WasmCodeGen.generateInstruction(instruction, context);
+
+ snapshotter.assertSnapshot(objdumpContext(result));
+ }
+}