Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/GlobalISel/CodeExpander.h
35315 views
//===- CodeExpander.h - Expand variables in a string ------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8/// \file Expand the variables in a string.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_UTILS_TABLEGEN_CODEEXPANDER_H13#define LLVM_UTILS_TABLEGEN_CODEEXPANDER_H1415#include "llvm/ADT/ArrayRef.h"16#include "llvm/ADT/StringRef.h"1718namespace llvm {19class CodeExpansions;20class SMLoc;21class raw_ostream;2223/// Emit the given code with all '${foo}' placeholders expanded to their24/// replacements.25///26/// It's an error to use an undefined expansion and expansion-like output that27/// needs to be emitted verbatim can be escaped as '\${foo}'28///29/// The emitted code can be given a custom indent to enable both indentation by30/// an arbitrary amount of whitespace and emission of the code as a comment.31class CodeExpander {32StringRef Code;33const CodeExpansions &Expansions;34const ArrayRef<SMLoc> &Loc;35bool ShowExpansions;36StringRef Indent;3738public:39CodeExpander(StringRef Code, const CodeExpansions &Expansions,40const ArrayRef<SMLoc> &Loc, bool ShowExpansions,41StringRef Indent = " ")42: Code(Code), Expansions(Expansions), Loc(Loc),43ShowExpansions(ShowExpansions), Indent(Indent) {}4445void emit(raw_ostream &OS) const;46};4748inline raw_ostream &operator<<(raw_ostream &OS, const CodeExpander &Expander) {49Expander.emit(OS);50return OS;51}52} // end namespace llvm5354#endif // ifndef LLVM_UTILS_TABLEGEN_CODEEXPANDER_H555657