aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-26 23:05:45 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-26 23:05:45 +0000
commit3f31e0a48561f1482a059e31fee2bed823463d97 (patch)
tree616b9719754a1e0b2e1423f60d0ab68bfb338d91
parentd245348585002dae57dd03ba4bb1e9382e6fffe9 (diff)
Add i64.store instruction
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI32Store(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected28
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI64Store(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected28
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI64Store.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.java5
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java26
6 files changed, 92 insertions, 1 deletions
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI32Store(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI32Store(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
new file mode 100644
index 00000000..1d34b733
--- /dev/null
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI32Store(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -0,0 +1,28 @@
+
+module.wasm: file format wasm 0x1
+
+Section Details:
+
+Type[1]:
+ - type[0] () -> nil
+Function[1]:
+ - func[0] sig=0 <f>
+Memory[1]:
+ - memory[0] pages: initial=0
+Code[1]:
+ - func[0] size=10 <f>
+Custom:
+ - name: "linking"
+ - symbol table [count=1]
+ - 0: F <f> func=0 [ binding=global vis=default ]
+Custom:
+ - name: "name"
+ - func[0] <f>
+
+Code Disassembly:
+
+00002f func[0] <f>:
+ 000030: 41 00 | i32.const 0
+ 000032: 41 00 | i32.const 0
+ 000034: 36 00 80 01 | i32.store 0 128
+ 000038: 0b | end \ No newline at end of file
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI64Store(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI64Store(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
new file mode 100644
index 00000000..568446cb
--- /dev/null
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI64Store(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -0,0 +1,28 @@
+
+module.wasm: file format wasm 0x1
+
+Section Details:
+
+Type[1]:
+ - type[0] () -> nil
+Function[1]:
+ - func[0] sig=0 <f>
+Memory[1]:
+ - memory[0] pages: initial=0
+Code[1]:
+ - func[0] size=10 <f>
+Custom:
+ - name: "linking"
+ - symbol table [count=1]
+ - 0: F <f> func=0 [ binding=global vis=default ]
+Custom:
+ - name: "name"
+ - func[0] <f>
+
+Code Disassembly:
+
+00002f func[0] <f>:
+ 000030: 41 00 | i32.const 0
+ 000032: 42 00 | i64.const 0
+ 000034: 37 00 80 01 | i64.store 0 128
+ 000038: 0b | end \ No newline at end of file
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI64Store.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI64Store.java
new file mode 100644
index 00000000..6fe32524
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI64Store.java
@@ -0,0 +1,4 @@
+package org.shedlang.compiler.backends.wasm.structure.ast.instructions;
+
+public record WasmI64Store(WasmMemoryArg memoryArg) 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 5198d187..0fdea692 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, WasmI64Load, WasmI64Ne, 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, WasmI64Add, WasmI64Const, WasmI64Eq, 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 0af98318..0d006c03 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
@@ -122,6 +122,11 @@ public class WasmBinaryFormatInstructions {
writeMemoryArg(i32Store.memoryArg(), writer);
}
+ case WasmI64Store i64Store -> {
+ writer.writeByte(0x37);
+ writeMemoryArg(i64Store.memoryArg(), writer);
+ }
+
case WasmMemoryGrow memoryGrow -> {
writer.writeByte(0x40);
writer.writeByte(0x00);
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 373ad37b..07a5d7b0 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
@@ -47,6 +47,32 @@ public class WasmBinaryFormatInstructionsTests {
snapshotter.assertSnapshot(result);
}
+ @Test
+ public void canSerializeI32Store(Snapshotter snapshotter) throws IOException, InterruptedException {
+ var instructions = List.of(
+ new WasmI32Const(0),
+ new WasmI32Const(0),
+ new WasmI32Store(new WasmMemoryArg(128, WasmAlignment.NONE))
+ );
+
+ var result = serializeInstructions(instructions);
+
+ snapshotter.assertSnapshot(result);
+ }
+
+ @Test
+ public void canSerializeI64Store(Snapshotter snapshotter) throws IOException, InterruptedException {
+ var instructions = List.of(
+ new WasmI32Const(0),
+ new WasmI64Const(0),
+ new WasmI64Store(new WasmMemoryArg(128, WasmAlignment.NONE))
+ );
+
+ var result = serializeInstructions(instructions);
+
+ snapshotter.assertSnapshot(result);
+ }
+
// == Numeric Instructions ==
@Test