]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/debuginfo/utils.rs
Auto merge of #61300 - indygreg:upgrade-cross-make, r=sanxiyn
[rust.git] / src / librustc_codegen_llvm / debuginfo / utils.rs
1 // Utility Functions.
2
3 use super::{CrateDebugContext};
4 use super::namespace::item_namespace;
5
6 use rustc::hir::def_id::DefId;
7 use rustc::ty::DefIdTree;
8
9 use crate::llvm;
10 use crate::llvm::debuginfo::{DIScope, DIBuilder, DIDescriptor, DIArray};
11 use crate::common::{CodegenCx};
12 use rustc_codegen_ssa::traits::*;
13
14 use syntax_pos::Span;
15
16 pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool
17 {
18     // The is_local_to_unit flag indicates whether a function is local to the
19     // current compilation unit (i.e., if it is *static* in the C-sense). The
20     // *reachable* set should provide a good approximation of this, as it
21     // contains everything that might leak out of the current crate (by being
22     // externally visible or by being inlined into something externally
23     // visible). It might better to use the `exported_items` set from
24     // `driver::CrateAnalysis` in the future, but (atm) this set is not
25     // available in the codegen pass.
26     !cx.tcx.is_reachable_non_generic(def_id)
27 }
28
29 #[allow(non_snake_case)]
30 pub fn create_DIArray(
31     builder: &DIBuilder<'ll>,
32     arr: &[Option<&'ll DIDescriptor>],
33 ) -> &'ll DIArray {
34     return unsafe {
35         llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
36     };
37 }
38
39 /// Returns syntax_pos::Loc corresponding to the beginning of the span
40 pub fn span_start(cx: &CodegenCx<'_, '_>, span: Span) -> syntax_pos::Loc {
41     cx.sess().source_map().lookup_char_pos(span.lo())
42 }
43
44 #[inline]
45 pub fn debug_context(cx: &'a CodegenCx<'ll, 'tcx>) -> &'a CrateDebugContext<'ll, 'tcx> {
46     cx.dbg_cx.as_ref().unwrap()
47 }
48
49 #[inline]
50 #[allow(non_snake_case)]
51 pub fn DIB(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> {
52     cx.dbg_cx.as_ref().unwrap().builder
53 }
54
55 pub fn get_namespace_for_item(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
56     item_namespace(cx, cx.tcx.parent(def_id)
57         .expect("get_namespace_for_item: missing parent?"))
58 }