-
Notifications
You must be signed in to change notification settings - Fork 50
Compiler Implementation
Brandon Holt edited this page Apr 15, 2013
·
10 revisions
In Doug Gregor's Extending Clang presentation, he talks about two different ways to do attributes.
Your annotation is just a string argument passed to annotate:
int foo __attribute__((annotate("grappa_global")));- In LLVM IR, these annotations show up as "calls" to
@llvm.var.annotation: https://gist.github.com/3615160 - Some instructions on how to parse these in an LLVM Pass: Stack Overflow: AnnotationManager
It seems fairly supported to hack a new attribute into Clang. This is a bit more work, but more robust since I think it should allow you to restrict what kinds of things it can be put on (i.e. only declarations of pointers).
- Problem with this approach is you do have to make changes to Clang source code, but hopefully in a limited number of places.
- Clang does allow new attributes to be added, but it doesn't do anything to make sure these annotations are preserved all the way to IR generation
- So, will use the changes to Clang Adrian had to add for EnerC.
- Working with Adrian to refactor things so we can share most of the annotation code he's written
- Ported the EnerC stuff from LLVM-2.9 to LLVM-3.2 (and its associated version of Clang), which is now in a private GitHub repo.
- Mostly working "global" qualifier using the
qual()attribute, with simple "type checking" implemented. - Current Limitations
- can't differentiate function overloading based on attributes (not a big deal)
- can't differentiate between putting
globalon the type or the pointer (or one of a couple levels of pointer). Yet to see if this will be a problem- For instance:
int global * x===global int * x.
- For instance:
# (from cmake directory)
bin/Debug/clang -Xclang -load -Xclang lib/Debug/libGrappaTypeChecker.dylib -Xclang -add-plugin -Xclang grappa-type-checker -I ../../tools/clang/enerc/checkers/grappa ../../tools/clang/enerc/test/grappa/basic.cpp