LLVM API Documentation
00001 //===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file provides useful services for TableGen backends... 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/ADT/Twine.h" 00015 #include "llvm/Support/raw_ostream.h" 00016 #include "llvm/TableGen/TableGenBackend.h" 00017 #include <algorithm> 00018 00019 using namespace llvm; 00020 00021 const size_t MAX_LINE_LEN = 80U; 00022 00023 static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, 00024 StringRef Suffix) { 00025 size_t Pos = (size_t)OS.tell(); 00026 assert((MAX_LINE_LEN - Prefix.str().size() - Suffix.size() > 0) && 00027 "header line exceeds max limit"); 00028 OS << Prefix; 00029 const size_t e = MAX_LINE_LEN - Suffix.size(); 00030 for (size_t i = (size_t)OS.tell() - Pos; i < e; ++i) 00031 OS << Fill; 00032 OS << Suffix << '\n'; 00033 } 00034 00035 void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) { 00036 printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\"); 00037 printLine(OS, "|*", ' ', "*|"); 00038 size_t Pos = 0U; 00039 size_t PosE; 00040 StringRef Prefix("|*"); 00041 StringRef Suffix(" *|"); 00042 do{ 00043 size_t PSLen = Suffix.size() + Prefix.size(); 00044 PosE = Pos + ((MAX_LINE_LEN > (Desc.size() - PSLen)) ? 00045 Desc.size() : 00046 MAX_LINE_LEN - PSLen); 00047 printLine(OS, Prefix + Desc.slice(Pos, PosE), ' ', Suffix); 00048 Pos = PosE; 00049 } while(Pos < Desc.size()); 00050 printLine(OS, Prefix, ' ', Suffix); 00051 printLine(OS, Prefix + " Automatically generated file, do not edit!", ' ', 00052 Suffix); 00053 printLine(OS, Prefix, ' ', Suffix); 00054 printLine(OS, "\\*===", '-', "===*/"); 00055 OS << '\n'; 00056 }