]> git.proxmox.com Git - rustc.git/blame - src/librustc_codegen_ssa/traits/declare.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_codegen_ssa / traits / declare.rs
CommitLineData
a1dfa0c6 1use super::BackendTypes;
dfeec247 2use rustc_hir::def_id::DefId;
ba9703b0
XL
3use rustc_middle::mir::mono::{Linkage, Visibility};
4use rustc_middle::ty::{Instance, Ty};
60c5eb7d 5use rustc_target::abi::call::FnAbi;
a1dfa0c6
XL
6
7pub trait DeclareMethods<'tcx>: BackendTypes {
8 /// Declare a global value.
9 ///
10 /// If there’s a value with the same name already declared, the function will
11 /// return its Value instead.
12 fn declare_global(&self, name: &str, ty: Self::Type) -> Self::Value;
13
14 /// Declare a C ABI function.
15 ///
16 /// Only use this for foreign function ABIs and glue. For Rust functions use
17 /// `declare_fn` instead.
18 ///
19 /// If there’s a value with the same name already declared, the function will
20 /// update the declaration and return existing Value instead.
e74abb32 21 fn declare_cfn(&self, name: &str, fn_type: Self::Type) -> Self::Function;
a1dfa0c6
XL
22
23 /// Declare a Rust function.
24 ///
25 /// If there’s a value with the same name already declared, the function will
26 /// update the declaration and return existing Value instead.
60c5eb7d 27 fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Function;
a1dfa0c6
XL
28
29 /// Declare a global with an intention to define it.
30 ///
31 /// Use this function when you intend to define a global. This function will
9fa01778 32 /// return `None` if the name already has a definition associated with it. In that
a1dfa0c6 33 /// case an error should be reported to the user, because it usually happens due
f9f354fc 34 /// to user’s fault (e.g., misuse of `#[no_mangle]` or `#[export_name]` attributes).
a1dfa0c6
XL
35 fn define_global(&self, name: &str, ty: Self::Type) -> Option<Self::Value>;
36
37 /// Declare a private global
38 ///
39 /// Use this function when you intend to define a global without a name.
40 fn define_private_global(&self, ty: Self::Type) -> Self::Value;
41
9fa01778 42 /// Gets declared value by name.
a1dfa0c6
XL
43 fn get_declared_value(&self, name: &str) -> Option<Self::Value>;
44
9fa01778 45 /// Gets defined or externally defined (AvailableExternally linkage) value by
a1dfa0c6
XL
46 /// name.
47 fn get_defined_value(&self, name: &str) -> Option<Self::Value>;
48}
49
50pub trait PreDefineMethods<'tcx>: BackendTypes {
51 fn predefine_static(
52 &self,
53 def_id: DefId,
54 linkage: Linkage,
55 visibility: Visibility,
56 symbol_name: &str,
57 );
58 fn predefine_fn(
59 &self,
60 instance: Instance<'tcx>,
61 linkage: Linkage,
62 visibility: Visibility,
63 symbol_name: &str,
64 );
65}