@@ -4,7 +4,7 @@ use llvm_sys::core::{LLVMIsTailCall, LLVMSetTailCall, LLVMGetTypeKind, LLVMTypeO
4
4
use llvm_sys:: prelude:: LLVMValueRef ;
5
5
6
6
#[ llvm_versions( 3.9 ..=latest) ]
7
- use crate :: attributes:: Attribute ;
7
+ use crate :: attributes:: { Attribute , AttributeLoc } ;
8
8
use crate :: support:: LLVMString ;
9
9
use crate :: values:: { AsValueRef , BasicValueEnum , InstructionValue , Value } ;
10
10
#[ llvm_versions( 3.9 ..=latest) ]
@@ -112,6 +112,7 @@ impl CallSiteValue {
112
112
/// # Example
113
113
///
114
114
/// ```no_run
115
+ /// use inkwell::attributes::AttributeLoc;
115
116
/// use inkwell::context::Context;
116
117
///
117
118
/// let context = Context::create();
@@ -128,15 +129,15 @@ impl CallSiteValue {
128
129
///
129
130
/// let call_site_value = builder.build_call(fn_value, &[], "my_fn");
130
131
///
131
- /// call_site_value.add_attribute(0 , string_attribute);
132
- /// call_site_value.add_attribute(0 , enum_attribute);
132
+ /// call_site_value.add_attribute(AttributeLoc::Return , string_attribute);
133
+ /// call_site_value.add_attribute(AttributeLoc::Return , enum_attribute);
133
134
/// ```
134
135
#[ llvm_versions( 3.9 ..=latest) ]
135
- pub fn add_attribute ( & self , index : u32 , attribute : Attribute ) {
136
+ pub fn add_attribute ( & self , loc : AttributeLoc , attribute : Attribute ) {
136
137
use llvm_sys:: core:: LLVMAddCallSiteAttribute ;
137
138
138
139
unsafe {
139
- LLVMAddCallSiteAttribute ( self . as_value_ref ( ) , index , attribute. attribute )
140
+ LLVMAddCallSiteAttribute ( self . as_value_ref ( ) , loc . get_index ( ) , attribute. attribute )
140
141
}
141
142
}
142
143
@@ -179,6 +180,7 @@ impl CallSiteValue {
179
180
/// # Example
180
181
///
181
182
/// ```no_run
183
+ /// use inkwell::attributes::AttributeLoc;
182
184
/// use inkwell::context::Context;
183
185
///
184
186
/// let context = Context::create();
@@ -195,17 +197,17 @@ impl CallSiteValue {
195
197
///
196
198
/// let call_site_value = builder.build_call(fn_value, &[], "my_fn");
197
199
///
198
- /// call_site_value.add_attribute(0 , string_attribute);
199
- /// call_site_value.add_attribute(0 , enum_attribute);
200
+ /// call_site_value.add_attribute(AttributeLoc::Return , string_attribute);
201
+ /// call_site_value.add_attribute(AttributeLoc::Return , enum_attribute);
200
202
///
201
- /// assert_eq!(call_site_value.count_attributes(0 ), 2);
203
+ /// assert_eq!(call_site_value.count_attributes(AttributeLoc::Return ), 2);
202
204
/// ```
203
205
#[ llvm_versions( 3.9 ..=latest) ]
204
- pub fn count_attributes ( & self , index : u32 ) -> u32 {
206
+ pub fn count_attributes ( & self , loc : AttributeLoc ) -> u32 {
205
207
use llvm_sys:: core:: LLVMGetCallSiteAttributeCount ;
206
208
207
209
unsafe {
208
- LLVMGetCallSiteAttributeCount ( self . as_value_ref ( ) , index )
210
+ LLVMGetCallSiteAttributeCount ( self . as_value_ref ( ) , loc . get_index ( ) )
209
211
}
210
212
}
211
213
@@ -214,6 +216,7 @@ impl CallSiteValue {
214
216
/// # Example
215
217
///
216
218
/// ```no_run
219
+ /// use inkwell::attributes::AttributeLoc;
217
220
/// use inkwell::context::Context;
218
221
///
219
222
/// let context = Context::create();
@@ -230,18 +233,18 @@ impl CallSiteValue {
230
233
///
231
234
/// let call_site_value = builder.build_call(fn_value, &[], "my_fn");
232
235
///
233
- /// call_site_value.add_attribute(0 , string_attribute);
234
- /// call_site_value.add_attribute(0 , enum_attribute);
236
+ /// call_site_value.add_attribute(AttributeLoc::Return , string_attribute);
237
+ /// call_site_value.add_attribute(AttributeLoc::Return , enum_attribute);
235
238
///
236
- /// assert_eq!(call_site_value.get_enum_attribute(0 , 1).unwrap(), enum_attribute);
239
+ /// assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return , 1).unwrap(), enum_attribute);
237
240
/// ```
238
241
// SubTypes: -> Attribute<Enum>
239
242
#[ llvm_versions( 3.9 ..=latest) ]
240
- pub fn get_enum_attribute ( & self , index : u32 , kind_id : u32 ) -> Option < Attribute > {
243
+ pub fn get_enum_attribute ( & self , loc : AttributeLoc , kind_id : u32 ) -> Option < Attribute > {
241
244
use llvm_sys:: core:: LLVMGetCallSiteEnumAttribute ;
242
245
243
246
let ptr = unsafe {
244
- LLVMGetCallSiteEnumAttribute ( self . as_value_ref ( ) , index , kind_id)
247
+ LLVMGetCallSiteEnumAttribute ( self . as_value_ref ( ) , loc . get_index ( ) , kind_id)
245
248
} ;
246
249
247
250
if ptr. is_null ( ) {
@@ -256,6 +259,7 @@ impl CallSiteValue {
256
259
/// # Example
257
260
///
258
261
/// ```no_run
262
+ /// use inkwell::attributes::AttributeLoc;
259
263
/// use inkwell::context::Context;
260
264
///
261
265
/// let context = Context::create();
@@ -272,18 +276,18 @@ impl CallSiteValue {
272
276
///
273
277
/// let call_site_value = builder.build_call(fn_value, &[], "my_fn");
274
278
///
275
- /// call_site_value.add_attribute(0 , string_attribute);
276
- /// call_site_value.add_attribute(0 , enum_attribute);
279
+ /// call_site_value.add_attribute(AttributeLoc::Return , string_attribute);
280
+ /// call_site_value.add_attribute(AttributeLoc::Return , enum_attribute);
277
281
///
278
- /// assert_eq!(call_site_value.get_string_attribute(0 , "my_key").unwrap(), string_attribute);
282
+ /// assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return , "my_key").unwrap(), string_attribute);
279
283
/// ```
280
284
// SubTypes: -> Attribute<String>
281
285
#[ llvm_versions( 3.9 ..=latest) ]
282
- pub fn get_string_attribute ( & self , index : u32 , key : & str ) -> Option < Attribute > {
286
+ pub fn get_string_attribute ( & self , loc : AttributeLoc , key : & str ) -> Option < Attribute > {
283
287
use llvm_sys:: core:: LLVMGetCallSiteStringAttribute ;
284
288
285
289
let ptr = unsafe {
286
- LLVMGetCallSiteStringAttribute ( self . as_value_ref ( ) , index , key. as_ptr ( ) as * const i8 , key. len ( ) as u32 )
290
+ LLVMGetCallSiteStringAttribute ( self . as_value_ref ( ) , loc . get_index ( ) , key. as_ptr ( ) as * const i8 , key. len ( ) as u32 )
287
291
} ;
288
292
289
293
if ptr. is_null ( ) {
@@ -298,6 +302,7 @@ impl CallSiteValue {
298
302
/// # Example
299
303
///
300
304
/// ```no_run
305
+ /// use inkwell::attributes::AttributeLoc;
301
306
/// use inkwell::context::Context;
302
307
///
303
308
/// let context = Context::create();
@@ -314,18 +319,18 @@ impl CallSiteValue {
314
319
///
315
320
/// let call_site_value = builder.build_call(fn_value, &[], "my_fn");
316
321
///
317
- /// call_site_value.add_attribute(0 , string_attribute);
318
- /// call_site_value.add_attribute(0 , enum_attribute);
319
- /// call_site_value.remove_enum_attribute(0 , 1);
322
+ /// call_site_value.add_attribute(AttributeLoc::Return , string_attribute);
323
+ /// call_site_value.add_attribute(AttributeLoc::Return , enum_attribute);
324
+ /// call_site_value.remove_enum_attribute(AttributeLoc::Return , 1);
320
325
///
321
- /// assert_eq!(call_site_value.get_enum_attribute(0 , 1), None);
326
+ /// assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return , 1), None);
322
327
/// ```
323
328
#[ llvm_versions( 3.9 ..=latest) ]
324
- pub fn remove_enum_attribute ( & self , index : u32 , kind_id : u32 ) {
329
+ pub fn remove_enum_attribute ( & self , loc : AttributeLoc , kind_id : u32 ) {
325
330
use llvm_sys:: core:: LLVMRemoveCallSiteEnumAttribute ;
326
331
327
332
unsafe {
328
- LLVMRemoveCallSiteEnumAttribute ( self . as_value_ref ( ) , index , kind_id)
333
+ LLVMRemoveCallSiteEnumAttribute ( self . as_value_ref ( ) , loc . get_index ( ) , kind_id)
329
334
}
330
335
}
331
336
@@ -334,6 +339,7 @@ impl CallSiteValue {
334
339
/// # Example
335
340
///
336
341
/// ```no_run
342
+ /// use inkwell::attributes::AttributeLoc;
337
343
/// use inkwell::context::Context;
338
344
///
339
345
/// let context = Context::create();
@@ -350,18 +356,18 @@ impl CallSiteValue {
350
356
///
351
357
/// let call_site_value = builder.build_call(fn_value, &[], "my_fn");
352
358
///
353
- /// call_site_value.add_attribute(0 , string_attribute);
354
- /// call_site_value.add_attribute(0 , enum_attribute);
355
- /// call_site_value.remove_string_attribute(0 , "my_key");
359
+ /// call_site_value.add_attribute(AttributeLoc::Return , string_attribute);
360
+ /// call_site_value.add_attribute(AttributeLoc::Return , enum_attribute);
361
+ /// call_site_value.remove_string_attribute(AttributeLoc::Return , "my_key");
356
362
///
357
- /// assert_eq!(call_site_value.get_string_attribute(0 , "my_key"), None);
363
+ /// assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return , "my_key"), None);
358
364
/// ```
359
365
#[ llvm_versions( 3.9 ..=latest) ]
360
- pub fn remove_string_attribute ( & self , index : u32 , key : & str ) {
366
+ pub fn remove_string_attribute ( & self , loc : AttributeLoc , key : & str ) {
361
367
use llvm_sys:: core:: LLVMRemoveCallSiteStringAttribute ;
362
368
363
369
unsafe {
364
- LLVMRemoveCallSiteStringAttribute ( self . as_value_ref ( ) , index , key. as_ptr ( ) as * const i8 , key. len ( ) as u32 )
370
+ LLVMRemoveCallSiteStringAttribute ( self . as_value_ref ( ) , loc . get_index ( ) , key. as_ptr ( ) as * const i8 , key. len ( ) as u32 )
365
371
}
366
372
}
367
373
@@ -370,6 +376,7 @@ impl CallSiteValue {
370
376
/// # Example
371
377
///
372
378
/// ```no_run
379
+ /// use inkwell::attributes::AttributeLoc;
373
380
/// use inkwell::context::Context;
374
381
///
375
382
/// let context = Context::create();
@@ -462,6 +469,7 @@ impl CallSiteValue {
462
469
/// # Example
463
470
///
464
471
/// ```no_run
472
+ /// use inkwell::attributes::AttributeLoc;
465
473
/// use inkwell::context::Context;
466
474
///
467
475
/// let context = Context::create();
@@ -476,13 +484,13 @@ impl CallSiteValue {
476
484
///
477
485
/// let call_site_value = builder.build_call(fn_value, &[], "my_fn");
478
486
///
479
- /// call_site_value.set_param_alignment_attribute(0 , 2);
487
+ /// call_site_value.set_alignment_attribute(AttributeLoc::Param(0) , 2);
480
488
/// ```
481
- pub fn set_param_alignment_attribute ( & self , index : u32 , alignment : u32 ) {
489
+ pub fn set_alignment_attribute ( & self , loc : AttributeLoc , alignment : u32 ) {
482
490
assert_eq ! ( alignment. count_ones( ) , 1 , "Alignment must be a power of two." ) ;
483
491
484
492
unsafe {
485
- LLVMSetInstrParamAlignment ( self . as_value_ref ( ) , index , alignment)
493
+ LLVMSetInstrParamAlignment ( self . as_value_ref ( ) , loc . get_index ( ) , alignment)
486
494
}
487
495
}
488
496
0 commit comments