Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions llvm/include/llvm/TableGen/CodeGenHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ class IfDefEmitter {
raw_ostream &OS;
};

// Simple RAII helper for emitting header include guard (ifndef-define-endif).
class IncludeGuardEmitter {
public:
IncludeGuardEmitter(raw_ostream &OS, StringRef Name)
: Name(Name.str()), OS(OS) {
OS << "#ifndef " << Name << "\n"
<< "#define " << Name << "\n\n";
}
~IncludeGuardEmitter() { OS << "\n#endif // " << Name << "\n"; }

private:
std::string Name;
raw_ostream &OS;
};

// Simple RAII helper for emitting namespace scope. Name can be a single
// namespace (empty for anonymous namespace) or nested namespace.
class NamespaceEmitter {
Expand Down
1 change: 1 addition & 0 deletions llvm/test/TableGen/directive1.td
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// CHECK-NEXT: static constexpr bool is_iterable = true;
// CHECK-NEXT: };
// CHECK-NEXT: } // namespace llvm
// CHECK-EMPTY:
// CHECK-NEXT: #endif // LLVM_Tdl_INC


Expand Down
1 change: 1 addition & 0 deletions llvm/test/TableGen/directive2.td
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// CHECK-NEXT: static constexpr bool is_iterable = true;
// CHECK-NEXT: };
// CHECK-NEXT: } // namespace llvm
// CHECK-EMPTY:
// CHECK-NEXT: #endif // LLVM_Tdl_INC

// IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
Expand Down
6 changes: 2 additions & 4 deletions llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,9 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
return;

StringRef Lang = DirLang.getName();
IncludeGuardEmitter IncGuard(OS, (Twine("LLVM_") + Lang + "_INC").str());

OS << "#ifndef LLVM_" << Lang << "_INC\n";
OS << "#define LLVM_" << Lang << "_INC\n";
OS << "\n#include \"llvm/ADT/ArrayRef.h\"\n";
OS << "#include \"llvm/ADT/ArrayRef.h\"\n";

if (DirLang.hasEnableBitmaskEnumInNamespace())
OS << "#include \"llvm/ADT/BitmaskEnum.h\"\n";
Expand Down Expand Up @@ -370,7 +369,6 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
OS << "};\n";
}
LlvmNS.close();
OS << "#endif // LLVM_" << Lang << "_INC\n";
}

// Given a list of spellings (for a given clause/directive), order them
Expand Down