diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs index 3596f64..07d167e 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs @@ -13,6 +13,10 @@ public LLVMAttributeRef(IntPtr handle) Handle = handle; } + public readonly uint Kind => LLVM.GetEnumAttributeKind(this); + + public readonly ulong Value => LLVM.GetEnumAttributeValue(this); + public static implicit operator LLVMAttributeRef(LLVMOpaqueAttributeRef* value) => new LLVMAttributeRef((IntPtr)value); public static implicit operator LLVMOpaqueAttributeRef*(LLVMAttributeRef value) => (LLVMOpaqueAttributeRef*)value.Handle; diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMContextRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMContextRef.cs index 0e8e149..a8904bb 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMContextRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMContextRef.cs @@ -86,6 +86,11 @@ public LLVMTypeRef CreateNamedStruct(ReadOnlySpan Name) return LLVM.StructCreateNamed(this, marshaledName); } + public LLVMAttributeRef CreateEnumAttribute(uint KindId, ulong Val) + { + return LLVM.CreateEnumAttribute(this, KindId, Val); + } + public void Dispose() { if (Handle != IntPtr.Zero) diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index 8565acd..1c8fbf1 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -953,6 +953,11 @@ public string GetAsString(out UIntPtr Length) } } + public void AddAttributeAtIndex(LLVMAttributeIndex Idx, LLVMAttributeRef A) + { + LLVM.AddAttributeAtIndex(this, Idx, A); + } + public LLVMAttributeRef[] GetAttributesAtIndex(LLVMAttributeIndex Idx) { var Attrs = new LLVMAttributeRef[GetAttributeCountAtIndex(Idx)]; diff --git a/tests/LLVMSharp.UnitTests/Functions.cs b/tests/LLVMSharp.UnitTests/Functions.cs index 0607ea9..7bea004 100644 --- a/tests/LLVMSharp.UnitTests/Functions.cs +++ b/tests/LLVMSharp.UnitTests/Functions.cs @@ -15,4 +15,17 @@ public void ParamTypesRoundtrip() var functionType = LLVMTypeRef.CreateFunction(returnType, parameterTypes); Assert.AreEqual(parameterTypes, functionType.ParamTypes); } + + [Test] + public void AddsAttributeAtIndex() + { + var module = LLVMModuleRef.CreateWithName("Test Module"); + var functionType = LLVMTypeRef.CreateFunction(LLVMTypeRef.Int8, new[] { LLVMTypeRef.Double }); + var functionValue = module.AddFunction("test", functionType); + var attr = module.Context.CreateEnumAttribute((uint)AttributeKind.ByVal, default); + functionValue.AddAttributeAtIndex((LLVMAttributeIndex)1, attr); + + var attrs = functionValue.GetAttributesAtIndex((LLVMAttributeIndex)1); + Assert.AreEqual(attrs[0].Kind, (uint)AttributeKind.ByVal); + } }