aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/Decoders/DecodedFunction.cs
blob: 49cd3a30ae73b25dbe986d02f5d358a90111f4d9 (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
using System;
using System.Collections.Generic;

namespace Ryujinx.Graphics.Shader.Decoders
{
    class DecodedFunction
    {
        private readonly HashSet<DecodedFunction> _callers;

        public bool IsCompilerGenerated => Type != FunctionType.User;
        public FunctionType Type { get; set; }
        public int Id { get; set; }

        public ulong Address { get; }
        public Block[] Blocks { get; private set; }

        public DecodedFunction(ulong address)
        {
            Address = address;
            _callers = new HashSet<DecodedFunction>();
            Type = FunctionType.User;
            Id = -1;
        }

        public void SetBlocks(Block[] blocks)
        {
            if (Blocks != null)
            {
                throw new InvalidOperationException("Blocks have already been set.");
            }

            Blocks = blocks;
        }

        public void AddCaller(DecodedFunction caller)
        {
            _callers.Add(caller);
        }

        public void RemoveCaller(DecodedFunction caller)
        {
            if (_callers.Remove(caller) && _callers.Count == 0)
            {
                Type = FunctionType.Unused;
            }
        }
    }
}