blob: 93d531babb1cf1b1725d5b07b090367d923e2265 [file] [log] [blame]
Ted Kremenek2dc651d2011-08-09 03:39:19 +00001//===- DiagTool.h - Classes for defining diagtool tools -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the boilerplate for defining diagtool tools.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef DIAGTOOL_DIAGTOOL_H
15#define DIAGTOOL_DIAGTOOL_H
16
17#include "llvm/ADT/StringRef.h"
Nick Lewycky83f06e82011-08-12 01:14:22 +000018#include "llvm/Support/ManagedStatic.h"
Chandler Carruthf59edb92012-12-04 09:25:21 +000019#include "llvm/Support/raw_ostream.h"
Ted Kremenek2dc651d2011-08-09 03:39:19 +000020#include <string>
21
22
23namespace diagtool {
24
25class DiagTool {
26 const std::string cmd;
27 const std::string description;
28public:
29 DiagTool(llvm::StringRef toolCmd, llvm::StringRef toolDesc);
30 virtual ~DiagTool();
31
32 llvm::StringRef getName() const { return cmd; }
33 llvm::StringRef getDescription() const { return description; }
34
35 virtual int run(unsigned argc, char *argv[], llvm::raw_ostream &out) = 0;
36};
37
38class DiagTools {
39 void *tools;
40public:
41 DiagTools();
42 ~DiagTools();
43
44 DiagTool *getTool(llvm::StringRef toolCmd);
45 void registerTool(DiagTool *tool);
46 void printCommands(llvm::raw_ostream &out);
47};
48
Nick Lewycky83f06e82011-08-12 01:14:22 +000049extern llvm::ManagedStatic<DiagTools> diagTools;
50
Ted Kremenek2dc651d2011-08-09 03:39:19 +000051template <typename DIAGTOOL>
52class RegisterDiagTool {
53public:
Nick Lewycky83f06e82011-08-12 01:14:22 +000054 RegisterDiagTool() { diagTools->registerTool(new DIAGTOOL()); }
Ted Kremenek2dc651d2011-08-09 03:39:19 +000055};
56
57} // end diagtool namespace
58
59#define DEF_DIAGTOOL(NAME, DESC, CLSNAME)\
60namespace {\
61class CLSNAME : public diagtool::DiagTool {\
62public:\
63 CLSNAME() : DiagTool(NAME, DESC) {}\
64 virtual ~CLSNAME() {}\
65 virtual int run(unsigned argc, char *argv[], llvm::raw_ostream &out);\
66};\
67diagtool::RegisterDiagTool<CLSNAME> Register##CLSNAME;\
68}
69
70#endif