GithubHelp home page GithubHelp logo

jeoyaoxiao / clangtool Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rdadolf/clangtool

0.0 2.0 0.0 172 KB

An example LLVM pass which can run automatically in clang.

Makefile 25.17% C++ 67.80% C 7.03%

clangtool's Introduction

Using LLVM plugins with clang

build status

The LLVM docs suggest using opt to load and run custom passes. This works, but for certain tasks, like building programs with complicated Makefiles or unusual environments, it is less than ideal. Instead, LLVM provides a hook to allow plugin modules to be run automatically when loaded by clang. This lets you add a couple of flags and use clang (and your pass) as a drop-in replacement for your normal C compiler. These files demonstrate how that works.

Using clangtool:

Two steps:

  1. Build your custom LLVM pass the normal way (as a shared library with the appropriate llvm flags).

  2. Run clang on your input code with the following extra options:

     clang -Xclang -load -Xclang <custom-pass>.so ...
    

That's it. Your pass will be run automatically. You can specify these with CFLAGS in a Makefile, override CC or CXX, or write a script to wrap clang and use that.

How it works:

The key is a static class called RegisterStandardPasses, which is defined in the PassManagerBuilder.h header. The constuctor for this class calls the addGlobalExtension function, which in turn adds your custom pass to the list of extensions that are loaded by default.

clangtool's People

Contributors

rdadolf avatar

Watchers

 avatar  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.