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