brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 7cead35 Raw
43 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// Defines common utilities for generating cpp files from tablegen10// structures.11//12//===----------------------------------------------------------------------===//13 14#include "CppGenUtilities.h"15#include "mlir/Support/IndentedOstream.h"16 17void mlir::tblgen::emitSummaryAndDescComments(llvm::raw_ostream &os,18                                              llvm::StringRef summary,19                                              llvm::StringRef description,20                                              bool terminateComment) {21  StringRef trimmedSummary = summary.trim();22  StringRef trimmedDesc = description.trim();23  raw_indented_ostream ros(os);24 25  bool empty = true;26  if (!trimmedSummary.empty()) {27    ros.printReindented(trimmedSummary, "/// ");28    empty = false;29  }30 31  if (!trimmedDesc.empty()) {32    if (!empty) {33      // If there is a summary, add a newline after it.34      ros << "\n";35    }36    ros.printReindented(trimmedDesc, "/// ");37    empty = false;38  }39 40  if (!empty && terminateComment)41    ros << "\n";42}43