summaryrefslogtreecommitdiff
path: root/src/wasm/literal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r--src/wasm/literal.cpp100
1 files changed, 51 insertions, 49 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index f0a065c45..699d3ea63 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -37,8 +37,8 @@ Literal::Literal(const Literal& other) { *this = other; }
Literal& Literal::operator=(const Literal& other) {
type = other.type;
- assert(!type.isMulti());
- switch (type.getSingle()) {
+ TODO_SINGLE_COMPOUND(type);
+ switch (type.getBasic()) {
case Type::i32:
case Type::f32:
i32 = other.i32;
@@ -153,7 +153,7 @@ Literal Literal::castToI64() {
}
int64_t Literal::getInteger() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return i32;
case Type::i64:
@@ -164,7 +164,7 @@ int64_t Literal::getInteger() const {
}
double Literal::getFloat() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return getf32();
case Type::f64:
@@ -176,7 +176,8 @@ double Literal::getFloat() const {
void Literal::getBits(uint8_t (&buf)[16]) const {
memset(buf, 0, 16);
- switch (type.getSingle()) {
+ TODO_SINGLE_COMPOUND(type);
+ switch (type.getBasic()) {
case Type::i32:
case Type::f32:
memcpy(buf, &i32, sizeof(i32));
@@ -317,7 +318,8 @@ void Literal::printVec128(std::ostream& o, const std::array<uint8_t, 16>& v) {
std::ostream& operator<<(std::ostream& o, Literal literal) {
prepareMinorColor(o);
- switch (literal.type.getSingle()) {
+ TODO_SINGLE_COMPOUND(literal.type);
+ switch (literal.type.getBasic()) {
case Type::none:
o << "?";
break;
@@ -558,7 +560,7 @@ Literal Literal::truncSatToUI64() const {
}
Literal Literal::eqz() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return eq(Literal(int32_t(0)));
case Type::i64:
@@ -580,7 +582,7 @@ Literal Literal::eqz() const {
}
Literal Literal::neg() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(-uint32_t(i32));
case Type::i64:
@@ -602,7 +604,7 @@ Literal Literal::neg() const {
}
Literal Literal::abs() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(std::abs(i32));
case Type::i64:
@@ -624,7 +626,7 @@ Literal Literal::abs() const {
}
Literal Literal::ceil() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(std::ceil(getf32()));
case Type::f64:
@@ -635,7 +637,7 @@ Literal Literal::ceil() const {
}
Literal Literal::floor() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(std::floor(getf32()));
case Type::f64:
@@ -646,7 +648,7 @@ Literal Literal::floor() const {
}
Literal Literal::trunc() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(std::trunc(getf32()));
case Type::f64:
@@ -657,7 +659,7 @@ Literal Literal::trunc() const {
}
Literal Literal::nearbyint() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(std::nearbyint(getf32()));
case Type::f64:
@@ -668,7 +670,7 @@ Literal Literal::nearbyint() const {
}
Literal Literal::sqrt() const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(std::sqrt(getf32()));
case Type::f64:
@@ -707,7 +709,7 @@ Literal Literal::demote() const {
}
Literal Literal::add(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) + uint32_t(other.i32));
case Type::i64:
@@ -729,7 +731,7 @@ Literal Literal::add(const Literal& other) const {
}
Literal Literal::sub(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) - uint32_t(other.i32));
case Type::i64:
@@ -822,7 +824,7 @@ Literal Literal::subSatUI16(const Literal& other) const {
}
Literal Literal::mul(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) * uint32_t(other.i32));
case Type::i64:
@@ -844,7 +846,7 @@ Literal Literal::mul(const Literal& other) const {
}
Literal Literal::div(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32: {
float lhs = getf32(), rhs = other.getf32();
float sign = std::signbit(lhs) == std::signbit(rhs) ? 0.f : -0.f;
@@ -923,7 +925,7 @@ Literal Literal::div(const Literal& other) const {
}
Literal Literal::divS(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 / other.i32);
case Type::i64:
@@ -934,7 +936,7 @@ Literal Literal::divS(const Literal& other) const {
}
Literal Literal::divU(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) / uint32_t(other.i32));
case Type::i64:
@@ -945,7 +947,7 @@ Literal Literal::divU(const Literal& other) const {
}
Literal Literal::remS(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 % other.i32);
case Type::i64:
@@ -956,7 +958,7 @@ Literal Literal::remS(const Literal& other) const {
}
Literal Literal::remU(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) % uint32_t(other.i32));
case Type::i64:
@@ -984,7 +986,7 @@ Literal Literal::avgrUInt(const Literal& other) const {
}
Literal Literal::and_(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 & other.i32);
case Type::i64:
@@ -995,7 +997,7 @@ Literal Literal::and_(const Literal& other) const {
}
Literal Literal::or_(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 | other.i32);
case Type::i64:
@@ -1006,7 +1008,7 @@ Literal Literal::or_(const Literal& other) const {
}
Literal Literal::xor_(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 ^ other.i32);
case Type::i64:
@@ -1017,7 +1019,7 @@ Literal Literal::xor_(const Literal& other) const {
}
Literal Literal::shl(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32)
<< Bits::getEffectiveShifts(other.i32, Type::i32));
@@ -1030,7 +1032,7 @@ Literal Literal::shl(const Literal& other) const {
}
Literal Literal::shrS(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 >> Bits::getEffectiveShifts(other.i32, Type::i32));
case Type::i64:
@@ -1041,7 +1043,7 @@ Literal Literal::shrS(const Literal& other) const {
}
Literal Literal::shrU(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) >>
Bits::getEffectiveShifts(other.i32, Type::i32));
@@ -1054,7 +1056,7 @@ Literal Literal::shrU(const Literal& other) const {
}
Literal Literal::rotL(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(RotateLeft(uint32_t(i32), uint32_t(other.i32)));
case Type::i64:
@@ -1065,7 +1067,7 @@ Literal Literal::rotL(const Literal& other) const {
}
Literal Literal::rotR(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(RotateRight(uint32_t(i32), uint32_t(other.i32)));
case Type::i64:
@@ -1076,7 +1078,7 @@ Literal Literal::rotR(const Literal& other) const {
}
Literal Literal::eq(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 == other.i32);
case Type::i64:
@@ -1098,7 +1100,7 @@ Literal Literal::eq(const Literal& other) const {
}
Literal Literal::ne(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 != other.i32);
case Type::i64:
@@ -1120,7 +1122,7 @@ Literal Literal::ne(const Literal& other) const {
}
Literal Literal::ltS(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 < other.i32);
case Type::i64:
@@ -1131,7 +1133,7 @@ Literal Literal::ltS(const Literal& other) const {
}
Literal Literal::ltU(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) < uint32_t(other.i32));
case Type::i64:
@@ -1142,7 +1144,7 @@ Literal Literal::ltU(const Literal& other) const {
}
Literal Literal::lt(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(getf32() < other.getf32());
case Type::f64:
@@ -1153,7 +1155,7 @@ Literal Literal::lt(const Literal& other) const {
}
Literal Literal::leS(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 <= other.i32);
case Type::i64:
@@ -1164,7 +1166,7 @@ Literal Literal::leS(const Literal& other) const {
}
Literal Literal::leU(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) <= uint32_t(other.i32));
case Type::i64:
@@ -1175,7 +1177,7 @@ Literal Literal::leU(const Literal& other) const {
}
Literal Literal::le(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(getf32() <= other.getf32());
case Type::f64:
@@ -1186,7 +1188,7 @@ Literal Literal::le(const Literal& other) const {
}
Literal Literal::gtS(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 > other.i32);
case Type::i64:
@@ -1197,7 +1199,7 @@ Literal Literal::gtS(const Literal& other) const {
}
Literal Literal::gtU(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) > uint32_t(other.i32));
case Type::i64:
@@ -1208,7 +1210,7 @@ Literal Literal::gtU(const Literal& other) const {
}
Literal Literal::gt(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(getf32() > other.getf32());
case Type::f64:
@@ -1219,7 +1221,7 @@ Literal Literal::gt(const Literal& other) const {
}
Literal Literal::geS(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(i32 >= other.i32);
case Type::i64:
@@ -1230,7 +1232,7 @@ Literal Literal::geS(const Literal& other) const {
}
Literal Literal::geU(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::i32:
return Literal(uint32_t(i32) >= uint32_t(other.i32));
case Type::i64:
@@ -1241,7 +1243,7 @@ Literal Literal::geU(const Literal& other) const {
}
Literal Literal::ge(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal(getf32() >= other.getf32());
case Type::f64:
@@ -1252,7 +1254,7 @@ Literal Literal::ge(const Literal& other) const {
}
Literal Literal::min(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32: {
auto l = getf32(), r = other.getf32();
if (l == r && l == 0) {
@@ -1295,7 +1297,7 @@ Literal Literal::min(const Literal& other) const {
}
Literal Literal::max(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32: {
auto l = getf32(), r = other.getf32();
if (l == r && l == 0) {
@@ -1338,7 +1340,7 @@ Literal Literal::max(const Literal& other) const {
}
Literal Literal::pmin(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
case Type::f64:
return other.lt(*this).geti32() ? other : *this;
@@ -1348,7 +1350,7 @@ Literal Literal::pmin(const Literal& other) const {
}
Literal Literal::pmax(const Literal& other) const {
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
case Type::f64:
return this->lt(other).geti32() ? other : *this;
@@ -1359,7 +1361,7 @@ Literal Literal::pmax(const Literal& other) const {
Literal Literal::copysign(const Literal& other) const {
// operate on bits directly, to avoid signalling bit being set on a float
- switch (type.getSingle()) {
+ switch (type.getBasic()) {
case Type::f32:
return Literal((i32 & 0x7fffffff) | (other.i32 & 0x80000000)).castToF32();
break;