2011-08-09 11:39:19 +08:00
|
|
|
//===- DiagTool.cpp - 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DiagTool.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2011-08-09 11:39:19 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace diagtool;
|
|
|
|
|
|
|
|
DiagTool::DiagTool(llvm::StringRef toolCmd,
|
|
|
|
llvm::StringRef toolDesc)
|
|
|
|
: cmd(toolCmd), description(toolDesc) {}
|
|
|
|
|
|
|
|
DiagTool::~DiagTool() {}
|
|
|
|
|
|
|
|
typedef llvm::StringMap<DiagTool *> ToolMap;
|
|
|
|
static inline ToolMap *getTools(void *v) { return static_cast<ToolMap*>(v); }
|
|
|
|
|
|
|
|
DiagTools::DiagTools() : tools(new ToolMap()) {}
|
|
|
|
DiagTools::~DiagTools() { delete getTools(tools); }
|
|
|
|
|
|
|
|
DiagTool *DiagTools::getTool(llvm::StringRef toolCmd) {
|
|
|
|
ToolMap::iterator it = getTools(tools)->find(toolCmd);
|
2014-06-08 16:38:04 +08:00
|
|
|
return (it == getTools(tools)->end()) ? nullptr : it->getValue();
|
2011-08-09 11:39:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiagTools::registerTool(DiagTool *tool) {
|
|
|
|
getTools(tools)->GetOrCreateValue(tool->getName(), tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiagTools::printCommands(llvm::raw_ostream &out) {
|
|
|
|
std::vector<llvm::StringRef> toolNames;
|
|
|
|
unsigned maxName = 0;
|
|
|
|
for (ToolMap::iterator it = getTools(tools)->begin(),
|
|
|
|
ei = getTools(tools)->end(); it != ei; ++it) {
|
|
|
|
toolNames.push_back(it->getKey());
|
|
|
|
unsigned len = it->getKey().size();
|
|
|
|
if (len > maxName)
|
|
|
|
maxName = len;
|
|
|
|
}
|
|
|
|
std::sort(toolNames.begin(), toolNames.end());
|
|
|
|
|
|
|
|
for (std::vector<llvm::StringRef>::iterator it = toolNames.begin(),
|
|
|
|
ei = toolNames.end(); it != ei; ++it) {
|
|
|
|
|
|
|
|
out << " " << (*it);
|
|
|
|
unsigned spaces = (maxName + 3) - (it->size());
|
|
|
|
for (unsigned i = 0; i < spaces; ++i)
|
|
|
|
out << ' ';
|
|
|
|
|
|
|
|
out << getTool(*it)->getDescription() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace diagtool {
|
2011-08-12 09:14:22 +08:00
|
|
|
llvm::ManagedStatic<DiagTools> diagTools;
|
2011-08-09 11:39:19 +08:00
|
|
|
}
|