mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-28 17:36:24 +02:00
[Spv.Generator] Address dotnet-format issues (#5394)
* dotnet format style --severity info Some changes were manually reverted. * Restore a few unused methods and variables * Silence dotnet format IDE0052 warnings * Address or silence dotnet format IDE1006 warnings * Address or silence dotnet format CA1069 warnings * Address review comments * Address most dotnet format whitespace warnings * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Address IDE0251 warnings * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * Rename Operand.cs to IOperand.cs * Update src/Spv.Generator/Module.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> * Remove NotNullWhen attribute and use conditional access to avoid NRE * Fix duplicated enum values * Remove unread member --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
This commit is contained in:
parent
cebfa54467
commit
981e0c082d
14 changed files with 490 additions and 497 deletions
|
@ -15,30 +15,30 @@ namespace Spv.Generator
|
|||
private uint _bound;
|
||||
|
||||
// Follow spec order here while keeping it as simple as possible.
|
||||
private List<Capability> _capabilities;
|
||||
private List<string> _extensions;
|
||||
private Dictionary<DeterministicStringKey, Instruction> _extInstImports;
|
||||
private readonly List<Capability> _capabilities;
|
||||
private readonly List<string> _extensions;
|
||||
private readonly Dictionary<DeterministicStringKey, Instruction> _extInstImports;
|
||||
private AddressingModel _addressingModel;
|
||||
private MemoryModel _memoryModel;
|
||||
|
||||
private List<Instruction> _entrypoints;
|
||||
private List<Instruction> _executionModes;
|
||||
private List<Instruction> _debug;
|
||||
private List<Instruction> _annotations;
|
||||
private readonly List<Instruction> _entrypoints;
|
||||
private readonly List<Instruction> _executionModes;
|
||||
private readonly List<Instruction> _debug;
|
||||
private readonly List<Instruction> _annotations;
|
||||
|
||||
// In the declaration block.
|
||||
private Dictionary<TypeDeclarationKey, Instruction> _typeDeclarations;
|
||||
private readonly Dictionary<TypeDeclarationKey, Instruction> _typeDeclarations;
|
||||
// In the declaration block.
|
||||
private List<Instruction> _globals;
|
||||
private readonly List<Instruction> _globals;
|
||||
// In the declaration block.
|
||||
private Dictionary<ConstantKey, Instruction> _constants;
|
||||
private readonly Dictionary<ConstantKey, Instruction> _constants;
|
||||
// In the declaration block, for function that aren't defined in the module.
|
||||
private List<Instruction> _functionsDeclarations;
|
||||
private readonly List<Instruction> _functionsDeclarations;
|
||||
|
||||
private List<Instruction> _functionsDefinitions;
|
||||
private readonly List<Instruction> _functionsDefinitions;
|
||||
|
||||
private GeneratorPool<Instruction> _instPool;
|
||||
private GeneratorPool<LiteralInteger> _integerPool;
|
||||
private readonly GeneratorPool<Instruction> _instPool;
|
||||
private readonly GeneratorPool<LiteralInteger> _integerPool;
|
||||
|
||||
public Module(uint version, GeneratorPool<Instruction> instPool = null, GeneratorPool<LiteralInteger> integerPool = null)
|
||||
{
|
||||
|
@ -143,7 +143,7 @@ namespace Spv.Generator
|
|||
_entrypoints.Add(entryPoint);
|
||||
}
|
||||
|
||||
public void AddExecutionMode(Instruction function, ExecutionMode mode, params Operand[] parameters)
|
||||
public void AddExecutionMode(Instruction function, ExecutionMode mode, params IOperand[] parameters)
|
||||
{
|
||||
Debug.Assert(function.Opcode == Op.OpFunction);
|
||||
|
||||
|
@ -225,7 +225,7 @@ namespace Spv.Generator
|
|||
_constants.Add(key, constant);
|
||||
}
|
||||
|
||||
public Instruction ExtInst(Instruction resultType, Instruction set, LiteralInteger instruction, params Operand[] parameters)
|
||||
public Instruction ExtInst(Instruction resultType, Instruction set, LiteralInteger instruction, params IOperand[] parameters)
|
||||
{
|
||||
Instruction result = NewInstruction(Op.OpExtInst, GetNewId(), resultType);
|
||||
|
||||
|
@ -262,104 +262,103 @@ namespace Spv.Generator
|
|||
// Estimate the size needed for the generated code, to avoid expanding the MemoryStream.
|
||||
int sizeEstimate = 1024 + _functionsDefinitions.Count * 32;
|
||||
|
||||
using (MemoryStream stream = new MemoryStream(sizeEstimate))
|
||||
using MemoryStream stream = new(sizeEstimate);
|
||||
|
||||
BinaryWriter writer = new(stream, System.Text.Encoding.ASCII);
|
||||
|
||||
// Header
|
||||
writer.Write(MagicNumber);
|
||||
writer.Write(_version);
|
||||
writer.Write(GeneratorId);
|
||||
writer.Write(_bound);
|
||||
writer.Write(0u);
|
||||
|
||||
// 1.
|
||||
foreach (Capability capability in _capabilities)
|
||||
{
|
||||
BinaryWriter writer = new BinaryWriter(stream, System.Text.Encoding.ASCII);
|
||||
Instruction capabilityInstruction = NewInstruction(Op.OpCapability);
|
||||
|
||||
// Header
|
||||
writer.Write(MagicNumber);
|
||||
writer.Write(_version);
|
||||
writer.Write(GeneratorId);
|
||||
writer.Write(_bound);
|
||||
writer.Write(0u);
|
||||
|
||||
// 1.
|
||||
foreach (Capability capability in _capabilities)
|
||||
{
|
||||
Instruction capabilityInstruction = NewInstruction(Op.OpCapability);
|
||||
|
||||
capabilityInstruction.AddOperand(capability);
|
||||
capabilityInstruction.Write(writer);
|
||||
}
|
||||
|
||||
// 2.
|
||||
foreach (string extension in _extensions)
|
||||
{
|
||||
Instruction extensionInstruction = NewInstruction(Op.OpExtension);
|
||||
|
||||
extensionInstruction.AddOperand(extension);
|
||||
extensionInstruction.Write(writer);
|
||||
}
|
||||
|
||||
// 3.
|
||||
foreach (Instruction extInstImport in _extInstImports.Values)
|
||||
{
|
||||
extInstImport.Write(writer);
|
||||
}
|
||||
|
||||
// 4.
|
||||
Instruction memoryModelInstruction = NewInstruction(Op.OpMemoryModel);
|
||||
memoryModelInstruction.AddOperand(_addressingModel);
|
||||
memoryModelInstruction.AddOperand(_memoryModel);
|
||||
memoryModelInstruction.Write(writer);
|
||||
|
||||
// 5.
|
||||
foreach (Instruction entrypoint in _entrypoints)
|
||||
{
|
||||
entrypoint.Write(writer);
|
||||
}
|
||||
|
||||
// 6.
|
||||
foreach (Instruction executionMode in _executionModes)
|
||||
{
|
||||
executionMode.Write(writer);
|
||||
}
|
||||
|
||||
// 7.
|
||||
// TODO: Order debug information correctly.
|
||||
foreach (Instruction debug in _debug)
|
||||
{
|
||||
debug.Write(writer);
|
||||
}
|
||||
|
||||
// 8.
|
||||
foreach (Instruction annotation in _annotations)
|
||||
{
|
||||
annotation.Write(writer);
|
||||
}
|
||||
|
||||
// Ensure that everything is in the right order in the declarations section.
|
||||
List<Instruction> declarations = new List<Instruction>();
|
||||
declarations.AddRange(_typeDeclarations.Values);
|
||||
declarations.AddRange(_globals);
|
||||
declarations.AddRange(_constants.Values);
|
||||
declarations.Sort((Instruction x, Instruction y) => x.Id.CompareTo(y.Id));
|
||||
|
||||
// 9.
|
||||
foreach (Instruction declaration in declarations)
|
||||
{
|
||||
declaration.Write(writer);
|
||||
}
|
||||
|
||||
// 10.
|
||||
foreach (Instruction functionDeclaration in _functionsDeclarations)
|
||||
{
|
||||
functionDeclaration.Write(writer);
|
||||
}
|
||||
|
||||
// 11.
|
||||
foreach (Instruction functionDefinition in _functionsDefinitions)
|
||||
{
|
||||
functionDefinition.Write(writer);
|
||||
}
|
||||
|
||||
_instPool.Clear();
|
||||
_integerPool.Clear();
|
||||
|
||||
LiteralInteger.UnregisterPool();
|
||||
|
||||
return stream.ToArray();
|
||||
capabilityInstruction.AddOperand(capability);
|
||||
capabilityInstruction.Write(writer);
|
||||
}
|
||||
|
||||
// 2.
|
||||
foreach (string extension in _extensions)
|
||||
{
|
||||
Instruction extensionInstruction = NewInstruction(Op.OpExtension);
|
||||
|
||||
extensionInstruction.AddOperand(extension);
|
||||
extensionInstruction.Write(writer);
|
||||
}
|
||||
|
||||
// 3.
|
||||
foreach (Instruction extInstImport in _extInstImports.Values)
|
||||
{
|
||||
extInstImport.Write(writer);
|
||||
}
|
||||
|
||||
// 4.
|
||||
Instruction memoryModelInstruction = NewInstruction(Op.OpMemoryModel);
|
||||
memoryModelInstruction.AddOperand(_addressingModel);
|
||||
memoryModelInstruction.AddOperand(_memoryModel);
|
||||
memoryModelInstruction.Write(writer);
|
||||
|
||||
// 5.
|
||||
foreach (Instruction entrypoint in _entrypoints)
|
||||
{
|
||||
entrypoint.Write(writer);
|
||||
}
|
||||
|
||||
// 6.
|
||||
foreach (Instruction executionMode in _executionModes)
|
||||
{
|
||||
executionMode.Write(writer);
|
||||
}
|
||||
|
||||
// 7.
|
||||
// TODO: Order debug information correctly.
|
||||
foreach (Instruction debug in _debug)
|
||||
{
|
||||
debug.Write(writer);
|
||||
}
|
||||
|
||||
// 8.
|
||||
foreach (Instruction annotation in _annotations)
|
||||
{
|
||||
annotation.Write(writer);
|
||||
}
|
||||
|
||||
// Ensure that everything is in the right order in the declarations section.
|
||||
List<Instruction> declarations = new();
|
||||
declarations.AddRange(_typeDeclarations.Values);
|
||||
declarations.AddRange(_globals);
|
||||
declarations.AddRange(_constants.Values);
|
||||
declarations.Sort((Instruction x, Instruction y) => x.Id.CompareTo(y.Id));
|
||||
|
||||
// 9.
|
||||
foreach (Instruction declaration in declarations)
|
||||
{
|
||||
declaration.Write(writer);
|
||||
}
|
||||
|
||||
// 10.
|
||||
foreach (Instruction functionDeclaration in _functionsDeclarations)
|
||||
{
|
||||
functionDeclaration.Write(writer);
|
||||
}
|
||||
|
||||
// 11.
|
||||
foreach (Instruction functionDefinition in _functionsDefinitions)
|
||||
{
|
||||
functionDefinition.Write(writer);
|
||||
}
|
||||
|
||||
_instPool.Clear();
|
||||
_integerPool.Clear();
|
||||
|
||||
LiteralInteger.UnregisterPool();
|
||||
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue