开发者

How to determine what compiler does with a metaprogram? (for boost.proto)

How do I determine what my compiler (g++) is doing with template code?

I am using boost.proto (an expression-template library) to evaluate some maths expressions at compile time. The code evaluates the expressions correctly, but I would like to see whether the compiler has expanded out the expression to the equivalent of hand-written c-code (i.e. eliminated all the temporaries), or whethe开发者_JS百科r there is still some further compile-time optimizations to be done.

Is there a way to see what the compiler has done with the templates?

Thanks


There are several ways to see a C++ code after the templates instantiation pass:

  • Use gcc -fdump-tree-original (or even -fdump-tree-all to see more passes)
  • Use Elsa C++ parser: http://scottmcpeak.com/elkhound/sources/elsa/
  • Use Clang and an LLVM C backend - the latter will give the most unreadable code, but it is still useful in some cases. There should be some AST dumping functionality in Clang itself as well.


g++ -S

is documented as "Compile only; do not assemble or link". Basically you get assembly output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜