1 use super::BackendTypes;
2 use rustc::hir::def_id::DefId;
3 use rustc::mir::mono::{Linkage, Visibility};
5 use rustc_mir::monomorphize::Instance;
7 pub trait DeclareMethods<'tcx>: BackendTypes {
8 /// Declare a global value.
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;
14 /// Declare a C ABI function.
16 /// Only use this for foreign function ABIs and glue. For Rust functions use
17 /// `declare_fn` instead.
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;
23 /// Declare a Rust function.
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;
29 /// Declare a global with an intention to define it.
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>;
37 /// Declare a private global
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;
42 /// Declare a Rust function with an intention to define it.
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;
49 /// Declare a Rust function with an intention to define it.
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;
56 /// Gets declared value by name.
57 fn get_declared_value(&self, name: &str) -> Option<Self::Value>;
59 /// Gets defined or externally defined (AvailableExternally linkage) value by
61 fn get_defined_value(&self, name: &str) -> Option<Self::Value>;
64 pub trait PreDefineMethods<'tcx>: BackendTypes {
69 visibility: Visibility,
74 instance: Instance<'tcx>,
76 visibility: Visibility,