2015-04-24 15:36:43 +12:00
|
|
|
// Utility Functions.
|
|
|
|
|
2016-04-06 15:37:19 +03:00
|
|
|
use super::namespace::item_namespace;
|
2019-12-22 17:42:04 -05:00
|
|
|
use super::CrateDebugContext;
|
2015-04-24 15:36:43 +12:00
|
|
|
|
2017-01-25 22:01:11 +02:00
|
|
|
use rustc::ty::DefIdTree;
|
2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir::def_id::DefId;
|
2015-08-16 06:32:28 -04:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
use crate::common::CodegenCx;
|
2019-02-18 03:58:58 +09:00
|
|
|
use crate::llvm;
|
2019-12-22 17:42:04 -05:00
|
|
|
use crate::llvm::debuginfo::{DIArray, DIBuilder, DIDescriptor, DIScope};
|
2015-04-29 18:14:37 +12:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {
|
2015-04-29 18:14:37 +12:00
|
|
|
// The is_local_to_unit flag indicates whether a function is local to the
|
2018-11-27 02:59:49 +00:00
|
|
|
// current compilation unit (i.e., if it is *static* in the C-sense). The
|
2015-04-29 18:14:37 +12:00
|
|
|
// *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 16:10:16 +03:00
|
|
|
// available in the codegen pass.
|
2018-02-22 12:18:16 +01:00
|
|
|
!cx.tcx.is_reachable_non_generic(def_id)
|
2015-04-29 18:14:37 +12:00
|
|
|
}
|
2015-04-24 15:36:43 +12:00
|
|
|
|
2015-04-29 18:14:37 +12:00
|
|
|
#[allow(non_snake_case)]
|
2019-12-22 17:42:04 -05:00
|
|
|
pub fn create_DIArray(builder: &DIBuilder<'ll>, arr: &[Option<&'ll DIDescriptor>]) -> &'ll DIArray {
|
2015-04-29 18:14:37 +12:00
|
|
|
return unsafe {
|
2016-08-02 02:35:09 +03:00
|
|
|
llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
|
2015-04-29 18:14:37 +12:00
|
|
|
};
|
|
|
|
}
|
2015-04-24 15:36:43 +12:00
|
|
|
|
|
|
|
#[inline]
|
2018-07-04 16:36:49 +03:00
|
|
|
pub fn debug_context(cx: &'a CodegenCx<'ll, 'tcx>) -> &'a CrateDebugContext<'ll, 'tcx> {
|
2018-01-05 06:58:34 +02:00
|
|
|
cx.dbg_cx.as_ref().unwrap()
|
2015-04-24 15:36:43 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[allow(non_snake_case)]
|
2018-07-17 18:45:33 +03:00
|
|
|
pub fn DIB(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> {
|
2018-01-05 06:58:34 +02:00
|
|
|
cx.dbg_cx.as_ref().unwrap().builder
|
2015-04-24 15:36:43 +12:00
|
|
|
}
|
|
|
|
|
2018-07-04 16:36:49 +03:00
|
|
|
pub fn get_namespace_for_item(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
2019-12-22 17:42:04 -05:00
|
|
|
item_namespace(cx, cx.tcx.parent(def_id).expect("get_namespace_for_item: missing parent?"))
|
2015-04-24 15:36:43 +12:00
|
|
|
}
|