}
/// Print the complete type of an operation in functional form.
- void printFunctionalType(Operation *op) {
- printFunctionalType(op->getOperandTypes(), op->getResultTypes());
- }
+ void printFunctionalType(Operation *op);
+
/// Print the two given type ranges in a functional form.
template <typename InputRangeT, typename ResultRangeT>
void printFunctionalType(InputRangeT &&inputs, ResultRangeT &&results) {
auto &os = getStream();
- os << "(";
+ os << '(';
llvm::interleaveComma(inputs, *this);
- os << ")";
+ os << ')';
printArrowTypeList(results);
}
virtual ParseResult parseOptionalEllipsis() = 0;
/// Parse an integer value from the stream.
- template <typename IntT> ParseResult parseInteger(IntT &result) {
+ template <typename IntT>
+ ParseResult parseInteger(IntT &result) {
auto loc = getCurrentLocation();
OptionalParseResult parseResult = parseOptionalInteger(result);
if (!parseResult.hasValue())
DialectAsmPrinter::~DialectAsmPrinter() {}
+//===--------------------------------------------------------------------===//
+// OpAsmPrinter
+//===--------------------------------------------------------------------===//
+
OpAsmPrinter::~OpAsmPrinter() {}
+void OpAsmPrinter::printFunctionalType(Operation *op) {
+ auto &os = getStream();
+ os << '(';
+ llvm::interleaveComma(op->getOperands(), os, [&](Value op) {
+ // Print the types of null values as <<NULL TYPE>>.
+ *this << (op ? op.getType() : Type());
+ });
+ os << ") -> ";
+
+ // Print the result list. We don't parenthesize single result types unless
+ // it is a function (avoiding a grammar ambiguity).
+ auto numResults = op->getNumResults();
+ bool wrapped = numResults != 1;
+ if (!wrapped && op->getResult(0).getType() &&
+ op->getResult(0).getType().isa<FunctionType>())
+ wrapped = true;
+
+ if (wrapped)
+ os << '(';
+
+ llvm::interleaveComma(op->getResults(), os, [&](const OpResult &r) {
+ // Print the types of null values as <<NULL TYPE>>.
+ *this << (r ? r.getType() : Type());
+ });
+
+ if (wrapped)
+ os << ')';
+}
+
//===--------------------------------------------------------------------===//
// Operation OpAsm interface.
//===--------------------------------------------------------------------===//
/// Return the type of this value.
Type Value::getType() const {
- // Support a null Value so the asmprinter doesn't crash on invalid IR (e.g.
- // operations that have dropAllReferences() called on them).
- if (!*this)
- return Type();
-
if (BlockArgument arg = dyn_cast<BlockArgument>())
return arg.getType();