LLVM 19.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"
15#include "llvm/Support/Path.h"
17#include <algorithm>
18#include <cassert>
19#include <cstddef>
20
21using namespace llvm;
22
23const size_t MAX_LINE_LEN = 80U;
24
28 return new cl::opt<FnT>(cl::desc("Action to perform:"));
29}
30} // namespace llvm::TableGen::Emitter
31
32static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
33 StringRef Suffix) {
34 size_t Pos = (size_t)OS.tell();
35 assert((Prefix.str().size() + Suffix.size() <= MAX_LINE_LEN) &&
36 "header line exceeds max limit");
37 OS << Prefix;
38 for (size_t i = (size_t)OS.tell() - Pos, e = MAX_LINE_LEN - Suffix.size();
39 i < e; ++i)
40 OS << Fill;
41 OS << Suffix << '\n';
42}
43
45 const RecordKeeper &Record) {
46 printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\");
47 StringRef Prefix("|* ");
48 StringRef Suffix(" *|");
49 printLine(OS, Prefix, ' ', Suffix);
50 size_t PSLen = Prefix.size() + Suffix.size();
51 assert(PSLen < MAX_LINE_LEN);
52 size_t Pos = 0U;
53 do {
54 size_t Length = std::min(Desc.size() - Pos, MAX_LINE_LEN - PSLen);
55 printLine(OS, Prefix + Desc.substr(Pos, Length), ' ', Suffix);
56 Pos += Length;
57 } while (Pos < Desc.size());
58 printLine(OS, Prefix, ' ', Suffix);
59 printLine(OS, Prefix + "Automatically generated file, do not edit!", ' ',
60 Suffix);
61
62 // Print the filename of source file
63 if (!Record.getInputFilename().empty())
65 OS, Prefix + "From: " + sys::path::filename(Record.getInputFilename()),
66 ' ', Suffix);
67 printLine(OS, Prefix, ' ', Suffix);
68 printLine(OS, "\\*===", '-', "===*/");
69 OS << '\n';
70}
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 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:150
ManagedStatic< cl::opt< FnT >, OptCreatorT > Action
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:579
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:456
void emitSourceFileHeader(StringRef Desc, raw_ostream &OS, const RecordKeeper &Record=RecordKeeper())
emitSourceFileHeader - Output an LLVM style file header to the specified raw_ostream.
Description of the encoding of one expression Op.