Skip to content

Changing Fatal() to assert() #4982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 14 additions & 42 deletions src/shell-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,116 +197,88 @@ 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<int8_t>(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<uint8_t>(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<int16_t>(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<uint16_t>(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<int32_t>(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<uint32_t>(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<int64_t>(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<uint64_t>(addr);
}
std::array<uint8_t, 16> 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<std::array<uint8_t, 16>>(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<int8_t>(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<int16_t>(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<int32_t>(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<int64_t>(addr, value);
}
void store128(Address addr,
const std::array<uint8_t, 16>& 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<std::array<uint8_t, 16>>(addr, value);
}
Expand Down
4 changes: 1 addition & 3 deletions src/tools/wasm-ctor-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,7 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
// TODO: handle unaligned too, see shell-interface
template<typename T> 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);
Expand Down