summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-05-13 10:11:01 -0700
committerGitHub <noreply@github.com>2022-05-13 10:11:01 -0700
commit48eb700ba16e8c98c4283fdde2064b78c3561fbd (patch)
treed5506f78d4a17e758f2c5f9793be611432ede356 /src
parent18aa94c087f79da9706e8d3af8104816ee79e573 (diff)
downloadbinaryen-48eb700ba16e8c98c4283fdde2064b78c3561fbd.tar.gz
binaryen-48eb700ba16e8c98c4283fdde2064b78c3561fbd.tar.bz2
binaryen-48eb700ba16e8c98c4283fdde2064b78c3561fbd.zip
[NFC] Make Literal::makeNull take a HeapType (#4664)
Taking a Type is redundant as we only care about the heap type - the nullability must be Nullable. This avoids needing an assertion in the function, that is, it makes the API more type-safe.
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp2
-rw-r--r--src/literal.h5
-rw-r--r--src/wasm-interpreter.h6
-rw-r--r--src/wasm/literal.cpp2
4 files changed, 7 insertions, 8 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index aa9f7e641..709672aa4 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -101,7 +101,7 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) {
return Literal::makeFunc(x.func);
case Type::anyref:
case Type::eqref:
- return Literal::makeNull(Type(x.type));
+ return Literal::makeNull(Type(x.type).getHeapType());
case Type::i31ref:
WASM_UNREACHABLE("TODO: i31ref");
case Type::dataref:
diff --git a/src/literal.h b/src/literal.h
index 555f89e5c..4caeab9d4 100644
--- a/src/literal.h
+++ b/src/literal.h
@@ -248,9 +248,8 @@ public:
WASM_UNREACHABLE("unexpected type");
}
}
- static Literal makeNull(Type type) {
- assert(type.isNullable());
- return Literal(type);
+ static Literal makeNull(HeapType type) {
+ return Literal(Type(type, Nullable));
}
static Literal makeFunc(Name func, Type type = Type::funcref) {
return Literal(func, type);
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 641684fe9..ef86b35f0 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1337,7 +1337,7 @@ public:
Flow visitCallRef(CallRef* curr) { WASM_UNREACHABLE("unimp"); }
Flow visitRefNull(RefNull* curr) {
NOTE_ENTER("RefNull");
- return Literal::makeNull(curr->type);
+ return Literal::makeNull(curr->type.getHeapType());
}
Flow visitRefIs(RefIs* curr) {
NOTE_ENTER("RefIs");
@@ -1531,7 +1531,7 @@ public:
if (auto* breaking = cast.getBreaking()) {
return *breaking;
} else if (cast.getNull()) {
- return Literal::makeNull(Type(curr->type.getHeapType(), Nullable));
+ return Literal::makeNull(curr->type.getHeapType());
} else if (auto* result = cast.getSuccess()) {
return *result;
}
@@ -2573,7 +2573,7 @@ private:
if (table->type.isNullable()) {
// Initial with nulls in a nullable table.
auto info = getTableInterfaceInfo(table->name);
- auto null = Literal::makeNull(table->type);
+ auto null = Literal::makeNull(table->type.getHeapType());
for (Address i = 0; i < table->initial; i++) {
info.interface->tableStore(info.name, i, null);
}
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index b7bb83155..80af9535e 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -238,7 +238,7 @@ Literal Literal::makeZero(Type type) {
if (type == Type::i31ref) {
return makeI31(0);
} else {
- return makeNull(type);
+ return makeNull(type.getHeapType());
}
} else if (type.isRtt()) {
return Literal(type);