OperandType.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. namespace ARMeilleure.IntermediateRepresentation
  3. {
  4. enum OperandType
  5. {
  6. None,
  7. I32,
  8. I64,
  9. FP32,
  10. FP64,
  11. V128
  12. }
  13. static class OperandTypeExtensions
  14. {
  15. public static bool IsInteger(this OperandType type)
  16. {
  17. return type == OperandType.I32 ||
  18. type == OperandType.I64;
  19. }
  20. public static RegisterType ToRegisterType(this OperandType type)
  21. {
  22. switch (type)
  23. {
  24. case OperandType.FP32: return RegisterType.Vector;
  25. case OperandType.FP64: return RegisterType.Vector;
  26. case OperandType.I32: return RegisterType.Integer;
  27. case OperandType.I64: return RegisterType.Integer;
  28. case OperandType.V128: return RegisterType.Vector;
  29. }
  30. throw new InvalidOperationException($"Invalid operand type \"{type}\".");
  31. }
  32. public static int GetSizeInBytes(this OperandType type)
  33. {
  34. switch (type)
  35. {
  36. case OperandType.FP32: return 4;
  37. case OperandType.FP64: return 8;
  38. case OperandType.I32: return 4;
  39. case OperandType.I64: return 8;
  40. case OperandType.V128: return 16;
  41. }
  42. throw new InvalidOperationException($"Invalid operand type \"{type}\".");
  43. }
  44. }
  45. }