3 use super::namespace::item_namespace;
4 use super::CrateDebugContext;
6 use rustc::ty::DefIdTree;
7 use rustc_hir::def_id::DefId;
9 use crate::common::CodegenCx;
11 use crate::llvm::debuginfo::{DIArray, DIBuilder, DIDescriptor, DIScope};
12 use rustc_codegen_ssa::traits::*;
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)
28 #[allow(non_snake_case)]
29 pub fn create_DIArray(builder: &DIBuilder<'ll>, arr: &[Option<&'ll DIDescriptor>]) -> &'ll DIArray {
31 llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
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())
41 pub fn debug_context(cx: &'a CodegenCx<'ll, 'tcx>) -> &'a CrateDebugContext<'ll, 'tcx> {
42 cx.dbg_cx.as_ref().unwrap()
46 #[allow(non_snake_case)]
47 pub fn DIB(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> {
48 cx.dbg_cx.as_ref().unwrap().builder
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?"))