9
9
// except according to those terms.
10
10
//! Declare various LLVM values.
11
11
//!
12
- //! Prefer using functions and methods from this module rather than calling LLVM functions
13
- //! directly. These functions do some additional work to ensure we do the right thing given
14
- //! the preconceptions of trans.
12
+ //! Prefer using functions and methods from this module rather than calling LLVM
13
+ //! functions directly. These functions do some additional work to ensure we do
14
+ //! the right thing given the preconceptions of trans.
15
15
//!
16
16
//! Some useful guidelines:
17
17
//!
18
- //! * Use declare_* family of methods if you are declaring, but are not interested in defining the
19
- //! ValueRef they return.
18
+ //! * Use declare_* family of methods if you are declaring, but are not
19
+ //! interested in defining the ValueRef they return.
20
20
//! * Use define_* family of methods when you might be defining the ValueRef.
21
21
//! * When in doubt, define.
22
22
use llvm:: { self , ValueRef } ;
@@ -37,8 +37,8 @@ use libc::c_uint;
37
37
38
38
/// Declare a global value.
39
39
///
40
- /// If there’s a value with the same name already declared, the function will return its ValueRef
41
- /// instead.
40
+ /// If there’s a value with the same name already declared, the function will
41
+ /// return its ValueRef instead.
42
42
pub fn declare_global ( ccx : & CrateContext , name : & str , ty : Type ) -> llvm:: ValueRef {
43
43
debug ! ( "declare_global(name={:?})" , name) ;
44
44
let namebuf = CString :: new ( name) . unwrap_or_else ( |_|{
@@ -54,10 +54,10 @@ pub fn declare_global(ccx: &CrateContext, name: &str, ty: Type) -> llvm::ValueRe
54
54
///
55
55
/// For rust functions use `declare_rust_fn` instead.
56
56
///
57
- /// If there’s a value with the same name already declared, the function will update the
58
- /// declaration and return existing ValueRef instead.
59
- pub fn declare_fn ( ccx : & CrateContext , name : & str , callconv : llvm:: CallConv , ty : Type ,
60
- output : ty:: FnOutput ) -> ValueRef {
57
+ /// If there’s a value with the same name already declared, the function will
58
+ /// update the declaration and return existing ValueRef instead.
59
+ pub fn declare_fn ( ccx : & CrateContext , name : & str , callconv : llvm:: CallConv ,
60
+ ty : Type , output : ty:: FnOutput ) -> ValueRef {
61
61
debug ! ( "declare_fn(name={:?})" , name) ;
62
62
let namebuf = CString :: new ( name) . unwrap_or_else ( |_|{
63
63
ccx. sess ( ) . bug ( & format ! ( "name {:?} contains an interior null byte" , name) )
@@ -67,7 +67,8 @@ pub fn declare_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
67
67
} ;
68
68
69
69
llvm:: SetFunctionCallConv ( llfn, callconv) ;
70
- // Function addresses in Rust are never significant, allowing functions to be merged.
70
+ // Function addresses in Rust are never significant, allowing functions to
71
+ // be merged.
71
72
llvm:: SetUnnamedAddr ( llfn, true ) ;
72
73
73
74
if output == ty:: FnDiverging {
@@ -88,23 +89,25 @@ pub fn declare_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
88
89
89
90
/// Declare a C ABI function.
90
91
///
91
- /// Only use this for foreign function ABIs and glue. For Rust functions use `declare_rust_fn`
92
- /// instead.
92
+ /// Only use this for foreign function ABIs and glue. For Rust functions use
93
+ /// `declare_rust_fn` instead.
93
94
///
94
- /// If there’s a value with the same name already declared, the function will update the
95
- /// declaration and return existing ValueRef instead.
96
- pub fn declare_cfn ( ccx : & CrateContext , name : & str , fn_type : Type , output : ty:: Ty ) -> ValueRef {
95
+ /// If there’s a value with the same name already declared, the function will
96
+ /// update the declaration and return existing ValueRef instead.
97
+ pub fn declare_cfn ( ccx : & CrateContext , name : & str , fn_type : Type ,
98
+ output : ty:: Ty ) -> ValueRef {
97
99
declare_fn ( ccx, name, llvm:: CCallConv , fn_type, ty:: FnConverging ( output) )
98
100
}
99
101
100
102
101
103
/// Declare a Rust function.
102
104
///
103
- /// If there’s a value with the same name already declared, the function will update the
104
- /// declaration and return existing ValueRef instead.
105
+ /// If there’s a value with the same name already declared, the function will
106
+ /// update the declaration and return existing ValueRef instead.
105
107
pub fn declare_rust_fn < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > , name : & str ,
106
108
fn_type : ty:: Ty < ' tcx > ) -> ValueRef {
107
- debug ! ( "declare_rust_fn(name={:?}, fn_type={})" , name, fn_type. repr( ccx. tcx( ) ) ) ;
109
+ debug ! ( "declare_rust_fn(name={:?}, fn_type={})" , name,
110
+ fn_type. repr( ccx. tcx( ) ) ) ;
108
111
let fn_type = monomorphize:: normalize_associated_type ( ccx. tcx ( ) , & fn_type) ;
109
112
debug ! ( "declare_rust_fn (after normalised associated types) fn_type={}" ,
110
113
fn_type. repr( ccx. tcx( ) ) ) ;
@@ -131,7 +134,8 @@ pub fn declare_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
131
134
let llfty = type_of:: type_of_rust_fn ( ccx, env, & sig, abi) ;
132
135
debug ! ( "declare_rust_fn llfty={}" , ccx. tn( ) . type_to_string( llfty) ) ;
133
136
134
- // it is ok to directly access sig.0.output because we erased all late-bound-regions above
137
+ // it is ok to directly access sig.0.output because we erased all
138
+ // late-bound-regions above
135
139
let llfn = declare_fn ( ccx, name, llvm:: CCallConv , llfty, sig. 0 . output ) ;
136
140
attributes:: from_fn_type ( ccx, fn_type) . apply_llfn ( llfn) ;
137
141
llfn
@@ -140,8 +144,8 @@ pub fn declare_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
140
144
141
145
/// Declare a Rust function with internal linkage.
142
146
///
143
- /// If there’s a value with the same name already declared, the function will update the
144
- /// declaration and return existing ValueRef instead.
147
+ /// If there’s a value with the same name already declared, the function will
148
+ /// update the declaration and return existing ValueRef instead.
145
149
pub fn declare_internal_rust_fn < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > , name : & str ,
146
150
fn_type : ty:: Ty < ' tcx > ) -> ValueRef {
147
151
let llfn = declare_rust_fn ( ccx, name, fn_type) ;
@@ -152,10 +156,10 @@ pub fn declare_internal_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &s
152
156
153
157
/// Declare a global with an intention to define it.
154
158
///
155
- /// Use this function when you intend to define a global. This function will return None if the
156
- /// name already has a definition associated with it. In that case an error should be reported to
157
- /// the user, because it usually happens due to user’s fault (e.g. misuse of #[no_mangle] or
158
- /// #[export_name] attributes).
159
+ /// Use this function when you intend to define a global. This function will
160
+ /// return None if the name already has a definition associated with it. In that
161
+ /// case an error should be reported to the user, because it usually happens due
162
+ /// to user’s fault (e.g. misuse of #[no_mangle] or #[export_name] attributes).
159
163
pub fn define_global ( ccx : & CrateContext , name : & str , ty : Type ) -> Option < ValueRef > {
160
164
if get_defined_value ( ccx, name) . is_some ( ) {
161
165
None
@@ -169,10 +173,10 @@ pub fn define_global(ccx: &CrateContext, name: &str, ty: Type) -> Option<ValueRe
169
173
///
170
174
/// For rust functions use `define_rust_fn` instead.
171
175
///
172
- /// Use this function when you intend to define a function. This function will return None if the
173
- /// name already has a definition associated with it. In that case an error should be reported to
174
- /// the user, because it usually happens due to user’s fault (e.g. misuse of #[no_mangle] or
175
- /// #[export_name] attributes).
176
+ /// Use this function when you intend to define a function. This function will
177
+ /// return None if the name already has a definition associated with it. In that
178
+ /// case an error should be reported to the user, because it usually happens due
179
+ /// to user’s fault (e.g. misuse of #[no_mangle] or #[export_name] attributes).
176
180
pub fn define_fn ( ccx : & CrateContext , name : & str , callconv : llvm:: CallConv , fn_type : Type ,
177
181
output : ty:: FnOutput ) -> Option < ValueRef > {
178
182
if get_defined_value ( ccx, name) . is_some ( ) {
@@ -185,13 +189,13 @@ pub fn define_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, fn_ty
185
189
186
190
/// Declare a C ABI function with an intention to define it.
187
191
///
188
- /// Use this function when you intend to define a function. This function will return None if the
189
- /// name already has a definition associated with it. In that case an error should be reported to
190
- /// the user, because it usually happens due to user’s fault (e.g. misuse of #[no_mangle] or
191
- /// #[export_name] attributes).
192
+ /// Use this function when you intend to define a function. This function will
193
+ /// return None if the name already has a definition associated with it. In that
194
+ /// case an error should be reported to the user, because it usually happens due
195
+ /// to user’s fault (e.g. misuse of #[no_mangle] or #[export_name] attributes).
192
196
///
193
- /// Only use this for foreign function ABIs and glue. For Rust functions use `declare_rust_fn`
194
- /// instead.
197
+ /// Only use this for foreign function ABIs and glue. For Rust functions use
198
+ /// `declare_rust_fn` instead.
195
199
pub fn define_cfn ( ccx : & CrateContext , name : & str , fn_type : Type ,
196
200
output : ty:: Ty ) -> Option < ValueRef > {
197
201
if get_defined_value ( ccx, name) . is_some ( ) {
@@ -204,10 +208,10 @@ pub fn define_cfn(ccx: &CrateContext, name: &str, fn_type: Type,
204
208
205
209
/// Declare a Rust function with an intention to define it.
206
210
///
207
- /// Use this function when you intend to define a function. This function will return None if the
208
- /// name already has a definition associated with it. In that case an error should be reported to
209
- /// the user, because it usually happens due to user’s fault (e.g. misuse of #[no_mangle] or
210
- /// #[export_name] attributes).
211
+ /// Use this function when you intend to define a function. This function will
212
+ /// return None if the name already has a definition associated with it. In that
213
+ /// case an error should be reported to the user, because it usually happens due
214
+ /// to user’s fault (e.g. misuse of #[no_mangle] or #[export_name] attributes).
211
215
pub fn define_rust_fn < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > , name : & str ,
212
216
fn_type : ty:: Ty < ' tcx > ) -> Option < ValueRef > {
213
217
if get_defined_value ( ccx, name) . is_some ( ) {
@@ -220,10 +224,10 @@ pub fn define_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
220
224
221
225
/// Declare a Rust function with an intention to define it.
222
226
///
223
- /// Use this function when you intend to define a function. This function will return None if the
224
- /// name already has a definition associated with it. In that case an error should be reported to
225
- /// the user, because it usually happens due to user’s fault (e.g. misuse of #[no_mangle] or
226
- /// #[export_name] attributes).
227
+ /// Use this function when you intend to define a function. This function will
228
+ /// return None if the name already has a definition associated with it. In that
229
+ /// case an error should be reported to the user, because it usually happens due
230
+ /// to user’s fault (e.g. misuse of #[no_mangle] or #[export_name] attributes).
227
231
pub fn define_internal_rust_fn < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > , name : & str ,
228
232
fn_type : ty:: Ty < ' tcx > ) -> Option < ValueRef > {
229
233
if get_defined_value ( ccx, name) . is_some ( ) {
@@ -250,8 +254,8 @@ fn get_defined_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
250
254
( llvm:: LLVMIsDeclaration ( val) != 0 ,
251
255
linkage == llvm:: AvailableExternallyLinkage as c_uint )
252
256
} ;
253
- debug ! ( "get_defined_value: found {:?} value (declaration: {}, aext_link: {})" , name ,
254
- declaration, aext_link) ;
257
+ debug ! ( "get_defined_value: found {:?} value (declaration: {}, \
258
+ aext_link: {})" , name , declaration, aext_link) ;
255
259
if !declaration || aext_link {
256
260
Some ( val)
257
261
} else {
0 commit comments