OpCode.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // System.Reflection.Emit.OpCode
  3. //
  4. // Author:
  5. // Sergey Chaban ([email protected])
  6. //
  7. using System;
  8. using System.Reflection;
  9. using System.Reflection.Emit;
  10. namespace System.Reflection.Emit {
  11. public struct OpCode {
  12. string name;
  13. internal byte op1;
  14. internal byte op2;
  15. byte size;
  16. byte type;
  17. byte flowCtrl;
  18. byte pop;
  19. byte push;
  20. byte operandType;
  21. internal OpCode (string name, int size,
  22. OpCodeType opcodeType,
  23. OperandType operandType,
  24. StackBehaviour pop,
  25. StackBehaviour push,
  26. FlowControl flowCtrl,
  27. byte op1, byte op2)
  28. {
  29. this.name = name;
  30. this.size = (byte)size;
  31. this.type = (byte)opcodeType;
  32. this.operandType = (byte)operandType;
  33. this.pop = (byte)pop;
  34. this.push = (byte)push;
  35. this.flowCtrl = (byte)flowCtrl;
  36. this.op1 = op1;
  37. this.op2 = op2;
  38. }
  39. public override int GetHashCode ()
  40. {
  41. return Value;
  42. }
  43. public override bool Equals (Object obj)
  44. {
  45. if (obj == null || !(obj is OpCode))
  46. return false;
  47. OpCode v = (OpCode)obj;
  48. return v.op1 == op1 && v.op2 == op2;
  49. }
  50. /// <summary>
  51. /// </summary>
  52. public string Name {
  53. get {
  54. return name;
  55. }
  56. }
  57. /// <summary>
  58. /// </summary>
  59. public int Size {
  60. get {
  61. return size;
  62. }
  63. }
  64. /// <summary>
  65. /// </summary>
  66. public OpCodeType OpCodeType {
  67. get {
  68. return (OpCodeType)type;
  69. }
  70. }
  71. /// <summary>
  72. /// </summary>
  73. public OperandType OperandType {
  74. get {
  75. return (OperandType)operandType;
  76. }
  77. }
  78. /// <summary>
  79. /// </summary>
  80. public FlowControl FlowControl {
  81. get {
  82. return (FlowControl)flowCtrl;
  83. }
  84. }
  85. /// <summary>
  86. /// </summary>
  87. public StackBehaviour StackBehaviourPop {
  88. get {
  89. return (StackBehaviour)pop;
  90. }
  91. }
  92. /// <summary>
  93. /// </summary>
  94. public StackBehaviour StackBehaviourPush {
  95. get {
  96. return (StackBehaviour)push;
  97. }
  98. }
  99. /// <summary>
  100. /// </summary>
  101. public short Value {
  102. get {
  103. if (size == 1) {
  104. return op2;
  105. } else {
  106. // two byte instruction - combine
  107. // Some old MS betas returned (op1 << 2) | op2 here...
  108. return (short) ((op1 << 8) | op2);
  109. }
  110. }
  111. }
  112. public override string ToString()
  113. {
  114. return Name;
  115. }
  116. } // OpCode
  117. } // System.Reflection.Emit