[cfe-dev] -emit-html example
Chris Lattner
clattner at apple.com
Thu Apr 17 14:41:02 PDT 2008
One of the spiffy things that Ted is doing with his static analysis
stuff is having it emit reports in HTML. A required part of this is
just being able to turn code itself into HTML. I think that the stuff
clang is doing is pretty cool, so I thought I'd show an example.
Here's "gcc.c" from llvm-gcc converted to html with:
$ clang -I <tons of stuff> gcc.c -emit-html -o gcc.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc.html.gz
Type: application/x-gzip
Size: 154298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080417/cc1abbed/attachment.bin>
-------------- next part --------------
the code has line numbers and is syntax highlighted. In addition, if
you float your mouse over a macro (which are displayed in red bold
letters), a pop-up shows the tokens that that instance of the macro
expanded out into. I picked gcc.c because it has a ton of macros.
Take a look at the examples around line 1410 and line 750 for some fun
examples.
One of this nice things about this is that it builds on the clang
rewriter, lexer, preprocessor etc, and as such is only a tiny amount
of code. Also, the HTML emission is really fast even thought this
makes a 1.1M html file :).
One of the things we're shooting for is self contained files (they
don't depend on external javascript or images for example), so that
the html can be copied around like this without losing pieces of the
content. Ted's analysis tool further annotates the output with the
bugs he finds, he'll send out an email about that in the next few days.
Anyway, give -emit-html a try, if you have ideas for making it better,
it's really easy to improve: for example, the code to do the macro
expansions is ~70 lines of commented code at the end of HTMLRewrite.
-Chris
More information about the cfe-dev
mailing list