aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-26 23:08:06 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-26 23:08:06 +0000
commit8d7289ae30b41c32a4c8e96d17679210cedcac27 (patch)
tree41abfa5f7583a3647863812090ebf9ed06e00a15 /src/main/java
parent3f31e0a48561f1482a059e31fee2bed823463d97 (diff)
Generate correct type for int loads
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java24
1 files changed, 19 insertions, 5 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 9e5f2f45..00f5cd00 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java
@@ -347,7 +347,8 @@ public class PatioToWasm {
case PatioMemoryLoad patioMemoryLoad -> {
context = generateOperand(patioMemoryLoad.pointer(), context);
- context = context.addInstruction(new WasmI32Load(
+ context = context.addInstruction(wasmIntLoad(
+ context.wasmLocalType(patioMemoryLoad.target()),
wasmMemoryArg(
patioMemoryLoad.layout(),
patioMemoryLoad.offset(),
@@ -769,7 +770,7 @@ public class PatioToWasm {
} else if (wasmValueType == WasmValueType.I64) {
return new WasmI64Eq();
} else {
- throw new IllegalArgumentException("Cannot create int const for " + wasmValueType);
+ throw new IllegalArgumentException("Cannot create int eq for " + wasmValueType);
}
}
@@ -779,7 +780,7 @@ public class PatioToWasm {
} else if (wasmValueType == WasmValueType.I64) {
return new WasmI64Ne();
} else {
- throw new IllegalArgumentException("Cannot create int const for " + wasmValueType);
+ throw new IllegalArgumentException("Cannot create int ne for " + wasmValueType);
}
}
@@ -789,7 +790,7 @@ public class PatioToWasm {
} else if (wasmValueType == WasmValueType.I64) {
return new WasmI64Add();
} else {
- throw new IllegalArgumentException("Cannot create int const for " + wasmValueType);
+ throw new IllegalArgumentException("Cannot create int add for " + wasmValueType);
}
}
@@ -799,7 +800,20 @@ public class PatioToWasm {
} else if (wasmValueType == WasmValueType.I64) {
return new WasmI64Sub();
} else {
- throw new IllegalArgumentException("Cannot create int const for " + wasmValueType);
+ throw new IllegalArgumentException("Cannot create int sub for " + wasmValueType);
+ }
+ }
+
+ private static WasmInstruction wasmIntLoad(
+ WasmValueType wasmValueType,
+ WasmMemoryArg memoryArg
+ ) {
+ if (wasmValueType == WasmValueType.I32) {
+ return new WasmI32Load(memoryArg);
+ } else if (wasmValueType == WasmValueType.I64) {
+ return new WasmI64Load(memoryArg);
+ } else {
+ throw new IllegalArgumentException("Cannot create int load for " + wasmValueType);
}
}