[InstCombine] Signed saturation patterns
[llvm-complete.git] / utils / TableGen / GlobalISel / CodeExpander.h
blobbd6946de592589e23389a598094f1feb6173c7af
1 //===- CodeExpander.h - Expand variables in a string ----------------------===//
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_CODEEXPANDER_H
14 #define LLVM_UTILS_TABLEGEN_CODEEXPANDER_H
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/SMLoc.h"
20 namespace llvm {
21 class CodeExpansions;
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 const 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 // ifndef LLVM_UTILS_TABLEGEN_CODEEXPANDER_H