Skip to content

Commit 62a15db

Browse files
committed
Address review comments about attributes
1 parent 8760482 commit 62a15db

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable<LLVMAt
88
{
99
public IntPtr Handle = handle;
1010

11-
public readonly uint EnumKind => IsEnumAttribute ? LLVM.GetEnumAttributeKind(this) : default;
12-
13-
public readonly ulong EnumValue => IsEnumAttribute ? LLVM.GetEnumAttributeValue(this) : default;
14-
11+
/// <summary>
12+
/// <see href="https://github.com/llvm/llvm-project/blob/a64e6f49284a7ffd5401183d0e94a94a7de39cfb/llvm/include/llvm/IR/Attributes.h#L233"/>
13+
/// </summary>
14+
public readonly bool HasKindAsEnum => Handle != IntPtr.Zero && LLVM.IsStringAttribute(this) == 0;
15+
16+
/// <summary>
17+
/// <see href="https://github.com/llvm/llvm-project/blob/de7bac6426e7f544189dfba7ae658dcf3d7be5f6/llvm/lib/IR/Core.cpp#L231">This returns true for enum attributes and int attributes.</see>
18+
/// </summary>
1519
public readonly bool IsEnumAttribute => Handle != IntPtr.Zero && LLVM.IsEnumAttribute(this) != 0;
1620

1721
public readonly bool IsStringAttribute => Handle != IntPtr.Zero && LLVM.IsStringAttribute(this) != 0;
1822

1923
public readonly bool IsTypeAttribute => Handle != IntPtr.Zero && LLVM.IsTypeAttribute(this) != 0;
2024

21-
public readonly string StringKind
25+
public readonly uint KindAsEnum => HasKindAsEnum ? LLVM.GetEnumAttributeKind(this) : default;
26+
27+
public readonly string KindAsString
2228
{
2329
get
2430
{
@@ -38,7 +44,12 @@ public readonly string StringKind
3844
}
3945
}
4046

41-
public readonly string StringValue
47+
/// <summary>
48+
/// <see href="https://github.com/llvm/llvm-project/blob/a64e6f49284a7ffd5401183d0e94a94a7de39cfb/llvm/lib/IR/Core.cpp#L175"/>
49+
/// </summary>
50+
public readonly ulong ValueAsInt => IsEnumAttribute ? LLVM.GetEnumAttributeValue(this) : default;
51+
52+
public readonly string ValueAsString
4253
{
4354
get
4455
{
@@ -58,7 +69,7 @@ public readonly string StringValue
5869
}
5970
}
6071

61-
public readonly LLVMTypeRef TypeValue => IsTypeAttribute ? LLVM.GetTypeAttributeValue(this) : default;
72+
public readonly LLVMTypeRef ValueAsType => IsTypeAttribute ? LLVM.GetTypeAttributeValue(this) : default;
6273

6374
public static implicit operator LLVMAttributeRef(LLVMOpaqueAttributeRef* value) => new LLVMAttributeRef((IntPtr)value);
6475

tests/LLVMSharp.UnitTests/Functions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public void AddsAttributeAtIndex()
2626
functionValue.AddAttributeAtIndex((LLVMAttributeIndex)1, attr);
2727

2828
var attrs = functionValue.GetAttributesAtIndex((LLVMAttributeIndex)1);
29-
Assert.That((AttributeKind)attrs[0].EnumKind, Is.EqualTo(AttributeKind.ByVal));
29+
Assert.That((AttributeKind)attrs[0].KindAsEnum, Is.EqualTo(AttributeKind.ByVal));
3030
}
3131
}

0 commit comments

Comments
 (0)