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