1 // Copyright 2015 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.
13 use super::{CrateDebugContext};
14 use super::namespace::item_namespace;
16 use rustc::hir::def_id::DefId;
17 use rustc::ty::DefIdTree;
20 use llvm::debuginfo::{DIScope, DIBuilder, DIDescriptor, DIArray};
21 use common::{CodegenCx};
22 use rustc_codegen_ssa::traits::*;
24 use syntax_pos::{self, Span};
26 pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool
28 // The is_local_to_unit flag indicates whether a function is local to the
29 // current compilation unit (i.e. if it is *static* in the C-sense). The
30 // *reachable* set should provide a good approximation of this, as it
31 // contains everything that might leak out of the current crate (by being
32 // externally visible or by being inlined into something externally
33 // visible). It might better to use the `exported_items` set from
34 // `driver::CrateAnalysis` in the future, but (atm) this set is not
35 // available in the codegen pass.
36 !cx.tcx.is_reachable_non_generic(def_id)
39 #[allow(non_snake_case)]
40 pub fn create_DIArray(
41 builder: &DIBuilder<'ll>,
42 arr: &[Option<&'ll DIDescriptor>],
45 llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
49 /// Return syntax_pos::Loc corresponding to the beginning of the span
50 pub fn span_start(cx: &CodegenCx, span: Span) -> syntax_pos::Loc {
51 cx.sess().source_map().lookup_char_pos(span.lo())
55 pub fn debug_context(cx: &'a CodegenCx<'ll, 'tcx>) -> &'a CrateDebugContext<'ll, 'tcx> {
56 cx.dbg_cx.as_ref().unwrap()
60 #[allow(non_snake_case)]
61 pub fn DIB(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> {
62 cx.dbg_cx.as_ref().unwrap().builder
65 pub fn get_namespace_for_item(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
66 item_namespace(cx, cx.tcx.parent(def_id)
67 .expect("get_namespace_for_item: missing parent?"))