[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / utils / TableGen / Common / GlobalISel / CodeExpander.h
blobbfcdc2a0813bcb8a973992e3388a13613441d039
1 //===- CodeExpander.h - Expand variables in a string ------------*- 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 /// \file Expand the variables in a string.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANDER_H
14 #define LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANDER_H
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/StringRef.h"
19 namespace llvm {
20 class CodeExpansions;
21 class SMLoc;
22 class raw_ostream;
24 /// Emit the given code with all '${foo}' placeholders expanded to their
25 /// replacements.
26 ///
27 /// It's an error to use an undefined expansion and expansion-like output that
28 /// needs to be emitted verbatim can be escaped as '\${foo}'
29 ///
30 /// The emitted code can be given a custom indent to enable both indentation by
31 /// an arbitrary amount of whitespace and emission of the code as a comment.
32 class CodeExpander {
33 StringRef Code;
34 const CodeExpansions &Expansions;
35 ArrayRef<SMLoc> Loc;
36 bool ShowExpansions;
37 StringRef Indent;
39 public:
40 CodeExpander(StringRef Code, const CodeExpansions &Expansions,
41 const ArrayRef<SMLoc> &Loc, bool ShowExpansions,
42 StringRef Indent = " ")
43 : Code(Code), Expansions(Expansions), Loc(Loc),
44 ShowExpansions(ShowExpansions), Indent(Indent) {}
46 void emit(raw_ostream &OS) const;
49 inline raw_ostream &operator<<(raw_ostream &OS, const CodeExpander &Expander) {
50 Expander.emit(OS);
51 return OS;
53 } // end namespace llvm
55 #endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANDER_H