diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/Tooling/CMakeLists.txt | 6 | ||||
-rw-r--r-- | examples/Tooling/ClangCheck.cpp | 108 | ||||
-rw-r--r-- | examples/Tooling/Makefile | 24 | ||||
-rw-r--r-- | examples/clang-interpreter/Makefile | 5 | ||||
-rw-r--r-- | examples/clang-interpreter/main.cpp | 2 | ||||
-rw-r--r-- | examples/wpa/Makefile | 9 |
7 files changed, 10 insertions, 145 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8e16ef1..317bc81 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,3 +1,2 @@ add_subdirectory(clang-interpreter) add_subdirectory(PrintFunctionNames) -add_subdirectory(Tooling) diff --git a/examples/Tooling/CMakeLists.txt b/examples/Tooling/CMakeLists.txt deleted file mode 100644 index 257d3ea..0000000 --- a/examples/Tooling/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(LLVM_USED_LIBS clangTooling clangBasic) - -add_clang_executable(clang-check - ClangCheck.cpp - ) - diff --git a/examples/Tooling/ClangCheck.cpp b/examples/Tooling/ClangCheck.cpp deleted file mode 100644 index 4128375..0000000 --- a/examples/Tooling/ClangCheck.cpp +++ /dev/null @@ -1,108 +0,0 @@ -//===- examples/Tooling/ClangCheck.cpp - Clang check tool -----------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "clang/Frontend/FrontendActions.h" -#include "clang/Tooling/Tooling.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/Twine.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Path.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" - -/// \brief Returns the absolute path of 'File', by prepending it with -/// 'BaseDirectory' if 'File' is not absolute. Otherwise returns 'File'. -/// If 'File' starts with "./", the returned path will not contain the "./". -/// Otherwise, the returned path will contain the literal path-concatenation of -/// 'BaseDirectory' and 'File'. -/// -/// \param File Either an absolute or relative path. -/// \param BaseDirectory An absolute path. -/// -/// FIXME: Put this somewhere where it is more generally available. -static std::string GetAbsolutePath( - llvm::StringRef File, llvm::StringRef BaseDirectory) { - assert(llvm::sys::path::is_absolute(BaseDirectory)); - if (llvm::sys::path::is_absolute(File)) { - return File; - } - llvm::StringRef RelativePath(File); - if (RelativePath.startswith("./")) { - RelativePath = RelativePath.substr(strlen("./")); - } - llvm::SmallString<1024> AbsolutePath(BaseDirectory); - llvm::sys::path::append(AbsolutePath, RelativePath); - return AbsolutePath.str(); -} - -int main(int argc, char **argv) { - if (argc < 3) { - llvm::outs() << "Usage: " << argv[0] << " <cmake-output-dir> " - << "<file1> <file2> ...\n"; - return 1; - } - // FIXME: We should pull how to find the database into the Tooling package. - llvm::OwningPtr<llvm::MemoryBuffer> JsonDatabase; - llvm::SmallString<1024> JsonDatabasePath(argv[1]); - llvm::sys::path::append(JsonDatabasePath, "compile_commands.json"); - llvm::error_code Result = - llvm::MemoryBuffer::getFile(JsonDatabasePath, JsonDatabase); - if (Result != 0) { - llvm::outs() << "Error while opening JSON database: " << Result.message() - << "\n"; - return 1; - } - llvm::StringRef BaseDirectory(::getenv("PWD")); - for (int I = 2; I < argc; ++I) { - llvm::SmallString<1024> File(GetAbsolutePath(argv[I], BaseDirectory)); - llvm::outs() << "Processing " << File << ".\n"; - std::string ErrorMessage; - clang::tooling::CompileCommand LookupResult = - clang::tooling::FindCompileArgsInJsonDatabase( - File.str(), JsonDatabase->getBuffer(), ErrorMessage); - if (!LookupResult.CommandLine.empty()) { - if (!clang::tooling::RunToolWithFlags( - new clang::SyntaxOnlyAction, - LookupResult.CommandLine.size(), - clang::tooling::CommandLineToArgv( - &LookupResult.CommandLine).data())) { - llvm::outs() << "Error while processing " << File << ".\n"; - } - } else { - llvm::outs() << "Skipping " << File << ". Command line not found.\n"; - } - } - return 0; -} diff --git a/examples/Tooling/Makefile b/examples/Tooling/Makefile deleted file mode 100644 index 66e86a0..0000000 --- a/examples/Tooling/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -##===- examples/Tooling/Makefile ---------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -CLANG_LEVEL := ../.. - -TOOLNAME = clang-check -NO_INSTALL = 1 - -# No plugins, optimize startup time. -TOOL_NO_EXPORTS = 1 - -LINK_COMPONENTS := support mc -USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a \ - clangTooling.a clangSema.a clangAnalysis.a \ - clangAST.a clangParse.a clangLex.a clangBasic.a - -include $(CLANG_LEVEL)/Makefile - diff --git a/examples/clang-interpreter/Makefile b/examples/clang-interpreter/Makefile index 3f02003..b565bb1 100644 --- a/examples/clang-interpreter/Makefile +++ b/examples/clang-interpreter/Makefile @@ -18,7 +18,8 @@ TOOL_NO_EXPORTS = 1 LINK_COMPONENTS := jit interpreter nativecodegen bitreader bitwriter ipo \ selectiondag asmparser instrumentation USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a clangCodeGen.a \ - clangSema.a clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a clangAnalysis.a clangRewrite.a \ - clangAST.a clangParse.a clangLex.a clangBasic.a + clangParse.a clangSema.a clangStaticAnalyzerFrontend.a \ + clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a \ + clangAnalysis.a clangRewrite.a clangAST.a clangLex.a clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp index ad39ece..16f4dab 100644 --- a/examples/clang-interpreter/main.cpp +++ b/examples/clang-interpreter/main.cpp @@ -94,7 +94,7 @@ int main(int argc, const char **argv, char * const *envp) { // We expect to get back exactly one command job, if we didn't something // failed. Extract that job from the compilation. const driver::JobList &Jobs = C->getJobs(); - if (Jobs.size() != 1 || !isa<driver::Command>(Jobs.begin())) { + if (Jobs.size() != 1 || !isa<driver::Command>(*Jobs.begin())) { llvm::SmallString<256> Msg; llvm::raw_svector_ostream OS(Msg); C->PrintJob(OS, C->getJobs(), "; ", true); diff --git a/examples/wpa/Makefile b/examples/wpa/Makefile index 2ce2040..2cfedbc 100644 --- a/examples/wpa/Makefile +++ b/examples/wpa/Makefile @@ -16,8 +16,11 @@ NO_INSTALL = 1 TOOL_NO_EXPORTS = 1 LINK_COMPONENTS := asmparser bitreader mc core -USEDLIBS = clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a clangIndex.a clangFrontend.a clangDriver.a \ - clangSema.a clangAnalysis.a clangSerialization.a \ - clangAST.a clangParse.a clangLex.a clangBasic.a +USEDLIBS = clangStaticAnalyzerFrontend.a \ + clangStaticAnalyzerCheckers.a \ + clangStaticAnalyzerCore.a \ + clangIndex.a clangFrontend.a clangDriver.a \ + clangParse.a clangSema.a clangAnalysis.a clangSerialization.a \ + clangAST.a clangLex.a clangBasic.a include $(CLANG_LEVEL)/Makefile |