1 //===- DiagTool.h - Classes for defining diagtool tools -------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the boilerplate for defining diagtool tools.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_TOOLS_DIAGTOOL_DIAGTOOL_H
14 #define LLVM_CLANG_TOOLS_DIAGTOOL_DIAGTOOL_H
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/ManagedStatic.h"
18 #include "llvm/Support/raw_ostream.h"
25 const std::string cmd
;
26 const std::string description
;
28 DiagTool(llvm::StringRef toolCmd
, llvm::StringRef toolDesc
);
31 llvm::StringRef
getName() const { return cmd
; }
32 llvm::StringRef
getDescription() const { return description
; }
34 virtual int run(unsigned argc
, char *argv
[], llvm::raw_ostream
&out
) = 0;
43 DiagTool
*getTool(llvm::StringRef toolCmd
);
44 void registerTool(DiagTool
*tool
);
45 void printCommands(llvm::raw_ostream
&out
);
48 extern llvm::ManagedStatic
<DiagTools
> diagTools
;
50 template <typename DIAGTOOL
>
51 class RegisterDiagTool
{
53 RegisterDiagTool() { diagTools
->registerTool(new DIAGTOOL()); }
56 } // end diagtool namespace
58 #define DEF_DIAGTOOL(NAME, DESC, CLSNAME)\
60 class CLSNAME : public diagtool::DiagTool {\
62 CLSNAME() : DiagTool(NAME, DESC) {}\
63 virtual ~CLSNAME() {}\
64 int run(unsigned argc, char *argv[], llvm::raw_ostream &out) override;\
66 diagtool::RegisterDiagTool<CLSNAME> Register##CLSNAME;\