Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there tools to transform source code in C++ to the source code in C/C++, but with instantiated (unrolled) templates? [closed]

Tags:

c++

Are there tools to transform source code in C++ to the source code in C/C++, but with instantiated (unrolled) templates? This is necessary for an unambiguous understanding, into the what code C++ templates converted. May be it is present in the IDEs(MSVS, QtCreator, ...) or in the compilers(ICC, GCC, MSVC, Clang)?

like image 488
Alex Avatar asked Mar 31 '13 12:03

Alex


1 Answers

This seems already answered on SO

  • Debugging template instantiations
  • link 2
  • link 3 (with a nice paper too)
  • How do you debug heavily templated code in c++?

The Idea/principle from Alexey Frunze to use the disassembled code is quite good, together with the use of simplified templates there is a pretty good chance to understand exactly what it does.

Edit 1 There are a few other possibilities on how to get an understanding of the things which the compiler had done

  1. Use: gcc -S -O1 {yourcode.cpp} to get the assembly and use the tool c++filt (its a part of binutils to convert the disassembly to C-Code if you feel more comfortable with C-Code
  2. Use: g++ -fdump-tree-original file.cpp to get some (pseudo) C++ code
  3. Use the MSVC++ debugger with the breakpoint after the last instantiation and see all types and values which are the parameters of the instantiated template
  4. Use: GCC XML for generating XML with instantiated templates (FAQ)
  5. To know how the compiler instantiated and optimized the templates you can use Clang: -emit-llvm to get the LLVM IR, and use llvm-dis to convert it to text
  6. CPP insights is a website of a LLVM based tool to see instantiations
like image 157
Quonux Avatar answered Oct 08 '22 15:10

Quonux