xref: /minix3/external/bsd/llvm/dist/clang/tools/diagtool/DiagTool.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===- DiagTool.h - Classes for defining diagtool tools -------------------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file implements the boilerplate for defining diagtool tools.
11f4a2713aSLionel Sambuc //
12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13f4a2713aSLionel Sambuc 
14*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_TOOLS_DIAGTOOL_DIAGTOOL_H
15*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_TOOLS_DIAGTOOL_DIAGTOOL_H
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc #include "llvm/ADT/StringRef.h"
18f4a2713aSLionel Sambuc #include "llvm/Support/ManagedStatic.h"
19f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h"
20f4a2713aSLionel Sambuc #include <string>
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc namespace diagtool {
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc class DiagTool {
26f4a2713aSLionel Sambuc   const std::string cmd;
27f4a2713aSLionel Sambuc   const std::string description;
28f4a2713aSLionel Sambuc public:
29f4a2713aSLionel Sambuc   DiagTool(llvm::StringRef toolCmd, llvm::StringRef toolDesc);
30f4a2713aSLionel Sambuc   virtual ~DiagTool();
31f4a2713aSLionel Sambuc 
getName()32f4a2713aSLionel Sambuc   llvm::StringRef getName() const { return cmd; }
getDescription()33f4a2713aSLionel Sambuc   llvm::StringRef getDescription() const { return description; }
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc   virtual int run(unsigned argc, char *argv[], llvm::raw_ostream &out) = 0;
36f4a2713aSLionel Sambuc };
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc class DiagTools {
39f4a2713aSLionel Sambuc   void *tools;
40f4a2713aSLionel Sambuc public:
41f4a2713aSLionel Sambuc   DiagTools();
42f4a2713aSLionel Sambuc   ~DiagTools();
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc   DiagTool *getTool(llvm::StringRef toolCmd);
45f4a2713aSLionel Sambuc   void registerTool(DiagTool *tool);
46f4a2713aSLionel Sambuc   void printCommands(llvm::raw_ostream &out);
47f4a2713aSLionel Sambuc };
48f4a2713aSLionel Sambuc 
49f4a2713aSLionel Sambuc extern llvm::ManagedStatic<DiagTools> diagTools;
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc template <typename DIAGTOOL>
52f4a2713aSLionel Sambuc class RegisterDiagTool {
53f4a2713aSLionel Sambuc public:
RegisterDiagTool()54f4a2713aSLionel Sambuc   RegisterDiagTool() { diagTools->registerTool(new DIAGTOOL()); }
55f4a2713aSLionel Sambuc };
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc } // end diagtool namespace
58f4a2713aSLionel Sambuc 
59f4a2713aSLionel Sambuc #define DEF_DIAGTOOL(NAME, DESC, CLSNAME)\
60f4a2713aSLionel Sambuc namespace {\
61f4a2713aSLionel Sambuc class CLSNAME : public diagtool::DiagTool {\
62f4a2713aSLionel Sambuc public:\
63f4a2713aSLionel Sambuc   CLSNAME() : DiagTool(NAME, DESC) {}\
64f4a2713aSLionel Sambuc   virtual ~CLSNAME() {}\
65*0a6a1f1dSLionel Sambuc   int run(unsigned argc, char *argv[], llvm::raw_ostream &out) override;\
66f4a2713aSLionel Sambuc };\
67f4a2713aSLionel Sambuc diagtool::RegisterDiagTool<CLSNAME> Register##CLSNAME;\
68f4a2713aSLionel Sambuc }
69f4a2713aSLionel Sambuc 
70f4a2713aSLionel Sambuc #endif
71