DecodedProgram.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Graphics.Shader.Decoders
  5. {
  6. readonly struct DecodedProgram : IEnumerable<DecodedFunction>
  7. {
  8. public DecodedFunction MainFunction { get; }
  9. private readonly IReadOnlyDictionary<ulong, DecodedFunction> _functions;
  10. private readonly List<DecodedFunction> _functionsWithId;
  11. public int FunctionsWithIdCount => _functionsWithId.Count;
  12. public DecodedProgram(DecodedFunction mainFunction, IReadOnlyDictionary<ulong, DecodedFunction> functions)
  13. {
  14. MainFunction = mainFunction;
  15. _functions = functions;
  16. _functionsWithId = new List<DecodedFunction>();
  17. }
  18. public DecodedFunction GetFunctionByAddress(ulong address)
  19. {
  20. if (_functions.TryGetValue(address, out DecodedFunction function))
  21. {
  22. return function;
  23. }
  24. return null;
  25. }
  26. public DecodedFunction GetFunctionById(int id)
  27. {
  28. if ((uint)id >= (uint)_functionsWithId.Count)
  29. {
  30. throw new ArgumentOutOfRangeException(nameof(id));
  31. }
  32. return _functionsWithId[id];
  33. }
  34. public void AddFunctionAndSetId(DecodedFunction function)
  35. {
  36. function.Id = _functionsWithId.Count;
  37. _functionsWithId.Add(function);
  38. }
  39. public IEnumerator<DecodedFunction> GetEnumerator()
  40. {
  41. return _functions.Values.GetEnumerator();
  42. }
  43. IEnumerator IEnumerable.GetEnumerator()
  44. {
  45. return GetEnumerator();
  46. }
  47. }
  48. }