================ @@ -447,6 +448,133 @@ mlir::LogicalResult cir::ReturnOp::verify() { return success(); } +//===----------------------------------------------------------------------===// +// IfOp +//===----------------------------------------------------------------------===// + +ParseResult cir::IfOp::parse(OpAsmParser &parser, OperationState &result) { + // create the regions for 'then'. + result.regions.reserve(2); + Region *thenRegion = result.addRegion(); + Region *elseRegion = result.addRegion(); + + mlir::Builder &builder = parser.getBuilder(); + OpAsmParser::UnresolvedOperand cond; + Type boolType = cir::BoolType::get(builder.getContext()); + + if (parser.parseOperand(cond) || + parser.resolveOperand(cond, boolType, result.operands)) + return failure(); + + // Parse 'then' region. + mlir::SMLoc parseThenLoc = parser.getCurrentLocation(); + if (parser.parseRegion(*thenRegion, /*arguments=*/{}, /*argTypes=*/{})) + return failure(); + + if (ensureRegionTerm(parser, *thenRegion, parseThenLoc).failed()) + return failure(); + + // If we find an 'else' keyword, parse the 'else' region. + if (!parser.parseOptionalKeyword("else")) { + mlir::SMLoc parseElseLoc = parser.getCurrentLocation(); + if (parser.parseRegion(*elseRegion, /*arguments=*/{}, /*argTypes=*/{})) + return failure(); + if (ensureRegionTerm(parser, *elseRegion, parseElseLoc).failed()) + return failure(); + } + + // Parse the optional attribute list. + if (parser.parseOptionalAttrDict(result.attributes)) + return failure(); + return success(); +} + +void cir::IfOp::print(OpAsmPrinter &p) { + ---------------- andykaylor wrote:
I don't like the blank line at the start of the function. I'm a little surprised clang-format doesn't remove that. https://github.com/llvm/llvm-project/pull/134333 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits