OperandHelper.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using ARMeilleure.Common;
  2. namespace ARMeilleure.IntermediateRepresentation
  3. {
  4. static class OperandHelper
  5. {
  6. public static Operand Const(OperandType type, long value)
  7. {
  8. return type == OperandType.I32 ? Operand().With((int)value) : Operand().With(value);
  9. }
  10. public static Operand Const(bool value)
  11. {
  12. return Operand().With(value ? 1 : 0);
  13. }
  14. public static Operand Const(int value)
  15. {
  16. return Operand().With(value);
  17. }
  18. public static Operand Const(uint value)
  19. {
  20. return Operand().With(value);
  21. }
  22. public static Operand Const(long value, bool relocatable = false, int? index = null)
  23. {
  24. return Operand().With(value, relocatable, index);
  25. }
  26. public static Operand Const(ulong value)
  27. {
  28. return Operand().With(value);
  29. }
  30. public static Operand ConstF(float value)
  31. {
  32. return Operand().With(value);
  33. }
  34. public static Operand ConstF(double value)
  35. {
  36. return Operand().With(value);
  37. }
  38. public static Operand Label()
  39. {
  40. return Operand().With(OperandKind.Label);
  41. }
  42. public static Operand Local(OperandType type)
  43. {
  44. return Operand().With(OperandKind.LocalVariable, type);
  45. }
  46. public static Operand Register(int index, RegisterType regType, OperandType type)
  47. {
  48. return Operand().With(index, regType, type);
  49. }
  50. public static Operand Undef()
  51. {
  52. return Operand().With(OperandKind.Undefined);
  53. }
  54. public static MemoryOperand MemoryOp(
  55. OperandType type,
  56. Operand baseAddress,
  57. Operand index = null,
  58. Multiplier scale = Multiplier.x1,
  59. int displacement = 0)
  60. {
  61. return MemoryOperand().With(type, baseAddress, index, scale, displacement);
  62. }
  63. #region "ThreadStaticPool"
  64. public static void PrepareOperandPool(int groupId = 0)
  65. {
  66. ThreadStaticPool<Operand>.PreparePool(groupId, ChunkSizeLimit.Large);
  67. ThreadStaticPool<MemoryOperand>.PreparePool(groupId, ChunkSizeLimit.Small);
  68. }
  69. private static Operand Operand()
  70. {
  71. return ThreadStaticPool<Operand>.Instance.Allocate();
  72. }
  73. private static MemoryOperand MemoryOperand()
  74. {
  75. return ThreadStaticPool<MemoryOperand>.Instance.Allocate();
  76. }
  77. public static void ResetOperandPool(int groupId = 0)
  78. {
  79. ThreadStaticPool<MemoryOperand>.ResetPool(groupId);
  80. ThreadStaticPool<Operand>.ResetPool(groupId);
  81. }
  82. public static void DisposeOperandPools()
  83. {
  84. ThreadStaticPool<Operand>.DisposePools();
  85. ThreadStaticPool<MemoryOperand>.DisposePools();
  86. }
  87. #endregion
  88. }
  89. }