LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
14 #include "llvm/ADT/Twine.h"
17 #include <algorithm>
18 
19 using namespace llvm;
20 
21 const size_t MAX_LINE_LEN = 80U;
22 
23 static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
24  StringRef Suffix) {
25  size_t Pos = (size_t)OS.tell();
26  assert((MAX_LINE_LEN - Prefix.str().size() - Suffix.size() > 0) &&
27  "header line exceeds max limit");
28  OS << Prefix;
29  const size_t e = MAX_LINE_LEN - Suffix.size();
30  for (size_t i = (size_t)OS.tell() - Pos; i < e; ++i)
31  OS << Fill;
32  OS << Suffix << '\n';
33 }
34 
36  printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\");
37  printLine(OS, "|*", ' ', "*|");
38  size_t Pos = 0U;
39  size_t PosE;
40  StringRef Prefix("|*");
41  StringRef Suffix(" *|");
42  do{
43  size_t PSLen = Suffix.size() + Prefix.size();
44  PosE = Pos + ((MAX_LINE_LEN > (Desc.size() - PSLen)) ?
45  Desc.size() :
46  MAX_LINE_LEN - PSLen);
47  printLine(OS, Prefix + Desc.slice(Pos, PosE), ' ', Suffix);
48  Pos = PosE;
49  } while(Pos < Desc.size());
50  printLine(OS, Prefix, ' ', Suffix);
51  printLine(OS, Prefix + " Automatically generated file, do not edit!", ' ',
52  Suffix);
53  printLine(OS, Prefix, ' ', Suffix);
54  printLine(OS, "\\*===", '-', "===*/");
55  OS << '\n';
56 }
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
const size_t MAX_LINE_LEN
std::string str() const
str - Return the twine contents as a std::string.
Definition: Twine.cpp:16
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:85
void emitSourceFileHeader(StringRef Desc, raw_ostream &OS)
static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, StringRef Suffix)
StringRef slice(size_t Start, size_t End) const
Definition: StringRef.h:421