2011-08-09 11:39:19 +08:00
|
|
|
//===- DiagTool.cpp - 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DiagTool.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;
|
|
|
|
|
2020-01-29 03:23:46 +08:00
|
|
|
DiagTool::DiagTool(llvm::StringRef toolCmd, llvm::StringRef toolDesc)
|
|
|
|
: cmd(std::string(toolCmd)), description(std::string(toolDesc)) {}
|
2011-08-09 11:39:19 +08:00
|
|
|
|
2015-10-20 21:23:58 +08:00
|
|
|
DiagTool::~DiagTool() {}
|
2011-08-09 11:39:19 +08:00
|
|
|
|
|
|
|
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) {
|
2014-11-19 11:06:06 +08:00
|
|
|
(*getTools(tools))[tool->getName()] = tool;
|
2011-08-09 11:39:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-09-27 06:16:28 +08:00
|
|
|
llvm::sort(toolNames);
|
2011-08-09 11:39:19 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|