diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-26 23:17:02 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-26 23:17:02 +0000 |
| commit | 1225dd927d23cb945f8476845f90dda3b4d30f00 (patch) | |
| tree | 12659fd6189550950cfc760038c31bc0ff20a07b /src/main/java | |
| parent | 4bc7688b28fc523211de5d1cfefbbf41f6fa82da (diff) | |
Use correct type for memory addresses
Diffstat (limited to 'src/main/java')
3 files changed, 11 insertions, 3 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java index 3389bb65..96217cc5 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java @@ -549,7 +549,10 @@ public class PatioToWasm { case PatioDataPtr patioDataPtr -> { var wasmMemoryAddress = new WasmMemoryAddress(patioDataPtr.name()); - yield context.addInstruction(new WasmMemoryAddressConst(wasmMemoryAddress)); + yield context.addInstruction(new WasmMemoryAddressConst( + context.platformTarget.indexType(), + wasmMemoryAddress + )); } case PatioFunctionPtr patioFunctionPtr -> { diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmMemoryAddressConst.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmMemoryAddressConst.java index 74b8816d..6f36b01a 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmMemoryAddressConst.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmMemoryAddressConst.java @@ -1,13 +1,15 @@ package org.shedlang.compiler.backends.wasm.structure.ast.instructions; import org.shedlang.compiler.backends.wasm.structure.ast.linking.WasmMemoryAddress; +import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmIndexType; /** - * This is a fake instruction that corresponds to an i32.const instruction for + * This is a fake instruction that corresponds to an iNN.const instruction for * an offset into a data segment. Encapsulating this in its own instruction * avoids having to separately track relocation. */ public record WasmMemoryAddressConst( + WasmIndexType indexType, WasmMemoryAddress address ) implements WasmInstruction { } 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 0d006c03..e7cefe21 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 @@ -193,7 +193,10 @@ public class WasmBinaryFormatInstructions { // == Relocatable Instructions == case WasmMemoryAddressConst memoryAddressConst -> { - writer.writeByte(0x41); + writer.writeByte(switch (memoryAddressConst.indexType()) { + case I32 -> 0x41; + case I64 -> 0x42; + }); writer.writeMemoryAddressConst(memoryAddressConst.address()); } |
