1 //===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides useful services for TableGen backends...
12 //===----------------------------------------------------------------------===//
14 #include "llvm/TableGen/TableGenBackend.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/raw_ostream.h"
20 const size_t MAX_LINE_LEN
= 80U;
22 static void printLine(raw_ostream
&OS
, const Twine
&Prefix
, char Fill
,
24 size_t Pos
= (size_t)OS
.tell();
25 assert((Prefix
.str().size() + Suffix
.size() <= MAX_LINE_LEN
) &&
26 "header line exceeds max limit");
28 for (size_t i
= (size_t)OS
.tell() - Pos
, e
= MAX_LINE_LEN
- Suffix
.size();
34 void llvm::emitSourceFileHeader(StringRef Desc
, raw_ostream
&OS
) {
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
);
43 size_t Length
= std::min(Desc
.size() - Pos
, MAX_LINE_LEN
- PSLen
);
44 printLine(OS
, Prefix
+ Desc
.substr(Pos
, Length
), ' ', Suffix
);
46 } while (Pos
< Desc
.size());
47 printLine(OS
, Prefix
, ' ', Suffix
);
48 printLine(OS
, Prefix
+ "Automatically generated file, do not edit!", ' ',
50 printLine(OS
, Prefix
, ' ', Suffix
);
51 printLine(OS
, "\\*===", '-', "===*/");