2011-08-09 11:39:19 +08:00
|
|
|
//===- DiagTool.h - Classes for defining diagtool tools -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the boilerplate for defining diagtool tools.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef DIAGTOOL_DIAGTOOL_H
|
|
|
|
#define DIAGTOOL_DIAGTOOL_H
|
|
|
|
|
|
|
|
#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
|
|
|
};
|
|
|
|
|
|
|
|
} // end diagtool namespace
|
|
|
|
|
|
|
|
#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
|