I'm curious if there are any projects out there that can take an LLVM parse tree and re-generate source code off of it. I'm particularly thinking of C/C++.
The LLVM target-independent code generator is a framework that provides a suite of reusable components for translating the LLVM internal representation to the machine code for a specified target—either in assembly form (suitable for a static compiler) or in binary machine code format (usable for a JIT compiler).
LLVM is a language-agnostic compiler toolchain that handles program optimization and code generation. It is based on its own internal representation, called LLVM IR, which is then transformed into machine code.
The Abstract Syntax Tree (AST)
An LLVM-only build will need about 1-3 GB of space. A full build of LLVM and Clang will need around 15-20 GB of disk space. The exact space requirements will vary by system. (It is so large because of all the debugging information and the fact that the libraries are statically linked into multiple tools).
If "LLVM parse tree" is AST from clang
Yes, you can regenerate source from clang's AST. Some references:
If "LLVM parse tree" is LLVM IR
There were several projects to generate sources from LLVM IR. The first one, the "C back-end" was dropped in LLVM 3.1.
Now there are several projects to generate C from LLVM IR:
Resurrected "C back-end" by Roel Jordans
[LLVMdev] [RFC] Resurrecting the C back-end (Mailing List Post), via cited phoronix news
"C++ -> LLVM IR -> Emscripten -> asm.js -> C" chain
Prototype of an LLVM IR => C compiler ("c backend"), via LLVM Weekly - #15
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With