DiagnosticInfo.cpp revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
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/DiagnosticInfo.h" 18#include "llvm/IR/DiagnosticPrinter.h" 19#include "llvm/IR/Function.h" 20#include "llvm/IR/Instruction.h" 21#include "llvm/IR/Metadata.h" 22#include "llvm/Support/Atomic.h" 23#include <string> 24 25using namespace llvm; 26 27int llvm::getNextAvailablePluginDiagnosticKind() { 28 static sys::cas_flag PluginKindID = DK_FirstPluginKind; 29 return (int)sys::AtomicIncrement(&PluginKindID); 30} 31 32DiagnosticInfoInlineAsm::DiagnosticInfoInlineAsm(const Instruction &I, 33 const Twine &MsgStr, 34 DiagnosticSeverity Severity) 35 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr), 36 Instr(&I) { 37 if (const MDNode *SrcLoc = I.getMetadata("srcloc")) { 38 if (SrcLoc->getNumOperands() != 0) 39 if (const ConstantInt *CI = dyn_cast<ConstantInt>(SrcLoc->getOperand(0))) 40 LocCookie = CI->getZExtValue(); 41 } 42} 43 44void DiagnosticInfoInlineAsm::print(DiagnosticPrinter &DP) const { 45 DP << getMsgStr(); 46 if (getLocCookie()) 47 DP << " at line " << getLocCookie(); 48} 49 50void DiagnosticInfoStackSize::print(DiagnosticPrinter &DP) const { 51 DP << "stack size limit exceeded (" << getStackSize() << ") in " 52 << getFunction(); 53} 54 55void DiagnosticInfoDebugMetadataVersion::print(DiagnosticPrinter &DP) const { 56 DP << "ignoring debug info with an invalid version (" << getMetadataVersion() 57 << ") in " << getModule(); 58} 59 60void DiagnosticInfoSampleProfile::print(DiagnosticPrinter &DP) const { 61 if (getFileName() && getLineNum() > 0) 62 DP << getFileName() << ":" << getLineNum() << ": "; 63 else if (getFileName()) 64 DP << getFileName() << ": "; 65 DP << getMsg(); 66} 67