]> git.lizzy.rs Git - rust.git/blob - src/librustc_llvm/diagnostic.rs
Auto merge of #31077 - nagisa:mir-temp-promotion, r=dotdash
[rust.git] / src / librustc_llvm / diagnostic.rs
1 // Copyright 2014 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 //! LLVM diagnostic reports.
12
13 pub use self::OptimizationDiagnosticKind::*;
14 pub use self::Diagnostic::*;
15
16 use libc::{c_char, c_uint};
17 use std::ptr;
18
19 use {ValueRef, TwineRef, DebugLocRef, DiagnosticInfoRef};
20
21 #[derive(Copy, Clone)]
22 pub enum OptimizationDiagnosticKind {
23     OptimizationRemark,
24     OptimizationMissed,
25     OptimizationAnalysis,
26     OptimizationFailure,
27 }
28
29 impl OptimizationDiagnosticKind {
30     pub fn describe(self) -> &'static str {
31         match self {
32             OptimizationRemark => "remark",
33             OptimizationMissed => "missed",
34             OptimizationAnalysis => "analysis",
35             OptimizationFailure => "failure",
36         }
37     }
38 }
39
40 pub struct OptimizationDiagnostic {
41     pub kind: OptimizationDiagnosticKind,
42     pub pass_name: *const c_char,
43     pub function: ValueRef,
44     pub debug_loc: DebugLocRef,
45     pub message: TwineRef,
46 }
47
48 impl OptimizationDiagnostic {
49     unsafe fn unpack(kind: OptimizationDiagnosticKind, di: DiagnosticInfoRef)
50             -> OptimizationDiagnostic {
51
52         let mut opt = OptimizationDiagnostic {
53             kind: kind,
54             pass_name: ptr::null(),
55             function: ptr::null_mut(),
56             debug_loc: ptr::null_mut(),
57             message: ptr::null_mut(),
58         };
59
60         super::LLVMUnpackOptimizationDiagnostic(di,
61             &mut opt.pass_name,
62             &mut opt.function,
63             &mut opt.debug_loc,
64             &mut opt.message);
65
66         opt
67     }
68 }
69
70 #[derive(Copy, Clone)]
71 pub struct InlineAsmDiagnostic {
72     pub cookie: c_uint,
73     pub message: TwineRef,
74     pub instruction: ValueRef,
75 }
76
77 impl InlineAsmDiagnostic {
78     unsafe fn unpack(di: DiagnosticInfoRef)
79             -> InlineAsmDiagnostic {
80
81         let mut opt = InlineAsmDiagnostic {
82             cookie: 0,
83             message: ptr::null_mut(),
84             instruction: ptr::null_mut(),
85         };
86
87         super::LLVMUnpackInlineAsmDiagnostic(di,
88             &mut opt.cookie,
89             &mut opt.message,
90             &mut opt.instruction);
91
92         opt
93     }
94 }
95
96 pub enum Diagnostic {
97     Optimization(OptimizationDiagnostic),
98     InlineAsm(InlineAsmDiagnostic),
99
100     /// LLVM has other types that we do not wrap here.
101     UnknownDiagnostic(DiagnosticInfoRef),
102 }
103
104 impl Diagnostic {
105     pub unsafe fn unpack(di: DiagnosticInfoRef) -> Diagnostic {
106         let kind = super::LLVMGetDiagInfoKind(di);
107
108         match kind {
109             super::DK_InlineAsm
110                 => InlineAsm(InlineAsmDiagnostic::unpack(di)),
111
112             super::DK_OptimizationRemark
113                 => Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di)),
114
115             super::DK_OptimizationRemarkMissed
116                 => Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di)),
117
118             super::DK_OptimizationRemarkAnalysis
119                 => Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di)),
120
121             super::DK_OptimizationFailure
122                 => Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di)),
123
124             _ => UnknownDiagnostic(di)
125         }
126     }
127 }