diff --git a/src/symbol.cc b/src/symbol.cc index e77c699f52..9dc5726908 100644 --- a/src/symbol.cc +++ b/src/symbol.cc @@ -37,6 +37,12 @@ bool Symbol::operator==(const Symbol& other) const { return val_ == other.val_; } +bool Symbol::operator<(const Symbol& other) const { + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Symbol, program_id_, + other.program_id_); + return val_ < other.val_; +} + std::string Symbol::to_str() const { return "$" + std::to_string(val_); } diff --git a/src/symbol.h b/src/symbol.h index 286e20d51b..4567ca8568 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -54,6 +54,11 @@ class Symbol { /// @returns true if the symbols are the same bool operator==(const Symbol& o) const; + /// Less-than operator + /// @param o the other symbol + /// @returns true if this symbol is ordered before symbol `o` + bool operator<(const Symbol& o) const; + /// @returns true if the symbol is valid bool IsValid() const { return val_ != static_cast(-1); }