@@ -10,39 +10,39 @@ use libc::c_uint;
10
10
use rustc_abi:: { Align , Size , WrappingRange } ;
11
11
use rustc_llvm:: RustString ;
12
12
13
- pub use self :: AtomicRmwBinOp :: * ;
14
- pub use self :: CallConv :: * ;
15
- pub use self :: CodeGenOptSize :: * ;
16
- pub use self :: IntPredicate :: * ;
17
- pub use self :: Linkage :: * ;
18
- pub use self :: MetadataType :: * ;
19
- pub use self :: RealPredicate :: * ;
20
- pub use self :: ffi:: * ;
13
+ pub ( crate ) use self :: CallConv :: * ;
14
+ pub ( crate ) use self :: CodeGenOptSize :: * ;
15
+ pub ( crate ) use self :: MetadataType :: * ;
16
+ pub ( crate ) use self :: ffi:: * ;
21
17
use crate :: common:: AsCCharPtr ;
22
18
23
- pub mod archive_ro;
24
- pub mod diagnostic;
25
- pub mod enzyme_ffi;
19
+ pub ( crate ) mod archive_ro;
20
+ pub ( crate ) mod diagnostic;
21
+ pub ( crate ) mod enzyme_ffi;
26
22
mod ffi;
27
23
28
- pub use self :: enzyme_ffi:: * ;
24
+ pub ( crate ) use self :: enzyme_ffi:: * ;
29
25
30
26
impl LLVMRustResult {
31
- pub fn into_result ( self ) -> Result < ( ) , ( ) > {
27
+ pub ( crate ) fn into_result ( self ) -> Result < ( ) , ( ) > {
32
28
match self {
33
29
LLVMRustResult :: Success => Ok ( ( ) ) ,
34
30
LLVMRustResult :: Failure => Err ( ( ) ) ,
35
31
}
36
32
}
37
33
}
38
34
39
- pub fn AddFunctionAttributes < ' ll > ( llfn : & ' ll Value , idx : AttributePlace , attrs : & [ & ' ll Attribute ] ) {
35
+ pub ( crate ) fn AddFunctionAttributes < ' ll > (
36
+ llfn : & ' ll Value ,
37
+ idx : AttributePlace ,
38
+ attrs : & [ & ' ll Attribute ] ,
39
+ ) {
40
40
unsafe {
41
41
LLVMRustAddFunctionAttributes ( llfn, idx. as_uint ( ) , attrs. as_ptr ( ) , attrs. len ( ) ) ;
42
42
}
43
43
}
44
44
45
- pub fn AddCallSiteAttributes < ' ll > (
45
+ pub ( crate ) fn AddCallSiteAttributes < ' ll > (
46
46
callsite : & ' ll Value ,
47
47
idx : AttributePlace ,
48
48
attrs : & [ & ' ll Attribute ] ,
@@ -52,7 +52,11 @@ pub fn AddCallSiteAttributes<'ll>(
52
52
}
53
53
}
54
54
55
- pub fn CreateAttrStringValue < ' ll > ( llcx : & ' ll Context , attr : & str , value : & str ) -> & ' ll Attribute {
55
+ pub ( crate ) fn CreateAttrStringValue < ' ll > (
56
+ llcx : & ' ll Context ,
57
+ attr : & str ,
58
+ value : & str ,
59
+ ) -> & ' ll Attribute {
56
60
unsafe {
57
61
LLVMCreateStringAttribute (
58
62
llcx,
@@ -64,7 +68,7 @@ pub fn CreateAttrStringValue<'ll>(llcx: &'ll Context, attr: &str, value: &str) -
64
68
}
65
69
}
66
70
67
- pub fn CreateAttrString < ' ll > ( llcx : & ' ll Context , attr : & str ) -> & ' ll Attribute {
71
+ pub ( crate ) fn CreateAttrString < ' ll > ( llcx : & ' ll Context , attr : & str ) -> & ' ll Attribute {
68
72
unsafe {
69
73
LLVMCreateStringAttribute (
70
74
llcx,
@@ -76,39 +80,39 @@ pub fn CreateAttrString<'ll>(llcx: &'ll Context, attr: &str) -> &'ll Attribute {
76
80
}
77
81
}
78
82
79
- pub fn CreateAlignmentAttr ( llcx : & Context , bytes : u64 ) -> & Attribute {
83
+ pub ( crate ) fn CreateAlignmentAttr ( llcx : & Context , bytes : u64 ) -> & Attribute {
80
84
unsafe { LLVMRustCreateAlignmentAttr ( llcx, bytes) }
81
85
}
82
86
83
- pub fn CreateDereferenceableAttr ( llcx : & Context , bytes : u64 ) -> & Attribute {
87
+ pub ( crate ) fn CreateDereferenceableAttr ( llcx : & Context , bytes : u64 ) -> & Attribute {
84
88
unsafe { LLVMRustCreateDereferenceableAttr ( llcx, bytes) }
85
89
}
86
90
87
- pub fn CreateDereferenceableOrNullAttr ( llcx : & Context , bytes : u64 ) -> & Attribute {
91
+ pub ( crate ) fn CreateDereferenceableOrNullAttr ( llcx : & Context , bytes : u64 ) -> & Attribute {
88
92
unsafe { LLVMRustCreateDereferenceableOrNullAttr ( llcx, bytes) }
89
93
}
90
94
91
- pub fn CreateByValAttr < ' ll > ( llcx : & ' ll Context , ty : & ' ll Type ) -> & ' ll Attribute {
95
+ pub ( crate ) fn CreateByValAttr < ' ll > ( llcx : & ' ll Context , ty : & ' ll Type ) -> & ' ll Attribute {
92
96
unsafe { LLVMRustCreateByValAttr ( llcx, ty) }
93
97
}
94
98
95
- pub fn CreateStructRetAttr < ' ll > ( llcx : & ' ll Context , ty : & ' ll Type ) -> & ' ll Attribute {
99
+ pub ( crate ) fn CreateStructRetAttr < ' ll > ( llcx : & ' ll Context , ty : & ' ll Type ) -> & ' ll Attribute {
96
100
unsafe { LLVMRustCreateStructRetAttr ( llcx, ty) }
97
101
}
98
102
99
- pub fn CreateUWTableAttr ( llcx : & Context , async_ : bool ) -> & Attribute {
103
+ pub ( crate ) fn CreateUWTableAttr ( llcx : & Context , async_ : bool ) -> & Attribute {
100
104
unsafe { LLVMRustCreateUWTableAttr ( llcx, async_) }
101
105
}
102
106
103
- pub fn CreateAllocSizeAttr ( llcx : & Context , size_arg : u32 ) -> & Attribute {
107
+ pub ( crate ) fn CreateAllocSizeAttr ( llcx : & Context , size_arg : u32 ) -> & Attribute {
104
108
unsafe { LLVMRustCreateAllocSizeAttr ( llcx, size_arg) }
105
109
}
106
110
107
- pub fn CreateAllocKindAttr ( llcx : & Context , kind_arg : AllocKindFlags ) -> & Attribute {
111
+ pub ( crate ) fn CreateAllocKindAttr ( llcx : & Context , kind_arg : AllocKindFlags ) -> & Attribute {
108
112
unsafe { LLVMRustCreateAllocKindAttr ( llcx, kind_arg. bits ( ) ) }
109
113
}
110
114
111
- pub fn CreateRangeAttr ( llcx : & Context , size : Size , range : WrappingRange ) -> & Attribute {
115
+ pub ( crate ) fn CreateRangeAttr ( llcx : & Context , size : Size , range : WrappingRange ) -> & Attribute {
112
116
let lower = range. start ;
113
117
let upper = range. end . wrapping_add ( 1 ) ;
114
118
let lower_words = [ lower as u64 , ( lower >> 64 ) as u64 ] ;
@@ -124,14 +128,14 @@ pub fn CreateRangeAttr(llcx: &Context, size: Size, range: WrappingRange) -> &Att
124
128
}
125
129
126
130
#[ derive( Copy , Clone ) ]
127
- pub enum AttributePlace {
131
+ pub ( crate ) enum AttributePlace {
128
132
ReturnValue ,
129
133
Argument ( u32 ) ,
130
134
Function ,
131
135
}
132
136
133
137
impl AttributePlace {
134
- pub fn as_uint ( self ) -> c_uint {
138
+ pub ( crate ) fn as_uint ( self ) -> c_uint {
135
139
match self {
136
140
AttributePlace :: ReturnValue => 0 ,
137
141
AttributePlace :: Argument ( i) => 1 + i,
@@ -142,7 +146,7 @@ impl AttributePlace {
142
146
143
147
#[ derive( Copy , Clone , PartialEq ) ]
144
148
#[ repr( C ) ]
145
- pub enum CodeGenOptSize {
149
+ pub ( crate ) enum CodeGenOptSize {
146
150
CodeGenOptSizeNone = 0 ,
147
151
CodeGenOptSizeDefault = 1 ,
148
152
CodeGenOptSizeAggressive = 2 ,
@@ -163,12 +167,12 @@ impl FromStr for ArchiveKind {
163
167
}
164
168
}
165
169
166
- pub fn SetInstructionCallConv ( instr : & Value , cc : CallConv ) {
170
+ pub ( crate ) fn SetInstructionCallConv ( instr : & Value , cc : CallConv ) {
167
171
unsafe {
168
172
LLVMSetInstructionCallConv ( instr, cc as c_uint ) ;
169
173
}
170
174
}
171
- pub fn SetFunctionCallConv ( fn_ : & Value , cc : CallConv ) {
175
+ pub ( crate ) fn SetFunctionCallConv ( fn_ : & Value , cc : CallConv ) {
172
176
unsafe {
173
177
LLVMSetFunctionCallConv ( fn_, cc as c_uint ) ;
174
178
}
@@ -180,82 +184,82 @@ pub fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
180
184
// value's name as the comdat value to make sure that it is in a 1-to-1 relationship to the
181
185
// function.
182
186
// For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52
183
- pub fn SetUniqueComdat ( llmod : & Module , val : & Value ) {
187
+ pub ( crate ) fn SetUniqueComdat ( llmod : & Module , val : & Value ) {
184
188
let name_buf = get_value_name ( val) . to_vec ( ) ;
185
189
let name =
186
190
CString :: from_vec_with_nul ( name_buf) . or_else ( |buf| CString :: new ( buf. into_bytes ( ) ) ) . unwrap ( ) ;
187
191
set_comdat ( llmod, val, & name) ;
188
192
}
189
193
190
- pub fn SetUnnamedAddress ( global : & Value , unnamed : UnnamedAddr ) {
194
+ pub ( crate ) fn SetUnnamedAddress ( global : & Value , unnamed : UnnamedAddr ) {
191
195
unsafe {
192
196
LLVMSetUnnamedAddress ( global, unnamed) ;
193
197
}
194
198
}
195
199
196
- pub fn set_thread_local_mode ( global : & Value , mode : ThreadLocalMode ) {
200
+ pub ( crate ) fn set_thread_local_mode ( global : & Value , mode : ThreadLocalMode ) {
197
201
unsafe {
198
202
LLVMSetThreadLocalMode ( global, mode) ;
199
203
}
200
204
}
201
205
202
206
impl AttributeKind {
203
207
/// Create an LLVM Attribute with no associated value.
204
- pub fn create_attr ( self , llcx : & Context ) -> & Attribute {
208
+ pub ( crate ) fn create_attr ( self , llcx : & Context ) -> & Attribute {
205
209
unsafe { LLVMRustCreateAttrNoValue ( llcx, self ) }
206
210
}
207
211
}
208
212
209
213
impl MemoryEffects {
210
214
/// Create an LLVM Attribute with these memory effects.
211
- pub fn create_attr ( self , llcx : & Context ) -> & Attribute {
215
+ pub ( crate ) fn create_attr ( self , llcx : & Context ) -> & Attribute {
212
216
unsafe { LLVMRustCreateMemoryEffectsAttr ( llcx, self ) }
213
217
}
214
218
}
215
219
216
- pub fn set_section ( llglobal : & Value , section_name : & CStr ) {
220
+ pub ( crate ) fn set_section ( llglobal : & Value , section_name : & CStr ) {
217
221
unsafe {
218
222
LLVMSetSection ( llglobal, section_name. as_ptr ( ) ) ;
219
223
}
220
224
}
221
225
222
- pub fn add_global < ' a > ( llmod : & ' a Module , ty : & ' a Type , name_cstr : & CStr ) -> & ' a Value {
226
+ pub ( crate ) fn add_global < ' a > ( llmod : & ' a Module , ty : & ' a Type , name_cstr : & CStr ) -> & ' a Value {
223
227
unsafe { LLVMAddGlobal ( llmod, ty, name_cstr. as_ptr ( ) ) }
224
228
}
225
229
226
- pub fn set_initializer ( llglobal : & Value , constant_val : & Value ) {
230
+ pub ( crate ) fn set_initializer ( llglobal : & Value , constant_val : & Value ) {
227
231
unsafe {
228
232
LLVMSetInitializer ( llglobal, constant_val) ;
229
233
}
230
234
}
231
235
232
- pub fn set_global_constant ( llglobal : & Value , is_constant : bool ) {
236
+ pub ( crate ) fn set_global_constant ( llglobal : & Value , is_constant : bool ) {
233
237
unsafe {
234
238
LLVMSetGlobalConstant ( llglobal, if is_constant { ffi:: True } else { ffi:: False } ) ;
235
239
}
236
240
}
237
241
238
- pub fn get_linkage ( llglobal : & Value ) -> Linkage {
242
+ pub ( crate ) fn get_linkage ( llglobal : & Value ) -> Linkage {
239
243
unsafe { LLVMGetLinkage ( llglobal) } . to_rust ( )
240
244
}
241
245
242
- pub fn set_linkage ( llglobal : & Value , linkage : Linkage ) {
246
+ pub ( crate ) fn set_linkage ( llglobal : & Value , linkage : Linkage ) {
243
247
unsafe {
244
248
LLVMSetLinkage ( llglobal, linkage) ;
245
249
}
246
250
}
247
251
248
- pub fn get_visibility ( llglobal : & Value ) -> Visibility {
252
+ pub ( crate ) fn get_visibility ( llglobal : & Value ) -> Visibility {
249
253
unsafe { LLVMGetVisibility ( llglobal) } . to_rust ( )
250
254
}
251
255
252
- pub fn set_visibility ( llglobal : & Value , visibility : Visibility ) {
256
+ pub ( crate ) fn set_visibility ( llglobal : & Value , visibility : Visibility ) {
253
257
unsafe {
254
258
LLVMSetVisibility ( llglobal, visibility) ;
255
259
}
256
260
}
257
261
258
- pub fn set_alignment ( llglobal : & Value , align : Align ) {
262
+ pub ( crate ) fn set_alignment ( llglobal : & Value , align : Align ) {
259
263
unsafe {
260
264
ffi:: LLVMSetAlignment ( llglobal, align. bytes ( ) as c_uint ) ;
261
265
}
@@ -265,15 +269,15 @@ pub fn set_alignment(llglobal: &Value, align: Align) {
265
269
///
266
270
/// Inserts the comdat into `llmod` if it does not exist.
267
271
/// It is an error to call this if the target does not support comdat.
268
- pub fn set_comdat ( llmod : & Module , llglobal : & Value , name : & CStr ) {
272
+ pub ( crate ) fn set_comdat ( llmod : & Module , llglobal : & Value , name : & CStr ) {
269
273
unsafe {
270
274
let comdat = LLVMGetOrInsertComdat ( llmod, name. as_ptr ( ) ) ;
271
275
LLVMSetComdat ( llglobal, comdat) ;
272
276
}
273
277
}
274
278
275
279
/// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
276
- pub fn get_param ( llfn : & Value , index : c_uint ) -> & Value {
280
+ pub ( crate ) fn get_param ( llfn : & Value , index : c_uint ) -> & Value {
277
281
unsafe {
278
282
assert ! (
279
283
index < LLVMCountParams ( llfn) ,
@@ -286,7 +290,7 @@ pub fn get_param(llfn: &Value, index: c_uint) -> &Value {
286
290
}
287
291
288
292
/// Safe wrapper for `LLVMGetValueName2` into a byte slice
289
- pub fn get_value_name ( value : & Value ) -> & [ u8 ] {
293
+ pub ( crate ) fn get_value_name ( value : & Value ) -> & [ u8 ] {
290
294
unsafe {
291
295
let mut len = 0 ;
292
296
let data = LLVMGetValueName2 ( value, & mut len) ;
@@ -295,28 +299,28 @@ pub fn get_value_name(value: &Value) -> &[u8] {
295
299
}
296
300
297
301
/// Safe wrapper for `LLVMSetValueName2` from a byte slice
298
- pub fn set_value_name ( value : & Value , name : & [ u8 ] ) {
302
+ pub ( crate ) fn set_value_name ( value : & Value , name : & [ u8 ] ) {
299
303
unsafe {
300
304
let data = name. as_c_char_ptr ( ) ;
301
305
LLVMSetValueName2 ( value, data, name. len ( ) ) ;
302
306
}
303
307
}
304
308
305
- pub fn build_string ( f : impl FnOnce ( & RustString ) ) -> Result < String , FromUtf8Error > {
309
+ pub ( crate ) fn build_string ( f : impl FnOnce ( & RustString ) ) -> Result < String , FromUtf8Error > {
306
310
String :: from_utf8 ( RustString :: build_byte_buffer ( f) )
307
311
}
308
312
309
- pub fn build_byte_buffer ( f : impl FnOnce ( & RustString ) ) -> Vec < u8 > {
313
+ pub ( crate ) fn build_byte_buffer ( f : impl FnOnce ( & RustString ) ) -> Vec < u8 > {
310
314
RustString :: build_byte_buffer ( f)
311
315
}
312
316
313
- pub fn twine_to_string ( tr : & Twine ) -> String {
317
+ pub ( crate ) fn twine_to_string ( tr : & Twine ) -> String {
314
318
unsafe {
315
319
build_string ( |s| LLVMRustWriteTwineToString ( tr, s) ) . expect ( "got a non-UTF8 Twine from LLVM" )
316
320
}
317
321
}
318
322
319
- pub fn last_error ( ) -> Option < String > {
323
+ pub ( crate ) fn last_error ( ) -> Option < String > {
320
324
unsafe {
321
325
let cstr = LLVMRustGetLastError ( ) ;
322
326
if cstr. is_null ( ) {
0 commit comments