Giter Club home page Giter Club logo

coarct's Introduction

CoARCT

Code Analysis and Refactoring with Clang Tools

CoARCT (pronounced like the word "corked") is a small set of tools built on Clang's LibTooling. CoARCT demonstrates some more sustained examples of refactoring and analyzing code with AST Matchers and the clang Refactoring Tool.

It includes library code and command line drivers that go beyond some of the (excellent!) tutorials that are available. The CoARCT examples are drawn from refactoring legacy codes:

  • Reporting which functions use which global variables;
  • Replacing global variables with local variables, including threading variables through a call chain;
  • Detecting which functions use which fields of a struct: this data can be used to analyze how to break up large structs;
  • Finding code associated with a classic C-style linked list;
  • Identifying struct fields defined with typedefs, reporting underlying types (apps/TypedefFinder.cc).

It also demonstrates a few useful things that were not immediately clear from the tutorials and examples I learned from, such as unit testing matchers and callbacks, and building out of the Clang/LLVM tree.

Our hope is that CoARCT will help demystify the Clang AST tools to users. If the CoARCT tools are directly useful in your work, let us know!

Prerequisites:

  1. CMake version 3+ (https://cmake.org/download/)
  2. Clang and LLVM libraries and headers (http://releases.llvm.org/download.html)
  3. libtinfo
  4. Boost (currently using 1.61, just needs boost/type_index in one spot)
  5. Google test (https://github.com/google/googletest)

Works with Clang 4.0.0 (also 3.9, 3.8).

Build

  1. Define these environment variables

    GTEST_DIR: Top level directory of google test installation
    BOOST_DIR: Top level of Boost (#include "boost/type_index.hpp" needs to work)
    TINFO_LIB_DIR: points to where libtinfo.a is installed.
    LLVM_LIB_DIR: points to where LLVM libraries are installed (e.g. ${HOME}/llvm/clang+llvm-4.0.0-x86_64-apple-darwin/lib)
    CLANG_LIB_DIR: points to where Clang libraries are installed. (e.g. ${HOME}/llvm/clang+llvm-4.0.0-x86_64-apple-darwin/lib)
    LibClang_INCLUDE_DIR: where Clang headers reside (e.g. ${HOME}/llvm/clang+llvm-4.0.0-x86_64-apple-darwin/include)
    
  2. Clone the repository

  3. Create a build directory

    /home/CoARCT $ mkdir build-clang-4.0.0
    /home/CoARCT $ cd build-clang-4.0.0
    
  4. Run cmake, make

    /home/CoARCT/build-clang-4.0.0 $ cmake ..
    /home/CoARCT/build-clang-4.0.0 $ make
    
  5. Run the unit tests

    /home/CoARCT/build-clang-4.0.0 $ ./test/corct-unittests
    ...
    [==========] 72 tests from 15 test cases ran. (157 ms total)
    [  PASSED  ] 72 tests.
    

Los Alamos National Security, LLC (LANS) owns the copyright to CoARCT, which it identifies internally as LA-CC-17-039. See the LICENSE file for license information.

coarct's People

Contributors

timmah avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.