1 use super::BackendTypes;
2 use rustc::hir::def_id::DefId;
3 use rustc::mir::mono::{Linkage, Visibility};
4 use rustc::ty::{self, Instance};
6 pub trait DeclareMethods<'tcx>: BackendTypes {
7 /// Declare a global value.
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;
13 /// Declare a C ABI function.
15 /// Only use this for foreign function ABIs and glue. For Rust functions use
16 /// `declare_fn` instead.
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::FuncId;
22 /// Declare a Rust function.
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::FuncId;
28 /// Declare a global with an intention to define it.
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>;
36 /// Declare a private global
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;
41 /// Declare a Rust function with an intention to define it.
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;
48 /// Declare a Rust function with an intention to define it.
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;
55 /// Gets declared value by name.
56 fn get_declared_value(&self, name: &str) -> Option<Self::Value>;
58 /// Gets defined or externally defined (AvailableExternally linkage) value by
60 fn get_defined_value(&self, name: &str) -> Option<Self::Value>;
63 pub trait PreDefineMethods<'tcx>: BackendTypes {
68 visibility: Visibility,
73 instance: Instance<'tcx>,
75 visibility: Visibility,