Add support for streaming an OperationName into a Diagnostic.

--

PiperOrigin-RevId: 248987646
This commit is contained in:
River Riddle 2019-05-19 22:35:01 -07:00 committed by Mehdi Amini
parent 68250edbfa
commit 039800bfb6
4 changed files with 14 additions and 3 deletions

View File

@ -38,6 +38,7 @@ class Identifier;
struct LogicalResult;
class MLIRContext;
class Operation;
class OperationName;
class Type;
namespace detail {
@ -234,6 +235,9 @@ public:
/// Stream in an Identifier.
Diagnostic &operator<<(Identifier val);
/// Stream in an OperationName.
Diagnostic &operator<<(OperationName val);
/// Stream in a range.
template <typename T> Diagnostic &operator<<(llvm::iterator_range<T> range) {
return appendRange(range);

View File

@ -123,6 +123,14 @@ Diagnostic &Diagnostic::operator<<(Identifier val) {
return *this;
}
/// Stream in an OperationName.
Diagnostic &Diagnostic::operator<<(OperationName val) {
// An OperationName is stored in the context, so we don't need to worry about
// the lifetime of its data.
arguments.push_back(DiagnosticArgument(val.getStringRef()));
return *this;
}
/// Outputs this diagnostic to a stream.
void Diagnostic::print(raw_ostream &os) const {
for (auto &arg : getArguments())

View File

@ -549,7 +549,7 @@ LogicalResult Operation::fold(ArrayRef<Attribute> operands,
/// Emit an error with the op name prefixed, like "'dim' op " which is
/// convenient for verifiers.
InFlightDiagnostic Operation::emitOpError(const Twine &message) {
return emitError() << "'" << getName().getStringRef() << "' op " << message;
return emitError() << "'" << getName() << "' op " << message;
}
//===----------------------------------------------------------------------===//

View File

@ -210,8 +210,7 @@ bool ModuleTranslation::convertOperation(Operation &opInst,
return false;
}
opInst.emitError("unsupported or non-LLVM operation: " +
opInst.getName().getStringRef());
opInst.emitError("unsupported or non-LLVM operation: ") << opInst.getName();
return true;
}