diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-26 22:32:51 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-26 22:32:51 +0000 |
| commit | 1f3ff130fb4ed927aaa6ffa5e30eb7a4df575d6e (patch) | |
| tree | 4f99a9d4c2319da4914dcf5c7b4cd495d3124577 | |
| parent | 011646c6f4f7b73d12d32fabfbc016c19bd536e0 (diff) | |
Add i64.add instruction
5 files changed, 59 insertions, 1 deletions
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI64Add(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI64Add(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected new file mode 100644 index 00000000..77ac9eb9 --- /dev/null +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatInstructionsTests]/[method:canSerializeI64Add(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -0,0 +1,27 @@ + +module.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> nil +Function[1]: + - func[0] sig=0 <f> +Code[1]: + - func[0] size=8 <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: + +000026 func[0] <f>: + 000027: 42 00 | i64.const 0 + 000029: 42 00 | i64.const 0 + 00002b: 7c | i64.add + 00002c: 1a | drop + 00002d: 0b | end
\ No newline at end of file diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI64Add.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI64Add.java new file mode 100644 index 00000000..73b85d05 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmI64Add.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.backends.wasm.structure.ast.instructions; + +public record WasmI64Add() 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 4b622a1b..718a3660 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, WasmI64Const, 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, 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 dbe07478..eec30522 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 @@ -144,6 +144,9 @@ public class WasmBinaryFormatInstructions { case WasmI32Sub i32Sub -> { writer.writeByte(0x6b); } + case WasmI64Add i64Add -> { + writer.writeByte(0x7c); + } // == Exception Instructions (v3 proposal) == 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 a0541da0..fd2c6f1e 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 @@ -15,6 +15,30 @@ import static org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFor @ExtendWith({SnapshotResolver.class}) public class WasmBinaryFormatInstructionsTests { + + // == Numeric Instructions == + + @Test + public void canSerializeI64Add(Snapshotter snapshotter) throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addFunction(new WasmFunction( + "f", + List.of(), + List.of(), + List.of(), + new WasmExpression(List.of( + new WasmI64Const(0), + new WasmI64Const(0), + new WasmI64Add(), + new WasmDrop() + )) + )); + + var result = serializeModuleWasm32(module); + + snapshotter.assertSnapshot(result); + } + // == Exception Instructions (v3 proposal) == @Test |
