diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-26 20:28:34 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-26 20:28:34 +0100 |
| commit | 70fec4f9190b98ea2f27ce9e3a1ff974c8072549 (patch) | |
| tree | 990da15708c5e4399100a49b1ff032a4a62112dc /src/main/java | |
| parent | ce407cc74ec827da9fb440d4601b21cad966bc95 (diff) | |
Fix naming of functions to write relocatable memory address
Diffstat (limited to 'src/main/java')
2 files changed, 21 insertions, 17 deletions
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++; |
