From 8b4e7af45f229fcce74cd380cc64399bc1d03384 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 14 Jul 2023 23:04:25 +0100 Subject: Support if instructions in WASM backend --- .../compiler/backends/wasm/WasmCodeGenIfTests.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/backends/wasm/WasmCodeGenIfTests.java (limited to 'src/test/java/org') 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)); + } +} -- cgit v1.2.3