LLVM  8.0.1
TableGenBackend.cpp
Go to the documentation of this file.
1 //===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides useful services for TableGen backends...
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/Twine.h"
17 
18 using namespace llvm;
19 
20 const size_t MAX_LINE_LEN = 80U;
21 
22 static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
23  StringRef Suffix) {
24  size_t Pos = (size_t)OS.tell();
25  assert((Prefix.str().size() + Suffix.size() <= MAX_LINE_LEN) &&
26  "header line exceeds max limit");
27  OS << Prefix;
28  for (size_t i = (size_t)OS.tell() - Pos, e = MAX_LINE_LEN - Suffix.size();
29  i < e; ++i)
30  OS << Fill;
31  OS << Suffix << '\n';
32 }
33 
35  printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\");
36  StringRef Prefix("|* ");
37  StringRef Suffix(" *|");
38  printLine(OS, Prefix, ' ', Suffix);
39  size_t PSLen = Prefix.size() + Suffix.size();
40  assert(PSLen < MAX_LINE_LEN);
41  size_t Pos = 0U;
42  do {
43  size_t Length = std::min(Desc.size() - Pos, MAX_LINE_LEN - PSLen);
44  printLine(OS, Prefix + Desc.substr(Pos, Length), ' ', Suffix);
45  Pos += Length;
46  } while (Pos < Desc.size());
47  printLine(OS, Prefix, ' ', Suffix);
48  printLine(OS, Prefix + "Automatically generated file, do not edit!", ' ',
49  Suffix);
50  printLine(OS, Prefix, ' ', Suffix);
51  printLine(OS, "\\*===", '-', "===*/");
52  OS << '\n';
53 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
const size_t MAX_LINE_LEN
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
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:18
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:100
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49