2022-05-31 20:12:46 +00:00
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Horizon.Generators.Kernel
|
|
|
|
|
{
|
|
|
|
|
class SyscallSyntaxReceiver : ISyntaxReceiver
|
|
|
|
|
{
|
|
|
|
|
public List<MethodDeclarationSyntax> SvcImplementations { get; }
|
|
|
|
|
|
|
|
|
|
public SyscallSyntaxReceiver()
|
|
|
|
|
{
|
|
|
|
|
SvcImplementations = new List<MethodDeclarationSyntax>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
|
|
|
|
|
{
|
2023-03-28 12:59:43 +00:00
|
|
|
|
if (!(syntaxNode is ClassDeclarationSyntax classDeclaration) || classDeclaration.AttributeLists.Count == 0)
|
2022-05-31 20:12:46 +00:00
|
|
|
|
{
|
2023-03-28 12:59:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!classDeclaration.AttributeLists.Any(attributeList =>
|
|
|
|
|
attributeList.Attributes.Any(x => x.Name.GetText().ToString() == "SvcImpl")))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-31 20:12:46 +00:00
|
|
|
|
|
2023-03-28 12:59:43 +00:00
|
|
|
|
foreach (var memberDeclaration in classDeclaration.Members)
|
|
|
|
|
{
|
|
|
|
|
if (memberDeclaration is MethodDeclarationSyntax methodDeclaration)
|
|
|
|
|
{
|
|
|
|
|
VisitMethod(methodDeclaration);
|
2022-05-31 20:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VisitMethod(MethodDeclarationSyntax methodDeclaration)
|
|
|
|
|
{
|
2023-03-28 12:59:43 +00:00
|
|
|
|
if (methodDeclaration.AttributeLists.Count == 0)
|
2022-05-31 20:12:46 +00:00
|
|
|
|
{
|
2023-03-28 12:59:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (methodDeclaration.AttributeLists.Any(attributeList =>
|
|
|
|
|
attributeList.Attributes.Any(x => x.Name.GetText().ToString() == "Svc")))
|
|
|
|
|
{
|
|
|
|
|
SvcImplementations.Add(methodDeclaration);
|
2022-05-31 20:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|