2015-04-24 03:36:43 +00:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
2015-04-24 05:25:35 +00:00
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
2015-04-24 03:36:43 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
2015-04-24 05:25:35 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
2015-04-24 03:36:43 +00:00
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Utility Functions.
|
|
|
|
|
2016-08-16 14:41:38 +00:00
|
|
|
use super::{CrateDebugContext};
|
2016-04-06 12:37:19 +00:00
|
|
|
use super::namespace::item_namespace;
|
2015-04-24 03:36:43 +00:00
|
|
|
|
2016-03-29 09:54:26 +00:00
|
|
|
use rustc::hir::def_id::DefId;
|
2017-01-25 20:01:11 +00:00
|
|
|
use rustc::ty::DefIdTree;
|
2015-08-16 10:32:28 +00:00
|
|
|
|
2015-04-24 03:36:43 +00:00
|
|
|
use llvm;
|
2018-07-04 13:36:49 +00:00
|
|
|
use llvm::debuginfo::{DIScope, DIBuilder, DIDescriptor, DIArray};
|
2018-01-05 05:01:54 +00:00
|
|
|
use common::{CodegenCx};
|
2015-04-24 03:36:43 +00:00
|
|
|
|
2016-06-21 22:08:13 +00:00
|
|
|
use syntax_pos::{self, Span};
|
2015-04-29 06:14:37 +00:00
|
|
|
|
2018-02-19 11:41:10 +00:00
|
|
|
pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool
|
2015-04-29 06:14:37 +00:00
|
|
|
{
|
|
|
|
// The is_local_to_unit flag indicates whether a function is local to the
|
|
|
|
// current compilation unit (i.e. if it is *static* in the C-sense). The
|
|
|
|
// *reachable* set should provide a good approximation of this, as it
|
|
|
|
// contains everything that might leak out of the current crate (by being
|
|
|
|
// externally visible or by being inlined into something externally
|
|
|
|
// visible). It might better to use the `exported_items` set from
|
|
|
|
// `driver::CrateAnalysis` in the future, but (atm) this set is not
|
2018-05-08 13:10:16 +00:00
|
|
|
// available in the codegen pass.
|
2018-02-22 11:18:16 +00:00
|
|
|
!cx.tcx.is_reachable_non_generic(def_id)
|
2015-04-29 06:14:37 +00:00
|
|
|
}
|
2015-04-24 03:36:43 +00:00
|
|
|
|
2015-04-29 06:14:37 +00:00
|
|
|
#[allow(non_snake_case)]
|
2018-07-04 13:36:49 +00:00
|
|
|
pub fn create_DIArray(builder: &'ll DIBuilder, arr: &[Option<&'ll DIDescriptor>]) -> &'ll DIArray {
|
2015-04-29 06:14:37 +00:00
|
|
|
return unsafe {
|
2016-08-01 23:35:09 +00:00
|
|
|
llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
|
2015-04-29 06:14:37 +00:00
|
|
|
};
|
|
|
|
}
|
2015-04-24 03:36:43 +00:00
|
|
|
|
2016-06-21 22:08:13 +00:00
|
|
|
/// Return syntax_pos::Loc corresponding to the beginning of the span
|
2018-01-05 05:01:54 +00:00
|
|
|
pub fn span_start(cx: &CodegenCx, span: Span) -> syntax_pos::Loc {
|
2017-07-31 20:04:34 +00:00
|
|
|
cx.sess().codemap().lookup_char_pos(span.lo())
|
2015-04-24 03:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-07-04 13:36:49 +00:00
|
|
|
pub fn debug_context(cx: &'a CodegenCx<'ll, 'tcx>) -> &'a CrateDebugContext<'ll, 'tcx> {
|
2018-01-05 04:58:34 +00:00
|
|
|
cx.dbg_cx.as_ref().unwrap()
|
2015-04-24 03:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[allow(non_snake_case)]
|
2018-07-03 13:02:38 +00:00
|
|
|
pub fn DIB(cx: &CodegenCx<'ll, '_>) -> &'ll DIBuilder {
|
2018-01-05 04:58:34 +00:00
|
|
|
cx.dbg_cx.as_ref().unwrap().builder
|
2015-04-24 03:36:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 13:36:49 +00:00
|
|
|
pub fn get_namespace_for_item(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
2018-01-05 04:58:34 +00:00
|
|
|
item_namespace(cx, cx.tcx.parent(def_id)
|
2017-07-07 12:23:38 +00:00
|
|
|
.expect("get_namespace_for_item: missing parent?"))
|
2015-04-24 03:36:43 +00:00
|
|
|
}
|