OperandType.cs
1 using System; 2 3 namespace ARMeilleure.IntermediateRepresentation 4 { 5 enum OperandType 6 { 7 None, 8 I32, 9 I64, 10 FP32, 11 FP64, 12 V128, 13 } 14 15 static class OperandTypeExtensions 16 { 17 public static bool IsInteger(this OperandType type) 18 { 19 return type == OperandType.I32 || 20 type == OperandType.I64; 21 } 22 23 public static RegisterType ToRegisterType(this OperandType type) 24 { 25 return type switch 26 { 27 OperandType.FP32 => RegisterType.Vector, 28 OperandType.FP64 => RegisterType.Vector, 29 OperandType.I32 => RegisterType.Integer, 30 OperandType.I64 => RegisterType.Integer, 31 OperandType.V128 => RegisterType.Vector, 32 _ => throw new InvalidOperationException($"Invalid operand type \"{type}\"."), 33 }; 34 } 35 36 public static int GetSizeInBytes(this OperandType type) 37 { 38 return type switch 39 { 40 OperandType.FP32 => 4, 41 OperandType.FP64 => 8, 42 OperandType.I32 => 4, 43 OperandType.I64 => 8, 44 OperandType.V128 => 16, 45 _ => throw new InvalidOperationException($"Invalid operand type \"{type}\"."), 46 }; 47 } 48 49 public static int GetSizeInBytesLog2(this OperandType type) 50 { 51 return type switch 52 { 53 OperandType.FP32 => 2, 54 OperandType.FP64 => 3, 55 OperandType.I32 => 2, 56 OperandType.I64 => 3, 57 OperandType.V128 => 4, 58 _ => throw new InvalidOperationException($"Invalid operand type \"{type}\"."), 59 }; 60 } 61 } 62 }