Skipping LLVM, CLang and LLC

I am implementing a new back-end for LLVM starting with the target CBackend. The ultimate goal is to use "llc" to generate the source transformations of the C input code. However, there are a number of optimizations that I would like to do that do not seem to be very well supported in this context. The LLVM object code is very low, and I have to check it to rediscover what really happens. This would be much easier to do at the AST level. However, it seems that the AST level is an internal Clang construct, and there is no easy way to connect to it.

Do I need to check the LLVM object code and independently reconstruct a higher level stream? (Do I have to do this every back-end? It seems wasteful!)

+4
source share
1 answer

In general, you cannot open everything. So, you have only two possibilities:

  • Do everything at the AST level.
  • Retrieve additional information (for example, through metadata) that can help you recover some aspects of the input source.

But in fact, you do not need to convert the source into a source at the LLVM IR level, this is the wrong tool for this purpose. You can surely connect to the AST level. For instance. Clang sources contain rewriting code that turns ObjC code into regular C.

+6
source

Source: https://habr.com/ru/post/1342471/


All Articles