Writing Clang Plugins: A Comprehensive Guide

clang plugins working group n.w
1 / 5
Embed
Share

Explore the world of Clang plugins with this detailed guide covering static analysis, code instrumentation, compiler plugins, and writing Clang plugins. Learn about use cases, how to extract control flow graphs, and how to implement AST visitors to build your own plugins. Discover valuable resources for further learning and development in the Clang ecosystem.

  • Clang Plugins
  • Static Analysis
  • Code Instrumentation
  • Compiler Plugins
  • AST Visitors

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Clang Plugins working group David Poliakoff

  2. Use cases Static analysis Code instrumentation https://github.com/LLNL/caliper-compiler Extract control flow graph How are STL containers used (push_back(), fixed-size/dynamic etc.)

  3. Compiler plugins Clang plugins vs. llvm passes For source code / IR: clang plugins For LLVM assembly: llvm passes Both can do loop analysis Pass info from clang to llvm through artifacts Other compilers gcc: Undocumented plugin interface Intel / XL: good luck Nvidia: run away Can use source-to-source compilation from clang Vs. ROSE etc. ROSE has easier source-code insertion Clang has bigger user base

  4. How to write a clang plugin Find source locations for patterns of interest with clang-query E.g. match forStmt(hasDescendant(declRefExpr())) Respects defs and includes in compile_commands.json Can be created with Cmake, bare make Use arcane compiler knowledge Implement AST visitors Visits AST nodes (ifs, fors, function decls, ...) Overwrite corresponding visitor method and do stuff Build plugin (use recipe, e.g. from Eli s website (see Resources)) Use plugin: clang++ -fplugin=myplugin.so source.cpp Can also build executables with plugin functionality

  5. Resources https://clang.llvm.org/doxygen http://eli.thegreenplace.net/2014/07/29/ast-matchers-and-clang- refactoring-tools https://github.com/eliben/llvm-clang-samples

More Related Content