How to get Register-Transfer-Language (RTL) Code f

2020-07-23 04:02发布

问题:

When any compiler like GCC compiles a C Program it generates intermediate code. Just like we can get Assembly code by applying -s option to any .c file, similarly I want to get Register-Transfer-Language (RTL) for C and JAVA file . How to get it ?

回答1:

The three adress code is called gimple, see e.g. https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html but this seems more frontend-backend communication, it can be dumped using

  gcc  -fdump-tree-gimple <file>  

See http://www.cse.iitb.ac.in/~uday/courses/cs324-05/gccProjects/node4.html

from some more IR related dumping options from HLL to deep. Probably you want option 4.

  1. Abstract Syntax Tree (AST). The -fdump-tree-original-raw switch dumps the textual representation of the AST for given input source.
  2. Gnu SIMPLE representation (GIMPLE) The -fdump-tree-gimple-raw switch dumps the GIMPLE representation of the input source.
  3. Control Flow Graph (CFG). The -fdump-tree-cfg-raw switch dumps the CFG form of the GIMPLE code.
  4. Register Transfer Language (RTL IR) The -da switch dumps the RTL IR of the input source program with the pass number as a part of the dump file name.
  5. Assembly Language (ASM). The -S switch dumps the target assembly code for the input. In our case, this is the Pentium assembly language.