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