Commit 13050d08 authored by nagayama15's avatar nagayama15

Implement operator<

parent 6f991a1a
...@@ -58,17 +58,13 @@ namespace wasm { ...@@ -58,17 +58,13 @@ namespace wasm {
if (std::tie(l.type, *l.condition, *l.ifTrue) < std::tie(r.type, *r.condition, *r.ifTrue)) { if (std::tie(l.type, *l.condition, *l.ifTrue) < std::tie(r.type, *r.condition, *r.ifTrue)) {
return true; return true;
} } else if (std::tie(r.type, *r.condition, *r.ifTrue) < std::tie(l.type, *l.condition, *l.ifTrue)) {
if (std::tie(r.type, *r.condition, *r.ifTrue) < std::tie(l.type, *l.condition, *l.ifTrue)) {
return false; return false;
} }
if (r.ifFalse == nullptr) { if (r.ifFalse == nullptr) {
return false; return false;
} } else if (l.ifFalse == nullptr) {
if (l.ifFalse == nullptr) {
return true; return true;
} }
...@@ -81,11 +77,63 @@ namespace wasm { ...@@ -81,11 +77,63 @@ namespace wasm {
return std::tie(l.type, *l.body) < std::tie(r.type, *r.body); return std::tie(l.type, *l.body) < std::tie(r.type, *r.body);
} }
case Expression::Id::BreakId: case Expression::Id::BreakId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<Break>();
const auto &r = *rhs.cast<Break>();
if (l.type != r.type) {
return l.type < r.type;
}
if (l.value != nullptr && r.value == nullptr) {
return false;
} else if (l.value == nullptr && r.value != nullptr) {
return true;
} else if (l.value != nullptr && r.value != nullptr) {
if (*l.value < *r.value) {
return true;
} else if (*r.value < *l.value) {
return false;
}
}
if (l.condition != nullptr && r.condition == nullptr) {
return false;
} else if (l.condition == nullptr && r.condition != nullptr) {
return true;
} else if (l.condition != nullptr && r.condition != nullptr) {
return std::tie(*l.condition, l.name) < std::tie(*r.condition, r.name);
}
return l.name < r.name;
}
case Expression::Id::SwitchId: {
const auto &l = *lhs.cast<Switch>();
const auto &r = *rhs.cast<Switch>();
if (l.type != r.type) {
return l.type < r.type;
}
if (*l.condition < *r.condition) {
return true;
} else if (*r.condition < *l.condition) {
return false;
}
if (l.value == nullptr && r.value == nullptr) {
return l.default_ < r.default_;
}
if (l.value == nullptr) {
return true;
} else if (r.value == nullptr) {
return false;
}
case Expression::Id::SwitchId: return std::tie(l.default_, *l.value) < std::tie(r.default_, *r.value);
WASM_UNREACHABLE(); // TODO: }
case Expression::Id::CallId: { case Expression::Id::CallId: {
const auto &l = *lhs.cast<Call>(); const auto &l = *lhs.cast<Call>();
...@@ -178,17 +226,19 @@ namespace wasm { ...@@ -178,17 +226,19 @@ namespace wasm {
if (r.value == nullptr) { if (r.value == nullptr) {
return false; return false;
} } else if (l.value == nullptr) {
if (l.value == nullptr) {
return true; return true;
} }
return *l.value < *r.value; return *l.value < *r.value;
} }
case Expression::Id::HostId: case Expression::Id::HostId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<Host>();
const auto &r = *rhs.cast<Host>();
return std::tie(l.type, l.op, l.operands, l.nameOperand) <
std::tie(r.type, r.op, r.operands, r.nameOperand);
}
case Expression::Id::AtomicRMWId: { case Expression::Id::AtomicRMWId: {
const auto &l = *lhs.cast<AtomicRMW>(); const auto &l = *lhs.cast<AtomicRMW>();
...@@ -217,32 +267,61 @@ namespace wasm { ...@@ -217,32 +267,61 @@ namespace wasm {
return std::tie(l.type, l.offset, *l.ptr, *l.wakeCount) < std::tie(r.type, r.offset, *r.ptr, *r.wakeCount); return std::tie(l.type, l.offset, *l.ptr, *l.wakeCount) < std::tie(r.type, r.offset, *r.ptr, *r.wakeCount);
} }
case Expression::Id::SIMDExtractId: case Expression::Id::SIMDExtractId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<SIMDExtract>();
const auto &r = *rhs.cast<SIMDExtract>();
return std::tie(l.type, l.op, *l.vec, l.index) < std::tie(r.type, r.op, *r.vec, r.index);
}
case Expression::Id::SIMDReplaceId: case Expression::Id::SIMDReplaceId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<SIMDReplace>();
const auto &r = *rhs.cast<SIMDReplace>();
return std::tie(l.type, l.op, *l.vec, l.index, *l.value) <
std::tie(r.type, r.op, *r.vec, r.index, *r.value);
}
case Expression::Id::SIMDShuffleId: case Expression::Id::SIMDShuffleId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<SIMDShuffle>();
const auto &r = *rhs.cast<SIMDShuffle>();
return std::tie(l.type, *l.left, *l.right, l.mask) < std::tie(r.type, *r.left, *r.right, r.mask);
}
case Expression::Id::SIMDBitselectId: case Expression::Id::SIMDBitselectId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<SIMDBitselect>();
const auto &r = *rhs.cast<SIMDBitselect>();
return std::tie(l.type, *l.left, *l.right, *l.cond) < std::tie(r.type, *r.left, *r.right, *r.cond);
}
case Expression::Id::SIMDShiftId: case Expression::Id::SIMDShiftId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<SIMDShift>();
const auto &r = *rhs.cast<SIMDShift>();
return std::tie(l.type, l.op, *l.vec, *l.shift) < std::tie(r.type, r.op, *r.vec, *r.shift);
}
case Expression::Id::MemoryInitId: case Expression::Id::MemoryInitId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<MemoryInit>();
const auto &r = *rhs.cast<MemoryInit>();
return std::tie(l.type, l.segment, *l.dest, *l.offset, *l.size) <
std::tie(r.type, r.segment, *r.dest, *r.offset, *r.size);
}
case Expression::Id::DataDropId: case Expression::Id::DataDropId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<DataDrop>();
const auto &r = *rhs.cast<DataDrop>();
return std::tie(l.type, l.segment) < std::tie(r.type, r.segment);
}
case Expression::Id::MemoryCopyId: case Expression::Id::MemoryCopyId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<MemoryCopy>();
const auto &r = *rhs.cast<MemoryCopy>();
return std::tie(l.type, *l.dest, *l.source, *l.size) < std::tie(r.type, *r.dest, *r.source, *r.size);
}
case Expression::Id::MemoryFillId: case Expression::Id::MemoryFillId: {
WASM_UNREACHABLE(); // TODO: const auto &l = *lhs.cast<MemoryFill>();
const auto &r = *rhs.cast<MemoryFill>();
return std::tie(l.type, *l.dest, *l.value, *l.size) < std::tie(r.type, *r.dest, *r.value, *r.size);
}
case Expression::Id::NopId: case Expression::Id::NopId:
case Expression::Id::UnreachableId: case Expression::Id::UnreachableId:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment