trs79
trs79

Reputation: 319

How to use Clang to translate from C++ to another language

I've recently compiled Clang and LLVM on Windows. My goal is to use it to translate from C++ to another language, but I'm not sure the best way to go about this. For example, if I invoke clang with the -ast-print "pretty print" option, it looks like Clang can get a faithful representation of the original code from its internal AST. Do I need to somehow mimic that code so I get a pretty print in my new language? Or should I walk the AST tree? Thanks for any help!

Upvotes: 1

Views: 977

Answers (1)

arrowd
arrowd

Reputation: 34411

First solution is to use libclang library to translate C/C++ source to whatever you want.

Second - write a LLVM backend, which would convert LLVM IR to your language (like C backend). This is more flexible (IMO), but will require you to work on much lower level than C++ source.

Upvotes: 1

Related Questions