2011-08-09 11:39:19 +08:00
|
|
|
//===- DiagTool.h - Classes for defining diagtool tools -------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-08-09 11:39:19 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the boilerplate for defining diagtool tools.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_DIAGTOOL_DIAGTOOL_H
|
|
|
|
#define LLVM_CLANG_TOOLS_DIAGTOOL_DIAGTOOL_H
|
2011-08-09 11:39:19 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2011-08-12 09:14:22 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-08-09 11:39:19 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
namespace diagtool {
|
|
|
|
|
|
|
|
class DiagTool {
|
|
|
|
const std::string cmd;
|
|
|
|
const std::string description;
|
|
|
|
public:
|
|
|
|
DiagTool(llvm::StringRef toolCmd, llvm::StringRef toolDesc);
|
|
|
|
virtual ~DiagTool();
|
|
|
|
|
|
|
|
llvm::StringRef getName() const { return cmd; }
|
|
|
|
llvm::StringRef getDescription() const { return description; }
|
|
|
|
|
|
|
|
virtual int run(unsigned argc, char *argv[], llvm::raw_ostream &out) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DiagTools {
|
|
|
|
void *tools;
|
|
|
|
public:
|
|
|
|
DiagTools();
|
|
|
|
~DiagTools();
|
|
|
|
|
|
|
|
DiagTool *getTool(llvm::StringRef toolCmd);
|
|
|
|
void registerTool(DiagTool *tool);
|
|
|
|
void printCommands(llvm::raw_ostream &out);
|
|
|
|
};
|
|
|
|
|
2011-08-12 09:14:22 +08:00
|
|
|
extern llvm::ManagedStatic<DiagTools> diagTools;
|
|
|
|
|
2011-08-09 11:39:19 +08:00
|
|
|
template <typename DIAGTOOL>
|
|
|
|
class RegisterDiagTool {
|
|
|
|
public:
|
2011-08-12 09:14:22 +08:00
|
|
|
RegisterDiagTool() { diagTools->registerTool(new DIAGTOOL()); }
|
2011-08-09 11:39:19 +08:00
|
|
|
};
|
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
} // end diagtool namespace
|
2011-08-09 11:39:19 +08:00
|
|
|
|
|
|
|
#define DEF_DIAGTOOL(NAME, DESC, CLSNAME)\
|
|
|
|
namespace {\
|
|
|
|
class CLSNAME : public diagtool::DiagTool {\
|
|
|
|
public:\
|
|
|
|
CLSNAME() : DiagTool(NAME, DESC) {}\
|
|
|
|
virtual ~CLSNAME() {}\
|
2014-03-15 15:47:46 +08:00
|
|
|
int run(unsigned argc, char *argv[], llvm::raw_ostream &out) override;\
|
2011-08-09 11:39:19 +08:00
|
|
|
};\
|
|
|
|
diagtool::RegisterDiagTool<CLSNAME> Register##CLSNAME;\
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|