]> git.lizzy.rs Git - rust.git/blob - src/librustc_llvm/diagnostic.rs
rollup merge of #19589: huonw/unboxed-closure-elision
[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;
17
18 use {ValueRef, TwineRef, DebugLocRef, DiagnosticInfoRef};
19
20 pub enum OptimizationDiagnosticKind {
21     OptimizationRemark,
22     OptimizationMissed,
23     OptimizationAnalysis,
24     OptimizationFailure,
25 }
26
27 impl Copy for OptimizationDiagnosticKind {}
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 Copy for OptimizationDiagnostic {}
49
50 impl OptimizationDiagnostic {
51     unsafe fn unpack(kind: OptimizationDiagnosticKind, di: DiagnosticInfoRef)
52             -> OptimizationDiagnostic {
53
54         let mut opt = OptimizationDiagnostic {
55             kind: kind,
56             pass_name: 0 as *const c_char,
57             function: 0 as ValueRef,
58             debug_loc: 0 as DebugLocRef,
59             message: 0 as TwineRef,
60         };
61
62         super::LLVMUnpackOptimizationDiagnostic(di,
63             &mut opt.pass_name,
64             &mut opt.function,
65             &mut opt.debug_loc,
66             &mut opt.message);
67
68         opt
69     }
70 }
71
72 pub enum Diagnostic {
73     Optimization(OptimizationDiagnostic),
74
75     /// LLVM has other types that we do not wrap here.
76     UnknownDiagnostic(DiagnosticInfoRef),
77 }
78
79 impl Copy for Diagnostic {}
80
81 impl Diagnostic {
82     pub unsafe fn unpack(di: DiagnosticInfoRef) -> Diagnostic {
83         let kind = super::LLVMGetDiagInfoKind(di);
84
85         match kind {
86             super::DK_OptimizationRemark
87                 => Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di)),
88
89             super::DK_OptimizationRemarkMissed
90                 => Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di)),
91
92             super::DK_OptimizationRemarkAnalysis
93                 => Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di)),
94
95             super::DK_OptimizationFailure
96                 => Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di)),
97
98             _ => UnknownDiagnostic(di)
99         }
100     }
101 }