1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use super::{CrateDebugContext};
use super::namespace::item_namespace;
use rustc::hir::def_id::DefId;
use rustc::ty::DefIdTree;
use llvm;
use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor, DIArray};
use machine;
use common::{CrateContext};
use type_::Type;
use syntax_pos::{self, Span};
use syntax::ast;
use std::ops;
pub fn is_node_local_to_unit(cx: &CrateContext, node_id: ast::NodeId) -> bool
{
!cx.exported_symbols().contains(&node_id)
}
#[allow(non_snake_case)]
pub fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
return unsafe {
llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
};
}
pub fn span_start(cx: &CrateContext, span: Span) -> syntax_pos::Loc {
cx.sess().codemap().lookup_char_pos(span.lo)
}
pub fn size_and_align_of(cx: &CrateContext, llvm_type: Type) -> (u64, u32) {
(machine::llsize_of_alloc(cx, llvm_type), machine::llalign_of_min(cx, llvm_type))
}
pub fn bytes_to_bits<T>(bytes: T) -> T
where T: ops::Mul<Output=T> + From<u8> {
bytes * 8u8.into()
}
#[inline]
pub fn debug_context<'a, 'tcx>(cx: &'a CrateContext<'a, 'tcx>)
-> &'a CrateDebugContext<'tcx> {
cx.dbg_cx().as_ref().unwrap()
}
#[inline]
#[allow(non_snake_case)]
pub fn DIB(cx: &CrateContext) -> DIBuilderRef {
cx.dbg_cx().as_ref().unwrap().builder
}
pub fn get_namespace_and_span_for_item(cx: &CrateContext, def_id: DefId)
-> (DIScope, Span) {
let containing_scope = item_namespace(cx, cx.tcx().parent(def_id)
.expect("get_namespace_and_span_for_item: missing parent?"));
let definition_span = cx.tcx().def_span(def_id);
(containing_scope, definition_span)
}