| 1 | //===- CppGenUtilities.cpp - MLIR cpp gen utilities --------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Defines common utilities for generating cpp files from tablegen |
| 10 | // structures. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CppGenUtilities.h" |
| 15 | #include "mlir/Support/IndentedOstream.h" |
| 16 | |
| 17 | std::string |
| 18 | mlir::tblgen::emitSummaryAndDescComments(llvm::StringRef summary, |
| 19 | llvm::StringRef description) { |
| 20 | |
| 21 | std::string comments = ""; |
| 22 | StringRef trimmedSummary = summary.trim(); |
| 23 | StringRef trimmedDesc = description.trim(); |
| 24 | llvm::raw_string_ostream os(comments); |
| 25 | raw_indented_ostream ros(os); |
| 26 | |
| 27 | if (!trimmedSummary.empty()) { |
| 28 | ros.printReindented(str: trimmedSummary, extraPrefix: "/// "); |
| 29 | } |
| 30 | |
| 31 | if (!trimmedDesc.empty()) { |
| 32 | if (!trimmedSummary.empty()) { |
| 33 | // If there is a summary, add a newline after it. |
| 34 | ros << "\n"; |
| 35 | } |
| 36 | ros.printReindented(str: trimmedDesc, extraPrefix: "/// "); |
| 37 | } |
| 38 | return comments; |
| 39 | } |
| 40 |
