1 //===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file provides useful services for TableGen backends...
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TableGen/TableGenBackend.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/raw_ostream.h"
19 const size_t MAX_LINE_LEN
= 80U;
21 static void printLine(raw_ostream
&OS
, const Twine
&Prefix
, char Fill
,
23 size_t Pos
= (size_t)OS
.tell();
24 assert((Prefix
.str().size() + Suffix
.size() <= MAX_LINE_LEN
) &&
25 "header line exceeds max limit");
27 for (size_t i
= (size_t)OS
.tell() - Pos
, e
= MAX_LINE_LEN
- Suffix
.size();
33 void llvm::emitSourceFileHeader(StringRef Desc
, raw_ostream
&OS
) {
34 printLine(OS
, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\");
35 StringRef
Prefix("|* ");
36 StringRef
Suffix(" *|");
37 printLine(OS
, Prefix
, ' ', Suffix
);
38 size_t PSLen
= Prefix
.size() + Suffix
.size();
39 assert(PSLen
< MAX_LINE_LEN
);
42 size_t Length
= std::min(Desc
.size() - Pos
, MAX_LINE_LEN
- PSLen
);
43 printLine(OS
, Prefix
+ Desc
.substr(Pos
, Length
), ' ', Suffix
);
45 } while (Pos
< Desc
.size());
46 printLine(OS
, Prefix
, ' ', Suffix
);
47 printLine(OS
, Prefix
+ "Automatically generated file, do not edit!", ' ',
49 printLine(OS
, Prefix
, ' ', Suffix
);
50 printLine(OS
, "\\*===", '-', "===*/");