@@ -42,13 +42,13 @@ using cir::MissingFeatures;
42
42
// CIR Custom Parser/Printer Signatures
43
43
// ===----------------------------------------------------------------------===//
44
44
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);
49
48
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);
52
52
static mlir::ParseResult parsePointerAddrSpace (mlir::AsmParser &p,
53
53
mlir::Attribute &addrSpaceAttr);
54
54
static void printPointerAddrSpace (mlir::AsmPrinter &p,
@@ -827,54 +827,31 @@ FuncType FuncType::clone(TypeRange inputs, TypeRange results) const {
827
827
return get (llvm::to_vector (inputs), results[0 ], isVarArg ());
828
828
}
829
829
830
- // A special parser is needed for function returning void to handle the missing
831
- // type.
832
- static mlir::ParseResult parseFuncTypeReturn (mlir::AsmParser &p,
833
- mlir::Type &optionalReturnType) {
834
- if (succeeded (p.parseOptionalArrow ())) {
835
- // `->` found. It must be followed by the return type.
836
- return p.parseType (optionalReturnType);
837
- }
838
- // Function has `void` return in C++, no return in MLIR.
839
- optionalReturnType = {};
840
- return success ();
841
- }
842
-
843
- // A special pretty-printer for function returning or not a result.
844
- static void printFuncTypeReturn (mlir::AsmPrinter &p,
845
- mlir::Type optionalReturnType) {
846
- if (optionalReturnType)
847
- p << " -> " << optionalReturnType;
848
- }
849
-
830
+ // Custom parser that parses function parameters of form `(<type>*, ...)`.
850
831
static mlir::ParseResult
851
- parseFuncTypeArgs (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> ¶ms,
852
- bool &isVarArg) {
832
+ parseFuncTypeParams (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> ¶ms,
833
+ bool &isVarArg) {
853
834
isVarArg = false ;
854
- if (failed (p.parseLParen ()))
855
- return failure ();
856
- if (succeeded (p.parseOptionalRParen ())) {
857
- // `()` empty argument list
858
- return mlir::success ();
859
- }
860
- do {
861
- if (succeeded (p.parseOptionalEllipsis ())) {
862
- // `...`, which must be the last thing in the list.
863
- isVarArg = true ;
864
- break ;
865
- } else {
866
- mlir::Type argType;
867
- if (failed (p.parseType (argType)))
868
- return failure ();
869
- params.push_back (argType);
870
- }
871
- } while (succeeded (p.parseOptionalComma ()));
872
- return p.parseRParen ();
835
+ return p.parseCommaSeparatedList (
836
+ AsmParser::Delimiter::Paren, [&]() -> mlir::ParseResult {
837
+ if (isVarArg)
838
+ return p.emitError (p.getCurrentLocation (),
839
+ " variadic `...` must be the last parameter" );
840
+ if (succeeded (p.parseOptionalEllipsis ())) {
841
+ isVarArg = true ;
842
+ return success ();
843
+ }
844
+ mlir::Type type;
845
+ if (failed (p.parseType (type)))
846
+ return failure ();
847
+ params.push_back (type);
848
+ return success ();
849
+ });
873
850
}
874
851
875
- static void printFuncTypeArgs (mlir::AsmPrinter &p,
876
- mlir::ArrayRef<mlir::Type> params,
877
- bool isVarArg) {
852
+ static void printFuncTypeParams (mlir::AsmPrinter &p,
853
+ mlir::ArrayRef<mlir::Type> params,
854
+ bool isVarArg) {
878
855
p << ' (' ;
879
856
llvm::interleaveComma (params, p,
880
857
[&p](mlir::Type type) { p.printType (type); });
@@ -886,23 +863,6 @@ static void printFuncTypeArgs(mlir::AsmPrinter &p,
886
863
p << ' )' ;
887
864
}
888
865
889
- // Use a custom parser to handle the optional return and argument types without
890
- // an optional anchor.
891
- static mlir::ParseResult parseFuncType (mlir::AsmParser &p,
892
- mlir::Type &optionalReturnType,
893
- llvm::SmallVector<mlir::Type> ¶ms,
894
- bool &isVarArg) {
895
- if (failed (parseFuncTypeArgs (p, params, isVarArg)))
896
- return failure ();
897
- return parseFuncTypeReturn (p, optionalReturnType);
898
- }
899
-
900
- static void printFuncType (mlir::AsmPrinter &p, mlir::Type optionalReturnType,
901
- mlir::ArrayRef<mlir::Type> params, bool isVarArg) {
902
- printFuncTypeArgs (p, params, isVarArg);
903
- printFuncTypeReturn (p, optionalReturnType);
904
- }
905
-
906
866
// / Get the C-style return type of the function, which is !cir.void if the
907
867
// / function returns nothing and the actual return type otherwise.
908
868
mlir::Type FuncType::getReturnType () const {
0 commit comments