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