Question

The clang 3.0 online demo page http://llvm.org/demo/index.cgi provides an option to output LLVM C++ API code" representing the LLVM-IR for the input program.

Is "produce LLVM C++ API code" output a clang option (and if so, what is it)?

Or is it an llvm tool option (which one)?

Is it possible to do the same thing but from LLVM-IR input? Basically I'd like to see the proper llvm c++ api calls needed to produce a particular given llvm-ir sequence. I'd like to learn backwards by example rather than forwards from the documentation.

Manual pages and --help and --help-hidden for clang, llvm-as and llvm-dis don't show anything obvious.

edit: OK now I see in the output on that web page, "generated by llvm2cpp". But I can't find that tool in recent llvm releases, only old releases, has a new tool in 2.9 and 3.0 taken over for llvm2cpp?

Was it helpful?

Solution

Yes. C++ backend is the tool which does this. Try "llc -march=cpp foo.bc"

OTHER TIPS

I ran into exactly the same problem and saw the CPPBuilder mentioned a couple of times. This approach unfortunately no longer works on recent LLVM versions as the CPPBackend was removed between 3.8 and 3.9.

If you want the CPP backend you (i) have to configure llvm and add cppbackend to -DLLVM_TARGETS_TO_BUILD during the initial configure and (ii) run an llvm <= 3.8.

The feature was removed because it did not use IRBuilder and almost nobody used it. My solution was to rely on the old version to get inspired, then implement it myself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top