mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-07 07:26:26 +02:00
Revert "Structural and Memory Safety Improvements, Analyzer Cleanup (ryubing/ryujinx!47)"
This reverts merge request !47
This commit is contained in:
parent
faf9e3cdd7
commit
77a797f154
307 changed files with 1245 additions and 1016 deletions
|
@ -146,15 +146,11 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
generator.AppendLine();
|
||||
|
||||
List<SyscallIdAndName> syscalls = [];
|
||||
Dictionary<string, bool> isStaticMethod = new();
|
||||
|
||||
foreach (MethodDeclarationSyntax method in syntaxReceiver.SvcImplementations)
|
||||
{
|
||||
bool isStatic = method.Modifiers.Any(SyntaxKind.StaticKeyword);
|
||||
isStaticMethod[method.Identifier.Text] = isStatic;
|
||||
|
||||
GenerateMethod32(generator, context.Compilation, method, isStatic);
|
||||
GenerateMethod64(generator, context.Compilation, method, isStatic);
|
||||
GenerateMethod32(generator, context.Compilation, method);
|
||||
GenerateMethod64(generator, context.Compilation, method);
|
||||
|
||||
foreach (AttributeSyntax attribute in method.AttributeLists.SelectMany(attributeList =>
|
||||
attributeList.Attributes.Where(attribute =>
|
||||
|
@ -170,9 +166,9 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
|
||||
syscalls.Sort();
|
||||
|
||||
GenerateDispatch(generator, syscalls, A32Suffix, isStaticMethod);
|
||||
GenerateDispatch(generator, syscalls, A32Suffix);
|
||||
generator.AppendLine();
|
||||
GenerateDispatch(generator, syscalls, A64Suffix, isStaticMethod);
|
||||
GenerateDispatch(generator, syscalls, A64Suffix);
|
||||
|
||||
generator.LeaveScope();
|
||||
generator.LeaveScope();
|
||||
|
@ -197,12 +193,9 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
generator.LeaveScope();
|
||||
}
|
||||
|
||||
private static void GenerateMethod32(CodeGenerator generator, Compilation compilation, MethodDeclarationSyntax method, bool isStatic)
|
||||
private static void GenerateMethod32(CodeGenerator generator, Compilation compilation, MethodDeclarationSyntax method)
|
||||
{
|
||||
string methodParams = isStatic
|
||||
? $"{TypeExecutionContext} context"
|
||||
: $"Syscall syscall, {TypeExecutionContext} context";
|
||||
generator.EnterScope($"private static void {method.Identifier.Text}{A32Suffix}({methodParams})");
|
||||
generator.EnterScope($"private static void {method.Identifier.Text}{A32Suffix}(Syscall syscall, {TypeExecutionContext} context)");
|
||||
|
||||
string[] args = new string[method.ParameterList.Parameters.Count];
|
||||
int index = 0;
|
||||
|
@ -273,10 +266,9 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
string result = null;
|
||||
string canonicalReturnTypeName = null;
|
||||
|
||||
string callPrefix = isStatic ? $"{(method.Parent is ClassDeclarationSyntax cls ? cls.Identifier.Text + "." : "")}{method.Identifier.Text}" : $"syscall.{method.Identifier.Text}";
|
||||
if (method.ReturnType.ToString() != "void")
|
||||
{
|
||||
generator.AppendLine($"var {ResultVariableName} = {callPrefix}({argsList});");
|
||||
generator.AppendLine($"var {ResultVariableName} = syscall.{method.Identifier.Text}({argsList});");
|
||||
canonicalReturnTypeName = GetCanonicalTypeName(compilation, method.ReturnType);
|
||||
|
||||
if (canonicalReturnTypeName == TypeResult)
|
||||
|
@ -297,7 +289,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
}
|
||||
else
|
||||
{
|
||||
generator.AppendLine($"{callPrefix}({argsList});");
|
||||
generator.AppendLine($"syscall.{method.Identifier.Text}({argsList});");
|
||||
}
|
||||
|
||||
foreach (OutParameter outParameter in outParameters)
|
||||
|
@ -321,12 +313,9 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
generator.AppendLine();
|
||||
}
|
||||
|
||||
private static void GenerateMethod64(CodeGenerator generator, Compilation compilation, MethodDeclarationSyntax method, bool isStatic)
|
||||
private static void GenerateMethod64(CodeGenerator generator, Compilation compilation, MethodDeclarationSyntax method)
|
||||
{
|
||||
string methodParams = isStatic
|
||||
? $"{TypeExecutionContext} context"
|
||||
: $"Syscall syscall, {TypeExecutionContext} context";
|
||||
generator.EnterScope($"private static void {method.Identifier.Text}{A64Suffix}({methodParams})");
|
||||
generator.EnterScope($"private static void {method.Identifier.Text}{A64Suffix}(Syscall syscall, {TypeExecutionContext} context)");
|
||||
|
||||
string[] args = new string[method.ParameterList.Parameters.Count];
|
||||
int registerIndex = 0;
|
||||
|
@ -367,10 +356,9 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
string result = null;
|
||||
string canonicalReturnTypeName = null;
|
||||
|
||||
string callPrefix = isStatic ? $"{(method.Parent is ClassDeclarationSyntax cls ? cls.Identifier.Text + "." : "")}{method.Identifier.Text}" : $"syscall.{method.Identifier.Text}";
|
||||
if (method.ReturnType.ToString() != "void")
|
||||
{
|
||||
generator.AppendLine($"var {ResultVariableName} = {callPrefix}({argsList});");
|
||||
generator.AppendLine($"var {ResultVariableName} = syscall.{method.Identifier.Text}({argsList});");
|
||||
canonicalReturnTypeName = GetCanonicalTypeName(compilation, method.ReturnType);
|
||||
|
||||
if (canonicalReturnTypeName == TypeResult)
|
||||
|
@ -386,7 +374,7 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
}
|
||||
else
|
||||
{
|
||||
generator.AppendLine($"{callPrefix}({argsList});");
|
||||
generator.AppendLine($"syscall.{method.Identifier.Text}({argsList});");
|
||||
}
|
||||
|
||||
foreach (OutParameter outParameter in outParameters)
|
||||
|
@ -405,55 +393,6 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
generator.AppendLine();
|
||||
}
|
||||
|
||||
private static void GenerateMethod32(CodeGenerator generator, Compilation compilation, MethodDeclarationSyntax method)
|
||||
{
|
||||
GenerateMethod32(generator, compilation, method, false);
|
||||
}
|
||||
|
||||
private static void GenerateMethod64(CodeGenerator generator, Compilation compilation, MethodDeclarationSyntax method)
|
||||
{
|
||||
GenerateMethod64(generator, compilation, method, false);
|
||||
}
|
||||
|
||||
private static void GenerateDispatch(CodeGenerator generator, List<SyscallIdAndName> syscalls, string suffix, Dictionary<string, bool> isStaticMethod)
|
||||
{
|
||||
generator.EnterScope($"public static void Dispatch{suffix}(Syscall syscall, {TypeExecutionContext} context, int id)");
|
||||
generator.EnterScope("switch (id)");
|
||||
|
||||
foreach (SyscallIdAndName syscall in syscalls)
|
||||
{
|
||||
generator.AppendLine($"case {syscall.Id}:");
|
||||
generator.IncreaseIndentation();
|
||||
|
||||
if (isStaticMethod.TryGetValue(syscall.Name, out bool isStatic) && isStatic)
|
||||
{
|
||||
generator.AppendLine($"{syscall.Name}{suffix}(context);");
|
||||
}
|
||||
else
|
||||
{
|
||||
generator.AppendLine($"{syscall.Name}{suffix}(syscall, context);");
|
||||
}
|
||||
|
||||
generator.AppendLine("break;");
|
||||
|
||||
generator.DecreaseIndentation();
|
||||
}
|
||||
|
||||
generator.AppendLine($"default:");
|
||||
generator.IncreaseIndentation();
|
||||
|
||||
generator.AppendLine("throw new NotImplementedException($\"SVC 0x{id:X4} is not implemented.\");");
|
||||
|
||||
generator.DecreaseIndentation();
|
||||
|
||||
generator.LeaveScope();
|
||||
generator.LeaveScope();
|
||||
}
|
||||
|
||||
private static void GenerateDispatch(CodeGenerator generator, List<SyscallIdAndName> syscalls, string suffix)
|
||||
{
|
||||
}
|
||||
|
||||
private static string GetFormattedLogValue(string value, string canonicalTypeName)
|
||||
{
|
||||
if (Is32BitInteger(canonicalTypeName))
|
||||
|
@ -524,6 +463,33 @@ namespace Ryujinx.Horizon.Kernel.Generators
|
|||
generator.AppendLine($"Logger.{logLevel}?.PrintMsg(LogClass.{logClass}, $\"{log}\");");
|
||||
}
|
||||
|
||||
private static void GenerateDispatch(CodeGenerator generator, List<SyscallIdAndName> syscalls, string suffix)
|
||||
{
|
||||
generator.EnterScope($"public static void Dispatch{suffix}(Syscall syscall, {TypeExecutionContext} context, int id)");
|
||||
generator.EnterScope("switch (id)");
|
||||
|
||||
foreach (SyscallIdAndName syscall in syscalls)
|
||||
{
|
||||
generator.AppendLine($"case {syscall.Id}:");
|
||||
generator.IncreaseIndentation();
|
||||
|
||||
generator.AppendLine($"{syscall.Name}{suffix}(syscall, context);");
|
||||
generator.AppendLine("break;");
|
||||
|
||||
generator.DecreaseIndentation();
|
||||
}
|
||||
|
||||
generator.AppendLine($"default:");
|
||||
generator.IncreaseIndentation();
|
||||
|
||||
generator.AppendLine("throw new NotImplementedException($\"SVC 0x{id:X4} is not implemented.\");");
|
||||
|
||||
generator.DecreaseIndentation();
|
||||
|
||||
generator.LeaveScope();
|
||||
generator.LeaveScope();
|
||||
}
|
||||
|
||||
private static bool Is32BitInteger(string canonicalTypeName)
|
||||
{
|
||||
return canonicalTypeName is TypeSystemInt32 or TypeSystemUInt32;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue