aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-26 23:57:35 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-26 23:57:35 +0000
commit2dde0a4a0e2828975080b900f5149bb4c3fd5c72 (patch)
treecc71d664e73e58d850094c860d17735a679756c0 /src
parent54bf166a77e29df4c14ca21f850a2c55199a9519 (diff)
Add i32.wrap_i64 instruction
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI32WrapI64.java4
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java2
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java3
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java14
4 files changed, 21 insertions, 2 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI32WrapI64.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI32WrapI64.java
new file mode 100644
index 00000000..16ac9855
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI32WrapI64.java
@@ -0,0 +1,4 @@
+package org.shedlang.compiler.backends.wasm.structure.ast.instructions;
+
+public record WasmI32WrapI64() implements WasmInstruction {
+}
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java
index 4d1b16fb..1fc5b7aa 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmInstruction.java
@@ -1,4 +1,4 @@
package org.shedlang.compiler.backends.wasm.structure.ast.instructions;
-public sealed interface WasmInstruction permits WasmBlock, WasmBr, WasmCall, WasmCallIndirect, WasmDrop, WasmGlobalGet, WasmGlobalSet, WasmI32Add, WasmI32Const, WasmI32Eq, WasmI32Load, WasmI32Ne, WasmI32Store, WasmI32Sub, WasmI64Add, WasmI64Const, WasmI64Eq, WasmI64ExtendI32Unsigned, WasmI64Load, WasmI64Ne, WasmI64Store, WasmI64Sub, WasmIf, WasmLocalGet, WasmLocalSet, WasmLoop, WasmMemoryAddressConst, WasmMemoryGrow, WasmReturn, WasmTableElementIndexConst, WasmThrow, WasmTry, WasmUnreachable {
+public sealed interface WasmInstruction permits WasmBlock, WasmBr, WasmCall, WasmCallIndirect, WasmDrop, WasmGlobalGet, WasmGlobalSet, WasmI32Add, WasmI32Const, WasmI32Eq, WasmI32Load, WasmI32Ne, WasmI32Store, WasmI32Sub, WasmI32WrapI64, WasmI64Add, WasmI64Const, WasmI64Eq, WasmI64ExtendI32Unsigned, WasmI64Load, WasmI64Ne, WasmI64Store, WasmI64Sub, WasmIf, WasmLocalGet, WasmLocalSet, WasmLoop, WasmMemoryAddressConst, WasmMemoryGrow, WasmReturn, WasmTableElementIndexConst, WasmThrow, WasmTry, WasmUnreachable {
}
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java
index 779b0adf..9235dd94 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java
@@ -166,6 +166,9 @@ public class WasmBinaryFormatInstructions {
case WasmI64Sub i64Sub -> {
writer.writeByte(0x7d);
}
+ case WasmI32WrapI64 i32WrapI64 -> {
+ writer.writeByte(0xa7);
+ }
case WasmI64ExtendI32Unsigned i64ExtendI32Unsigned -> {
writer.writeByte(0xad);
}
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java
index 2fef1222..ef00a349 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java
@@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.shedlang.compiler.backends.wasm.structure.ast.instructions.*;
import org.shedlang.compiler.backends.wasm.structure.ast.modules.*;
-import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmIndexType;
import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmLimits;
import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmMemoryType;
import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType;
@@ -188,6 +187,19 @@ public class WasmBinaryFormatInstructionsTests {
}
@Test
+ public void canSerializeI32WrapI64(Snapshotter snapshotter) throws IOException, InterruptedException {
+ var instructions = List.of(
+ new WasmI64Const(0),
+ new WasmI32WrapI64(),
+ new WasmDrop()
+ );
+
+ var result = serializeInstructions(instructions);
+
+ snapshotter.assertSnapshot(result);
+ }
+
+ @Test
public void canSerializeI64ExtendI32Unsigned(Snapshotter snapshotter) throws IOException, InterruptedException {
var instructions = List.of(
new WasmI32Const(0),