From 70fec4f9190b98ea2f27ce9e3a1ff974c8072549 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 26 Jun 2023 20:28:34 +0100 Subject: Fix naming of functions to write relocatable memory address --- .../binary/WasmBinaryFormatInstructions.java | 2 +- .../wasm/structure/binary/WasmBinaryWriter.java | 36 ++++++++++++---------- 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'src/main/java') 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 6eaf7093..af9f5db8 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 @@ -57,7 +57,7 @@ public class WasmBinaryFormatInstructions { case WasmMemoryAddressConst memoryAddressConst -> { writer.writeByte(0x41); - writer.writeMemoryAddressUnsignedInt32(memoryAddressConst.address()); + writer.writeMemoryAddressSignedInt32(memoryAddressConst.address()); } } } diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java index 92985baf..8617976b 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java @@ -28,18 +28,34 @@ public class WasmBinaryWriter { Leb128Encoding.encodePaddedUnsignedInt32(value, writer); } - public void writeMemoryAddressUnsignedInt32(WasmMemoryAddress index) { - writeRelocatableUnsignedInt32( + public void writeSignedInt32(int value) { + Leb128Encoding.encodeSignedInt32(value, writer); + } + + public void writePaddedSignedInt32(int value) { + Leb128Encoding.encodePaddedSignedInt32(value, writer); + } + + public void writeSignedInt64(long value) { + Leb128Encoding.encodeSignedInt64(value, writer); + } + + public void writeString(String value) { + WasmBinaryFormatValues.writeString(value, writer); + } + + public void writeMemoryAddressSignedInt32(WasmMemoryAddress index) { + writeRelocatableSignedInt32( WasmRelocationType.MEMORY_ADDR_SLEB, index ); } - private void writeRelocatableUnsignedInt32(WasmRelocationType relocationType, WasmMemoryAddress index) { + private void writeRelocatableSignedInt32(WasmRelocationType relocationType, WasmMemoryAddress index) { // TODO: handle relocatable values in non-CODE sections var sectionContentsOffset = writer.position() - sectionContentsStart; - writePaddedUnsignedInt32(0); + writePaddedSignedInt32(0); if (!relocationEntries.containsKey(sectionIndex)) { relocationEntries.put(sectionIndex, new ArrayList<>()); @@ -52,18 +68,6 @@ public class WasmBinaryWriter { )); } - public void writeSignedInt32(int value) { - Leb128Encoding.encodeSignedInt32(value, writer); - } - - public void writeSignedInt64(long value) { - Leb128Encoding.encodeSignedInt64(value, writer); - } - - public void writeString(String value) { - WasmBinaryFormatValues.writeString(value, writer); - } - // TODO: extract write interface public void writeSection(WasmSectionId sectionId, WasmBinaryFormatModules.Write writeContents) throws IOException { sectionIndex++; -- cgit v1.2.3