[LLVMdev] C Backend Ressurected

James Courtier-Dutton james.dutton at gmail.com
Wed Sep 3 14:13:16 PDT 2014


On 18 August 2014 15:18, Carback, Richard T., III <rcarback at draper.com> wrote:
> Hi All,
>
> 2 of my summer interns (Aimee Dipietro and Greg Simpson) used their time
> over the summer to resurrect the LLVM C Backend:
>
> https://github.com/draperlaboratory/llvm-cbe
>
> Improvements include recovery of simple for/while loops (instead of goto),
> better variable naming, inline asm support, and making it work on a more
> recent version of llvm. I believe they used the repository here as a
> starting point:
>
> https://github.com/glycerine/llvm/tree/cbe_revival
>
> Feedback is welcomed. I would like to see this feature put back into LLVM,
> and any help on how to make that happen would be appreciated.
>
>
I am not sure implementing a C backend is really what you want.
LLVM IR is in SSA CFG form.
I would have thought that the next step would have been trying to
convert it into AST, i.e. The format CLANG uses.
Once it is in AST, it is trivial to output in C or whatever other
language/format you wish.
I know going from CFG to AST is hard, but I think that would be a
better problem to solve.
As building AST from CFG is very different from building a C backend,
I would have though that it might have been good to use LLVM as a
library to read the LLVM IR format, manipulate the CFG into other
forms that are more AST friendly, and then write your own classes to
then convert that to AST.
Once in AST form, you could then use existing refactoring tools to
then output more readable C source code.

Well, that is just my idea, I am currently writing a tool to go from
Binary to LLVM IR. Once I have that done, I was going to do the next
tool to go from LLVM IR to AST.

Kind Regards

James



More information about the llvm-dev mailing list