summaryrefslogtreecommitdiffstats
path: root/tools/clang-check
diff options
context:
space:
mode:
Diffstat (limited to 'tools/clang-check')
-rw-r--r--tools/clang-check/CMakeLists.txt15
-rw-r--r--tools/clang-check/ClangCheck.cpp104
-rw-r--r--tools/clang-check/Makefile4
3 files changed, 79 insertions, 44 deletions
diff --git a/tools/clang-check/CMakeLists.txt b/tools/clang-check/CMakeLists.txt
index 851d6cd..85e229f 100644
--- a/tools/clang-check/CMakeLists.txt
+++ b/tools/clang-check/CMakeLists.txt
@@ -1,5 +1,18 @@
-set(LLVM_USED_LIBS clangTooling clangBasic)
+set(LLVM_LINK_COMPONENTS
+ ${LLVM_TARGETS_TO_BUILD}
+ asmparser
+ support
+ mc
+ )
add_clang_executable(clang-check
ClangCheck.cpp
)
+
+target_link_libraries(clang-check
+ clangTooling
+ clangBasic
+ )
+
+install(TARGETS clang-check
+ RUNTIME DESTINATION bin)
diff --git a/tools/clang-check/ClangCheck.cpp b/tools/clang-check/ClangCheck.cpp
index d68e282..9e58077 100644
--- a/tools/clang-check/ClangCheck.cpp
+++ b/tools/clang-check/ClangCheck.cpp
@@ -1,4 +1,4 @@
-//===- examples/Tooling/ClangCheck.cpp - Clang check tool -----------------===//
+//===- tools/clang-check/ClangCheck.cpp - Clang check tool ----------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,57 +10,79 @@
// This file implements a clang-check tool that runs the
// clang::SyntaxOnlyAction over a number of translation units.
//
-// Usage:
-// clang-check <cmake-output-dir> <file1> <file2> ...
-//
-// Where <cmake-output-dir> is a CMake build directory in which a file named
-// compile_commands.json exists (enable -DCMAKE_EXPORT_COMPILE_COMMANDS in
-// CMake to get this output).
-//
-// <file1> ... specify the paths of files in the CMake source tree. This path
-// is looked up in the compile command database. If the path of a file is
-// absolute, it needs to point into CMake's source tree. If the path is
-// relative, the current working directory needs to be in the CMake source
-// tree and the file must be in a subdirectory of the current working
-// directory. "./" prefixes in the relative files will be automatically
-// removed, but the rest of a relative path must be a suffix of a path in
-// the compile command line database.
-//
-// For example, to use clang-check on all files in a subtree of the source
-// tree, use:
-//
-// /path/in/subtree $ find . -name '*.cpp'| xargs clang-check /path/to/source
+// This tool uses the Clang Tooling infrastructure, see
+// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
+// for details on setting it up with LLVM source tree.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/CommandLine.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Driver/OptTable.h"
+#include "clang/Driver/Options.h"
+#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/FrontendActions.h"
-#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/CommandLineClangTool.h"
#include "clang/Tooling/Tooling.h"
+using namespace clang::driver;
using namespace clang::tooling;
using namespace llvm;
-cl::opt<std::string> BuildPath(
- cl::Positional,
- cl::desc("<build-path>"));
+static const char *MoreHelpText =
+ "\tFor example, to run clang-check on all files in a subtree of the\n"
+ "\tsource tree, use:\n"
+ "\n"
+ "\t find path/in/subtree -name '*.cpp'|xargs clang-check\n"
+ "\n"
+ "\tor using a specific build path:\n"
+ "\n"
+ "\t find path/in/subtree -name '*.cpp'|xargs clang-check -p build/path\n"
+ "\n"
+ "\tNote, that path/in/subtree and current directory should follow the\n"
+ "\trules described above.\n"
+ "\n";
-cl::list<std::string> SourcePaths(
- cl::Positional,
- cl::desc("<source0> [... <sourceN>]"),
- cl::OneOrMore);
+namespace {
+class ActionFactory {
+public:
+ ActionFactory()
+ : Options(createDriverOptTable()),
+ ASTDump(
+ "ast-dump",
+ cl::desc(Options->getOptionHelpText(options::OPT_ast_dump))),
+ ASTList(
+ "ast-list",
+ cl::desc(Options->getOptionHelpText(options::OPT_ast_list))),
+ ASTPrint(
+ "ast-print",
+ cl::desc(Options->getOptionHelpText(options::OPT_ast_print))),
+ ASTDumpFilter(
+ "ast-dump-filter",
+ cl::desc(Options->getOptionHelpText(options::OPT_ast_dump_filter))) {}
-int main(int argc, const char **argv) {
- llvm::OwningPtr<CompilationDatabase> Compilations(
- FixedCompilationDatabase::loadFromCommandLine(argc, argv));
- cl::ParseCommandLineOptions(argc, argv);
- if (!Compilations) {
- std::string ErrorMessage;
- Compilations.reset(CompilationDatabase::loadFromDirectory(BuildPath,
- ErrorMessage));
- if (!Compilations)
- llvm::report_fatal_error(ErrorMessage);
+ clang::ASTConsumer *newASTConsumer() {
+ if (ASTList)
+ return clang::CreateASTDeclNodeLister();
+ if (ASTDump)
+ return clang::CreateASTDumper(ASTDumpFilter);
+ if (ASTPrint)
+ return clang::CreateASTPrinter(&llvm::outs(), ASTDumpFilter);
+ return new clang::ASTConsumer();
}
- ClangTool Tool(*Compilations, SourcePaths);
- return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());
+private:
+ OwningPtr<OptTable> Options;
+ cl::opt<bool> ASTDump;
+ cl::opt<bool> ASTList;
+ cl::opt<bool> ASTPrint;
+ cl::opt<std::string> ASTDumpFilter;
+};
+}
+
+int main(int argc, const char **argv) {
+ ActionFactory Factory;
+ CommandLineClangTool Tool;
+ cl::extrahelp MoreHelp(MoreHelpText);
+ Tool.initialize(argc, argv);
+ return Tool.run(newFrontendActionFactory(&Factory));
}
diff --git a/tools/clang-check/Makefile b/tools/clang-check/Makefile
index 49b1ada..6775c65 100644
--- a/tools/clang-check/Makefile
+++ b/tools/clang-check/Makefile
@@ -10,12 +10,12 @@
CLANG_LEVEL := ../..
TOOLNAME = clang-check
-NO_INSTALL = 1
# No plugins, optimize startup time.
TOOL_NO_EXPORTS = 1
-LINK_COMPONENTS := support mc
+include $(CLANG_LEVEL)/../../Makefile.config
+LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser support mc
USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a \
clangTooling.a clangParse.a clangSema.a clangAnalysis.a \
clangEdit.a clangAST.a clangLex.a clangBasic.a
OpenPOWER on IntegriCloud