[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / clang / tools / diagtool / DiagTool.h
blob1d9da75bf3964d378a2cf7e00866f28c32818686
1 //===- DiagTool.h - Classes for defining diagtool tools -------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
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"
19 #include <string>
22 namespace diagtool {
24 class DiagTool {
25 const std::string cmd;
26 const std::string description;
27 public:
28 DiagTool(llvm::StringRef toolCmd, llvm::StringRef toolDesc);
29 virtual ~DiagTool();
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;
37 class DiagTools {
38 void *tools;
39 public:
40 DiagTools();
41 ~DiagTools();
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 {
52 public:
53 RegisterDiagTool() { diagTools->registerTool(new DIAGTOOL()); }
56 } // end diagtool namespace
58 #define DEF_DIAGTOOL(NAME, DESC, CLSNAME)\
59 namespace {\
60 class CLSNAME : public diagtool::DiagTool {\
61 public:\
62 CLSNAME() : DiagTool(NAME, DESC) {}\
63 virtual ~CLSNAME() {}\
64 int run(unsigned argc, char *argv[], llvm::raw_ostream &out) override;\
65 };\
66 diagtool::RegisterDiagTool<CLSNAME> Register##CLSNAME;\
69 #endif