Giter Site home page Giter Site logo

cpp977 / instantiator Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 2.0 23.69 MB

Clang based tool to automatically insert all needed explicit instantiations in implementation files for `c++` projects

License: Apache License 2.0

CMake 19.29% C++ 50.09% JavaScript 2.88% CSS 23.44% HTML 3.18% Shell 1.12%
cpp template tool llvm clang clang-13 clang-14 clang-15

instantiator's Introduction

TESTS

Instantiator

clang based tool to automatically insert all needed explicit instantiations in implementation files for c++ projects.

What does it can do?

The tool allows you to implement your function and class templates in the same manner as normal function and classes. I.e. you can put the declarations in header files (.hpp) and the definitions in implementation files (.cpp). If you do this without using this tool the compiled object files of the provided implementations are empty because they do not exist any template instantiations. If you run

Instantiator -p <path/to/compile_command.json> <MAIN_CPPFILE>

all needed instantiations of your function and class templates will be placed automatically to the correct position. Then you can build your project without linking errors but with all the benefits of having separate translation units:

  • Parallel compilation
  • Fast incremental rebuilds

The tool only adds instantiations for things you use. That ensures that the c++ template paradigm you only get object code for things you really use is respected. The compilation step involves exactly the same effort as if you had everything in the header files.

What does it (currently) not can do?

  • It does not manage the includes for you. If it inserts a needed template instantiation with a type not known in that translation unit, you will get a compiler error.

How to build?

git clone https://github.com/cpp977/Instantiator
mkdir build && cd build
cmake .. 
make && [sudo] make install

For a successful build you need a c++-17 compiler and LLVM/clang libraries. Because of recent bufix in clang (https://reviews.llvm.org/D108794) version 14 of LLVM/clang is needed for full functionality. With an older version of LLVM/clang you might run into troubles with the correct formatting of template template parameters. To control which version of LLVM is used, you can set the cmake variable LLVM_ROOT to the root of the llvm installation. To control which version of clang is used, you can set the cmake variable Clang_DIR to the root of the directory where the file ClangConfig.cmake is located.

Roadmap for version 1.0.0

  • Noninvasive mode: instantiations are not inserted directly to the source file but in extra files which can then be included in the source files.

How does it work?

See the documentation.

Contributions

Contributions are very welcome! The following is only a part of things which needs to be done:

Acknowledgments

The tool is heavily based on clang and its libtooling library which is of course acknowledged. Beside that, the tool uses some small c++ utility libraries which are also acknowledged:

  1. termcolor โ€” for colored logging output
  2. doxygen layout โ€” for pretty online documentation

instantiator's People

Contributors

cpp977 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

ywen-cmd gmh5225

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.