Verified Commit 8b368114 authored by nagayama15's avatar nagayama15

add operator<(Function,Function)

parent 16ed4772
......@@ -24,7 +24,7 @@ namespace kyut::methods::function_reordering {
start,
end,
[](const auto& a, const auto& b) {
return *a->body < *b->body;
return *a < *b;
});
return size_bits;
......@@ -44,7 +44,7 @@ namespace kyut::methods::function_reordering {
start,
end,
[](const auto& a, const auto& b) {
return *a->body < *b->body;
return *a < *b;
});
return size_bits;
......
......@@ -347,6 +347,10 @@ namespace wasm {
}
inline bool operator<(const ExpressionList& a, const ExpressionList& b) {
if (a.size() != b.size()) {
return a.size() < b.size();
}
return std::lexicographical_compare(
std::begin(a),
std::end(a),
......@@ -356,6 +360,12 @@ namespace wasm {
return *a < *b;
});
}
inline bool operator<(const Function& a, const Function& b) {
// wasm::Function::getNumVars() does not modify states
return std::forward_as_tuple(a.sig, const_cast<Function&>(a).getNumVars(), *a.body) <
std::forward_as_tuple(b.sig, const_cast<Function&>(b).getNumVars(), *b.body);
}
} // namespace wasm
#endif // INCLUDE_kyut_wasm_ext_Compare_inl_hpp
......@@ -7,6 +7,7 @@ namespace wasm {
bool operator<(const Literal& a, const Literal& b);
bool operator<(const Expression& a, const Expression& b);
bool operator<(const ExpressionList& a, const ExpressionList& b);
bool operator<(const Function& a, const Function& b);
} // namespace wasm
#include "Compare-inl.hpp"
......
......@@ -37,6 +37,9 @@ TEST(kyut_Reordering, embed_by_reordering) {
check_embed("2314", "\x50"sv, 20, 4, "2314");
check_embed("2314", "\x00"sv, 20, 4, "1234");
// check_embed("1223", "\x00"sv, 20, 2, "1232");
// check_embed("1223", "\x40"sv, 20, 2, "2132");
}
namespace {
......@@ -69,6 +72,9 @@ TEST(kyut_Reordering, extract_by_reordering) {
check_extract("4231", 20, 4, "\x30"sv);
check_extract("1324", 20, 4, "\x40"sv);
check_extract("2314", 20, 4, "\x50"sv);
// check_extract("1232", 20, 2, "\x00"sv);
// check_extract("2132", 20, 2, "\x40"sv);
}
namespace {
......
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