Add warning capabilities in LLVM.
[oota-llvm.git] / lib / Support / DiagnosticInfo.cpp
1 //===- llvm/Support/DiagnosticInfo.cpp - Diagnostic Definitions -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the different classes involved in low level diagnostics.
11 //
12 // Diagnostics reporting is still done as part of the LLVMContext.
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/Instruction.h"
19 #include "llvm/IR/Metadata.h"
20 #include "llvm/Support/Atomic.h"
21 #include "llvm/Support/DiagnosticInfo.h"
22 #include "llvm/Support/DiagnosticPrinter.h"
23
24 #include <string>
25
26 using namespace llvm;
27
28 int getNextAvailablePluginDiagnosticKind() {
29   static sys::cas_flag PluginKindID = DK_FirstPluginKind;
30   return (int)sys::AtomicIncrement(&PluginKindID);
31 }
32
33 DiagnosticInfoInlineAsm::DiagnosticInfoInlineAsm(const Instruction &I,
34                                                  const Twine &MsgStr,
35                                                  DiagnosticSeverity Severity)
36     : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
37       Instr(&I) {
38   if (const MDNode *SrcLoc = I.getMetadata("srcloc")) {
39     if (SrcLoc->getNumOperands() != 0)
40       if (const ConstantInt *CI = dyn_cast<ConstantInt>(SrcLoc->getOperand(0)))
41         LocCookie = CI->getZExtValue();
42   }
43 }
44
45 void DiagnosticInfoInlineAsm::print(DiagnosticPrinter &DP) const {
46   DP << getMsgStr();
47   if (getLocCookie())
48     DP << " at line " << getLocCookie();
49 }
50
51 void DiagnosticInfoStackSize::print(DiagnosticPrinter &DP) const {
52   DP << "stack size limit exceeded (" << getStackSize() << ") in "
53      << getFunction();
54 }