Source to source translation.

Hello,

I’m trying to do a source to source translation from C++ code to C++ code. I want the output to contains some automatically inserted annotations, and the rest of the code exactly the same as it was before the processing. Is this possible with llvm?

Thanks.

Hi Carlos,

I'm trying to do a source to source translation from C++ code to C++ code. I
want the output to contains some automatically inserted annotations, and the
rest of the code exactly the same as it was before the processing. Is this
possible with llvm?

this may be possible with clang. I suggest you ask on the clang mailing list.

Best wishes,

Duncan.

That's possible with Clang. Please post on the cfe-dev list.

Sebastian

Hello Carlos,

I don’t think so.
LLVM is not a source-to-source translator, but an optimizing compiler based on a portable, typed, assembly-like intermediate representation. One of the primary goals of LLVM is to generate optimized object code on a variety of platforms.
Even if you do not use any optimizations, your C++ code would still need to be lowered to LLVM, which makes it very hard to get the same code back (if at all possible).
Maybe something along the lines of TXL would be more appropriate for what you want to do?

Matthieu

Check out clang's ASTConsumer, and its various driver, and front end components. I cannot give you more details, as I'm
about to start doing this myself, albeit from C++ source to a non-source foreign language library. However I believe
your goal is most definitely doable.

Garrison

Thanks for your answer Garrison! I will check out clang’s ASTConsumer as you say.

Greetings.

Thanks for your answer Matthieu! I will check out TXL as you say. I have been reading it’s documentation and it seems to provide the functionality I need.

Greetings and thanks again.