From 8d7289ae30b41c32a4c8e96d17679210cedcac27 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 26 Dec 2023 23:08:06 +0000 Subject: Generate correct type for int loads --- .../compiler/backends/wasm/PatioToWasm.java | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/main/java') 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); } } -- cgit v1.2.3