Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/IR/Diagnostics.h
Show All 36 Lines | |||||
} // end namespace detail | } // end namespace detail | ||||
/// Defines the different supported severity of a diagnostic. | /// Defines the different supported severity of a diagnostic. | ||||
enum class DiagnosticSeverity { | enum class DiagnosticSeverity { | ||||
Note, | Note, | ||||
Warning, | Warning, | ||||
Error, | Error, | ||||
Remark, | Remark, | ||||
Debugging, | |||||
}; | }; | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// DiagnosticArgument | // DiagnosticArgument | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
/// A variant type that holds a single argument for a diagnostic. | /// A variant type that holds a single argument for a diagnostic. | ||||
class DiagnosticArgument { | class DiagnosticArgument { | ||||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
/// Reports the diagnostic to the engine. | /// Reports the diagnostic to the engine. | ||||
void report(); | void report(); | ||||
/// Abandons this diagnostic so that it will no longer be reported. | /// Abandons this diagnostic so that it will no longer be reported. | ||||
void abandon(); | void abandon(); | ||||
Diagnostic &getDiagnostic() { | |||||
assert(isActive() && "diagnostic not active"); | |||||
return impl.getValue(); | |||||
} | |||||
/// Allow an inflight diagnostic to be converted to 'failure', otherwise | /// Allow an inflight diagnostic to be converted to 'failure', otherwise | ||||
/// 'success' if this is an empty diagnostic. | /// 'success' if this is an empty diagnostic. | ||||
operator LogicalResult() const; | operator LogicalResult() const; | ||||
private: | private: | ||||
InFlightDiagnostic &operator=(const InFlightDiagnostic &) = delete; | InFlightDiagnostic &operator=(const InFlightDiagnostic &) = delete; | ||||
InFlightDiagnostic &operator=(InFlightDiagnostic &&) = delete; | InFlightDiagnostic &operator=(InFlightDiagnostic &&) = delete; | ||||
InFlightDiagnostic(DiagnosticEngine *owner, Diagnostic &&rhs) | InFlightDiagnostic(DiagnosticEngine *owner, Diagnostic &&rhs) | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public: | ||||
/// Register a new handler for diagnostics to the engine. Diagnostics are | /// Register a new handler for diagnostics to the engine. Diagnostics are | ||||
/// process by handlers in stack-like order, meaning that the last added | /// process by handlers in stack-like order, meaning that the last added | ||||
/// handlers will process diagnostics first. This function returns a unique | /// handlers will process diagnostics first. This function returns a unique | ||||
/// identifier for the registered handler, which can be used to unregister | /// identifier for the registered handler, which can be used to unregister | ||||
/// this handler at a later time. | /// this handler at a later time. | ||||
HandlerID registerHandler(const HandlerTy &handler); | HandlerID registerHandler(const HandlerTy &handler); | ||||
/// Register a handler to the engine to collect the diagnostic for debugging | |||||
/// purpose. The debugging diagnostic will be discarded if there's no | |||||
/// registered handler. | |||||
HandlerTy registerDebuggingHandler(const HandlerTy &handler); | |||||
/// Return true if it has a registered debugging handler. | |||||
bool hasDebuggingHandler() const; | |||||
/// Set the diagnostic handler with a function that returns void. This is a | /// Set the diagnostic handler with a function that returns void. This is a | ||||
/// convenient wrapper for handlers that always completely process the given | /// convenient wrapper for handlers that always completely process the given | ||||
/// diagnostic. | /// diagnostic. | ||||
template <typename FuncTy, typename RetT = decltype(std::declval<FuncTy>()( | template <typename FuncTy, typename RetT = decltype(std::declval<FuncTy>()( | ||||
std::declval<Diagnostic &>()))> | std::declval<Diagnostic &>()))> | ||||
std::enable_if_t<std::is_same<RetT, void>::value, HandlerID> | std::enable_if_t<std::is_same<RetT, void>::value, HandlerID> | ||||
registerHandler(FuncTy &&handler) { | registerHandler(FuncTy &&handler) { | ||||
return registerHandler([=](Diagnostic &diag) { | return registerHandler([=](Diagnostic &diag) { | ||||
handler(diag); | handler(diag); | ||||
return success(); | return success(); | ||||
}); | }); | ||||
} | } | ||||
/// Erase the registered diagnostic handler with the given identifier. | /// Erase the registered diagnostic handler with the given identifier. | ||||
void eraseHandler(HandlerID id); | void eraseHandler(HandlerID id); | ||||
/// Erase the registered debugging handler. | |||||
void eraseDebuggingHandler(); | |||||
/// Create a new inflight diagnostic with the given location and severity. | /// Create a new inflight diagnostic with the given location and severity. | ||||
InFlightDiagnostic emit(Location loc, DiagnosticSeverity severity) { | InFlightDiagnostic emit(Location loc, DiagnosticSeverity severity) { | ||||
assert(severity != DiagnosticSeverity::Note && | assert(severity != DiagnosticSeverity::Note && | ||||
"notes should not be emitted directly"); | "notes should not be emitted directly"); | ||||
return InFlightDiagnostic(this, Diagnostic(loc, severity)); | return InFlightDiagnostic(this, Diagnostic(loc, severity)); | ||||
} | } | ||||
/// Emit a diagnostic using the registered issue handler if present, or with | /// Emit a diagnostic using the registered issue handler if present, or with | ||||
Show All 15 Lines | |||||
/// Utility method to emit a warning message using this location. | /// Utility method to emit a warning message using this location. | ||||
InFlightDiagnostic emitWarning(Location loc); | InFlightDiagnostic emitWarning(Location loc); | ||||
InFlightDiagnostic emitWarning(Location loc, const Twine &message); | InFlightDiagnostic emitWarning(Location loc, const Twine &message); | ||||
/// Utility method to emit a remark message using this location. | /// Utility method to emit a remark message using this location. | ||||
InFlightDiagnostic emitRemark(Location loc); | InFlightDiagnostic emitRemark(Location loc); | ||||
InFlightDiagnostic emitRemark(Location loc, const Twine &message); | InFlightDiagnostic emitRemark(Location loc, const Twine &message); | ||||
/// Utility method to emit a debugging message using this location. | |||||
LogicalResult emitDebugging(Location loc, | |||||
function_ref<void(Diagnostic &)> reasonCallback); | |||||
/// Overloads of the above emission functions that take an optionally null | /// Overloads of the above emission functions that take an optionally null | ||||
/// location. If the location is null, no diagnostic is emitted and a failure is | /// location. If the location is null, no diagnostic is emitted and a failure is | ||||
/// returned. Given that the provided location may be null, these methods take | /// returned. Given that the provided location may be null, these methods take | ||||
/// the diagnostic arguments directly instead of relying on the returned | /// the diagnostic arguments directly instead of relying on the returned | ||||
/// InFlightDiagnostic. | /// InFlightDiagnostic. | ||||
template <typename... Args> | template <typename... Args> | ||||
LogicalResult emitOptionalError(Optional<Location> loc, Args &&... args) { | LogicalResult emitOptionalError(Optional<Location> loc, Args &&... args) { | ||||
if (loc) | if (loc) | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | private: | ||||
/// The unique id for the scoped handler. | /// The unique id for the scoped handler. | ||||
DiagnosticEngine::HandlerID handlerID; | DiagnosticEngine::HandlerID handlerID; | ||||
/// The context to erase the handler from. | /// The context to erase the handler from. | ||||
MLIRContext *ctx; | MLIRContext *ctx; | ||||
}; | }; | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// ScopedDebuggingHandler | |||||
//===----------------------------------------------------------------------===// | |||||
class ScopedDebuggingHandler { | |||||
public: | |||||
explicit ScopedDebuggingHandler(MLIRContext *ctx) : ctx(ctx) {} | |||||
template <typename FuncTy> | |||||
ScopedDebuggingHandler(MLIRContext *ctx, FuncTy &&handler) : ctx(ctx) { | |||||
setHandler(std::forward<FuncTy>(handler)); | |||||
} | |||||
~ScopedDebuggingHandler(); | |||||
protected: | |||||
template <typename FuncTy> | |||||
void setHandler(FuncTy &&handler) { | |||||
auto &diagEngine = ctx->getDiagEngine(); | |||||
old = diagEngine.registerDebuggingHandler(std::forward<FuncTy>(handler)); | |||||
} | |||||
private: | |||||
DiagnosticEngine::HandlerTy old; | |||||
/// The context to erase the handler from. | |||||
MLIRContext *ctx; | |||||
}; | |||||
//===----------------------------------------------------------------------===// | |||||
// SourceMgrDiagnosticHandler | // SourceMgrDiagnosticHandler | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
namespace detail { | namespace detail { | ||||
struct SourceMgrDiagnosticHandlerImpl; | struct SourceMgrDiagnosticHandlerImpl; | ||||
} // end namespace detail | } // end namespace detail | ||||
/// This class is a utility diagnostic handler for use with llvm::SourceMgr. | /// This class is a utility diagnostic handler for use with llvm::SourceMgr. | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |