HipcGenerator: return FrozenDictionary<,>.Empty
when there are no command implementations, otherwise create FrozenDictionary
from a IEnumerable<KeyValuePair<,>>
instead of a
Dictionary<,>``
This commit is contained in:
parent
e27f3c7e79
commit
bfb83f0341
1 changed files with 44 additions and 35 deletions
|
@ -116,63 +116,72 @@ namespace Ryujinx.Horizon.Generators.Hipc
|
||||||
private static void GenerateMethodTable(CodeGenerator generator, Compilation compilation, CommandInterface commandInterface)
|
private static void GenerateMethodTable(CodeGenerator generator, Compilation compilation, CommandInterface commandInterface)
|
||||||
{
|
{
|
||||||
generator.EnterScope($"public IReadOnlyDictionary<int, CommandHandler> GetCommandHandlers()");
|
generator.EnterScope($"public IReadOnlyDictionary<int, CommandHandler> GetCommandHandlers()");
|
||||||
generator.EnterScope($"return new Dictionary<int, CommandHandler>()");
|
|
||||||
|
|
||||||
foreach (var method in commandInterface.CommandImplementations)
|
if (commandInterface.CommandImplementations.Count == 0)
|
||||||
{
|
{
|
||||||
foreach (var commandId in GetAttributeArguments(compilation, method, TypeCommandAttribute, 0))
|
generator.AppendLine("return FrozenDictionary<int, CommandHandler>.Empty;");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
generator.EnterScope($"return FrozenDictionary.ToFrozenDictionary(new []");
|
||||||
|
|
||||||
|
foreach (var method in commandInterface.CommandImplementations)
|
||||||
{
|
{
|
||||||
string[] args = new string[method.ParameterList.Parameters.Count];
|
foreach (var commandId in GetAttributeArguments(compilation, method, TypeCommandAttribute, 0))
|
||||||
|
|
||||||
if (args.Length == 0)
|
|
||||||
{
|
{
|
||||||
generator.AppendLine($"{{ {commandId}, new CommandHandler({method.Identifier.Text}, Array.Empty<CommandArg>()) }},");
|
string[] args = new string[method.ParameterList.Parameters.Count];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
foreach (var parameter in method.ParameterList.Parameters)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
string canonicalTypeName = GetCanonicalTypeNameWithGenericArguments(compilation, parameter.Type);
|
generator.AppendLine($"KeyValuePair.Create({commandId}, new CommandHandler({method.Identifier.Text}, Array.Empty<CommandArg>())),");
|
||||||
CommandArgType argType = GetCommandArgType(compilation, parameter);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
string arg;
|
foreach (var parameter in method.ParameterList.Parameters)
|
||||||
|
|
||||||
if (argType == CommandArgType.Buffer)
|
|
||||||
{
|
{
|
||||||
string bufferFlags = GetFirstAttributeArgument(compilation, parameter, TypeBufferAttribute, 0);
|
string canonicalTypeName = GetCanonicalTypeNameWithGenericArguments(compilation, parameter.Type);
|
||||||
string bufferFixedSize = GetFirstAttributeArgument(compilation, parameter, TypeBufferAttribute, 1);
|
CommandArgType argType = GetCommandArgType(compilation, parameter);
|
||||||
|
|
||||||
if (bufferFixedSize != null)
|
string arg;
|
||||||
|
|
||||||
|
if (argType == CommandArgType.Buffer)
|
||||||
{
|
{
|
||||||
arg = $"new CommandArg({bufferFlags} | HipcBufferFlags.FixedSize, {bufferFixedSize})";
|
string bufferFlags = GetFirstAttributeArgument(compilation, parameter, TypeBufferAttribute, 0);
|
||||||
|
string bufferFixedSize = GetFirstAttributeArgument(compilation, parameter, TypeBufferAttribute, 1);
|
||||||
|
|
||||||
|
if (bufferFixedSize != null)
|
||||||
|
{
|
||||||
|
arg = $"new CommandArg({bufferFlags} | HipcBufferFlags.FixedSize, {bufferFixedSize})";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arg = $"new CommandArg({bufferFlags})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (argType == CommandArgType.InArgument || argType == CommandArgType.OutArgument)
|
||||||
|
{
|
||||||
|
string alignment = GetTypeAlignmentExpression(compilation, parameter.Type);
|
||||||
|
|
||||||
|
arg = $"new CommandArg(CommandArgType.{argType}, Unsafe.SizeOf<{canonicalTypeName}>(), {alignment})";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
arg = $"new CommandArg({bufferFlags})";
|
arg = $"new CommandArg(CommandArgType.{argType})";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (argType == CommandArgType.InArgument || argType == CommandArgType.OutArgument)
|
|
||||||
{
|
|
||||||
string alignment = GetTypeAlignmentExpression(compilation, parameter.Type);
|
|
||||||
|
|
||||||
arg = $"new CommandArg(CommandArgType.{argType}, Unsafe.SizeOf<{canonicalTypeName}>(), {alignment})";
|
args[index++] = arg;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
arg = $"new CommandArg(CommandArgType.{argType})";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args[index++] = arg;
|
generator.AppendLine($"KeyValuePair.Create({commandId}, new CommandHandler({method.Identifier.Text}, {string.Join(", ", args)})),");
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.AppendLine($"{{ {commandId}, new CommandHandler({method.Identifier.Text}, {string.Join(", ", args)}) }},");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generator.LeaveScope(");");
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.LeaveScope(".ToFrozenDictionary();");
|
|
||||||
generator.LeaveScope();
|
generator.LeaveScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue