Running user-defined actions by using Clang plug-ins
You can write Clang plug-ins to run extra user-defined actions during compilation.
Note: To use Clang plug-ins, you must build your plug-ins by using
Clang 3.8.
Procedure
- Write your plug-in. For more information about writing Clang plug-ins, see the Clang 3.8 documentation at http://www.llvm.org/releases/3.8.0/tools/clang/docs/ClangPlugins.html.
- Register the plug-in in a dynamic library.
- Run the plug-in during compilation.Note: You must prefix each Clang plug-in option and argument with -Xclang.
- Specify the -load option to load the dynamic library in which the plug-in is registered. All plug-ins that are registered in that dynamic library are loaded. You can specify this option multiple times to load several libraries for dispersed plug-ins.
- Specify the -add-plugin option to select the plug-in to run. You can specify this option multiple times to run several plug-ins.
- Optional: Specify arguments for the plug-in by using the -plugin-arg-plugin_name option.
Example
In the following example, CountVariableUsage.so is the dynamic library that contains the target plug-in count-vars, and -static-only is the argument for the count-vars plug-in.xlC myprogram.cpp -Xclang -load -Xclang CountVariableUsage.so \
-Xclang -add-plugin -Xclang count-vars \
-Xclang -plugin-arg-count-vars -Xclang -static-only