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.
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.
11 //! LLVM diagnostic reports.
13 pub use self::OptimizationDiagnosticKind
::*;
14 pub use self::Diagnostic
::*;
16 use libc
::{c_char, c_uint}
;
19 use {ValueRef, TwineRef, DebugLocRef, DiagnosticInfoRef}
;
21 #[derive(Copy, Clone)]
22 pub enum OptimizationDiagnosticKind
{
29 impl OptimizationDiagnosticKind
{
30 pub fn describe(self) -> &'
static str {
32 OptimizationRemark
=> "remark",
33 OptimizationMissed
=> "missed",
34 OptimizationAnalysis
=> "analysis",
35 OptimizationFailure
=> "failure",
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
,
48 impl OptimizationDiagnostic
{
49 unsafe fn unpack(kind
: OptimizationDiagnosticKind
, di
: DiagnosticInfoRef
)
50 -> OptimizationDiagnostic
{
52 let mut opt
= OptimizationDiagnostic
{
54 pass_name
: ptr
::null(),
55 function
: ptr
::null_mut(),
56 debug_loc
: ptr
::null_mut(),
57 message
: ptr
::null_mut(),
60 super::LLVMUnpackOptimizationDiagnostic(di
,
70 #[derive(Copy, Clone)]
71 pub struct InlineAsmDiagnostic
{
73 pub message
: TwineRef
,
74 pub instruction
: ValueRef
,
77 impl InlineAsmDiagnostic
{
78 unsafe fn unpack(di
: DiagnosticInfoRef
)
79 -> InlineAsmDiagnostic
{
81 let mut opt
= InlineAsmDiagnostic
{
83 message
: ptr
::null_mut(),
84 instruction
: ptr
::null_mut(),
87 super::LLVMUnpackInlineAsmDiagnostic(di
,
90 &mut opt
.instruction
);
97 Optimization(OptimizationDiagnostic
),
98 InlineAsm(InlineAsmDiagnostic
),
100 /// LLVM has other types that we do not wrap here.
101 UnknownDiagnostic(DiagnosticInfoRef
),
105 pub unsafe fn unpack(di
: DiagnosticInfoRef
) -> Diagnostic
{
106 let kind
= super::LLVMGetDiagInfoKind(di
);
110 => InlineAsm(InlineAsmDiagnostic
::unpack(di
)),
112 super::DK_OptimizationRemark
113 => Optimization(OptimizationDiagnostic
::unpack(OptimizationRemark
, di
)),
115 super::DK_OptimizationRemarkMissed
116 => Optimization(OptimizationDiagnostic
::unpack(OptimizationMissed
, di
)),
118 super::DK_OptimizationRemarkAnalysis
119 => Optimization(OptimizationDiagnostic
::unpack(OptimizationAnalysis
, di
)),
121 super::DK_OptimizationFailure
122 => Optimization(OptimizationDiagnostic
::unpack(OptimizationFailure
, di
)),
124 _
=> UnknownDiagnostic(di
)