Giter Club home page Giter Club logo

faic's Introduction

FAIC

Standing for Function Analysis in Codebases, FAIC is a C++ program that makes heavy use of LLVM Clang's LibTooling to produce a function call graph from an undocumented C++ library. This works mainly by parsing the source code's Abstract Syntax Tree and analysing the function use and hierarchy to determine their relevance and scope to the library's user. This map is, in turn, passed into automata learning algorithms, which will perform an in-depth analysis of the code and provide the user with warnings on how to use the library.

Getting Started (macOS)

Make sure you have the following dependencies:

  • Cmake
  • Make
  • LLVM
  • Clang
  • Clang Headers
  • Boost

Most of these come included with the Xcode CLI Tools. To install them download Xcode and run:

xcode-select --install

We can install other dependencies using Homebrew:

brew install cmake llvm clang boost

Make sure the new LLVM bins are added to your path:

export PATH="/usr/local/opt/llvm/bin:$PATH"
export CC=clang
export CXX=clang++

Let's now clone the source code:

git clone https://github.com/UCL-PPLV/FAIC && cd FAIC

Getting Started (Linux)

sudo apt-get update
sudo apt-get install git cmake make libcurses-dev

On Linux the only way I've found to get all the required Clang dependencies is by building from source. For this we have to clone LLVM and Clang:

git clone https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone https://github.com/llvm-mirror/clang.git
cd ../..

LLVM does not support building in the source tree, so create a build foder by its side:

mkdir build
cd build

Now compile LLVM and Clang:

  • Make sure you have enough memory for this. We are literally compiling a compiler, my Linux VM needed at least 16GB of memory.
  • This might take some hours, if you haven't had your daily dose of caffeine, this is your chance. โ˜•
cmake -G "Unix Makefiles" ../llvm && make

To make sure everything went as planned:

make check-clang

If everything seems to be fine install it with:

sudo make install

Building FAIC

FAIC uses CMake to manage the build process. We recommend building FAIC in a subfolder:

mkdir build && cd build

Depending on your environment and preference you may pass CMake different flags. To simply setup the build or use a CLI editor:

cmake .. && make

To setup the build and use an IDE (Xcode for example):

cmake -G Xcode .. && open FAIC.xcodeproj

Author

Tiago Ferreira | Twitter | Website

License

FAIC Copyright (C) 2017 Tiago Ferreira

Please check the license file embed in this project for more details.

faic's People

Contributors

tiferrei avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

faic's Issues

Clang AST Call parser adding duplicates

The clang call parser seems to add duplicate calls when they're detected.
As a quick fix a cleanup() method has been added, but it's extremely hacky, and adding duplicates would make the program extremely inefficient when ran over large codebases.

Unit Testing

Test-driven development is essential for such a complex project. Most modern programming languages provide built-in test frameworks. This doesn't seem to be the case with C++. There are, however, some great open source frameworks available. The major players seem to be:

Google Test

// Tests factorial of 0.
TEST(FactorialTest, HandlesZeroInput) {
  EXPECT_EQ(1, Factorial(0));
}

// Tests factorial of positive numbers.
TEST(FactorialTest, HandlesPositiveInput) {
  EXPECT_EQ(1, Factorial(1));
  EXPECT_EQ(2, Factorial(2));
  EXPECT_EQ(6, Factorial(3));
  EXPECT_EQ(40320, Factorial(8));
}
  • ๐Ÿ‘ PROS
    • Widely-used, used by LLVM which is the base of this project.
    • Very active community, almost weekly commits.
    • Clean and easy to use
  • ๐Ÿ‘Ž CONS
    • Build system has to be adapted
    • Not header only

CATCH2

SCENARIO( "vectors can be sized and resized", "[vector]" ) {

    GIVEN( "A vector with some items" ) {
        std::vector<int> v( 5 );
        
        REQUIRE( v.size() == 5 );
        REQUIRE( v.capacity() >= 5 );
        
        WHEN( "the size is increased" ) {
            v.resize( 10 );
            
            THEN( "the size and capacity change" ) {
                REQUIRE( v.size() == 10 );
                REQUIRE( v.capacity() >= 10 );
            }
        }
        WHEN( "the size is reduced" ) {
            v.resize( 0 );
            
            THEN( "the size changes but not capacity" ) {
                REQUIRE( v.size() == 0 );
                REQUIRE( v.capacity() >= 5 );
            }
        }
        WHEN( "more capacity is reserved" ) {
            v.reserve( 10 );
            
            THEN( "the capacity changes but not the size" ) {
                REQUIRE( v.size() == 5 );
                REQUIRE( v.capacity() >= 10 );
            }
        }
        WHEN( "less capacity is reserved" ) {
            v.reserve( 0 );
            
            THEN( "neither size nor capacity are changed" ) {
                REQUIRE( v.size() == 5 );
                REQUIRE( v.capacity() >= 5 );
            }
        }
    }
}
  • ๐Ÿ‘ PROS
    • Extremely easy to use.
    • Header only, minimal changes to the build system.
  • ๐Ÿ‘Ž CONS
    • Might be slower when used in separate binaries.

Boost Test

#include <boost/test/included/unit_test.hpp>
using namespace boost::unit_test;

void free_test_function()
{
  BOOST_TEST( true /* test assertion */ );
}

test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
{
  if( framework::master_test_suite().argc > 1 )
    return 0;

  framework::master_test_suite().
    add( BOOST_TEST_CASE( &free_test_function ) );

  return 0;
}
  • ๐Ÿ‘ PROS
    • Part of Boost, carries a strong reputation.
    • We already use boost so that's in our favour.
  • ๐Ÿ‘Ž CONS
    • A bit older
    • Not so modern approach.

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.