File tree 5 files changed +128
-0
lines changed
LLVMSharp.Interop/Extensions
tests/LLVMSharp.UnitTests
5 files changed +128
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ public LLVMAttributeRef(IntPtr handle)
13
13
Handle = handle ;
14
14
}
15
15
16
+ public readonly uint Kind => LLVM . GetEnumAttributeKind ( this ) ;
17
+
18
+ public readonly ulong Value => LLVM . GetEnumAttributeValue ( this ) ;
19
+
16
20
public static implicit operator LLVMAttributeRef ( LLVMOpaqueAttributeRef * value ) => new LLVMAttributeRef ( ( IntPtr ) value ) ;
17
21
18
22
public static implicit operator LLVMOpaqueAttributeRef * ( LLVMAttributeRef value ) => ( LLVMOpaqueAttributeRef * ) value . Handle ;
Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ public LLVMTypeRef CreateNamedStruct(ReadOnlySpan<char> Name)
86
86
return LLVM . StructCreateNamed ( this , marshaledName ) ;
87
87
}
88
88
89
+ public LLVMAttributeRef CreateEnumAttribute ( uint KindId , ulong Val )
90
+ {
91
+ return LLVM . CreateEnumAttribute ( this , KindId , Val ) ;
92
+ }
93
+
89
94
public void Dispose ( )
90
95
{
91
96
if ( Handle != IntPtr . Zero )
Original file line number Diff line number Diff line change @@ -953,6 +953,11 @@ public string GetAsString(out UIntPtr Length)
953
953
}
954
954
}
955
955
956
+ public void AddAttributeAtIndex ( LLVMAttributeIndex Idx , LLVMAttributeRef A )
957
+ {
958
+ LLVM . AddAttributeAtIndex ( this , Idx , A ) ;
959
+ }
960
+
956
961
public LLVMAttributeRef [ ] GetAttributesAtIndex ( LLVMAttributeIndex Idx )
957
962
{
958
963
var Attrs = new LLVMAttributeRef [ GetAttributeCountAtIndex ( Idx ) ] ;
Original file line number Diff line number Diff line change @@ -21,3 +21,104 @@ public sealed class Attribute : IEquatable<Attribute>
21
21
22
22
public override string ToString ( ) => Handle . ToString ( ) ;
23
23
}
24
+
25
+ public enum AttributeKind
26
+ {
27
+ #pragma warning disable CA1069 // Enums values should not be duplicated
28
+ None ,
29
+
30
+ FirstEnumAttr = 1 ,
31
+ AllocAlign = 1 ,
32
+ AllocatedPointer = 2 ,
33
+ AlwaysInline = 3 ,
34
+ Builtin = 4 ,
35
+ Cold = 5 ,
36
+ Convergent = 6 ,
37
+ DisableSanitizerInstrumentation = 7 ,
38
+ FnRetThunkExtern = 8 ,
39
+ Hot = 9 ,
40
+ ImmArg = 10 ,
41
+ InReg = 11 ,
42
+ InlineHint = 12 ,
43
+ JumpTable = 13 ,
44
+ MinSize = 14 ,
45
+ MustProgress = 15 ,
46
+ Naked = 16 ,
47
+ Nest = 17 ,
48
+ NoAlias = 18 ,
49
+ NoBuiltin = 19 ,
50
+ NoCallback = 20 ,
51
+ NoCapture = 21 ,
52
+ NoCfCheck = 22 ,
53
+ NoDuplicate = 23 ,
54
+ NoFree = 24 ,
55
+ NoImplicitFloat = 25 ,
56
+ NoInline = 26 ,
57
+ NoMerge = 27 ,
58
+ NoProfile = 28 ,
59
+ NoRecurse = 29 ,
60
+ NoRedZone = 30 ,
61
+ NoReturn = 31 ,
62
+ NoSanitizeBounds = 32 ,
63
+ NoSanitizeCoverage = 33 ,
64
+ NoSync = 34 ,
65
+ NoUndef = 35 ,
66
+ NoUnwind = 36 ,
67
+ NonLazyBind = 37 ,
68
+ NonNull = 38 ,
69
+ NullPointerIsValid = 39 ,
70
+ OptForFuzzing = 40 ,
71
+ OptimizeForSize = 41 ,
72
+ OptimizeNone = 42 ,
73
+ PresplitCoroutine = 43 ,
74
+ ReadNone = 44 ,
75
+ ReadOnly = 45 ,
76
+ Returned = 46 ,
77
+ ReturnsTwice = 47 ,
78
+ SExt = 48 ,
79
+ SafeStack = 49 ,
80
+ SanitizeAddress = 50 ,
81
+ SanitizeHWAddress = 51 ,
82
+ SanitizeMemTag = 52 ,
83
+ SanitizeMemory = 53 ,
84
+ SanitizeThread = 54 ,
85
+ ShadowCallStack = 55 ,
86
+ SkipProfile = 56 ,
87
+ Speculatable = 57 ,
88
+ SpeculativeLoadHardening = 58 ,
89
+ StackProtect = 59 ,
90
+ StackProtectReq = 60 ,
91
+ StackProtectStrong = 61 ,
92
+ StrictFP = 62 ,
93
+ SwiftAsync = 63 ,
94
+ SwiftError = 64 ,
95
+ SwiftSelf = 65 ,
96
+ WillReturn = 66 ,
97
+ WriteOnly = 67 ,
98
+ ZExt = 68 ,
99
+ LastEnumAttr = 68 ,
100
+ FirstTypeAttr = 69 ,
101
+ ByRef = 69 ,
102
+ ByVal = 70 ,
103
+ ElementType = 71 ,
104
+ InAlloca = 72 ,
105
+ Preallocated = 73 ,
106
+ StructRet = 74 ,
107
+ LastTypeAttr = 74 ,
108
+ FirstIntAttr = 75 ,
109
+ Alignment = 75 ,
110
+ AllocKind = 76 ,
111
+ AllocSize = 77 ,
112
+ Dereferenceable = 78 ,
113
+ DereferenceableOrNull = 79 ,
114
+ Memory = 80 ,
115
+ StackAlignment = 81 ,
116
+ UWTable = 82 ,
117
+ VScaleRange = 83 ,
118
+ LastIntAttr = 83 ,
119
+
120
+ EndAttrKinds ,
121
+ EmptyKey ,
122
+ TombstoneKey ,
123
+ #pragma warning restore CA1069 // Enums values should not be duplicated
124
+ }
Original file line number Diff line number Diff line change @@ -15,4 +15,17 @@ public void ParamTypesRoundtrip()
15
15
var functionType = LLVMTypeRef . CreateFunction ( returnType , parameterTypes ) ;
16
16
Assert . AreEqual ( parameterTypes , functionType . ParamTypes ) ;
17
17
}
18
+
19
+ [ Test ]
20
+ public void AddsAttributeAtIndex ( )
21
+ {
22
+ var module = LLVMModuleRef . CreateWithName ( "Test Module" ) ;
23
+ var functionType = LLVMTypeRef . CreateFunction ( LLVMTypeRef . Int8 , new [ ] { LLVMTypeRef . Double } ) ;
24
+ var functionValue = module . AddFunction ( "test" , functionType ) ;
25
+ var attr = module . Context . CreateEnumAttribute ( ( uint ) AttributeKind . ByVal , default ) ;
26
+ functionValue . AddAttributeAtIndex ( ( LLVMAttributeIndex ) 1 , attr ) ;
27
+
28
+ var attrs = functionValue . GetAttributesAtIndex ( ( LLVMAttributeIndex ) 1 ) ;
29
+ Assert . AreEqual ( attrs [ 0 ] . Kind , ( uint ) AttributeKind . ByVal ) ;
30
+ }
18
31
}
You can’t perform that action at this time.
0 commit comments