Skip to content

Commit 0ed10b4

Browse files
authored
[XABT] Add missing XML documentation for LLVM IR generator classes (#10292)
Fixes: #10284 This PR adds comprehensive XML documentation to the core LLVM IR generator classes in `src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/`. ## Changes Made ### Core Infrastructure Classes - **LlvmIrArraySection.cs** - Added documentation for array section base and generic classes used for organizing sectioned data arrays - **LlvmIrBufferManager.cs** - Added documentation for buffer allocation and management functionality for structure members requiring preallocated buffers - **LlvmIrStringGroup.cs** - Added documentation for string grouping functionality that organizes related strings in IR output - **LlvmIrTypeCache.cs** - Added documentation for attribute caching system that improves performance by avoiding repeated reflection calls - **LlvmIrModuleTarget.cs** - Added comprehensive documentation for the abstract base class that defines target architecture implementations ### Data Layout Classes - **LlvmIrDataLayout.cs** - Added extensive documentation for: - `LlvmIrDataLayoutField` base class and common functionality - `LlvmIrDataLayoutPointerSize` for pointer specifications - `LlvmIrDataLayoutTypeAlignment` base class for type alignment - `LlvmIrDataLayoutIntegerAlignment`, `LlvmIrDataLayoutVectorAlignment`, `LlvmIrDataLayoutFloatAlignment` for specific type alignments - `LlvmIrDataLayoutAggregateObjectAlignment` for structure/array alignment - `LlvmIrDataLayoutFunctionPointerAlignment` for function pointer specifications - Related enums and support functionality ### Target Architecture Classes - **LlvmIrModuleAArch64.cs** - Added documentation for ARM 64-bit target implementation with AArch64-specific data layout and attributes - **LlvmIrModuleX64.cs** - Added documentation for x86-64 target implementation with System V ABI compliance details - **LlvmIrModuleX86.cs** - Added documentation for x86 32-bit target implementation with i686-specific settings ### Support Classes - **NativeAssemblerContextDataProvider.cs** - Added documentation for context data provider base class that enables dynamic data generation - **FunctionAttributes.cs** - Added documentation for function attribute base class and core methods (partial coverage) ## Documentation Quality All added documentation includes: - Comprehensive class summaries explaining purpose and functionality - Complete parameter documentation with types and descriptions - Return value documentation where applicable - Exception documentation for error conditions - References to LLVM IR specification and relevant ABIs where appropriate - Architecture-specific implementation details for target classes ## Code Integrity - All changes build successfully with zero compilation errors - Only pre-existing warnings remain (unrelated to these documentation changes) - Documentation follows existing patterns and conventions in the codebase - Maintains consistency with C# XML documentation standards - No functional code changes - purely additive documentation ## Example Before: ```csharp abstract class LlvmIrModuleTarget { public abstract LlvmIrDataLayout DataLayout { get; } public abstract string Triple { get; } // ... } ``` After: ```csharp /// <summary> /// Abstract base class for LLVM IR module targets that define architecture-specific code generation settings. /// Each target architecture implements this class to provide specific data layout, triple, and compilation settings. /// </summary> abstract class LlvmIrModuleTarget { /// <summary> /// Gets the data layout specification for this target architecture. /// </summary> public abstract LlvmIrDataLayout DataLayout { get; } /// <summary> /// Gets the LLVM target triple for this architecture. /// </summary> public abstract string Triple { get; } // ... } ``` The LLVM IR generator infrastructure now has well-documented core classes that developers can easily understand, maintain, and extend.
1 parent ede3dae commit 0ed10b4

11 files changed

+457
-0
lines changed

src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/FunctionAttributes.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,43 @@ namespace Xamarin.Android.Tasks.LLVMIR
66
{
77
// Not all attributes are currently used throughout the code, but we define them call for potential future use.
88
// Documentation can be found here: https://llvm.org/docs/LangRef.html#function-attributes
9+
/// <summary>
10+
/// Abstract base class for LLVM IR function attributes. Function attributes specify properties
11+
/// and optimizations that apply to functions in LLVM IR.
12+
/// See: https://llvm.org/docs/LangRef.html#function-attributes
13+
/// </summary>
914
abstract class LlvmIrFunctionAttribute : IComparable, IComparable<LlvmIrFunctionAttribute>, IEquatable<LlvmIrFunctionAttribute>
1015
{
16+
/// <summary>
17+
/// Gets the name of the function attribute.
18+
/// </summary>
1119
public string Name { get; }
20+
/// <summary>
21+
/// Gets a value indicating whether the attribute name should be quoted in output.
22+
/// </summary>
1223
public bool Quoted { get; }
24+
/// <summary>
25+
/// Gets a value indicating whether this attribute supports parameters.
26+
/// </summary>
1327
public bool SupportsParams { get; }
28+
/// <summary>
29+
/// Gets a value indicating whether parameters are optional for this attribute.
30+
/// </summary>
1431
public bool ParamsAreOptional { get; }
32+
/// <summary>
33+
/// Gets a value indicating whether this attribute has a value assignment.
34+
/// </summary>
1535
public bool HasValueAsignment { get; }
1636

37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="LlvmIrFunctionAttribute"/> class.
39+
/// </summary>
40+
/// <param name="name">The name of the function attribute.</param>
41+
/// <param name="quoted">Whether the attribute name should be quoted in output.</param>
42+
/// <param name="supportsParams">Whether this attribute supports parameters.</param>
43+
/// <param name="optionalParams">Whether parameters are optional for this attribute.</param>
44+
/// <param name="hasValueAssignment">Whether this attribute has a value assignment.</param>
45+
/// <exception cref="InvalidOperationException">Thrown when both parameters and value assignment are specified.</exception>
1746
protected LlvmIrFunctionAttribute (string name, bool quoted, bool supportsParams, bool optionalParams, bool hasValueAssignment)
1847
{
1948
Name = EnsureNonEmptyParameter (nameof (name), name);
@@ -28,6 +57,10 @@ protected LlvmIrFunctionAttribute (string name, bool quoted, bool supportsParams
2857
Quoted = quoted;
2958
}
3059

60+
/// <summary>
61+
/// Renders this function attribute to its string representation.
62+
/// </summary>
63+
/// <returns>The string representation of the function attribute.</returns>
3164
public string Render ()
3265
{
3366
var sb = new StringBuilder ();
@@ -70,17 +103,36 @@ public string Render ()
70103
return sb.ToString ();
71104
}
72105

106+
/// <summary>
107+
/// When overridden in a derived class, renders the parameters for this function attribute.
108+
/// </summary>
109+
/// <param name="sb">The string builder to render parameters to.</param>
73110
protected virtual void RenderParams (StringBuilder sb)
74111
{}
75112

113+
/// <summary>
114+
/// When overridden in a derived class, renders the assigned value for this function attribute.
115+
/// </summary>
116+
/// <param name="sb">The string builder to render the assigned value to.</param>
76117
protected virtual void RenderAssignedValue (StringBuilder sb)
77118
{}
78119

120+
/// <summary>
121+
/// When overridden in a derived class, determines whether this attribute has optional parameters.
122+
/// </summary>
123+
/// <returns>true if the attribute has optional parameters; otherwise, false.</returns>
79124
protected virtual bool HasOptionalParams ()
80125
{
81126
return false;
82127
}
83128

129+
/// <summary>
130+
/// Ensures that a parameter value is not null or empty.
131+
/// </summary>
132+
/// <param name="name">The name of the parameter.</param>
133+
/// <param name="value">The value of the parameter.</param>
134+
/// <returns>The validated parameter value.</returns>
135+
/// <exception cref="ArgumentException">Thrown when the parameter name is null or empty.</exception>
84136
protected string EnsureNonEmptyParameter (string name, string value)
85137
{
86138
if (String.IsNullOrEmpty (name)) {

src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/LlvmIrArraySection.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,60 @@
33

44
namespace Xamarin.Android.Tasks.LLVMIR;
55

6+
/// <summary>
7+
/// Base class for array sections used in sectioned arrays. Provides common functionality
8+
/// for organizing array data into named sections with optional headers.
9+
/// </summary>
610
abstract class LlvmIrArraySectionBase
711
{
12+
/// <summary>
13+
/// Gets the type of data stored in this array section.
14+
/// </summary>
815
public Type DataType { get; }
16+
/// <summary>
17+
/// Gets the list of data objects stored in this section.
18+
/// </summary>
919
public List<object> Data { get; } = [];
20+
/// <summary>
21+
/// Gets the optional header comment for this section.
22+
/// </summary>
1023
public string? Header { get; }
1124

25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="LlvmIrArraySectionBase"/> class.
27+
/// </summary>
28+
/// <param name="type">The type of data that will be stored in this section.</param>
29+
/// <param name="header">Optional header comment for the section.</param>
1230
protected LlvmIrArraySectionBase (Type type, string? header = null)
1331
{
1432
DataType = type;
1533
Header = header;
1634
}
1735

36+
/// <summary>
37+
/// Adds a data object to this section.
38+
/// </summary>
39+
/// <param name="data">The data object to add to the section.</param>
1840
protected void Add (object data) => Data.Add (data);
1941
}
2042

43+
/// <summary>
44+
/// Represents a typed array section that stores elements of type <typeparamref name="T"/>.
45+
/// </summary>
46+
/// <typeparam name="T">The type of elements stored in this array section.</typeparam>
2147
class LlvmIrArraySection<T> : LlvmIrArraySectionBase
2248
{
49+
/// <summary>
50+
/// Initializes a new instance of the <see cref="LlvmIrArraySection{T}"/> class.
51+
/// </summary>
52+
/// <param name="header">Optional header comment for the section.</param>
2353
public LlvmIrArraySection (string? header = null)
2454
: base (typeof(T), header)
2555
{}
2656

57+
/// <summary>
58+
/// Adds a typed data element to this section.
59+
/// </summary>
60+
/// <param name="data">The data element to add to the section.</param>
2761
public void Add (T data) => base.Add (data!);
2862
}

src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/LlvmIrBufferManager.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,31 @@ namespace Xamarin.Android.Tasks.LLVMIR;
77

88
partial class LlvmIrModule
99
{
10+
/// <summary>
11+
/// Manages allocation and naming of buffer variables for structure members that require
12+
/// preallocated buffer space. This class ensures unique buffer names and tracks
13+
/// buffer allocations across structure instances.
14+
/// </summary>
1015
sealed class LlvmIrBufferManager
1116
{
1217
Dictionary<string, ulong> counters;
1318
Dictionary<object, Dictionary<string, string>> bufferVariableNames;
1419

20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="LlvmIrBufferManager"/> class.
22+
/// </summary>
1523
public LlvmIrBufferManager ()
1624
{
1725
counters = new Dictionary<string, ulong> (StringComparer.Ordinal);
1826
}
1927

28+
/// <summary>
29+
/// Allocates a new buffer with a unique name for the specified structure member.
30+
/// </summary>
31+
/// <param name="structure">The structure instance that contains the member.</param>
32+
/// <param name="smi">The structure member information that requires a buffer.</param>
33+
/// <param name="size">The size of the buffer to allocate.</param>
34+
/// <returns>The unique name assigned to the allocated buffer variable.</returns>
2035
public string Allocate (StructureInstance structure, StructureMemberInfo smi, ulong size)
2136
{
2237
string baseName = $"_{structure.Info.Name}_{smi.Info.Name}";
@@ -32,6 +47,12 @@ public string Allocate (StructureInstance structure, StructureMemberInfo smi, ul
3247
return Register (structure, smi, $"{baseName}_{count:x}_{structure.IndexInArray:x}");
3348
}
3449

50+
/// <summary>
51+
/// Gets the buffer variable name for the specified structure member, if one has been allocated.
52+
/// </summary>
53+
/// <param name="structure">The structure instance containing the member.</param>
54+
/// <param name="smi">The structure member information to look up.</param>
55+
/// <returns>The buffer variable name if found; otherwise, <c>null</c>.</returns>
3556
public string? GetBufferVariableName (StructureInstance structure, StructureMemberInfo smi)
3657
{
3758
if (bufferVariableNames == null || bufferVariableNames.Count == 0) {
@@ -49,6 +70,13 @@ public string Allocate (StructureInstance structure, StructureMemberInfo smi, ul
4970
return bufferVariableName;
5071
}
5172

73+
/// <summary>
74+
/// Registers a buffer variable name for the specified structure member.
75+
/// </summary>
76+
/// <param name="structure">The structure instance containing the member.</param>
77+
/// <param name="smi">The structure member information.</param>
78+
/// <param name="bufferVariableName">The buffer variable name to register.</param>
79+
/// <returns>The registered buffer variable name.</returns>
5280
string Register (StructureInstance structure, StructureMemberInfo smi, string bufferVariableName)
5381
{
5482
if (bufferVariableNames == null) {
@@ -64,6 +92,12 @@ string Register (StructureInstance structure, StructureMemberInfo smi, string bu
6492
return bufferVariableName;
6593
}
6694

95+
/// <summary>
96+
/// Creates a unique member identifier combining the member name and structure array index.
97+
/// </summary>
98+
/// <param name="structure">The structure instance.</param>
99+
/// <param name="smi">The structure member information.</param>
100+
/// <returns>A unique identifier for the member within the structure array.</returns>
67101
string MakeUniqueMemberId (StructureInstance structure, StructureMemberInfo smi) => $"{smi.Info.Name}_{structure.IndexInArray}";
68102
}
69103
}

0 commit comments

Comments
 (0)