From 42c1a57cd441d1cefd0aea277758b5be83ecf97e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 28 Jun 2023 20:30:06 +0100 Subject: Fix endianness of string lengths --- ...rings(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected | 2 +- ...oData(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected | 2 +- .../java/org/shedlang/compiler/backends/wasm/WasmCodeGenStrings.java | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.WasmCodeGenPushStringTests]/[method:canHaveMultipleStrings(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.WasmCodeGenPushStringTests]/[method:canHaveMultipleStrings(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 0bc8c636..13467187 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.WasmCodeGenPushStringTests]/[method:canHaveMultipleStrings(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.WasmCodeGenPushStringTests]/[method:canHaveMultipleStrings(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -14,7 +14,7 @@ Code[1]: - func[0] size=14 Data[1]: - segment[0] <.data> memory=0 size=21 - init i32=0 - - 0000000: 0000 0005 6865 6c6c 6f00 0000 0000 0005 ....hello....... + - 0000000: 0500 0000 6865 6c6c 6f00 0000 0500 0000 ....hello....... - 0000010: 776f 726c 64 world Custom: - name: "linking" diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.WasmCodeGenPushStringTests]/[method:pushStringIsCompiledToDataAndIndexToData(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.WasmCodeGenPushStringTests]/[method:pushStringIsCompiledToDataAndIndexToData(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 914b6ce4..59ded219 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.WasmCodeGenPushStringTests]/[method:pushStringIsCompiledToDataAndIndexToData(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.WasmCodeGenPushStringTests]/[method:pushStringIsCompiledToDataAndIndexToData(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -14,7 +14,7 @@ Code[1]: - func[0] size=8 Data[1]: - segment[0] <.data> memory=0 size=9 - init i32=0 - - 0000000: 0000 0005 6865 6c6c 6f ....hello + - 0000000: 0500 0000 6865 6c6c 6f ....hello Custom: - name: "linking" - segment info [count=1] diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/WasmCodeGenStrings.java b/src/main/java/org/shedlang/compiler/backends/wasm/WasmCodeGenStrings.java index 29fda47d..a7266091 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmCodeGenStrings.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmCodeGenStrings.java @@ -4,6 +4,7 @@ import org.shedlang.compiler.backends.wasm.structure.ast.linking.WasmMemoryAddre import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmAlignment; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; public class WasmCodeGenStrings { @@ -16,6 +17,7 @@ public class WasmCodeGenStrings { ) { var codeUnits = value.getBytes(StandardCharsets.UTF_8); var data = ByteBuffer.allocate(4 + codeUnits.length); + data.order(ByteOrder.LITTLE_ENDIAN); data.putInt(codeUnits.length); data.put(codeUnits); -- cgit v1.2.3