AstOperation.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. using static Ryujinx.Graphics.Shader.StructuredIr.AstHelper;
  3. namespace Ryujinx.Graphics.Shader.StructuredIr
  4. {
  5. class AstOperation : AstNode
  6. {
  7. public Instruction Inst { get; }
  8. public int Index { get; }
  9. private IAstNode[] _sources;
  10. public int SourcesCount => _sources.Length;
  11. public AstOperation(Instruction inst, IAstNode[] sources, int sourcesCount)
  12. {
  13. Inst = inst;
  14. _sources = sources;
  15. for (int index = 0; index < sources.Length; index++)
  16. {
  17. if (index < sourcesCount)
  18. {
  19. AddUse(sources[index], this);
  20. }
  21. else
  22. {
  23. AddDef(sources[index], this);
  24. }
  25. }
  26. Index = 0;
  27. }
  28. public AstOperation(Instruction inst, int index, IAstNode[] sources, int sourcesCount) : this(inst, sources, sourcesCount)
  29. {
  30. Index = index;
  31. }
  32. public AstOperation(Instruction inst, params IAstNode[] sources) : this(inst, sources, sources.Length)
  33. {
  34. }
  35. public IAstNode GetSource(int index)
  36. {
  37. return _sources[index];
  38. }
  39. public void SetSource(int index, IAstNode source)
  40. {
  41. RemoveUse(_sources[index], this);
  42. AddUse(source, this);
  43. _sources[index] = source;
  44. }
  45. }
  46. }