[llvm] [NFC][TableGen] Add IfGuardEmitter and adopt it in InstrInfoEmitter (PR #168616)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 18 16:48:55 PST 2025
================
@@ -46,6 +46,23 @@ class IfDefEmitter {
bool LateUndef;
};
+// Simple RAII helper for emitting #if guard. It emits:
+// #if <Condition>
+// #endif // <Condition>
+class IfGuardEmitter {
+public:
+ IfGuardEmitter(raw_ostream &OS, StringRef Condition)
+ : Condition(Condition.str()), OS(OS) {
+ OS << "#if " << Condition << "\n\n";
+ }
+
+ ~IfGuardEmitter() { OS << "\n#endif // " << Condition << "\n\n"; }
+
+private:
+ std::string Condition;
----------------
jurahul wrote:
I anticipate use cases where condition can be a temporary value just like in other emitters, so creating a copy. Also, for uniformity with other emitters, creating a copy.
https://github.com/llvm/llvm-project/pull/168616
More information about the llvm-commits
mailing list