PhiOperation.cs 1012 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using ARMeilleure.Translation;
  2. using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
  3. namespace ARMeilleure.IntermediateRepresentation
  4. {
  5. readonly struct PhiOperation
  6. {
  7. private readonly Operation _operation;
  8. public PhiOperation(Operation operation)
  9. {
  10. _operation = operation;
  11. }
  12. public int SourcesCount => _operation.SourcesCount / 2;
  13. public BasicBlock GetBlock(ControlFlowGraph cfg, int index)
  14. {
  15. return cfg.PostOrderBlocks[cfg.PostOrderMap[_operation.GetSource(index * 2).AsInt32()]];
  16. }
  17. public void SetBlock(int index, BasicBlock block)
  18. {
  19. _operation.SetSource(index * 2, Const(block.Index));
  20. }
  21. public Operand GetSource(int index)
  22. {
  23. return _operation.GetSource(index * 2 + 1);
  24. }
  25. public void SetSource(int index, Operand operand)
  26. {
  27. _operation.SetSource(index * 2 + 1, operand);
  28. }
  29. }
  30. }