LLVM  10.0.0svn
TableGenBackend.cpp
Go to the documentation of this file.
1 //===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===//
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 // This file provides useful services for TableGen backends...
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/ADT/Twine.h"
16 
17 using namespace llvm;
18 
19 const size_t MAX_LINE_LEN = 80U;
20 
21 static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
22  StringRef Suffix) {
23  size_t Pos = (size_t)OS.tell();
24  assert((Prefix.str().size() + Suffix.size() <= MAX_LINE_LEN) &&
25  "header line exceeds max limit");
26  OS << Prefix;
27  for (size_t i = (size_t)OS.tell() - Pos, e = MAX_LINE_LEN - Suffix.size();
28  i < e; ++i)
29  OS << Fill;
30  OS << Suffix << '\n';
31 }
32 
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);
40  size_t Pos = 0U;
41  do {
42  size_t Length = std::min(Desc.size() - Pos, MAX_LINE_LEN - PSLen);
43  printLine(OS, Prefix + Desc.substr(Pos, Length), ' ', Suffix);
44  Pos += Length;
45  } while (Pos < Desc.size());
46  printLine(OS, Prefix, ' ', Suffix);
47  printLine(OS, Prefix + "Automatically generated file, do not edit!", ' ',
48  Suffix);
49  printLine(OS, Prefix, ' ', Suffix);
50  printLine(OS, "\\*===", '-', "===*/");
51  OS << '\n';
52 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
const size_t MAX_LINE_LEN
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:592
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:144
void emitSourceFileHeader(StringRef Desc, raw_ostream &OS)
emitSourceFileHeader - Output an LLVM style file header to the specified raw_ostream.
static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, StringRef Suffix)
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:111
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48