Dan Dan - 13 days ago 4
C++ Question

llvm ir back to human-readable source language?

Is there an easy way of going from llvm ir to working source code?

Specifically, I'd like to start with some simple C++ code that merely modifies PODs (mainly arrays of ints, floats, etc), convert it to llvm ir, perform some simple analysis and translation on it and then convert it back into C++ code?

It don't really mind about any of the names getting mangled, I'd just like to be able to hack about with the source before doing the machine-dependent optimisations.

Answer

There is an issue here... it might not be possible to easily represent the IR back into the language.

I mean, you'll probably be able to get some representation, but it might be less readable.

The issue is that the IR is not concerned with high-level semantic, and without it...

I'd rather advise you to learn to read the IR. I can read a bit of it without that much effort, and I am far from being a llvm expert.

Otherwise, you can C code from the IR. It won't be much more similar to your C++ code, but you'll perhaps feel better without ssa and phi nodes.