]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/declare.rs
typeck: remove redundant diverges code
[rust.git] / src / librustc_codegen_ssa / traits / declare.rs
1 use super::BackendTypes;
2 use rustc::mir::mono::{Linkage, Visibility};
3 use rustc::ty::{Instance, Ty};
4 use rustc_hir::def_id::DefId;
5 use rustc_target::abi::call::FnAbi;
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::Function;
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, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Function;
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     /// Gets declared value by name.
43     fn get_declared_value(&self, name: &str) -> Option<Self::Value>;
44
45     /// Gets defined or externally defined (AvailableExternally linkage) value by
46     /// name.
47     fn get_defined_value(&self, name: &str) -> Option<Self::Value>;
48 }
49
50 pub 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 }