blob: 7c8367ab9dfea61fe901863fed6405bbfdc029f1 [file] [log] [blame]
Jakob Stoklund Olesen1c66b872012-06-13 05:15:49 +00001//===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===//
Misha Brukman650ba8e2005-04-22 00:00:37 +00002//
John Criswelld3032032003-10-20 20:20:30 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner8adcd9f2007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman650ba8e2005-04-22 00:00:37 +00007//
John Criswelld3032032003-10-20 20:20:30 +00008//===----------------------------------------------------------------------===//
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00009//
10// This file provides useful services for TableGen backends...
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer83aa9472012-06-19 17:04:16 +000014#include "llvm/ADT/Twine.h"
Jakob Stoklund Olesen1c66b872012-06-13 05:15:49 +000015#include "llvm/Support/raw_ostream.h"
Peter Collingbourne84c287e2011-10-01 16:41:13 +000016#include "llvm/TableGen/TableGenBackend.h"
Chris Lattner68478662004-08-01 03:55:39 +000017using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000018
Benjamin Kramer83aa9472012-06-19 17:04:16 +000019static 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
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000028void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) {
Benjamin Kramer83aa9472012-06-19 17:04:16 +000029 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';
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000037}