1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use super::BackendTypes;
12 use rustc::hir::def_id::DefId;
13 use rustc::mir::mono::{Linkage, Visibility};
15 use rustc_mir::monomorphize::Instance;
17 pub trait DeclareMethods<'tcx>: BackendTypes {
18 /// Declare a global value.
20 /// If there’s a value with the same name already declared, the function will
21 /// return its Value instead.
22 fn declare_global(&self, name: &str, ty: Self::Type) -> Self::Value;
24 /// Declare a C ABI function.
26 /// Only use this for foreign function ABIs and glue. For Rust functions use
27 /// `declare_fn` instead.
29 /// If there’s a value with the same name already declared, the function will
30 /// update the declaration and return existing Value instead.
31 fn declare_cfn(&self, name: &str, fn_type: Self::Type) -> Self::Value;
33 /// Declare a Rust function.
35 /// If there’s a value with the same name already declared, the function will
36 /// update the declaration and return existing Value instead.
37 fn declare_fn(&self, name: &str, sig: ty::PolyFnSig<'tcx>) -> Self::Value;
39 /// Declare a global with an intention to define it.
41 /// Use this function when you intend to define a global. This function will
42 /// return None if the name already has a definition associated with it. In that
43 /// case an error should be reported to the user, because it usually happens due
44 /// to user’s fault (e.g. misuse of #[no_mangle] or #[export_name] attributes).
45 fn define_global(&self, name: &str, ty: Self::Type) -> Option<Self::Value>;
47 /// Declare a private global
49 /// Use this function when you intend to define a global without a name.
50 fn define_private_global(&self, ty: Self::Type) -> Self::Value;
52 /// Declare a Rust function with an intention to define it.
54 /// Use this function when you intend to define a function. This function will
55 /// return panic if the name already has a definition associated with it. This
56 /// can happen with #[no_mangle] or #[export_name], for example.
57 fn define_fn(&self, name: &str, fn_sig: ty::PolyFnSig<'tcx>) -> Self::Value;
59 /// Declare a Rust function with an intention to define it.
61 /// Use this function when you intend to define a function. This function will
62 /// return panic if the name already has a definition associated with it. This
63 /// can happen with #[no_mangle] or #[export_name], for example.
64 fn define_internal_fn(&self, name: &str, fn_sig: ty::PolyFnSig<'tcx>) -> Self::Value;
66 /// Get declared value by name.
67 fn get_declared_value(&self, name: &str) -> Option<Self::Value>;
69 /// Get defined or externally defined (AvailableExternally linkage) value by
71 fn get_defined_value(&self, name: &str) -> Option<Self::Value>;
74 pub trait PreDefineMethods<'tcx>: BackendTypes {
79 visibility: Visibility,
84 instance: Instance<'tcx>,
86 visibility: Visibility,