From 0229e2b96ec58f83b35a532a72c63c24d855e51e Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Mon, 28 Jan 2013 07:35:33 +0000 Subject: [PATCH] =?UTF-8?q?A=20bugfix=20for=20tblgen,=20in=20the=20functio?= =?UTF-8?q?n=20=E2=80=98emitSourceFileHeader=E2=80=99.=20When=20the=20firs?= =?UTF-8?q?t=20parameter=20(=E2=80=98Desc=E2=80=99)=20is=20more=20than=208?= =?UTF-8?q?0=20characters=20long,=20it=20will=20result=20the=20header=20li?= =?UTF-8?q?ne=20that=20contains=20the=20description=20to=20be=20more=20Tha?= =?UTF-8?q?n=20(4GB!)=20long.=20Not=20only=20it=20takes=20forever=20to=20p?= =?UTF-8?q?roduce,=20the=20output=20file=20cannot=20be=20open,=20since=20i?= =?UTF-8?q?ts=20ginormous.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Elior Malul. llvm-svn: 173672 --- lib/TableGen/TableGenBackend.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/TableGen/TableGenBackend.cpp b/lib/TableGen/TableGenBackend.cpp index 7c8367ab9df..79d567753a6 100644 --- a/lib/TableGen/TableGenBackend.cpp +++ b/lib/TableGen/TableGenBackend.cpp @@ -14,13 +14,20 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TableGen/TableGenBackend.h" +#include + 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((MAX_LINE_LEN - Prefix.str().size() - Suffix.size() > 0) && + "header line exceeds max limit"); OS << Prefix; - for (unsigned i = OS.tell() - Pos, e = 80 - Suffix.size(); i != e; ++i) + const size_t e = MAX_LINE_LEN - Suffix.size(); + for (size_t i = (size_t)OS.tell() - Pos; i < e; ++i) OS << Fill; OS << Suffix << '\n'; } @@ -28,10 +35,22 @@ static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, 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, "|*", ' ', "*|"); + size_t Pos = 0U; + size_t PosE; + StringRef Prefix("|*"); + StringRef Suffix(" *|"); + do{ + size_t PSLen = Suffix.size() + Prefix.size(); + PosE = Pos + ((MAX_LINE_LEN > (Desc.size() - PSLen)) ? + Desc.size() : + MAX_LINE_LEN - PSLen); + printLine(OS, Prefix + Desc.slice(Pos, PosE), ' ', Suffix); + Pos = PosE; + } 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'; }