@@ -42,13 +42,13 @@ using cir::MissingFeatures;
4242// CIR Custom Parser/Printer Signatures
4343// ===----------------------------------------------------------------------===//
4444
45- static mlir::ParseResult parseFuncType (mlir::AsmParser &p,
46- mlir::Type &optionalReturnTypes,
47- llvm::SmallVector<mlir::Type> ¶ms,
48- bool &isVarArg);
45+ static mlir::ParseResult
46+ parseFuncTypeParams (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> ¶ms,
47+ bool &isVarArg);
4948
50- static void printFuncType (mlir::AsmPrinter &p, mlir::Type optionalReturnTypes,
51- mlir::ArrayRef<mlir::Type> params, bool isVarArg);
49+ static void printFuncTypeParams (mlir::AsmPrinter &p,
50+ mlir::ArrayRef<mlir::Type> params,
51+ bool isVarArg);
5252static mlir::ParseResult parsePointerAddrSpace (mlir::AsmParser &p,
5353 mlir::Attribute &addrSpaceAttr);
5454static void printPointerAddrSpace (mlir::AsmPrinter &p,
@@ -933,54 +933,31 @@ FuncType FuncType::clone(TypeRange inputs, TypeRange results) const {
933933 return get (llvm::to_vector (inputs), results[0 ], isVarArg ());
934934}
935935
936- // A special parser is needed for function returning void to handle the missing
937- // type.
938- static mlir::ParseResult parseFuncTypeReturn (mlir::AsmParser &p,
939- mlir::Type &optionalReturnType) {
940- if (succeeded (p.parseOptionalArrow ())) {
941- // `->` found. It must be followed by the return type.
942- return p.parseType (optionalReturnType);
943- }
944- // Function has `void` return in C++, no return in MLIR.
945- optionalReturnType = {};
946- return success ();
947- }
948-
949- // A special pretty-printer for function returning or not a result.
950- static void printFuncTypeReturn (mlir::AsmPrinter &p,
951- mlir::Type optionalReturnType) {
952- if (optionalReturnType)
953- p << " -> " << optionalReturnType;
954- }
955-
936+ // Custom parser that parses function parameters of form `(<type>*, ...)`.
956937static mlir::ParseResult
957- parseFuncTypeArgs (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> ¶ms,
958- bool &isVarArg) {
938+ parseFuncTypeParams (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> ¶ms,
939+ bool &isVarArg) {
959940 isVarArg = false ;
960- if (failed (p.parseLParen ()))
961- return failure ();
962- if (succeeded (p.parseOptionalRParen ())) {
963- // `()` empty argument list
964- return mlir::success ();
965- }
966- do {
967- if (succeeded (p.parseOptionalEllipsis ())) {
968- // `...`, which must be the last thing in the list.
969- isVarArg = true ;
970- break ;
971- } else {
972- mlir::Type argType;
973- if (failed (p.parseType (argType)))
974- return failure ();
975- params.push_back (argType);
976- }
977- } while (succeeded (p.parseOptionalComma ()));
978- return p.parseRParen ();
941+ return p.parseCommaSeparatedList (
942+ AsmParser::Delimiter::Paren, [&]() -> mlir::ParseResult {
943+ if (isVarArg)
944+ return p.emitError (p.getCurrentLocation (),
945+ " variadic `...` must be the last parameter" );
946+ if (succeeded (p.parseOptionalEllipsis ())) {
947+ isVarArg = true ;
948+ return success ();
949+ }
950+ mlir::Type type;
951+ if (failed (p.parseType (type)))
952+ return failure ();
953+ params.push_back (type);
954+ return success ();
955+ });
979956}
980957
981- static void printFuncTypeArgs (mlir::AsmPrinter &p,
982- mlir::ArrayRef<mlir::Type> params,
983- bool isVarArg) {
958+ static void printFuncTypeParams (mlir::AsmPrinter &p,
959+ mlir::ArrayRef<mlir::Type> params,
960+ bool isVarArg) {
984961 p << ' (' ;
985962 llvm::interleaveComma (params, p,
986963 [&p](mlir::Type type) { p.printType (type); });
@@ -992,23 +969,6 @@ static void printFuncTypeArgs(mlir::AsmPrinter &p,
992969 p << ' )' ;
993970}
994971
995- // Use a custom parser to handle the optional return and argument types without
996- // an optional anchor.
997- static mlir::ParseResult parseFuncType (mlir::AsmParser &p,
998- mlir::Type &optionalReturnType,
999- llvm::SmallVector<mlir::Type> ¶ms,
1000- bool &isVarArg) {
1001- if (failed (parseFuncTypeArgs (p, params, isVarArg)))
1002- return failure ();
1003- return parseFuncTypeReturn (p, optionalReturnType);
1004- }
1005-
1006- static void printFuncType (mlir::AsmPrinter &p, mlir::Type optionalReturnType,
1007- mlir::ArrayRef<mlir::Type> params, bool isVarArg) {
1008- printFuncTypeArgs (p, params, isVarArg);
1009- printFuncTypeReturn (p, optionalReturnType);
1010- }
1011-
1012972// / Get the C-style return type of the function, which is !cir.void if the
1013973// / function returns nothing and the actual return type otherwise.
1014974mlir::Type FuncType::getReturnType () const {
0 commit comments