• Home
  • Raw
  • Download

Lines Matching +full:git +full:- +full:tool

5 This document is intended to show how to build a useful source-to-source
6 translation tool based on Clang's `LibTooling <LibTooling.html>`_. It is
20 repositories, but we'll be accessing them through the git mirror. For
24 .. code-block:: console
26 mkdir ~/clang-llvm && cd ~/clang-llvm
27 git clone http://llvm.org/git/llvm.git
29 git clone http://llvm.org/git/clang.git
31 git clone http://llvm.org/git/clang-tools-extra.git extra
33 Next you need to obtain the CMake build system and Ninja build tool. You
37 .. code-block:: console
39 cd ~/clang-llvm
40 git clone https://github.com/martine/ninja.git
42 git checkout release
46 cd ~/clang-llvm
47 git clone git://cmake.org/stage/cmake.git
49 git checkout next
56 .. code-block:: console
58 cd ~/clang-llvm
60 cmake -G Ninja ../llvm -DLLVM_BUILD_TESTS=ON # Enable tests; default is off.
63 ninja clang-test # Test Clang only.
69 you can catch LLVM and Clang out of sync. Running ``'git svn rebase'``
74 .. code-block:: console
76 cd ~/clang-llvm/build
92 already exists as ``clang-check``, it's important to understand what's
95 First, we'll need to create a new directory for our tool and tell CMake
96 that it exists. As this is not going to be a core clang tool, it will
99 .. code-block:: console
101 cd ~/clang-llvm/llvm/tools/clang
102 mkdir tools/extra/loop-convert
103 echo 'add_subdirectory(loop-convert)' >> tools/extra/CMakeLists.txt
104 vim tools/extra/loop-convert/CMakeLists.txt
112 add_clang_executable(loop-convert
115 target_link_libraries(loop-convert
121 With that done, Ninja will be able to compile our tool. Let's give it
123 ``tools/extra/loop-convert/LoopConvert.cpp``. A detailed explanation of
127 .. code-block:: c++
139 // Apply a custom category to all command-line options so that they are the
141 static llvm::cl::OptionCategory MyToolCategory("my-tool options");
144 // command-line options related to the compilation database and input files.
148 // A help message for this specific tool can be added afterwards.
153 ClangTool Tool(OptionsParser.getCompilations(),
155 return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
158 And that's it! You can compile our new tool by running ninja from the
161 .. code-block:: console
163 cd ~/clang-llvm/build
167 ``~/clang-llvm/build/bin``, on any source file. Try it!
169 .. code-block:: console
172 bin/loop-convert test.cpp --
176 them from a compilation database - there just aren't any options needed
194 .. code-block:: c++
215 .. code-block:: c++
226 .. code-block:: c++
233 .. code-block:: c++
240 .. code-block:: c++
255 .. code-block:: c++
268 .. code-block:: c++
284 FS->dump();
290 .. code-block:: c++
294 ClangTool Tool(OptionsParser.getCompilations(),
301 return Tool.run(newFrontendActionFactory(&Finder).get());
308 .. code-block:: console
310 cd ~/clang-llvm/llvm/llvm_build/
311 ninja loop-convert
312 vim ~/test-files/simple-loops.cc
313 bin/loop-convert ~/test-files/simple-loops.cc
324 for translation to range-based syntax? Range based loops over arrays of
327 - start at index ``0``
328 - iterate consecutively
329 - end at index ``N-1``
335 require a pre- or post-increment of the same variable declared in the
343 In any case, we can start building this sub-matcher. We can require that
346 .. code-block:: c++
356 .. code-block:: c++
365 .. code-block:: c++
374 .. code-block:: c++
388 only one problem - we don't know which array we're iterating over
393 .. code-block:: c++
397 It makes sense to ensure that the left-hand side is a reference to a
398 variable, and that the right-hand side has integer type.
400 .. code-block:: c++
408 ``test-files/simple.cpp``, zero of them have a matching condition. A
410 previous iteration of loop-convert, shows us the answer:
430 applied to the first operand (i.e. the LHS) of the less-than operator,
431 an L-value to R-value conversion applied to the expression referencing
437 .. code-block:: c++
446 extracting the identifier strings into variables, we have array-step-2
471 .. code-block:: c++
477 .. code-block:: c++
495 .. code-block:: c++
501 if (!FS || !Context->getSourceManager().isFromMainFile(FS->getForLoc()))
509 llvm::outs() << "Potential array-based loop discovered.\n";
517 .. code-block:: c++
521 First->getCanonicalDecl() == Second->getCanonicalDecl();
527 .. code-block:: c++
539 .. code-block:: c++
546 First->Profile(FirstID, *Context, true);
547 Second->Profile(SecondID, *Context, true);
558 test-files/simple.cpp, try to figure out which ones will be considered