[cfe-dev] [LLVMdev] LLVM targeting HLLs
csdavec at swan.ac.uk
Mon Jan 24 14:35:29 PST 2011
On 24 Jan 2011, at 22:04, Eric Christopher wrote:
> On Jan 24, 2011, at 2:01 PM, David Given wrote:
>> I am interested in using LLVM to translate C and C++ into high-level
>> language code. (As an update to an earlier project of mine, Clue, which
>> Perl 5, C, Java and Common Lisp, with a disturbing amount of success.
>> See http://cluecc.sourceforge.net for details.)
>> The obvious place to start on this is the C backend, except in these 2.8
>> days the C backend is so hedged about with caveats I'm rather wary of
>> basing anything on it. I also recall seeing comments here that it's due
>> for a rewrite from scratch, and that various people were looking into
>> it. Can anyone go into more detail as to what exactly is wrong with the
>> C backend, and whether this rewrite is happening?
>> The other thing I could do is to use the LLVMTargetMachine and treat my
>> HLL as a low-level machine; this gets me a certain amount of good stuff
>> like register allocation and more optimisations, but the documentation
>> is still pretty basic (e.g.
>> http://wiki.llvm.org/Absolute_Minimum_Backend is three short paragraphs)
>> and I'm not certain as to whether LLVMTargetMachine is suitable. For
>> example: my HLL can largely be treated as a register machine with an
>> arbitrary number of registers. Can LLVMTargetMachine handle this?
> You could create a different code generator from clang or use the rewriting
-- Send from my Jacquard Loom
A better approach would probably be to use Clang's CodeGen lib as inspiration, and write an equivalent that emitted your high-level language code instead of LLVM IR. For example, consider C++ classes:
The same is true even for pure C structures - you'd want to represent these as objects with named fields. This information is in the Clang AST, but it's lost by the time you get to LLVM IR. Taking an example from Apple's Foundation framework, you have two structures:
CGFloat x, y;
CGFloat width, height;
this.x = 0;
this.y = 0;
this.width = 0;
this.width = 0;
This is pretty simple to generate from the Clang AST, but will be a huge amount of effort to generate from LLVM IR.
-- Sent from my PDP-11
More information about the cfe-dev