From e4d183ff66f79330004b7b0c7973b929ec8a9df9 Mon Sep 17 00:00:00 2001 From: Ashley Nelson Date: Sat, 27 Aug 2022 05:10:48 +0000 Subject: [PATCH] changing to asserts --- src/shell-interface.h | 56 +++++++++--------------------------- src/tools/wasm-ctor-eval.cpp | 4 +-- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/src/shell-interface.h b/src/shell-interface.h index 98349055b16..e27f5c69062 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -197,106 +197,80 @@ struct ShellExternalInterface : ModuleRunner::ExternalInterface { int8_t load8s(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load8s on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get(addr); } uint8_t load8u(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load8u on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get(addr); } int16_t load16s(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load16s on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get(addr); } uint16_t load16u(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load16u on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get(addr); } int32_t load32s(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load32s on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get(addr); } uint32_t load32u(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load32u on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get(addr); } int64_t load64s(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load64s on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get(addr); } uint64_t load64u(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load64u on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get(addr); } std::array load128(Address addr, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("load128 on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; return memory.get>(addr); } void store8(Address addr, int8_t value, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("store8 on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; memory.set(addr, value); } void store16(Address addr, int16_t value, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("store16 on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; memory.set(addr, value); } void store32(Address addr, int32_t value, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("store32 on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; memory.set(addr, value); } void store64(Address addr, int64_t value, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("store64 on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; memory.set(addr, value); } @@ -304,9 +278,7 @@ struct ShellExternalInterface : ModuleRunner::ExternalInterface { const std::array& value, Name memoryName) override { auto it = memories.find(memoryName); - if (it == memories.end()) { - trap("store128 on non-existing memory"); - } + assert(it != memories.end()); auto& memory = it->second; memory.set>(addr, value); } diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 91128471cd2..5e9874cccfb 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -408,9 +408,7 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface { // TODO: handle unaligned too, see shell-interface template T* getMemory(Address address, Name memoryName) { auto it = memories.find(memoryName); - if (it == memories.end()) { - Fatal() << "memory not found: " << memoryName; - } + assert(it != memories.end()); auto& memory = it->second; // resize the memory buffer as needed. auto max = address + sizeof(T);