aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-26 23:17:02 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-26 23:17:02 +0000
commit1225dd927d23cb945f8476845f90dda3b4d30f00 (patch)
tree12659fd6189550950cfc760038c31bc0ff20a07b /src/main/java
parent4bc7688b28fc523211de5d1cfefbbf41f6fa82da (diff)
Use correct type for memory addresses
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java5
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/ast/instructions/WasmMemoryAddressConst.java4
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructions.java5
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());
}