Operation.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. namespace ARMeilleure.IntermediateRepresentation
  2. {
  3. class Operation : Node
  4. {
  5. public Instruction Instruction { get; private set; }
  6. public Operation() : base() { }
  7. public Operation(
  8. Instruction instruction,
  9. Operand destination,
  10. Operand[] sources) : base(destination, sources.Length)
  11. {
  12. Instruction = instruction;
  13. for (int index = 0; index < sources.Length; index++)
  14. {
  15. SetSource(index, sources[index]);
  16. }
  17. }
  18. public Operation With(Instruction instruction, Operand destination)
  19. {
  20. With(destination, 0);
  21. Instruction = instruction;
  22. return this;
  23. }
  24. public Operation With(Instruction instruction, Operand destination, Operand[] sources)
  25. {
  26. With(destination, sources.Length);
  27. Instruction = instruction;
  28. for (int index = 0; index < sources.Length; index++)
  29. {
  30. SetSource(index, sources[index]);
  31. }
  32. return this;
  33. }
  34. public Operation With(Instruction instruction, Operand destination,
  35. Operand source0)
  36. {
  37. With(destination, 1);
  38. Instruction = instruction;
  39. SetSource(0, source0);
  40. return this;
  41. }
  42. public Operation With(Instruction instruction, Operand destination,
  43. Operand source0, Operand source1)
  44. {
  45. With(destination, 2);
  46. Instruction = instruction;
  47. SetSource(0, source0);
  48. SetSource(1, source1);
  49. return this;
  50. }
  51. public Operation With(Instruction instruction, Operand destination,
  52. Operand source0, Operand source1, Operand source2)
  53. {
  54. With(destination, 3);
  55. Instruction = instruction;
  56. SetSource(0, source0);
  57. SetSource(1, source1);
  58. SetSource(2, source2);
  59. return this;
  60. }
  61. public Operation With(
  62. Instruction instruction,
  63. Operand[] destinations,
  64. Operand[] sources)
  65. {
  66. With(destinations, sources.Length);
  67. Instruction = instruction;
  68. for (int index = 0; index < sources.Length; index++)
  69. {
  70. SetSource(index, sources[index]);
  71. }
  72. return this;
  73. }
  74. public void TurnIntoCopy(Operand source)
  75. {
  76. Instruction = Instruction.Copy;
  77. SetSource(source);
  78. }
  79. }
  80. }