From 49be18cfc69098c6a740b52db3c80869c12e1fc6 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Fri, 16 Jan 2009 07:02:28 +0000 Subject: [PATCH] Registry.h should not depend on CommandLine.h. Split Support/Registry.h into two files so that we have less to recompile every time CommandLine.h is changed. llvm-svn: 62312 --- include/llvm/Support/Registry.h | 30 +--------- include/llvm/Support/RegistryParser.h | 55 +++++++++++++++++++ include/llvm/Target/TargetMachineRegistry.h | 1 + lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp | 1 + lib/CodeGen/OcamlGC.cpp | 1 + .../SelectionDAG/SelectionDAGBuild.cpp | 1 + lib/CodeGen/ShadowStackGC.cpp | 1 + lib/ExecutionEngine/JIT/TargetSelect.cpp | 3 +- tools/llc/llc.cpp | 5 +- 9 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 include/llvm/Support/RegistryParser.h diff --git a/include/llvm/Support/Registry.h b/include/llvm/Support/Registry.h index 5a7d7fa65e3..454679bda83 100644 --- a/include/llvm/Support/Registry.h +++ b/include/llvm/Support/Registry.h @@ -14,8 +14,6 @@ #ifndef LLVM_SUPPORT_REGISTRY_H #define LLVM_SUPPORT_REGISTRY_H -#include "llvm/Support/CommandLine.h" - namespace llvm { /// A simple registry entry which provides only a name, description, and /// no-argument constructor. @@ -204,33 +202,7 @@ namespace llvm { : Entry(Name, Desc, CtorFn), Node(Entry) {} }; - - /// A command-line parser for a registry. Use like such: - /// - /// static cl::opt::entry, false, - /// Registry::Parser> - /// GCOpt("gc", cl::desc("Garbage collector to use."), - /// cl::value_desc()); - /// - /// To make use of the value: - /// - /// Collector *TheCollector = GCOpt->instantiate(); - /// - class Parser : public cl::parser, public listener{ - typedef U traits; - typedef typename U::entry entry; - - protected: - void registered(const entry &E) { - addLiteralOption(traits::nameof(E), &E, traits::descof(E)); - } - - public: - void initialize(cl::Option &O) { - listener::init(); - cl::parser::initialize(O); - } - }; + /// Registry::Parser now lives in llvm/Support/RegistryParser.h. }; diff --git a/include/llvm/Support/RegistryParser.h b/include/llvm/Support/RegistryParser.h new file mode 100644 index 00000000000..2cc578370fe --- /dev/null +++ b/include/llvm/Support/RegistryParser.h @@ -0,0 +1,55 @@ +//=== RegistryParser.h - Linker-supported plugin registries -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Defines a command-line parser for a registry. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_REGISTRY_PARSER_H +#define LLVM_SUPPORT_REGISTRY_PARSER_H + +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Registry.h" + +namespace llvm { + + /// A command-line parser for a registry. Use like such: + /// + /// static cl::opt::entry, false, + /// RegistryParser > + /// GCOpt("gc", cl::desc("Garbage collector to use."), + /// cl::value_desc()); + /// + /// To make use of the value: + /// + /// Collector *TheCollector = GCOpt->instantiate(); + /// + template > + class RegistryParser : + public cl::parser, + public Registry::listener { + typedef U traits; + typedef typename U::entry entry; + typedef typename Registry::listener listener; + + protected: + void registered(const entry &E) { + addLiteralOption(traits::nameof(E), &E, traits::descof(E)); + } + + public: + void initialize(cl::Option &O) { + listener::init(); + cl::parser::initialize(O); + } + }; + +} + +#endif // LLVM_SUPPORT_REGISTRY_PARSER_H diff --git a/include/llvm/Target/TargetMachineRegistry.h b/include/llvm/Target/TargetMachineRegistry.h index d14308547ea..b7ea448b203 100644 --- a/include/llvm/Target/TargetMachineRegistry.h +++ b/include/llvm/Target/TargetMachineRegistry.h @@ -17,6 +17,7 @@ #ifndef LLVM_TARGET_TARGETMACHINEREGISTRY_H #define LLVM_TARGET_TARGETMACHINEREGISTRY_H +#include "llvm/Module.h" #include "llvm/Support/Registry.h" namespace llvm { diff --git a/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp b/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp index d2e8d0026bf..8ba903a65d7 100644 --- a/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp @@ -15,6 +15,7 @@ #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/GCMetadataPrinter.h" #include "llvm/Module.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetData.h" diff --git a/lib/CodeGen/OcamlGC.cpp b/lib/CodeGen/OcamlGC.cpp index 5c6e29a6b00..f7bc9f3d31d 100644 --- a/lib/CodeGen/OcamlGC.cpp +++ b/lib/CodeGen/OcamlGC.cpp @@ -16,6 +16,7 @@ #include "llvm/CodeGen/GCs.h" #include "llvm/CodeGen/GCStrategy.h" +#include "llvm/Support/Compiler.h" using namespace llvm; diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 6dc45bdb2ba..7dc64e01ff1 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -47,6 +47,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp index 472bd374d94..5a55760c7c5 100644 --- a/lib/CodeGen/ShadowStackGC.cpp +++ b/lib/CodeGen/ShadowStackGC.cpp @@ -31,6 +31,7 @@ #include "llvm/CodeGen/GCStrategy.h" #include "llvm/IntrinsicInst.h" #include "llvm/Module.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/IRBuilder.h" using namespace llvm; diff --git a/lib/ExecutionEngine/JIT/TargetSelect.cpp b/lib/ExecutionEngine/JIT/TargetSelect.cpp index ce646b2b574..98819c19b83 100644 --- a/lib/ExecutionEngine/JIT/TargetSelect.cpp +++ b/lib/ExecutionEngine/JIT/TargetSelect.cpp @@ -15,6 +15,7 @@ #include "JIT.h" #include "llvm/Module.h" #include "llvm/ModuleProvider.h" +#include "llvm/Support/RegistryParser.h" #include "llvm/Support/Streams.h" #include "llvm/Target/SubtargetFeature.h" #include "llvm/Target/TargetMachine.h" @@ -22,7 +23,7 @@ using namespace llvm; static cl::opt + RegistryParser > MArch("march", cl::desc("Architecture to generate assembly for:")); static cl::opt diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 60adc835141..087a77097be 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -27,10 +27,11 @@ #include "llvm/PassManager.h" #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/FileUtilities.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PluginLoader.h" -#include "llvm/Support/FileUtilities.h" +#include "llvm/Support/RegistryParser.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Analysis/Verifier.h" #include "llvm/System/Signals.h" @@ -60,7 +61,7 @@ static cl::opt TargetTriple("mtriple", cl::desc("Override target triple for module")); static cl::opt + RegistryParser > MArch("march", cl::desc("Architecture to generate code for:")); static cl::opt