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