X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTableGen%2FTableGenBackend.cpp;h=77ed8414b15f978eaba530c0f0351b14eec2184d;hb=d77e9352a80c954cf91335c236224e4ca7d9c5f4;hp=7c8367ab9dfea61fe901863fed6405bbfdc029f1;hpb=90540ad7992d0ce490eb862543a58d040d7a2316;p=oota-llvm.git diff --git a/lib/TableGen/TableGenBackend.cpp b/lib/TableGen/TableGenBackend.cpp index 7c8367ab9df..77ed8414b15 100644 --- a/lib/TableGen/TableGenBackend.cpp +++ b/lib/TableGen/TableGenBackend.cpp @@ -11,27 +11,43 @@ // //===----------------------------------------------------------------------===// +#include "llvm/TableGen/TableGenBackend.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/TableGen/TableGenBackend.h" + using namespace llvm; +const size_t MAX_LINE_LEN = 80U; + static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, StringRef Suffix) { - uint64_t Pos = OS.tell(); + size_t Pos = (size_t)OS.tell(); + assert((Prefix.str().size() + Suffix.size() <= MAX_LINE_LEN) && + "header line exceeds max limit"); OS << Prefix; - for (unsigned i = OS.tell() - Pos, e = 80 - Suffix.size(); i != e; ++i) + for (size_t i = (size_t)OS.tell() - Pos, e = MAX_LINE_LEN - Suffix.size(); + i < e; ++i) OS << Fill; OS << Suffix << '\n'; } void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) { printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\"); - printLine(OS, "|*", ' ', "*|"); - printLine(OS, "|* " + Desc, ' ', "*|"); - printLine(OS, "|*", ' ', "*|"); - printLine(OS, "|* Automatically generated file, do not edit!", ' ', "*|"); - printLine(OS, "|*", ' ', "*|"); + StringRef Prefix("|* "); + StringRef Suffix(" *|"); + printLine(OS, Prefix, ' ', Suffix); + 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!", ' ', + Suffix); + printLine(OS, Prefix, ' ', Suffix); printLine(OS, "\\*===", '-', "===*/"); OS << '\n'; }