From 5f87067ef24196721358046775f3e9df06fb30df Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Wed, 30 Jul 2025 21:40:09 -0700 Subject: [PATCH 01/23] Add more properties to the wrapper structs --- .../Extensions/LLVMAttributeRef.cs | 52 ++++++++++- .../Extensions/LLVMBasicBlockRef.cs | 14 +++ .../Extensions/LLVMMetadataRef.cs | 93 +++++++++++++++++++ .../Extensions/LLVMModuleRef.cs | 78 ++++++++++++++++ .../Extensions/LLVMNamedMDNodeRef.cs | 24 +++++ .../Extensions/LLVMUseRef.cs | 4 + .../Extensions/LLVMValueRef.cs | 44 +++++++++ tests/LLVMSharp.UnitTests/Functions.cs | 2 +- 8 files changed, 308 insertions(+), 3 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs index 08154b3c..5df2b249 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs @@ -8,9 +8,57 @@ public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable LLVM.GetEnumAttributeKind(this); + public readonly uint EnumKind => IsEnumAttribute ? LLVM.GetEnumAttributeKind(this) : default; - public readonly ulong Value => LLVM.GetEnumAttributeValue(this); + public readonly ulong EnumValue => IsEnumAttribute ? LLVM.GetEnumAttributeValue(this) : default; + + public readonly bool IsEnumAttribute => Handle != IntPtr.Zero && LLVM.IsEnumAttribute(this) != 0; + + public readonly bool IsStringAttribute => Handle != IntPtr.Zero && LLVM.IsStringAttribute(this) != 0; + + public readonly bool IsTypeAttribute => Handle != IntPtr.Zero && LLVM.IsTypeAttribute(this) != 0; + + public readonly string StringKind + { + get + { + if (!IsStringAttribute) + { + return string.Empty; + } + + uint length = 0; + var kindPtr = LLVM.GetStringAttributeKind(this, &length); + if (kindPtr == null) + { + return string.Empty; + } + + return new ReadOnlySpan(kindPtr, (int)length).AsString(); + } + } + + public readonly string StringValue + { + get + { + if (!IsStringAttribute) + { + return string.Empty; + } + + uint length = 0; + var valuePtr = LLVM.GetStringAttributeValue(this, &length); + if (valuePtr == null) + { + return string.Empty; + } + + return new ReadOnlySpan(valuePtr, (int)length).AsString(); + } + } + + public readonly LLVMTypeRef TypeValue => IsTypeAttribute ? LLVM.GetTypeAttributeValue(this) : default; public static implicit operator LLVMAttributeRef(LLVMOpaqueAttributeRef* value) => new LLVMAttributeRef((IntPtr)value); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs index d6bd9a9a..398fa0e6 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. using System; +using System.Collections.Generic; namespace LLVMSharp.Interop; @@ -10,6 +11,19 @@ public unsafe partial struct LLVMBasicBlockRef(IntPtr handle) : IEquatable (Handle != IntPtr.Zero) ? LLVM.GetFirstInstruction(this) : default; + public readonly IEnumerable Instructions + { + get + { + var instruction = FirstInstruction; + while (instruction.Handle != IntPtr.Zero) + { + yield return instruction; + instruction = instruction.NextInstruction; + } + } + } + public readonly LLVMValueRef LastInstruction => (Handle != IntPtr.Zero) ? LLVM.GetLastInstruction(this) : default; public readonly LLVMBasicBlockRef Next => (Handle != IntPtr.Zero) ? LLVM.GetNextBasicBlock(this) : default; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs index 7d49e735..dc50f747 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs @@ -8,6 +8,99 @@ public unsafe partial struct LLVMMetadataRef(IntPtr handle) : IEquatable IsType ? LLVM.DITypeGetAlignInBits(this) : default; + + public readonly uint Column => Kind switch { + LLVMMetadataKind.LLVMDILocationMetadataKind => LLVM.DILocationGetColumn(this), + _ => default, + }; + + public readonly LLVMMetadataRef Expression => Kind switch { + LLVMMetadataKind.LLVMDIGlobalVariableExpressionMetadataKind => LLVM.DIGlobalVariableExpressionGetExpression(this), + _ => default, + }; + + public readonly LLVMMetadataRef File => Kind switch { + LLVMMetadataKind.LLVMDIFileMetadataKind => this, + LLVMMetadataKind.LLVMDISubprogramMetadataKind => LLVM.DIScopeGetFile(this), + _ when IsVariable => LLVM.DIVariableGetFile(this), + _ => default, + }; + + public readonly LLVMDIFlags Flags => IsType ? LLVM.DITypeGetFlags(this) : default; + + public readonly LLVMMetadataRef InlinedAt => Kind switch { + LLVMMetadataKind.LLVMDILocationMetadataKind => LLVM.DILocationGetInlinedAt(this), + _ => default, + }; + + public readonly bool IsDINode => Kind is >= LLVMMetadataKind.LLVMDILocationMetadataKind and <= LLVMMetadataKind.LLVMDIAssignIDMetadataKind; + + public readonly bool IsType => Kind switch { + LLVMMetadataKind.LLVMDICompositeTypeMetadataKind => true, + LLVMMetadataKind.LLVMDIDerivedTypeMetadataKind => true, + LLVMMetadataKind.LLVMDIStringTypeMetadataKind => true, + LLVMMetadataKind.LLVMDIBasicTypeMetadataKind => true, + LLVMMetadataKind.LLVMDISubroutineTypeMetadataKind => true, + LLVMMetadataKind.LLVMDITemplateTypeParameterMetadataKind => true, + _ => false, + }; + + public readonly bool IsVariable => Kind switch { + LLVMMetadataKind.LLVMDILocalVariableMetadataKind => true, + LLVMMetadataKind.LLVMDIGlobalVariableMetadataKind => true, + _ => false, + }; + + public readonly LLVMMetadataKind Kind => Handle == default + ? (LLVMMetadataKind)(-1) // 0 is a valid kind, so we use -1 to indicate a null metadata reference + : (LLVMMetadataKind)LLVM.GetMetadataKind(this); + + public readonly uint Line => Kind switch { + LLVMMetadataKind.LLVMDISubprogramMetadataKind => LLVM.DISubprogramGetLine(this), + LLVMMetadataKind.LLVMDILocationMetadataKind => LLVM.DILocationGetLine(this), + _ when IsType => LLVM.DITypeGetLine(this), + _ when IsVariable => LLVM.DIVariableGetLine(this), + _ => default, + }; + + public readonly string Name + { + get + { + if (!IsType) + { + return ""; + } + + nuint nameLength = 0; + sbyte* namePtr = LLVM.DITypeGetName(this, &nameLength); + if (namePtr == null) + { + return ""; + } + + return new ReadOnlySpan(namePtr, (int)nameLength).AsString(); + } + } + + public readonly ulong OffsetInBits => IsType ? LLVM.DITypeGetOffsetInBits(this) : default; + + public readonly LLVMMetadataRef Scope => Kind switch { + LLVMMetadataKind.LLVMDILocationMetadataKind => LLVM.DILocationGetScope(this), + _ when IsVariable => LLVM.DIVariableGetScope(this), + _ => default, + }; + + public readonly ulong SizeInBits => IsType ? LLVM.DITypeGetSizeInBits(this) : default; + + public readonly ushort Tag => IsDINode ? LLVM.GetDINodeTag(this) : default; + + public readonly LLVMMetadataRef Variable => Kind switch { + LLVMMetadataKind.LLVMDIGlobalVariableExpressionMetadataKind => LLVM.DIGlobalVariableExpressionGetVariable(this), + _ => default, + }; + public static implicit operator LLVMMetadataRef(LLVMOpaqueMetadata* value) => new LLVMMetadataRef((IntPtr)value); public static implicit operator LLVMOpaqueMetadata*(LLVMMetadataRef value) => (LLVMOpaqueMetadata*)value.Handle; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs index 9f5b60fa..df8dbb7b 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. using System; +using System.Collections.Generic; using System.Runtime.InteropServices; namespace LLVMSharp.Interop; @@ -41,10 +42,87 @@ public readonly string DataLayout public readonly LLVMValueRef FirstGlobal => (Handle != IntPtr.Zero) ? LLVM.GetFirstGlobal(this) : default; + public readonly LLVMValueRef FirstGlobalAlias => (Handle != IntPtr.Zero) ? LLVM.GetFirstGlobalAlias(this) : default; + + public readonly LLVMValueRef FirstGlobalIFunc => (Handle != IntPtr.Zero) ? LLVM.GetFirstGlobalIFunc(this) : default; + + public readonly LLVMNamedMDNodeRef FirstNamedMetadata => (Handle != IntPtr.Zero) ? LLVM.GetFirstNamedMetadata(this) : default; + + public readonly IEnumerable Functions + { + get + { + LLVMValueRef function = FirstFunction; + while (function.Handle != 0) + { + yield return function; + function = function.NextFunction; + } + } + } + + public readonly IEnumerable Globals + { + get + { + LLVMValueRef global = FirstGlobal; + while (global.Handle != 0) + { + yield return global; + global = global.NextGlobal; + } + } + } + + public readonly IEnumerable GlobalAliases + { + get + { + LLVMValueRef alias = FirstGlobalAlias; + while (alias.Handle != 0) + { + yield return alias; + alias = alias.NextGlobalAlias; + } + } + } + + public readonly IEnumerable GlobalIFuncs + { + get + { + LLVMValueRef ifunc = FirstGlobalIFunc; + while (ifunc.Handle != 0) + { + yield return ifunc; + ifunc = ifunc.NextGlobalIFunc; + } + } + } + public readonly LLVMValueRef LastFunction => (Handle != IntPtr.Zero) ? LLVM.GetLastFunction(this) : default; public readonly LLVMValueRef LastGlobal => (Handle != IntPtr.Zero) ? LLVM.GetLastGlobal(this) : default; + public readonly LLVMValueRef LastGlobalAlias => (Handle != IntPtr.Zero) ? LLVM.GetLastGlobalAlias(this) : default; + + public readonly LLVMValueRef LastGlobalIFunc => (Handle != IntPtr.Zero) ? LLVM.GetLastGlobalIFunc(this) : default; + + public readonly LLVMNamedMDNodeRef LastNamedMetadata => (Handle != IntPtr.Zero) ? LLVM.GetLastNamedMetadata(this) : default; + + public readonly IEnumerable NamedMetadata + { + get + { + LLVMNamedMDNodeRef namedMetadata = FirstNamedMetadata; + while (namedMetadata.Handle != 0) + { + yield return namedMetadata; + namedMetadata = namedMetadata.NextNamedMetadata; + } + } + } + public readonly string Target { get diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs index 8ecdc155..1359ecd3 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs @@ -8,6 +8,30 @@ public unsafe partial struct LLVMNamedMDNodeRef(IntPtr handle) : IEquatable(namePtr, (int)nameLength).AsString(); + } + } + + public readonly LLVMNamedMDNodeRef NextNamedMetadata => Handle != IntPtr.Zero ? LLVM.GetNextNamedMetadata(this) : default; + + public readonly LLVMNamedMDNodeRef PreviousNamedMetadata => Handle != IntPtr.Zero ? LLVM.GetPreviousNamedMetadata(this) : default; + public static implicit operator LLVMNamedMDNodeRef(LLVMOpaqueNamedMDNode* value) => new LLVMNamedMDNodeRef((IntPtr)value); public static implicit operator LLVMOpaqueNamedMDNode*(LLVMNamedMDNodeRef value) => (LLVMOpaqueNamedMDNode*)value.Handle; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs index cd81413d..d8299e65 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs @@ -8,6 +8,10 @@ public unsafe partial struct LLVMUseRef(IntPtr handle) : IEquatable { public IntPtr Handle = handle; + public readonly LLVMUseRef Next => Handle != IntPtr.Zero ? LLVM.GetNextUse(this) : default; + + public readonly LLVMValueRef User => Handle != IntPtr.Zero ? LLVM.GetUser(this) : default; + public static implicit operator LLVMUseRef(LLVMOpaqueUse* Use) => new LLVMUseRef((IntPtr)Use); public static implicit operator LLVMOpaqueUse*(LLVMUseRef Use) => (LLVMOpaqueUse*)Use.Handle; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index 41edce31..01a1dbd5 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. using System; +using System.Collections.Generic; using static LLVMSharp.Interop.LLVMTailCallKind; namespace LLVMSharp.Interop; @@ -56,6 +57,8 @@ public readonly LLVMValueRef Condition public readonly LLVMOpcode ConstOpcode => (IsAConstantExpr != null) ? LLVM.GetConstOpcode(this) : default; + public readonly double ConstRealDouble => (IsAConstantFP != null) ? GetConstRealDouble(out _) : default; + public readonly LLVMDLLStorageClass DLLStorageClass { get @@ -491,10 +494,16 @@ public readonly string Name public readonly LLVMValueRef NextGlobal => (IsAGlobalVariable != null) ? LLVM.GetNextGlobal(this) : default; + public readonly LLVMValueRef NextGlobalAlias => (IsAGlobalAlias != null) ? LLVM.GetNextGlobalAlias(this) : default; + + public readonly LLVMValueRef NextGlobalIFunc => (IsAGlobalIFunc != null) ? LLVM.GetNextGlobalIFunc(this) : default; + public readonly LLVMValueRef NextInstruction => (IsAInstruction != null) ? LLVM.GetNextInstruction(this) : default; public readonly LLVMValueRef NextParam => (IsAArgument != null) ? LLVM.GetNextParam(this) : default; + public readonly LLVMOpcode Opcode => Kind is LLVMValueKind.LLVMInstructionValueKind ? InstructionOpcode : ConstOpcode; + public readonly int OperandCount => ((Kind == LLVMValueKind.LLVMMetadataAsValueValueKind) || (IsAUser != null)) ? LLVM.GetNumOperands(this) : default; public readonly uint ParamsCount => (IsAFunction != null) ? LLVM.CountParams(this) : default; @@ -516,6 +525,10 @@ public readonly LLVMValueRef PersonalityFn public readonly LLVMValueRef PreviousGlobal => (IsAGlobalVariable != null) ? LLVM.GetPreviousGlobal(this) : default; + public readonly LLVMValueRef PreviousGlobalAlias => (IsAGlobalAlias != null) ? LLVM.GetPreviousGlobalAlias(this) : default; + + public readonly LLVMValueRef PreviousGlobalIFunc => (IsAGlobalIFunc != null) ? LLVM.GetPreviousGlobalIFunc(this) : default; + public readonly LLVMValueRef PreviousInstruction => (IsAInstruction != null) ? LLVM.GetPreviousInstruction(this) : default; public readonly LLVMValueRef PreviousParam => (IsAArgument != null) ? LLVM.GetPreviousParam(this) : default; @@ -548,6 +561,8 @@ public readonly string Section } } + public readonly LLVMMetadataRef Subprogram => (IsAFunction != null) ? LLVM.GetSubprogram(this) : default; + public readonly uint SuccessorsCount => (IsAInstruction != null) ? LLVM.GetNumSuccessors(this) : default; public readonly LLVMBasicBlockRef SwitchDefaultDest => (IsASwitchInst != null) ? LLVM.GetSwitchDefaultDest(this) : default; @@ -580,6 +595,19 @@ public readonly LLVMThreadLocalMode ThreadLocalMode public readonly LLVMTypeRef TypeOf => (Handle != IntPtr.Zero) ? LLVM.TypeOf(this) : default; + public readonly IEnumerable Uses + { + get + { + var use = FirstUse; + while (use.Handle != IntPtr.Zero) + { + yield return use.User; + use = use.Next; + } + } + } + public readonly LLVMVisibility Visibility { get @@ -1022,6 +1050,22 @@ public readonly string GetMDString(out uint Len) public readonly LLVMValueRef GetOperand(uint Index) => LLVM.GetOperand(this, Index); + public readonly LLVMValueRef[] GetOperands() + { + int numOperands = OperandCount; + if (numOperands == 0) + { + return []; + } + + LLVMValueRef[] operands = new LLVMValueRef[numOperands]; + for (int i = 0; i < numOperands; i++) + { + operands[i] = GetOperand((uint)i); + } + return operands; + } + public readonly LLVMUseRef GetOperandUse(uint Index) => LLVM.GetOperandUse(this, Index); public readonly LLVMValueRef GetParam(uint Index) => LLVM.GetParam(this, Index); diff --git a/tests/LLVMSharp.UnitTests/Functions.cs b/tests/LLVMSharp.UnitTests/Functions.cs index 05c9314b..0f27fd53 100644 --- a/tests/LLVMSharp.UnitTests/Functions.cs +++ b/tests/LLVMSharp.UnitTests/Functions.cs @@ -26,6 +26,6 @@ public void AddsAttributeAtIndex() functionValue.AddAttributeAtIndex((LLVMAttributeIndex)1, attr); var attrs = functionValue.GetAttributesAtIndex((LLVMAttributeIndex)1); - Assert.That((AttributeKind)attrs[0].Kind, Is.EqualTo(AttributeKind.ByVal)); + Assert.That((AttributeKind)attrs[0].EnumKind, Is.EqualTo(AttributeKind.ByVal)); } } From 21f258ab50777ba70beb3e6c48fb1b687273f98c Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Wed, 30 Jul 2025 22:34:31 -0700 Subject: [PATCH 02/23] LLVMValueRef::Instructions --- .../Extensions/LLVMValueRef.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index 01a1dbd5..c3001672 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -176,6 +176,40 @@ public readonly uint InstructionCallConv public readonly LLVMBasicBlockRef InstructionParent => (IsAInstruction != null) ? LLVM.GetInstructionParent(this) : default; + public readonly IEnumerable Instructions + { + get + { + if (IsAFunction != default) + { + return GetFunctionInstructions(this); + } + else if (IsABasicBlock != default) + { + return AsBasicBlock().Instructions; + } + else if (IsAInstruction != default) + { + return [this]; + } + else + { + return []; + } + + static IEnumerable GetFunctionInstructions(LLVMValueRef function) + { + foreach (LLVMBasicBlockRef basicBlock in function.GetBasicBlocks()) + { + foreach (LLVMValueRef instruction in basicBlock.Instructions) + { + yield return instruction; + } + } + } + } + } + public readonly uint IntrinsicID => (Handle != IntPtr.Zero) ? LLVM.GetIntrinsicID(this) : default; public readonly LLVMValueRef IsAAddrSpaceCastInst => LLVM.IsAAddrSpaceCastInst(this); From 8760482393a9294b6b9ad5bc3d7e3f5fa31d7b21 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Thu, 21 Aug 2025 12:50:53 -0700 Subject: [PATCH 03/23] Eliminate allocations for enumerable properties --- .../LLVMBasicBlockInstructionsEnumerable.cs | 34 ++++++++++ .../Extensions/LLVMBasicBlockRef.cs | 14 +--- .../LLVMModuleFunctionsEnumerable.cs | 34 ++++++++++ .../LLVMModuleGlobalAliasesEnumerable.cs | 34 ++++++++++ .../LLVMModuleGlobalIFuncsEnumerable.cs | 34 ++++++++++ .../Extensions/LLVMModuleGlobalsEnumerable.cs | 34 ++++++++++ .../LLVMModuleNamedMetadataEnumerable.cs | 34 ++++++++++ .../Extensions/LLVMModuleRef.cs | 65 ++----------------- .../Extensions/LLVMUseRef.cs | 2 +- .../Extensions/LLVMValueRef.cs | 27 +------- .../Extensions/LLVMValueUsesEnumerable.cs | 34 ++++++++++ 11 files changed, 248 insertions(+), 98 deletions(-) create mode 100644 sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs create mode 100644 sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs create mode 100644 sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs create mode 100644 sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs create mode 100644 sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs create mode 100644 sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs create mode 100644 sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs new file mode 100644 index 00000000..9ef6e56d --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace LLVMSharp.Interop; + +public readonly record struct LLVMBasicBlockInstructionsEnumerable(LLVMBasicBlockRef BasicBlock) : IEnumerable +{ + public Enumerator GetEnumerator() => new(BasicBlock); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator(LLVMBasicBlockRef basicBlock) : IEnumerator + { + public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; + readonly void IDisposable.Dispose() { } + public bool MoveNext() + { + if (Current.Handle == 0) + { + Current = basicBlock.FirstInstruction; + } + else + { + Current = Current.NextInstruction; + } + return Current.Handle != 0; + } + public void Reset() => Current = default; + } +} diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs index 398fa0e6..9502151a 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. using System; -using System.Collections.Generic; namespace LLVMSharp.Interop; @@ -11,18 +10,7 @@ public unsafe partial struct LLVMBasicBlockRef(IntPtr handle) : IEquatable (Handle != IntPtr.Zero) ? LLVM.GetFirstInstruction(this) : default; - public readonly IEnumerable Instructions - { - get - { - var instruction = FirstInstruction; - while (instruction.Handle != IntPtr.Zero) - { - yield return instruction; - instruction = instruction.NextInstruction; - } - } - } + public readonly LLVMBasicBlockInstructionsEnumerable Instructions => new LLVMBasicBlockInstructionsEnumerable(this); public readonly LLVMValueRef LastInstruction => (Handle != IntPtr.Zero) ? LLVM.GetLastInstruction(this) : default; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs new file mode 100644 index 00000000..2ceacc47 --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace LLVMSharp.Interop; + +public readonly record struct LLVMModuleFunctionsEnumerable(LLVMModuleRef Module) : IEnumerable +{ + public Enumerator GetEnumerator() => new(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator(LLVMModuleRef module) : IEnumerator + { + public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; + readonly void IDisposable.Dispose() { } + public bool MoveNext() + { + if (Current.Handle == 0) + { + Current = module.FirstFunction; + } + else + { + Current = Current.NextFunction; + } + return Current.Handle != 0; + } + public void Reset() => Current = default; + } +} diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs new file mode 100644 index 00000000..27daf2d9 --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace LLVMSharp.Interop; + +public readonly record struct LLVMModuleGlobalAliasesEnumerable(LLVMModuleRef Module) : IEnumerable +{ + public Enumerator GetEnumerator() => new(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator(LLVMModuleRef module) : IEnumerator + { + public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; + readonly void IDisposable.Dispose() { } + public bool MoveNext() + { + if (Current.Handle == 0) + { + Current = module.FirstGlobalAlias; + } + else + { + Current = Current.NextGlobalAlias; + } + return Current.Handle != 0; + } + public void Reset() => Current = default; + } +} diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs new file mode 100644 index 00000000..b48f1c2d --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace LLVMSharp.Interop; + +public readonly record struct LLVMModuleGlobalIFuncsEnumerable(LLVMModuleRef Module) : IEnumerable +{ + public Enumerator GetEnumerator() => new(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator(LLVMModuleRef module) : IEnumerator + { + public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; + readonly void IDisposable.Dispose() { } + public bool MoveNext() + { + if (Current.Handle == 0) + { + Current = module.FirstGlobalIFunc; + } + else + { + Current = Current.NextGlobalIFunc; + } + return Current.Handle != 0; + } + public void Reset() => Current = default; + } +} diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs new file mode 100644 index 00000000..98bd6a16 --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace LLVMSharp.Interop; + +public readonly record struct LLVMModuleGlobalsEnumerable(LLVMModuleRef Module) : IEnumerable +{ + public Enumerator GetEnumerator() => new(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator(LLVMModuleRef module) : IEnumerator + { + public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; + readonly void IDisposable.Dispose() { } + public bool MoveNext() + { + if (Current.Handle == 0) + { + Current = module.FirstGlobal; + } + else + { + Current = Current.NextGlobal; + } + return Current.Handle != 0; + } + public void Reset() => Current = default; + } +} diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs new file mode 100644 index 00000000..18b9ecb9 --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace LLVMSharp.Interop; + +public readonly record struct LLVMModuleNamedMetadataEnumerable(LLVMModuleRef Module) : IEnumerable +{ + public Enumerator GetEnumerator() => new(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator(LLVMModuleRef module) : IEnumerator + { + public LLVMNamedMDNodeRef Current { get; private set; } + readonly object IEnumerator.Current => Current; + readonly void IDisposable.Dispose() { } + public bool MoveNext() + { + if (Current.Handle == 0) + { + Current = module.FirstNamedMetadata; + } + else + { + Current = Current.NextNamedMetadata; + } + return Current.Handle != 0; + } + public void Reset() => Current = default; + } +} diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs index df8dbb7b..61044437 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs @@ -48,57 +48,13 @@ public readonly string DataLayout public readonly LLVMNamedMDNodeRef FirstNamedMetadata => (Handle != IntPtr.Zero) ? LLVM.GetFirstNamedMetadata(this) : default; - public readonly IEnumerable Functions - { - get - { - LLVMValueRef function = FirstFunction; - while (function.Handle != 0) - { - yield return function; - function = function.NextFunction; - } - } - } + public readonly LLVMModuleFunctionsEnumerable Functions => new(this); - public readonly IEnumerable Globals - { - get - { - LLVMValueRef global = FirstGlobal; - while (global.Handle != 0) - { - yield return global; - global = global.NextGlobal; - } - } - } + public readonly LLVMModuleGlobalsEnumerable Globals => new(this); - public readonly IEnumerable GlobalAliases - { - get - { - LLVMValueRef alias = FirstGlobalAlias; - while (alias.Handle != 0) - { - yield return alias; - alias = alias.NextGlobalAlias; - } - } - } + public readonly LLVMModuleGlobalAliasesEnumerable GlobalAliases => new(this); - public readonly IEnumerable GlobalIFuncs - { - get - { - LLVMValueRef ifunc = FirstGlobalIFunc; - while (ifunc.Handle != 0) - { - yield return ifunc; - ifunc = ifunc.NextGlobalIFunc; - } - } - } + public readonly LLVMModuleGlobalIFuncsEnumerable GlobalIFuncs => new(this); public readonly LLVMValueRef LastFunction => (Handle != IntPtr.Zero) ? LLVM.GetLastFunction(this) : default; @@ -110,18 +66,7 @@ public readonly IEnumerable GlobalIFuncs public readonly LLVMNamedMDNodeRef LastNamedMetadata => (Handle != IntPtr.Zero) ? LLVM.GetLastNamedMetadata(this) : default; - public readonly IEnumerable NamedMetadata - { - get - { - LLVMNamedMDNodeRef namedMetadata = FirstNamedMetadata; - while (namedMetadata.Handle != 0) - { - yield return namedMetadata; - namedMetadata = namedMetadata.NextNamedMetadata; - } - } - } + public readonly LLVMModuleNamedMetadataEnumerable NamedMetadata => new(this); public readonly string Target { diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs index d8299e65..51319e6d 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs @@ -8,7 +8,7 @@ public unsafe partial struct LLVMUseRef(IntPtr handle) : IEquatable { public IntPtr Handle = handle; - public readonly LLVMUseRef Next => Handle != IntPtr.Zero ? LLVM.GetNextUse(this) : default; + public readonly LLVMUseRef NextUse => Handle != IntPtr.Zero ? LLVM.GetNextUse(this) : default; public readonly LLVMValueRef User => Handle != IntPtr.Zero ? LLVM.GetUser(this) : default; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index c3001672..b5a8dd9c 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Linq; using static LLVMSharp.Interop.LLVMTailCallKind; namespace LLVMSharp.Interop; @@ -182,7 +183,7 @@ public readonly IEnumerable Instructions { if (IsAFunction != default) { - return GetFunctionInstructions(this); + return GetBasicBlocks().SelectMany(b => b.Instructions); } else if (IsABasicBlock != default) { @@ -196,17 +197,6 @@ public readonly IEnumerable Instructions { return []; } - - static IEnumerable GetFunctionInstructions(LLVMValueRef function) - { - foreach (LLVMBasicBlockRef basicBlock in function.GetBasicBlocks()) - { - foreach (LLVMValueRef instruction in basicBlock.Instructions) - { - yield return instruction; - } - } - } } } @@ -629,18 +619,7 @@ public readonly LLVMThreadLocalMode ThreadLocalMode public readonly LLVMTypeRef TypeOf => (Handle != IntPtr.Zero) ? LLVM.TypeOf(this) : default; - public readonly IEnumerable Uses - { - get - { - var use = FirstUse; - while (use.Handle != IntPtr.Zero) - { - yield return use.User; - use = use.Next; - } - } - } + public readonly LLVMValueUsesEnumerable Uses => new(this); public readonly LLVMVisibility Visibility { diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs new file mode 100644 index 00000000..8529d3dd --- /dev/null +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace LLVMSharp.Interop; + +public readonly record struct LLVMValueUsesEnumerable(LLVMValueRef Module) : IEnumerable +{ + public Enumerator GetEnumerator() => new(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public struct Enumerator(LLVMValueRef module) : IEnumerator + { + public LLVMUseRef Current { get; private set; } + readonly object IEnumerator.Current => Current; + readonly void IDisposable.Dispose() { } + public bool MoveNext() + { + if (Current.Handle == 0) + { + Current = module.FirstUse; + } + else + { + Current = Current.NextUse; + } + return Current.Handle != 0; + } + public void Reset() => Current = default; + } +} From 62a15dbca8d7aae0bba42f102e636f38beedce5b Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Thu, 21 Aug 2025 13:21:32 -0700 Subject: [PATCH 04/23] Address review comments about attributes --- .../Extensions/LLVMAttributeRef.cs | 25 +++++++++++++------ tests/LLVMSharp.UnitTests/Functions.cs | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs index 5df2b249..4c50627a 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs @@ -8,17 +8,23 @@ public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable IsEnumAttribute ? LLVM.GetEnumAttributeKind(this) : default; - - public readonly ulong EnumValue => IsEnumAttribute ? LLVM.GetEnumAttributeValue(this) : default; - + /// + /// + /// + public readonly bool HasKindAsEnum => Handle != IntPtr.Zero && LLVM.IsStringAttribute(this) == 0; + + /// + /// This returns true for enum attributes and int attributes. + /// public readonly bool IsEnumAttribute => Handle != IntPtr.Zero && LLVM.IsEnumAttribute(this) != 0; public readonly bool IsStringAttribute => Handle != IntPtr.Zero && LLVM.IsStringAttribute(this) != 0; public readonly bool IsTypeAttribute => Handle != IntPtr.Zero && LLVM.IsTypeAttribute(this) != 0; - public readonly string StringKind + public readonly uint KindAsEnum => HasKindAsEnum ? LLVM.GetEnumAttributeKind(this) : default; + + public readonly string KindAsString { get { @@ -38,7 +44,12 @@ public readonly string StringKind } } - public readonly string StringValue + /// + /// + /// + public readonly ulong ValueAsInt => IsEnumAttribute ? LLVM.GetEnumAttributeValue(this) : default; + + public readonly string ValueAsString { get { @@ -58,7 +69,7 @@ public readonly string StringValue } } - public readonly LLVMTypeRef TypeValue => IsTypeAttribute ? LLVM.GetTypeAttributeValue(this) : default; + public readonly LLVMTypeRef ValueAsType => IsTypeAttribute ? LLVM.GetTypeAttributeValue(this) : default; public static implicit operator LLVMAttributeRef(LLVMOpaqueAttributeRef* value) => new LLVMAttributeRef((IntPtr)value); diff --git a/tests/LLVMSharp.UnitTests/Functions.cs b/tests/LLVMSharp.UnitTests/Functions.cs index 0f27fd53..4235b819 100644 --- a/tests/LLVMSharp.UnitTests/Functions.cs +++ b/tests/LLVMSharp.UnitTests/Functions.cs @@ -26,6 +26,6 @@ public void AddsAttributeAtIndex() functionValue.AddAttributeAtIndex((LLVMAttributeIndex)1, attr); var attrs = functionValue.GetAttributesAtIndex((LLVMAttributeIndex)1); - Assert.That((AttributeKind)attrs[0].EnumKind, Is.EqualTo(AttributeKind.ByVal)); + Assert.That((AttributeKind)attrs[0].KindAsEnum, Is.EqualTo(AttributeKind.ByVal)); } } From c7f8e409066887b13ad156319ba1ea98505e010e Mon Sep 17 00:00:00 2001 From: Jeremy Pritts <49847914+ds5678@users.noreply.github.com> Date: Sun, 7 Sep 2025 20:47:07 -0700 Subject: [PATCH 05/23] Update sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs Co-authored-by: Tanner Gooding --- sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs index 4c50627a..f063216f 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs @@ -11,7 +11,7 @@ public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable /// /// - public readonly bool HasKindAsEnum => Handle != IntPtr.Zero && LLVM.IsStringAttribute(this) == 0; + public readonly bool HasKindAsEnum => (Handle != IntPtr.Zero) && (LLVM.IsStringAttribute(this) == 0); /// /// This returns true for enum attributes and int attributes. From f82136f9e289c5c275858d203f32967407e63fb7 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 7 Sep 2025 20:50:59 -0700 Subject: [PATCH 06/23] Remove links to LLVM source --- sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs index f063216f..e61620e8 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs @@ -9,12 +9,12 @@ public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable - /// + /// This returns true for all attributes except string attributes. /// public readonly bool HasKindAsEnum => (Handle != IntPtr.Zero) && (LLVM.IsStringAttribute(this) == 0); /// - /// This returns true for enum attributes and int attributes. + /// This returns true for enum attributes and int attributes. /// public readonly bool IsEnumAttribute => Handle != IntPtr.Zero && LLVM.IsEnumAttribute(this) != 0; @@ -44,9 +44,6 @@ public readonly string KindAsString } } - /// - /// - /// public readonly ulong ValueAsInt => IsEnumAttribute ? LLVM.GetEnumAttributeValue(this) : default; public readonly string ValueAsString From 11267402eb41df4560209fb4b3a0b2c8215d5383 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 7 Sep 2025 20:55:31 -0700 Subject: [PATCH 07/23] Fix new() --- .../Extensions/LLVMBasicBlockInstructionsEnumerable.cs | 2 +- .../Extensions/LLVMModuleFunctionsEnumerable.cs | 2 +- .../Extensions/LLVMModuleGlobalAliasesEnumerable.cs | 2 +- .../Extensions/LLVMModuleGlobalIFuncsEnumerable.cs | 2 +- .../LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs | 2 +- .../Extensions/LLVMModuleNamedMetadataEnumerable.cs | 2 +- sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs index 9ef6e56d..08723c20 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs @@ -8,7 +8,7 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMBasicBlockInstructionsEnumerable(LLVMBasicBlockRef BasicBlock) : IEnumerable { - public Enumerator GetEnumerator() => new(BasicBlock); + public Enumerator GetEnumerator() => new Enumerator(BasicBlock); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs index 2ceacc47..36cbe554 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs @@ -8,7 +8,7 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleFunctionsEnumerable(LLVMModuleRef Module) : IEnumerable { - public Enumerator GetEnumerator() => new(Module); + public Enumerator GetEnumerator() => new Enumerator(Module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs index 27daf2d9..b73b3ad0 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs @@ -8,7 +8,7 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleGlobalAliasesEnumerable(LLVMModuleRef Module) : IEnumerable { - public Enumerator GetEnumerator() => new(Module); + public Enumerator GetEnumerator() => new Enumerator(Module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs index b48f1c2d..b0394a34 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs @@ -8,7 +8,7 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleGlobalIFuncsEnumerable(LLVMModuleRef Module) : IEnumerable { - public Enumerator GetEnumerator() => new(Module); + public Enumerator GetEnumerator() => new Enumerator(Module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs index 98bd6a16..8c1c8dbf 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs @@ -8,7 +8,7 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleGlobalsEnumerable(LLVMModuleRef Module) : IEnumerable { - public Enumerator GetEnumerator() => new(Module); + public Enumerator GetEnumerator() => new Enumerator(Module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs index 18b9ecb9..a1175307 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs @@ -8,7 +8,7 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleNamedMetadataEnumerable(LLVMModuleRef Module) : IEnumerable { - public Enumerator GetEnumerator() => new(Module); + public Enumerator GetEnumerator() => new Enumerator(Module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs index 8529d3dd..2627300d 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs @@ -8,7 +8,7 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMValueUsesEnumerable(LLVMValueRef Module) : IEnumerable { - public Enumerator GetEnumerator() => new(Module); + public Enumerator GetEnumerator() => new Enumerator(Module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); From be0ab873370192ce575ba726146017b7e29969b9 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 7 Sep 2025 20:58:01 -0700 Subject: [PATCH 08/23] New lines --- .../Extensions/LLVMBasicBlockInstructionsEnumerable.cs | 10 +++++++++- .../Extensions/LLVMModuleFunctionsEnumerable.cs | 10 +++++++++- .../Extensions/LLVMModuleGlobalAliasesEnumerable.cs | 10 +++++++++- .../Extensions/LLVMModuleGlobalIFuncsEnumerable.cs | 10 +++++++++- .../Extensions/LLVMModuleGlobalsEnumerable.cs | 10 +++++++++- .../Extensions/LLVMModuleNamedMetadataEnumerable.cs | 10 +++++++++- .../Extensions/LLVMValueUsesEnumerable.cs | 10 +++++++++- 7 files changed, 63 insertions(+), 7 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs index 08723c20..2812365e 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs @@ -9,14 +9,21 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMBasicBlockInstructionsEnumerable(LLVMBasicBlockRef BasicBlock) : IEnumerable { public Enumerator GetEnumerator() => new Enumerator(BasicBlock); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public struct Enumerator(LLVMBasicBlockRef basicBlock) : IEnumerator { public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; - readonly void IDisposable.Dispose() { } + + readonly void IDisposable.Dispose() + { + } + public bool MoveNext() { if (Current.Handle == 0) @@ -29,6 +36,7 @@ public bool MoveNext() } return Current.Handle != 0; } + public void Reset() => Current = default; } } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs index 36cbe554..31c61445 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs @@ -9,14 +9,21 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleFunctionsEnumerable(LLVMModuleRef Module) : IEnumerable { public Enumerator GetEnumerator() => new Enumerator(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public struct Enumerator(LLVMModuleRef module) : IEnumerator { public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; - readonly void IDisposable.Dispose() { } + + readonly void IDisposable.Dispose() + { + } + public bool MoveNext() { if (Current.Handle == 0) @@ -29,6 +36,7 @@ public bool MoveNext() } return Current.Handle != 0; } + public void Reset() => Current = default; } } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs index b73b3ad0..83def6ae 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs @@ -9,14 +9,21 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleGlobalAliasesEnumerable(LLVMModuleRef Module) : IEnumerable { public Enumerator GetEnumerator() => new Enumerator(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public struct Enumerator(LLVMModuleRef module) : IEnumerator { public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; - readonly void IDisposable.Dispose() { } + + readonly void IDisposable.Dispose() + { + } + public bool MoveNext() { if (Current.Handle == 0) @@ -29,6 +36,7 @@ public bool MoveNext() } return Current.Handle != 0; } + public void Reset() => Current = default; } } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs index b0394a34..c65abdb3 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs @@ -9,14 +9,21 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleGlobalIFuncsEnumerable(LLVMModuleRef Module) : IEnumerable { public Enumerator GetEnumerator() => new Enumerator(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public struct Enumerator(LLVMModuleRef module) : IEnumerator { public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; - readonly void IDisposable.Dispose() { } + + readonly void IDisposable.Dispose() + { + } + public bool MoveNext() { if (Current.Handle == 0) @@ -29,6 +36,7 @@ public bool MoveNext() } return Current.Handle != 0; } + public void Reset() => Current = default; } } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs index 8c1c8dbf..112a807a 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs @@ -9,14 +9,21 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleGlobalsEnumerable(LLVMModuleRef Module) : IEnumerable { public Enumerator GetEnumerator() => new Enumerator(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public struct Enumerator(LLVMModuleRef module) : IEnumerator { public LLVMValueRef Current { get; private set; } + readonly object IEnumerator.Current => Current; - readonly void IDisposable.Dispose() { } + + readonly void IDisposable.Dispose() + { + } + public bool MoveNext() { if (Current.Handle == 0) @@ -29,6 +36,7 @@ public bool MoveNext() } return Current.Handle != 0; } + public void Reset() => Current = default; } } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs index a1175307..4dbf0081 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs @@ -9,14 +9,21 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMModuleNamedMetadataEnumerable(LLVMModuleRef Module) : IEnumerable { public Enumerator GetEnumerator() => new Enumerator(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public struct Enumerator(LLVMModuleRef module) : IEnumerator { public LLVMNamedMDNodeRef Current { get; private set; } + readonly object IEnumerator.Current => Current; - readonly void IDisposable.Dispose() { } + + readonly void IDisposable.Dispose() + { + } + public bool MoveNext() { if (Current.Handle == 0) @@ -29,6 +36,7 @@ public bool MoveNext() } return Current.Handle != 0; } + public void Reset() => Current = default; } } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs index 2627300d..fa3b1b6f 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs @@ -9,14 +9,21 @@ namespace LLVMSharp.Interop; public readonly record struct LLVMValueUsesEnumerable(LLVMValueRef Module) : IEnumerable { public Enumerator GetEnumerator() => new Enumerator(Module); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public struct Enumerator(LLVMValueRef module) : IEnumerator { public LLVMUseRef Current { get; private set; } + readonly object IEnumerator.Current => Current; - readonly void IDisposable.Dispose() { } + + readonly void IDisposable.Dispose() + { + } + public bool MoveNext() { if (Current.Handle == 0) @@ -29,6 +36,7 @@ public bool MoveNext() } return Current.Handle != 0; } + public void Reset() => Current = default; } } From 659edb9f291295e86ffca63767c7a59222b13511 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 7 Sep 2025 21:00:34 -0700 Subject: [PATCH 09/23] No records --- .../Extensions/LLVMBasicBlockInstructionsEnumerable.cs | 4 ++-- .../Extensions/LLVMModuleFunctionsEnumerable.cs | 4 ++-- .../Extensions/LLVMModuleGlobalAliasesEnumerable.cs | 4 ++-- .../Extensions/LLVMModuleGlobalIFuncsEnumerable.cs | 4 ++-- .../Extensions/LLVMModuleGlobalsEnumerable.cs | 4 ++-- .../Extensions/LLVMModuleNamedMetadataEnumerable.cs | 4 ++-- .../LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs index 2812365e..eb908c3c 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockInstructionsEnumerable.cs @@ -6,9 +6,9 @@ namespace LLVMSharp.Interop; -public readonly record struct LLVMBasicBlockInstructionsEnumerable(LLVMBasicBlockRef BasicBlock) : IEnumerable +public readonly struct LLVMBasicBlockInstructionsEnumerable(LLVMBasicBlockRef basicBlock) : IEnumerable { - public Enumerator GetEnumerator() => new Enumerator(BasicBlock); + public Enumerator GetEnumerator() => new Enumerator(basicBlock); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs index 31c61445..954c303d 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFunctionsEnumerable.cs @@ -6,9 +6,9 @@ namespace LLVMSharp.Interop; -public readonly record struct LLVMModuleFunctionsEnumerable(LLVMModuleRef Module) : IEnumerable +public readonly struct LLVMModuleFunctionsEnumerable(LLVMModuleRef module) : IEnumerable { - public Enumerator GetEnumerator() => new Enumerator(Module); + public Enumerator GetEnumerator() => new Enumerator(module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs index 83def6ae..a741b8fa 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalAliasesEnumerable.cs @@ -6,9 +6,9 @@ namespace LLVMSharp.Interop; -public readonly record struct LLVMModuleGlobalAliasesEnumerable(LLVMModuleRef Module) : IEnumerable +public readonly struct LLVMModuleGlobalAliasesEnumerable(LLVMModuleRef module) : IEnumerable { - public Enumerator GetEnumerator() => new Enumerator(Module); + public Enumerator GetEnumerator() => new Enumerator(module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs index c65abdb3..d2ea05a8 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalIFuncsEnumerable.cs @@ -6,9 +6,9 @@ namespace LLVMSharp.Interop; -public readonly record struct LLVMModuleGlobalIFuncsEnumerable(LLVMModuleRef Module) : IEnumerable +public readonly struct LLVMModuleGlobalIFuncsEnumerable(LLVMModuleRef module) : IEnumerable { - public Enumerator GetEnumerator() => new Enumerator(Module); + public Enumerator GetEnumerator() => new Enumerator(module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs index 112a807a..f47772c9 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleGlobalsEnumerable.cs @@ -6,9 +6,9 @@ namespace LLVMSharp.Interop; -public readonly record struct LLVMModuleGlobalsEnumerable(LLVMModuleRef Module) : IEnumerable +public readonly struct LLVMModuleGlobalsEnumerable(LLVMModuleRef module) : IEnumerable { - public Enumerator GetEnumerator() => new Enumerator(Module); + public Enumerator GetEnumerator() => new Enumerator(module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs index 4dbf0081..dda91a80 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleNamedMetadataEnumerable.cs @@ -6,9 +6,9 @@ namespace LLVMSharp.Interop; -public readonly record struct LLVMModuleNamedMetadataEnumerable(LLVMModuleRef Module) : IEnumerable +public readonly struct LLVMModuleNamedMetadataEnumerable(LLVMModuleRef module) : IEnumerable { - public Enumerator GetEnumerator() => new Enumerator(Module); + public Enumerator GetEnumerator() => new Enumerator(module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs index fa3b1b6f..540223bb 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueUsesEnumerable.cs @@ -6,9 +6,9 @@ namespace LLVMSharp.Interop; -public readonly record struct LLVMValueUsesEnumerable(LLVMValueRef Module) : IEnumerable +public readonly struct LLVMValueUsesEnumerable(LLVMValueRef module) : IEnumerable { - public Enumerator GetEnumerator() => new Enumerator(Module); + public Enumerator GetEnumerator() => new Enumerator(module); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); From f712d72d540a9c2f0890a01c84eb795d62cfa3dd Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 7 Sep 2025 21:07:05 -0700 Subject: [PATCH 10/23] More new() --- sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs | 10 +++++----- sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs index 61044437..bcc24212 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs @@ -48,13 +48,13 @@ public readonly string DataLayout public readonly LLVMNamedMDNodeRef FirstNamedMetadata => (Handle != IntPtr.Zero) ? LLVM.GetFirstNamedMetadata(this) : default; - public readonly LLVMModuleFunctionsEnumerable Functions => new(this); + public readonly LLVMModuleFunctionsEnumerable Functions => new LLVMModuleFunctionsEnumerable(this); - public readonly LLVMModuleGlobalsEnumerable Globals => new(this); + public readonly LLVMModuleGlobalsEnumerable Globals => new LLVMModuleGlobalsEnumerable(this); - public readonly LLVMModuleGlobalAliasesEnumerable GlobalAliases => new(this); + public readonly LLVMModuleGlobalAliasesEnumerable GlobalAliases => new LLVMModuleGlobalAliasesEnumerable(this); - public readonly LLVMModuleGlobalIFuncsEnumerable GlobalIFuncs => new(this); + public readonly LLVMModuleGlobalIFuncsEnumerable GlobalIFuncs => new LLVMModuleGlobalIFuncsEnumerable(this); public readonly LLVMValueRef LastFunction => (Handle != IntPtr.Zero) ? LLVM.GetLastFunction(this) : default; @@ -66,7 +66,7 @@ public readonly string DataLayout public readonly LLVMNamedMDNodeRef LastNamedMetadata => (Handle != IntPtr.Zero) ? LLVM.GetLastNamedMetadata(this) : default; - public readonly LLVMModuleNamedMetadataEnumerable NamedMetadata => new(this); + public readonly LLVMModuleNamedMetadataEnumerable NamedMetadata => new LLVMModuleNamedMetadataEnumerable(this); public readonly string Target { diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index b5a8dd9c..82791afb 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -619,7 +619,7 @@ public readonly LLVMThreadLocalMode ThreadLocalMode public readonly LLVMTypeRef TypeOf => (Handle != IntPtr.Zero) ? LLVM.TypeOf(this) : default; - public readonly LLVMValueUsesEnumerable Uses => new(this); + public readonly LLVMValueUsesEnumerable Uses => new LLVMValueUsesEnumerable(this); public readonly LLVMVisibility Visibility { From 7d0f8dacec39eb5b09f349e8107b9fc7731f2743 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 7 Sep 2025 21:07:57 -0700 Subject: [PATCH 11/23] Handle != IntPtr.Zero --- sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs | 6 +++--- sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs | 4 ++-- sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs index e61620e8..37424e07 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs @@ -16,11 +16,11 @@ public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable /// This returns true for enum attributes and int attributes. /// - public readonly bool IsEnumAttribute => Handle != IntPtr.Zero && LLVM.IsEnumAttribute(this) != 0; + public readonly bool IsEnumAttribute => (Handle != IntPtr.Zero) && LLVM.IsEnumAttribute(this) != 0; - public readonly bool IsStringAttribute => Handle != IntPtr.Zero && LLVM.IsStringAttribute(this) != 0; + public readonly bool IsStringAttribute => (Handle != IntPtr.Zero) && LLVM.IsStringAttribute(this) != 0; - public readonly bool IsTypeAttribute => Handle != IntPtr.Zero && LLVM.IsTypeAttribute(this) != 0; + public readonly bool IsTypeAttribute => (Handle != IntPtr.Zero) && LLVM.IsTypeAttribute(this) != 0; public readonly uint KindAsEnum => HasKindAsEnum ? LLVM.GetEnumAttributeKind(this) : default; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs index 1359ecd3..031fbb60 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs @@ -28,9 +28,9 @@ public readonly string Name } } - public readonly LLVMNamedMDNodeRef NextNamedMetadata => Handle != IntPtr.Zero ? LLVM.GetNextNamedMetadata(this) : default; + public readonly LLVMNamedMDNodeRef NextNamedMetadata => (Handle != IntPtr.Zero) ? LLVM.GetNextNamedMetadata(this) : default; - public readonly LLVMNamedMDNodeRef PreviousNamedMetadata => Handle != IntPtr.Zero ? LLVM.GetPreviousNamedMetadata(this) : default; + public readonly LLVMNamedMDNodeRef PreviousNamedMetadata => (Handle != IntPtr.Zero) ? LLVM.GetPreviousNamedMetadata(this) : default; public static implicit operator LLVMNamedMDNodeRef(LLVMOpaqueNamedMDNode* value) => new LLVMNamedMDNodeRef((IntPtr)value); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs index 51319e6d..17168c83 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs @@ -8,9 +8,9 @@ public unsafe partial struct LLVMUseRef(IntPtr handle) : IEquatable { public IntPtr Handle = handle; - public readonly LLVMUseRef NextUse => Handle != IntPtr.Zero ? LLVM.GetNextUse(this) : default; + public readonly LLVMUseRef NextUse => (Handle != IntPtr.Zero) ? LLVM.GetNextUse(this) : default; - public readonly LLVMValueRef User => Handle != IntPtr.Zero ? LLVM.GetUser(this) : default; + public readonly LLVMValueRef User => (Handle != IntPtr.Zero) ? LLVM.GetUser(this) : default; public static implicit operator LLVMUseRef(LLVMOpaqueUse* Use) => new LLVMUseRef((IntPtr)Use); From 638b03069d92989784b64d49c640930905e95aed Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 7 Sep 2025 21:10:34 -0700 Subject: [PATCH 12/23] GetInstructions --- .../Extensions/LLVMValueRef.cs | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index 82791afb..a7ce1cfa 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -177,29 +177,6 @@ public readonly uint InstructionCallConv public readonly LLVMBasicBlockRef InstructionParent => (IsAInstruction != null) ? LLVM.GetInstructionParent(this) : default; - public readonly IEnumerable Instructions - { - get - { - if (IsAFunction != default) - { - return GetBasicBlocks().SelectMany(b => b.Instructions); - } - else if (IsABasicBlock != default) - { - return AsBasicBlock().Instructions; - } - else if (IsAInstruction != default) - { - return [this]; - } - else - { - return []; - } - } - } - public readonly uint IntrinsicID => (Handle != IntPtr.Zero) ? LLVM.GetIntrinsicID(this) : default; public readonly LLVMValueRef IsAAddrSpaceCastInst => LLVM.IsAAddrSpaceCastInst(this); @@ -934,6 +911,26 @@ public readonly void GetBasicBlocks(Span destination) } } + public readonly IEnumerable GetInstructions() + { + if (IsAFunction != default) + { + return GetBasicBlocks().SelectMany(b => b.Instructions); + } + else if (IsABasicBlock != default) + { + return AsBasicBlock().Instructions; + } + else if (IsAInstruction != default) + { + return [this]; + } + else + { + return []; + } + } + public readonly LLVMValueRef[] GetMDNodeOperands() { if (Kind != LLVMValueKind.LLVMMetadataAsValueValueKind) From a847464f66c257fd55af91ab26fb4591edf714be Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Thu, 11 Sep 2025 11:05:39 -0700 Subject: [PATCH 13/23] IsTemplateParameter property --- sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs index dc50f747..8a0466c5 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs @@ -36,13 +36,18 @@ public unsafe partial struct LLVMMetadataRef(IntPtr handle) : IEquatable Kind is >= LLVMMetadataKind.LLVMDILocationMetadataKind and <= LLVMMetadataKind.LLVMDIAssignIDMetadataKind; + public readonly bool IsTemplateParameter => Kind switch { + LLVMMetadataKind.LLVMDITemplateTypeParameterMetadataKind => true, + LLVMMetadataKind.LLVMDITemplateValueParameterMetadataKind => true, + _ => false, + }; + public readonly bool IsType => Kind switch { LLVMMetadataKind.LLVMDICompositeTypeMetadataKind => true, LLVMMetadataKind.LLVMDIDerivedTypeMetadataKind => true, LLVMMetadataKind.LLVMDIStringTypeMetadataKind => true, LLVMMetadataKind.LLVMDIBasicTypeMetadataKind => true, LLVMMetadataKind.LLVMDISubroutineTypeMetadataKind => true, - LLVMMetadataKind.LLVMDITemplateTypeParameterMetadataKind => true, _ => false, }; From c14cf1673dc8815f6016685663a53588ef4a7ff2 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 19:29:04 -0700 Subject: [PATCH 14/23] LLVMModuleRef::IsNewDbgInfoFormat --- .../LLVMSharp.Interop/Extensions/LLVMModuleRef.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs index bcc24212..804c0d42 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs @@ -56,6 +56,19 @@ public readonly string DataLayout public readonly LLVMModuleGlobalIFuncsEnumerable GlobalIFuncs => new LLVMModuleGlobalIFuncsEnumerable(this); + public readonly int IsNewDbgInfoFormat + { + get + { + return (Handle != IntPtr.Zero) ? LLVM.IsNewDbgInfoFormat(this) : 0; + } + + set + { + LLVM.SetIsNewDbgInfoFormat(this, value); + } + } + public readonly LLVMValueRef LastFunction => (Handle != IntPtr.Zero) ? LLVM.GetLastFunction(this) : default; public readonly LLVMValueRef LastGlobal => (Handle != IntPtr.Zero) ? LLVM.GetLastGlobal(this) : default; From f777907d063645f030d38102084b256e1eec1ecb Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 19:45:19 -0700 Subject: [PATCH 15/23] LLVMValueRef::GetAllMetadataOtherThanDebugLoc --- .../Extensions/LLVMValueRef.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index a7ce1cfa..3270c7fb 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -985,6 +985,24 @@ public readonly void GetParams(Span destination) } } + public readonly LLVMMetadataRef[] GetAllMetadataOtherThanDebugLoc() + { + if (IsAInstruction == null) + { + return []; + } + + nuint metadataCount = 0; + var metadataEntries = LLVM.InstructionGetAllMetadataOtherThanDebugLoc(this, &metadataCount); + var metadataArray = new LLVMMetadataRef[metadataCount]; + for (uint i = 0; i < metadataCount; i++) + { + metadataArray[i] = LLVM.ValueMetadataEntriesGetMetadata(metadataEntries, i); + } + LLVM.DisposeValueMetadataEntries(metadataEntries); + return metadataArray; + } + public readonly void AddAttributeAtIndex(LLVMAttributeIndex Idx, LLVMAttributeRef A) { LLVM.AddAttributeAtIndex(this, Idx, A); From 1d1c9355d7f04cdd00528a8d9e1bbe1e1acaff82 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 19:46:19 -0700 Subject: [PATCH 16/23] Move it to be more alphabetical --- .../Extensions/LLVMValueRef.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index 3270c7fb..fe6caa65 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -868,6 +868,24 @@ public readonly LLVMBasicBlockRef AppendBasicBlock(ReadOnlySpan Name) public readonly bool Equals(LLVMValueRef other) => this == other; + public readonly LLVMMetadataRef[] GetAllMetadataOtherThanDebugLoc() + { + if (IsAInstruction == null) + { + return []; + } + + nuint metadataCount = 0; + var metadataEntries = LLVM.InstructionGetAllMetadataOtherThanDebugLoc(this, &metadataCount); + var metadataArray = new LLVMMetadataRef[metadataCount]; + for (uint i = 0; i < metadataCount; i++) + { + metadataArray[i] = LLVM.ValueMetadataEntriesGetMetadata(metadataEntries, i); + } + LLVM.DisposeValueMetadataEntries(metadataEntries); + return metadataArray; + } + public readonly string GetAsString(out UIntPtr Length) { fixed (UIntPtr* pLength = &Length) @@ -985,24 +1003,6 @@ public readonly void GetParams(Span destination) } } - public readonly LLVMMetadataRef[] GetAllMetadataOtherThanDebugLoc() - { - if (IsAInstruction == null) - { - return []; - } - - nuint metadataCount = 0; - var metadataEntries = LLVM.InstructionGetAllMetadataOtherThanDebugLoc(this, &metadataCount); - var metadataArray = new LLVMMetadataRef[metadataCount]; - for (uint i = 0; i < metadataCount; i++) - { - metadataArray[i] = LLVM.ValueMetadataEntriesGetMetadata(metadataEntries, i); - } - LLVM.DisposeValueMetadataEntries(metadataEntries); - return metadataArray; - } - public readonly void AddAttributeAtIndex(LLVMAttributeIndex Idx, LLVMAttributeRef A) { LLVM.AddAttributeAtIndex(this, Idx, A); From 71ecbcc0ea8e8b459d4172ab9e9ffc49c4d74428 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 20:02:40 -0700 Subject: [PATCH 17/23] Eliminate allocations of zero-length arrays --- .../Extensions/LLVMValueRef.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index fe6caa65..fbfbd1b9 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -876,13 +876,24 @@ public readonly LLVMMetadataRef[] GetAllMetadataOtherThanDebugLoc() } nuint metadataCount = 0; - var metadataEntries = LLVM.InstructionGetAllMetadataOtherThanDebugLoc(this, &metadataCount); - var metadataArray = new LLVMMetadataRef[metadataCount]; - for (uint i = 0; i < metadataCount; i++) + var ptr = LLVM.InstructionGetAllMetadataOtherThanDebugLoc(this, &metadataCount); + + LLVMMetadataRef[] metadataArray; + if (metadataCount == 0) { - metadataArray[i] = LLVM.ValueMetadataEntriesGetMetadata(metadataEntries, i); + metadataArray = []; } - LLVM.DisposeValueMetadataEntries(metadataEntries); + else + { + metadataArray = new LLVMMetadataRef[metadataCount]; + for (uint i = 0; i < metadataCount; i++) + { + metadataArray[i] = LLVM.ValueMetadataEntriesGetMetadata(ptr, i); + } + LLVM.DisposeValueMetadataEntries(ptr); + } + + LLVM.DisposeValueMetadataEntries(ptr); return metadataArray; } From c35e0b4c4ac521309d8e4c6acabd9573f153fe6a Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 20:17:07 -0700 Subject: [PATCH 18/23] LLVMModuleRef::DebugMetadataVersion and LLVMValueRef::AsMetadata() --- sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs | 2 ++ sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs index 804c0d42..200873de 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs @@ -38,6 +38,8 @@ public readonly string DataLayout } } + public readonly uint DebugMetadataVersion => (Handle != IntPtr.Zero) ? LLVM.GetModuleDebugMetadataVersion(this) : default; + public readonly LLVMValueRef FirstFunction => (Handle != IntPtr.Zero) ? LLVM.GetFirstFunction(this) : default; public readonly LLVMValueRef FirstGlobal => (Handle != IntPtr.Zero) ? LLVM.GetFirstGlobal(this) : default; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index fbfbd1b9..a8d6df4a 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -858,6 +858,8 @@ public readonly LLVMBasicBlockRef AppendBasicBlock(ReadOnlySpan Name) public readonly LLVMBasicBlockRef AsBasicBlock() => LLVM.ValueAsBasicBlock(this); + public readonly LLVMMetadataRef AsMetadata() => LLVM.ValueAsMetadata(this); + public readonly void DeleteFunction() => LLVM.DeleteFunction(this); public readonly void DeleteGlobal() => LLVM.DeleteGlobal(this); From e6a643f84749c0c6dda86080341510bddad3a23a Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 20:35:42 -0700 Subject: [PATCH 19/23] LLVMValueRef::Context --- sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index a8d6df4a..c7ace722 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -60,6 +60,8 @@ public readonly LLVMValueRef Condition public readonly double ConstRealDouble => (IsAConstantFP != null) ? GetConstRealDouble(out _) : default; + public readonly LLVMContextRef Context => (Handle != IntPtr.Zero) ? LLVM.GetValueContext(this) : default; + public readonly LLVMDLLStorageClass DLLStorageClass { get From 1a05529aee03970bb240a28cb705de62c87f7683 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 20:48:25 -0700 Subject: [PATCH 20/23] LLVMMetadataRef::GetMDString --- sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs index 8a0466c5..c6d90710 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs @@ -120,5 +120,11 @@ public readonly string Name public override readonly int GetHashCode() => Handle.GetHashCode(); + public readonly string GetMDString(LLVMContextRef context, out uint length) + { + var value = context.MetadataAsValue(this); + return value.GetMDString(out length); + } + public override readonly string ToString() => $"{nameof(LLVMMetadataRef)}: {Handle:X}"; } From 940c3b48cb91a2263b469197f0a9ea351d8f16c2 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 20:50:42 -0700 Subject: [PATCH 21/23] LLVMMetadataRef::AsValue --- sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs index c6d90710..09c5f9ea 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs @@ -114,6 +114,8 @@ public readonly string Name public static bool operator !=(LLVMMetadataRef left, LLVMMetadataRef right) => !(left == right); + public readonly LLVMValueRef AsValue(LLVMContextRef context) => context.MetadataAsValue(this); + public override readonly bool Equals(object? obj) => (obj is LLVMMetadataRef other) && Equals(other); public readonly bool Equals(LLVMMetadataRef other) => this == other; From 992d562a5668df91aaceb3cf4847e9a1d62231a7 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 21:50:41 -0700 Subject: [PATCH 22/23] LLVMValueRef::HasMetadata for functions and global variables --- sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index c7ace722..d5ca4f96 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -126,7 +126,7 @@ public readonly string GC public readonly LLVMModuleRef GlobalParent => (IsAGlobalValue != null) ? LLVM.GetGlobalParent(this) : default; - public readonly bool HasMetadata => (IsAInstruction != null) && LLVM.HasMetadata(this) != 0; + public readonly bool HasMetadata => ((IsAInstruction != null) || (IsAFunction != null) || (IsAGlobalVariable != null)) && LLVM.HasMetadata(this) != 0; public readonly bool HasPersonalityFn => (IsAFunction != null) && LLVM.HasPersonalityFn(this) != 0; From 18fa00c30b33efb9ebf93aaf5cd5f2bf012adca0 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Fri, 19 Sep 2025 22:12:39 -0700 Subject: [PATCH 23/23] Undo previous commit --- sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index d5ca4f96..c7ace722 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -126,7 +126,7 @@ public readonly string GC public readonly LLVMModuleRef GlobalParent => (IsAGlobalValue != null) ? LLVM.GetGlobalParent(this) : default; - public readonly bool HasMetadata => ((IsAInstruction != null) || (IsAFunction != null) || (IsAGlobalVariable != null)) && LLVM.HasMetadata(this) != 0; + public readonly bool HasMetadata => (IsAInstruction != null) && LLVM.HasMetadata(this) != 0; public readonly bool HasPersonalityFn => (IsAFunction != null) && LLVM.HasPersonalityFn(this) != 0;