AstHelper.cs 2.0 KB

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