Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/IR/Diagnostics.cpp
//===- Diagnostics.cpp - MLIR Diagnostics ---------------------------------===// | //===- Diagnostics.cpp - MLIR Diagnostics ---------------------------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "mlir/IR/Diagnostics.h" | #include "mlir/IR/Diagnostics.h" | ||||
#include "mlir/IR/Attributes.h" | #include "mlir/IR/Attributes.h" | ||||
#include "mlir/IR/Identifier.h" | |||||
#include "mlir/IR/Location.h" | #include "mlir/IR/Location.h" | ||||
#include "mlir/IR/MLIRContext.h" | #include "mlir/IR/MLIRContext.h" | ||||
#include "mlir/IR/Operation.h" | #include "mlir/IR/Operation.h" | ||||
#include "mlir/IR/Types.h" | #include "mlir/IR/Types.h" | ||||
#include "llvm/ADT/MapVector.h" | #include "llvm/ADT/MapVector.h" | ||||
#include "llvm/ADT/SmallString.h" | #include "llvm/ADT/SmallString.h" | ||||
#include "llvm/ADT/StringMap.h" | #include "llvm/ADT/StringMap.h" | ||||
#include "llvm/ADT/TypeSwitch.h" | #include "llvm/ADT/TypeSwitch.h" | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | Diagnostic &Diagnostic::operator<<(const Twine &val) { | ||||
arguments.push_back(DiagnosticArgument(twineToStrRef(val, strings))); | arguments.push_back(DiagnosticArgument(twineToStrRef(val, strings))); | ||||
return *this; | return *this; | ||||
} | } | ||||
Diagnostic &Diagnostic::operator<<(Twine &&val) { | Diagnostic &Diagnostic::operator<<(Twine &&val) { | ||||
arguments.push_back(DiagnosticArgument(twineToStrRef(val, strings))); | arguments.push_back(DiagnosticArgument(twineToStrRef(val, strings))); | ||||
return *this; | return *this; | ||||
} | } | ||||
/// Stream in an Identifier. | Diagnostic &Diagnostic::operator<<(StringAttr val) { | ||||
Diagnostic &Diagnostic::operator<<(Identifier val) { | arguments.push_back(DiagnosticArgument(val)); | ||||
// An identifier is stored in the context, so we don't need to worry about the | |||||
// lifetime of its data. | |||||
arguments.push_back(DiagnosticArgument(val.strref())); | |||||
return *this; | return *this; | ||||
} | } | ||||
/// Stream in an OperationName. | /// Stream in an OperationName. | ||||
Diagnostic &Diagnostic::operator<<(OperationName val) { | Diagnostic &Diagnostic::operator<<(OperationName val) { | ||||
// An OperationName is stored in the context, so we don't need to worry about | // An OperationName is stored in the context, so we don't need to worry about | ||||
// the lifetime of its data. | // the lifetime of its data. | ||||
arguments.push_back(DiagnosticArgument(val.getStringRef())); | arguments.push_back(DiagnosticArgument(val.getStringRef())); | ||||
▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | if (smloc.isValid()) | ||||
return mgr.PrintMessage(os, smloc, getDiagKind(kind), message); | return mgr.PrintMessage(os, smloc, getDiagKind(kind), message); | ||||
} | } | ||||
// If the conversion was unsuccessful, create a diagnostic with the file | // If the conversion was unsuccessful, create a diagnostic with the file | ||||
// information. We manually combine the line and column to avoid asserts in | // information. We manually combine the line and column to avoid asserts in | ||||
// the constructor of SMDiagnostic that takes a location. | // the constructor of SMDiagnostic that takes a location. | ||||
std::string locStr; | std::string locStr; | ||||
llvm::raw_string_ostream locOS(locStr); | llvm::raw_string_ostream locOS(locStr); | ||||
locOS << fileLoc->getFilename() << ":" << fileLoc->getLine() << ":" | locOS << fileLoc->getFilename().getValue() << ":" << fileLoc->getLine() << ":" | ||||
<< fileLoc->getColumn(); | << fileLoc->getColumn(); | ||||
llvm::SMDiagnostic diag(locOS.str(), getDiagKind(kind), message.str()); | llvm::SMDiagnostic diag(locOS.str(), getDiagKind(kind), message.str()); | ||||
diag.print(nullptr, os); | diag.print(nullptr, os); | ||||
} | } | ||||
/// Emit the given diagnostic with the held source manager. | /// Emit the given diagnostic with the held source manager. | ||||
void SourceMgrDiagnosticHandler::emitDiagnostic(Diagnostic &diag) { | void SourceMgrDiagnosticHandler::emitDiagnostic(Diagnostic &diag) { | ||||
SmallVector<std::pair<Location, StringRef>> locationStack; | SmallVector<std::pair<Location, StringRef>> locationStack; | ||||
▲ Show 20 Lines • Show All 490 Lines • Show Last 20 Lines |