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"
15 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/TableGen/TableGenBackend.h"
17 using namespace llvm;
18
printLine(raw_ostream & OS,const Twine & Prefix,char Fill,StringRef Suffix)19 static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
20 StringRef Suffix) {
21 uint64_t Pos = OS.tell();
22 OS << Prefix;
23 for (unsigned i = OS.tell() - Pos, e = 80 - Suffix.size(); i != e; ++i)
24 OS << Fill;
25 OS << Suffix << '\n';
26 }
27
emitSourceFileHeader(StringRef Desc,raw_ostream & OS)28 void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) {
29 printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\");
30 printLine(OS, "|*", ' ', "*|");
31 printLine(OS, "|* " + Desc, ' ', "*|");
32 printLine(OS, "|*", ' ', "*|");
33 printLine(OS, "|* Automatically generated file, do not edit!", ' ', "*|");
34 printLine(OS, "|*", ' ', "*|");
35 printLine(OS, "\\*===", '-', "===*/");
36 OS << '\n';
37 }
38