2012-08-15 19:34:23 +00:00
|
|
|
//===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===//
|
2009-06-02 17:52:33 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides useful services for TableGen backends...
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-05-27 18:44:32 +00:00
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
2012-08-15 19:34:23 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2013-04-08 18:41:23 +00:00
|
|
|
const size_t MAX_LINE_LEN = 80U;
|
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
|
|
|
|
StringRef Suffix) {
|
2013-04-08 18:41:23 +00:00
|
|
|
size_t Pos = (size_t)OS.tell();
|
2015-05-27 18:44:32 +00:00
|
|
|
assert((Prefix.str().size() + Suffix.size() <= MAX_LINE_LEN) &&
|
|
|
|
"header line exceeds max limit");
|
2012-08-15 19:34:23 +00:00
|
|
|
OS << Prefix;
|
2015-05-27 18:44:32 +00:00
|
|
|
for (size_t i = (size_t)OS.tell() - Pos, e = MAX_LINE_LEN - Suffix.size();
|
|
|
|
i < e; ++i)
|
2012-08-15 19:34:23 +00:00
|
|
|
OS << Fill;
|
|
|
|
OS << Suffix << '\n';
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) {
|
|
|
|
printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\");
|
2015-05-27 18:44:32 +00:00
|
|
|
StringRef Prefix("|* ");
|
2013-04-08 18:41:23 +00:00
|
|
|
StringRef Suffix(" *|");
|
|
|
|
printLine(OS, Prefix, ' ', Suffix);
|
2015-05-27 18:44:32 +00:00
|
|
|
size_t PSLen = Prefix.size() + Suffix.size();
|
|
|
|
assert(PSLen < MAX_LINE_LEN);
|
|
|
|
size_t Pos = 0U;
|
|
|
|
do {
|
|
|
|
size_t Length = std::min(Desc.size() - Pos, MAX_LINE_LEN - PSLen);
|
|
|
|
printLine(OS, Prefix + Desc.substr(Pos, Length), ' ', Suffix);
|
|
|
|
Pos += Length;
|
|
|
|
} while (Pos < Desc.size());
|
|
|
|
printLine(OS, Prefix, ' ', Suffix);
|
|
|
|
printLine(OS, Prefix + "Automatically generated file, do not edit!", ' ',
|
2013-04-08 18:41:23 +00:00
|
|
|
Suffix);
|
|
|
|
printLine(OS, Prefix, ' ', Suffix);
|
2012-08-15 19:34:23 +00:00
|
|
|
printLine(OS, "\\*===", '-', "===*/");
|
|
|
|
OS << '\n';
|
|
|
|
}
|