Register.cs 948 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. namespace ARMeilleure.IntermediateRepresentation
  3. {
  4. struct Register : IEquatable<Register>
  5. {
  6. public int Index { get; }
  7. public RegisterType Type { get; }
  8. public Register(int index, RegisterType type)
  9. {
  10. Index = index;
  11. Type = type;
  12. }
  13. public override int GetHashCode()
  14. {
  15. return (ushort)Index | ((int)Type << 16);
  16. }
  17. public static bool operator ==(Register x, Register y)
  18. {
  19. return x.Equals(y);
  20. }
  21. public static bool operator !=(Register x, Register y)
  22. {
  23. return !x.Equals(y);
  24. }
  25. public override bool Equals(object obj)
  26. {
  27. return obj is Register reg && Equals(reg);
  28. }
  29. public bool Equals(Register other)
  30. {
  31. return other.Index == Index &&
  32. other.Type == Type;
  33. }
  34. }
  35. }