]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/declare.rs
rustc_codegen_ssa: move debuginfo-related things to a new mir::debuginfo module.
[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::{self, Instance};
5
6 pub trait DeclareMethods<'tcx>: BackendTypes {
7     /// Declare a global value.
8     ///
9     /// If there’s a value with the same name already declared, the function will
10     /// return its Value instead.
11     fn declare_global(&self, name: &str, ty: Self::Type) -> Self::Value;
12
13     /// Declare a C ABI function.
14     ///
15     /// Only use this for foreign function ABIs and glue. For Rust functions use
16     /// `declare_fn` instead.
17     ///
18     /// If there’s a value with the same name already declared, the function will
19     /// update the declaration and return existing Value instead.
20     fn declare_cfn(&self, name: &str, fn_type: Self::Type) -> Self::Function;
21
22     /// Declare a Rust function.
23     ///
24     /// If there’s a value with the same name already declared, the function will
25     /// update the declaration and return existing Value instead.
26     fn declare_fn(&self, name: &str, sig: ty::PolyFnSig<'tcx>) -> Self::Function;
27
28     /// Declare a global with an intention to define it.
29     ///
30     /// Use this function when you intend to define a global. This function will
31     /// return `None` if the name already has a definition associated with it. In that
32     /// case an error should be reported to the user, because it usually happens due
33     /// to user’s fault (e.g., misuse of #[no_mangle] or #[export_name] attributes).
34     fn define_global(&self, name: &str, ty: Self::Type) -> Option<Self::Value>;
35
36     /// Declare a private global
37     ///
38     /// Use this function when you intend to define a global without a name.
39     fn define_private_global(&self, ty: Self::Type) -> Self::Value;
40
41     /// Declare a Rust function with an intention to define it.
42     ///
43     /// Use this function when you intend to define a function. This function will
44     /// return panic if the name already has a definition associated with it. This
45     /// can happen with #[no_mangle] or #[export_name], for example.
46     fn define_fn(&self, name: &str, fn_sig: ty::PolyFnSig<'tcx>) -> Self::Value;
47
48     /// Declare a Rust function with an intention to define it.
49     ///
50     /// Use this function when you intend to define a function. This function will
51     /// return panic if the name already has a definition associated with it. This
52     /// can happen with #[no_mangle] or #[export_name], for example.
53     fn define_internal_fn(&self, name: &str, fn_sig: ty::PolyFnSig<'tcx>) -> Self::Value;
54
55     /// Gets declared value by name.
56     fn get_declared_value(&self, name: &str) -> Option<Self::Value>;
57
58     /// Gets defined or externally defined (AvailableExternally linkage) value by
59     /// name.
60     fn get_defined_value(&self, name: &str) -> Option<Self::Value>;
61 }
62
63 pub trait PreDefineMethods<'tcx>: BackendTypes {
64     fn predefine_static(
65         &self,
66         def_id: DefId,
67         linkage: Linkage,
68         visibility: Visibility,
69         symbol_name: &str,
70     );
71     fn predefine_fn(
72         &self,
73         instance: Instance<'tcx>,
74         linkage: Linkage,
75         visibility: Visibility,
76         symbol_name: &str,
77     );
78 }