OperandHelper.cs 2.9 KB

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