aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/StructuredIr/AstHelper.cs
blob: 06d13c90b8a54d764cf4cab0f73110d1ccfcc0e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using Ryujinx.Graphics.Shader.Translation;

namespace Ryujinx.Graphics.Shader.StructuredIr
{
    static class AstHelper
    {
        public static void AddUse(IAstNode node, IAstNode parent)
        {
            if (node is AstOperand operand && operand.Type == OperandType.LocalVariable)
            {
                operand.Uses.Add(parent);
            }
        }

        public static void AddDef(IAstNode node, IAstNode parent)
        {
            if (node is AstOperand operand && operand.Type == OperandType.LocalVariable)
            {
                operand.Defs.Add(parent);
            }
        }

        public static void RemoveUse(IAstNode node, IAstNode parent)
        {
            if (node is AstOperand operand && operand.Type == OperandType.LocalVariable)
            {
                operand.Uses.Remove(parent);
            }
        }

        public static void RemoveDef(IAstNode node, IAstNode parent)
        {
            if (node is AstOperand operand && operand.Type == OperandType.LocalVariable)
            {
                operand.Defs.Remove(parent);
            }
        }

        public static AstAssignment Assign(IAstNode destination, IAstNode source)
        {
            return new AstAssignment(destination, source);
        }

        public static AstOperand Const(int value)
        {
            return new AstOperand(OperandType.Constant, value);
        }

        public static AstOperand Local(AggregateType type)
        {
            AstOperand local = new(OperandType.LocalVariable)
            {
                VarType = type,
            };

            return local;
        }

        public static IAstNode InverseCond(IAstNode cond)
        {
            return new AstOperation(Instruction.LogicalNot, cond);
        }

        public static IAstNode Next(IAstNode node)
        {
            return node.LLNode.Next?.Value;
        }

        public static IAstNode Previous(IAstNode node)
        {
            return node.LLNode.Previous?.Value;
        }
    }
}