]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/declare.rs
Rollup merge of #58440 - gnzlbg:v6, r=japaric
[rust.git] / src / librustc_codegen_ssa / traits / declare.rs
1 use super::BackendTypes;
2 use rustc::hir::def_id::DefId;
3 use rustc::mir::mono::{Linkage, Visibility};
4 use rustc::ty;
5 use rustc_mir::monomorphize::Instance;
6
7 pub 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.
21     fn declare_cfn(&self, name: &str, fn_type: Self::Type) -> Self::Value;
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.
27     fn declare_fn(&self, name: &str, sig: ty::PolyFnSig<'tcx>) -> Self::Value;
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
32     /// return `None` if the name already has a definition associated with it. In that
33     /// case an error should be reported to the user, because it usually happens due
34     /// to user’s fault (e.g., misuse of #[no_mangle] or #[export_name] attributes).
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
42     /// Declare a Rust function with an intention to define it.
43     ///
44     /// Use this function when you intend to define a function. This function will
45     /// return panic if the name already has a definition associated with it. This
46     /// can happen with #[no_mangle] or #[export_name], for example.
47     fn define_fn(&self, name: &str, fn_sig: ty::PolyFnSig<'tcx>) -> Self::Value;
48
49     /// Declare a Rust function with an intention to define it.
50     ///
51     /// Use this function when you intend to define a function. This function will
52     /// return panic if the name already has a definition associated with it. This
53     /// can happen with #[no_mangle] or #[export_name], for example.
54     fn define_internal_fn(&self, name: &str, fn_sig: ty::PolyFnSig<'tcx>) -> Self::Value;
55
56     /// Gets declared value by name.
57     fn get_declared_value(&self, name: &str) -> Option<Self::Value>;
58
59     /// Gets defined or externally defined (AvailableExternally linkage) value by
60     /// name.
61     fn get_defined_value(&self, name: &str) -> Option<Self::Value>;
62 }
63
64 pub trait PreDefineMethods<'tcx>: BackendTypes {
65     fn predefine_static(
66         &self,
67         def_id: DefId,
68         linkage: Linkage,
69         visibility: Visibility,
70         symbol_name: &str,
71     );
72     fn predefine_fn(
73         &self,
74         instance: Instance<'tcx>,
75         linkage: Linkage,
76         visibility: Visibility,
77         symbol_name: &str,
78     );
79 }