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