AstHelper.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. using Ryujinx.Graphics.Shader.Translation;
  3. namespace Ryujinx.Graphics.Shader.StructuredIr
  4. {
  5. static class AstHelper
  6. {
  7. public static void AddUse(IAstNode node, IAstNode parent)
  8. {
  9. if (node is AstOperand operand && operand.Type == OperandType.LocalVariable)
  10. {
  11. operand.Uses.Add(parent);
  12. }
  13. }
  14. public static void AddDef(IAstNode node, IAstNode parent)
  15. {
  16. if (node is AstOperand operand && operand.Type == OperandType.LocalVariable)
  17. {
  18. operand.Defs.Add(parent);
  19. }
  20. }
  21. public static void RemoveUse(IAstNode node, IAstNode parent)
  22. {
  23. if (node is AstOperand operand && operand.Type == OperandType.LocalVariable)
  24. {
  25. operand.Uses.Remove(parent);
  26. }
  27. }
  28. public static void RemoveDef(IAstNode node, IAstNode parent)
  29. {
  30. if (node is AstOperand operand && operand.Type == OperandType.LocalVariable)
  31. {
  32. operand.Defs.Remove(parent);
  33. }
  34. }
  35. public static AstAssignment Assign(IAstNode destination, IAstNode source)
  36. {
  37. return new AstAssignment(destination, source);
  38. }
  39. public static AstOperand Const(int value)
  40. {
  41. return new AstOperand(OperandType.Constant, value);
  42. }
  43. public static AstOperand Local(AggregateType type)
  44. {
  45. AstOperand local = new AstOperand(OperandType.LocalVariable);
  46. local.VarType = type;
  47. return local;
  48. }
  49. public static IAstNode InverseCond(IAstNode cond)
  50. {
  51. return new AstOperation(Instruction.LogicalNot, cond);
  52. }
  53. public static IAstNode Next(IAstNode node)
  54. {
  55. return node.LLNode.Next?.Value;
  56. }
  57. public static IAstNode Previous(IAstNode node)
  58. {
  59. return node.LLNode.Previous?.Value;
  60. }
  61. }
  62. }