]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/debuginfo.rs
Rollup merge of #56796 - KrishnaSannasi:try_from_impl_change, r=shepmaster
[rust.git] / src / librustc_codegen_ssa / debuginfo.rs
1 use syntax_pos::{BytePos, Span};
2 use rustc::hir::def_id::CrateNum;
3 use std::cell::Cell;
4
5 pub enum FunctionDebugContext<D> {
6     RegularContext(FunctionDebugContextData<D>),
7     DebugInfoDisabled,
8     FunctionWithoutDebugInfo,
9 }
10
11 impl<D> FunctionDebugContext<D> {
12     pub fn get_ref<'a>(&'a self, span: Span) -> &'a FunctionDebugContextData<D> {
13         match *self {
14             FunctionDebugContext::RegularContext(ref data) => data,
15             FunctionDebugContext::DebugInfoDisabled => {
16                 span_bug!(
17                     span,
18                     "debuginfo: Error trying to access FunctionDebugContext \
19                      although debug info is disabled!",
20                 );
21             }
22             FunctionDebugContext::FunctionWithoutDebugInfo => {
23                 span_bug!(
24                     span,
25                     "debuginfo: Error trying to access FunctionDebugContext \
26                      for function that should be ignored by debug info!",
27                 );
28             }
29         }
30     }
31 }
32
33 /// Enables emitting source locations for the given functions.
34 ///
35 /// Since we don't want source locations to be emitted for the function prelude,
36 /// they are disabled when beginning to codegen a new function. This functions
37 /// switches source location emitting on and must therefore be called before the
38 /// first real statement/expression of the function is codegened.
39 pub fn start_emitting_source_locations<D>(dbg_context: &FunctionDebugContext<D>) {
40     match *dbg_context {
41         FunctionDebugContext::RegularContext(ref data) => {
42             data.source_locations_enabled.set(true)
43         },
44         _ => { /* safe to ignore */ }
45     }
46 }
47
48 pub struct FunctionDebugContextData<D> {
49     pub fn_metadata: D,
50     pub source_locations_enabled: Cell<bool>,
51     pub defining_crate: CrateNum,
52 }
53
54 pub enum VariableAccess<'a, V> {
55     // The llptr given is an alloca containing the variable's value
56     DirectVariable { alloca: V },
57     // The llptr given is an alloca containing the start of some pointer chain
58     // leading to the variable's content.
59     IndirectVariable { alloca: V, address_operations: &'a [i64] }
60 }
61
62 pub enum VariableKind {
63     ArgumentVariable(usize /*index*/),
64     LocalVariable,
65 }
66
67
68 #[derive(Clone, Copy, Debug)]
69 pub struct MirDebugScope<D> {
70     pub scope_metadata: Option<D>,
71     // Start and end offsets of the file to which this DIScope belongs.
72     // These are used to quickly determine whether some span refers to the same file.
73     pub file_start_pos: BytePos,
74     pub file_end_pos: BytePos,
75 }
76
77 impl<D> MirDebugScope<D> {
78     pub fn is_valid(&self) -> bool {
79         !self.scope_metadata.is_none()
80     }
81 }