]> git.proxmox.com Git - rustc.git/blame - src/librustc_codegen_llvm/debuginfo/utils.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_codegen_llvm / debuginfo / utils.rs
CommitLineData
d9579d0f
AL
1// Utility Functions.
2
a7813a04 3use super::namespace::item_namespace;
dfeec247 4use super::CrateDebugContext;
d9579d0f 5
dfeec247 6use rustc_hir::def_id::DefId;
ba9703b0 7use rustc_middle::ty::DefIdTree;
e9174d1e 8
dfeec247 9use crate::common::CodegenCx;
9fa01778 10use crate::llvm;
dfeec247 11use crate::llvm::debuginfo::{DIArray, DIBuilder, DIDescriptor, DIScope};
d9579d0f 12
dfeec247 13pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {
d9579d0f 14 // The is_local_to_unit flag indicates whether a function is local to the
0731742a 15 // current compilation unit (i.e., if it is *static* in the C-sense). The
d9579d0f
AL
16 // *reachable* set should provide a good approximation of this, as it
17 // contains everything that might leak out of the current crate (by being
18 // externally visible or by being inlined into something externally
19 // visible). It might better to use the `exported_items` set from
20 // `driver::CrateAnalysis` in the future, but (atm) this set is not
94b46f34 21 // available in the codegen pass.
0531ce1d 22 !cx.tcx.is_reachable_non_generic(def_id)
d9579d0f
AL
23}
24
25#[allow(non_snake_case)]
dfeec247 26pub fn create_DIArray(builder: &DIBuilder<'ll>, arr: &[Option<&'ll DIDescriptor>]) -> &'ll DIArray {
ba9703b0 27 unsafe { llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32) }
d9579d0f
AL
28}
29
d9579d0f 30#[inline]
b7449926 31pub fn debug_context(cx: &'a CodegenCx<'ll, 'tcx>) -> &'a CrateDebugContext<'ll, 'tcx> {
2c00a5a8 32 cx.dbg_cx.as_ref().unwrap()
d9579d0f
AL
33}
34
35#[inline]
36#[allow(non_snake_case)]
b7449926 37pub fn DIB(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> {
2c00a5a8 38 cx.dbg_cx.as_ref().unwrap().builder
d9579d0f
AL
39}
40
b7449926 41pub fn get_namespace_for_item(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
dfeec247 42 item_namespace(cx, cx.tcx.parent(def_id).expect("get_namespace_for_item: missing parent?"))
d9579d0f 43}