Commit 13050d08 authored by nagayama15's avatar nagayama15

Implement operator<

parent 6f991a1a
......@@ -58,17 +58,13 @@ namespace wasm {
if (std::tie(l.type, *l.condition, *l.ifTrue) < std::tie(r.type, *r.condition, *r.ifTrue)) {
return true;
}
if (std::tie(r.type, *r.condition, *r.ifTrue) < std::tie(l.type, *l.condition, *l.ifTrue)) {
} else if (std::tie(r.type, *r.condition, *r.ifTrue) < std::tie(l.type, *l.condition, *l.ifTrue)) {
return false;
}
if (r.ifFalse == nullptr) {
return false;
}
if (l.ifFalse == nullptr) {
} else if (l.ifFalse == nullptr) {
return true;
}
......@@ -81,11 +77,63 @@ namespace wasm {
return std::tie(l.type, *l.body) < std::tie(r.type, *r.body);
}
case Expression::Id::BreakId:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::BreakId: {
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:
WASM_UNREACHABLE(); // TODO:
return std::tie(l.default_, *l.value) < std::tie(r.default_, *r.value);
}
case Expression::Id::CallId: {
const auto &l = *lhs.cast<Call>();
......@@ -178,17 +226,19 @@ namespace wasm {
if (r.value == nullptr) {
return false;
}
if (l.value == nullptr) {
} else if (l.value == nullptr) {
return true;
}
return *l.value < *r.value;
}
case Expression::Id::HostId:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::HostId: {
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: {
const auto &l = *lhs.cast<AtomicRMW>();
......@@ -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);
}
case Expression::Id::SIMDExtractId:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::SIMDExtractId: {
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:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::SIMDReplaceId: {
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:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::SIMDShuffleId: {
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:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::SIMDBitselectId: {
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:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::SIMDShiftId: {
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:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::MemoryInitId: {
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:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::DataDropId: {
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:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::MemoryCopyId: {
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:
WASM_UNREACHABLE(); // TODO:
case Expression::Id::MemoryFillId: {
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::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