LLVM 17.0.0git
TableGenBackend.cpp
Go to the documentation of this file.
1//===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides useful services for TableGen backends...
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/Twine.h"
16#include <algorithm>
17#include <cassert>
18#include <cstddef>
19
20using namespace llvm;
21
22const size_t MAX_LINE_LEN = 80U;
23
27 return new cl::opt<FnT>(cl::desc("Action to perform:"));
28}
29} // namespace llvm::TableGen::Emitter
30
31static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
32 StringRef Suffix) {
33 size_t Pos = (size_t)OS.tell();
34 assert((Prefix.str().size() + Suffix.size() <= MAX_LINE_LEN) &&
35 "header line exceeds max limit");
36 OS << Prefix;
37 for (size_t i = (size_t)OS.tell() - Pos, e = MAX_LINE_LEN - Suffix.size();
38 i < e; ++i)
39 OS << Fill;
40 OS << Suffix << '\n';
41}
42
44 printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\");
45 StringRef Prefix("|* ");
46 StringRef Suffix(" *|");
47 printLine(OS, Prefix, ' ', Suffix);
48 size_t PSLen = Prefix.size() + Suffix.size();
49 assert(PSLen < MAX_LINE_LEN);
50 size_t Pos = 0U;
51 do {
52 size_t Length = std::min(Desc.size() - Pos, MAX_LINE_LEN - PSLen);
53 printLine(OS, Prefix + Desc.substr(Pos, Length), ' ', Suffix);
54 Pos += Length;
55 } while (Pos < Desc.size());
56 printLine(OS, Prefix, ' ', Suffix);
57 printLine(OS, Prefix + "Automatically generated file, do not edit!", ' ',
58 Suffix);
59 printLine(OS, Prefix, ' ', Suffix);
60 printLine(OS, "\\*===", '-', "===*/");
61 OS << '\n';
62}
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
const size_t MAX_LINE_LEN
static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, StringRef Suffix)
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:575
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:134
ManagedStatic< cl::opt< FnT >, OptCreatorT > Action
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:440
void emitSourceFileHeader(StringRef Desc, raw_ostream &OS)
emitSourceFileHeader - Output an LLVM style file header to the specified raw_ostream.