blob: 7c8367ab9dfea61fe901863fed6405bbfdc029f1 [file] [log] [blame]
Jakob Stoklund Olesen764dc752012-06-13 05:15:49 +00001//===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
John Criswell01d45822003-10-20 20:20:30 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-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 Brukman3da94ae2005-04-22 00:00:37 +00007//
John Criswell01d45822003-10-20 20:20:30 +00008//===----------------------------------------------------------------------===//
Chris Lattner2c0f2c72003-08-06 04:23:04 +00009//
10// This file provides useful services for TableGen backends...
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer90540ad2012-06-19 17:04:16 +000014#include "llvm/ADT/Twine.h"
Jakob Stoklund Olesen764dc752012-06-13 05:15:49 +000015#include "llvm/Support/raw_ostream.h"
Peter Collingbourne7c788882011-10-01 16:41:13 +000016#include "llvm/TableGen/TableGenBackend.h"
Chris Lattner2082ebe2004-08-01 03:55:39 +000017using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000018
Benjamin Kramer90540ad2012-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 Olesen6f36fa92012-06-11 15:37:55 +000028void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) {
Benjamin Kramer90540ad2012-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 Lattner2c0f2c72003-08-06 04:23:04 +000037}