/// Enum that represents the different kinds of diagnostic arguments
/// supported.
enum class DiagnosticArgumentKind {
+ Attribute,
Double,
Integer,
String,
/// Returns the kind of this argument.
DiagnosticArgumentKind getKind() const { return kind; }
+ /// Returns this argument as an Attribute.
+ Attribute getAsAttribute() const;
+
/// Returns this argument as a double.
double getAsDouble() const {
assert(getKind() == DiagnosticArgumentKind::Double);
private:
friend class Diagnostic;
+ // Construct from an Attribute.
+ explicit DiagnosticArgument(Attribute attr);
+
// Construct from a floating point number.
explicit DiagnosticArgument(double val)
: kind(DiagnosticArgumentKind::Double), doubleVal(val) {}
// =============================================================================
#include "mlir/IR/Diagnostics.h"
+#include "mlir/IR/Attributes.h"
#include "mlir/IR/Identifier.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/MLIRContext.h"
// DiagnosticArgument
//===----------------------------------------------------------------------===//
+// Construct from an Attribute.
+DiagnosticArgument::DiagnosticArgument(Attribute attr)
+ : kind(DiagnosticArgumentKind::Attribute),
+ opaqueVal(reinterpret_cast<intptr_t>(attr.getAsOpaquePointer())) {}
+
// Construct from a Type.
DiagnosticArgument::DiagnosticArgument(Type val)
: kind(DiagnosticArgumentKind::Type),
opaqueVal(reinterpret_cast<intptr_t>(val.getAsOpaquePointer())) {}
+/// Returns this argument as an Attribute.
+Attribute DiagnosticArgument::getAsAttribute() const {
+ assert(getKind() == DiagnosticArgumentKind::Attribute);
+ return Attribute::getFromOpaquePointer(
+ reinterpret_cast<const void *>(opaqueVal));
+}
+
/// Returns this argument as a Type.
Type DiagnosticArgument::getAsType() const {
assert(getKind() == DiagnosticArgumentKind::Type);
/// Outputs this argument to a stream.
void DiagnosticArgument::print(raw_ostream &os) const {
switch (kind) {
+ case DiagnosticArgumentKind::Attribute:
+ os << getAsAttribute();
+ break;
case DiagnosticArgumentKind::Double:
os << getAsDouble();
break;
for (const auto &affineMap : affineMapComposition) {
if (affineMap.getNumDims() != dim) {
if (location)
- context->emitError(
- *location,
- "memref affine map dimension mismatch between " +
- (i == 0 ? Twine("memref rank") : "affine map " + Twine(i)) +
- " and affine map" + Twine(i + 1) + ": " + Twine(dim) +
- " != " + Twine(affineMap.getNumDims()));
+ context->emitError(*location)
+ << "memref affine map dimension mismatch between "
+ << (i == 0 ? Twine("memref rank") : "affine map " + Twine(i))
+ << " and affine map" << i + 1 << ": " << dim
+ << " != " << affineMap.getNumDims();
return nullptr;
}
"expected 'predicate' attribute of string type");
int predicateValue = getICmpPredicateByName(predicateStr.getValue());
if (predicateValue == -1)
- return parser->emitError(
- predicateLoc,
- "'" + Twine(predicateStr.getValue()) +
- "' is an incorrect value of the 'predicate' attribute");
+ return parser->emitError(predicateLoc)
+ << "'" << predicateStr.getValue()
+ << "' is an incorrect value of the 'predicate' attribute";
attrs[0].second = parser->getBuilder().getI64IntegerAttr(predicateValue);
return parser->emitError(parser->getNameLoc(),
"view type expected for first type");
if (indexingsInfo.size() != baseViewType.getRank())
- return parser->emitError(parser->getNameLoc(),
- "expected " + Twine(baseViewType.getRank()) +
- " indexings");
+ return parser->emitError(parser->getNameLoc(), "expected ")
+ << baseViewType.getRank() << " indexings";
ViewType viewType = types.back().dyn_cast<ViewType>();
if (!viewType)
return parser->emitError(parser->getNameLoc(), "view type expected");
ArrayRef<Type> indexingTypes =
ArrayRef<Type>(types).drop_front(1).drop_back(1);
if (indexingTypes.size() != baseViewType.getRank())
- return parser->emitError(parser->getNameLoc(),
- "expected " + Twine(baseViewType.getRank()) +
- " indexing types");
+ return parser->emitError(parser->getNameLoc(), "expected ")
+ << baseViewType.getRank() << " indexing types";
return failure(
parser->resolveOperand(baseInfo, baseViewType, result->operands) ||
(!indexingsInfo.empty() &&
if (!viewType)
return parser->emitError(parser->getNameLoc(), "view type expected");
if (viewType.getRank() != indexingsInfo.size())
- return parser->emitError(parser->getNameLoc(),
- "expected" + Twine(viewType.getRank()) +
- " range indexings");
+ return parser->emitError(parser->getNameLoc(), "expected")
+ << viewType.getRank() << " range indexings";
return failure(
parser->resolveOperand(
bufferInfo,
StringRef predicateName = predicateNameAttr.cast<StringAttr>().getValue();
auto predicate = getPredicateByName(predicateName);
if (predicate == CmpIPredicate::NumPredicates)
- return parser->emitError(parser->getNameLoc(),
- "unknown comparison predicate \"" + predicateName +
- "\"");
+ return parser->emitError(parser->getNameLoc())
+ << "unknown comparison predicate \"" << predicateName << "\"";
auto builder = parser->getBuilder();
Type i1Type = getCheckedI1SameShape(&builder, type);