www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D + LLVM?

reply Stephen Waits <steve waits.net> writes:
Has anyone looked at marrying the D front end to LLVM?

--Steve
May 30 2007
next sibling parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Stephen Waits wrote:
 Has anyone looked at marrying the D front end to LLVM?
It has been suggested here before, but AFAIK nothing working ever came of it (I'm not even sure anyone seriously tried). If you want to give it a try GDC may be a good place to start since IIRC the GCC C and C++ frontends were already adapted to work with LLVM.
May 30 2007
prev sibling next sibling parent Brad Roberts <braddr puremagic.com> writes:
Stephen Waits wrote:
 Has anyone looked at marrying the D front end to LLVM?
 
 --Steve
I looked at llvm a while ago with an eye towards what would it take to hook up the D front end to it. There were two things that stopped me: 1) time.. I figured it'd take at least 3 months of work, quite possibly more. 2) exception handling in llvm was pretty weak and D without exceptions seemed like a bad plan. With llvm 2.0, that support has progressed a lot from what I read, but it's of interest that g++/llvm still doesn't support exceptions by default (it's enableable, but they weren't confident enough to enable it by default). I think it'd be a very interesting experiment, but to make something production quality would take an investment of time that I just don't have. If I took a leave of absence from work and really focused, I'm sure it's doable. Later, Brad
May 30 2007
prev sibling next sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Stephen Waits wrote:
 Has anyone looked at marrying the D front end to LLVM?
 
 --Steve
I've thought about it a few times. At this stage, I think it would be really good to have a second, completely independent implementation of D that doesn't depend on the DMD front-end. What I'd really like to[1] write is a very simple, easily modified D compiler that spits out LLVM bytecode so that new language features could be prototyped. Maybe one of these days :P -- Daniel [1] have the time to -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
May 30 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Daniel,

 I've thought about it a few times.  At this stage, I think it would be
 really good to have a second, completely independent implementation of
 D that doesn't depend on the DMD front-end.
 
 What I'd really like to[1] write is a very simple, easily modified D
 compiler that spits out LLVM bytecode so that new language features
 could be prototyped.
 
 Maybe one of these days :P
 
 -- Daniel
 
You just quoted the comment out of the top of a program I'm working on. It's just a lexer at this point[1] and the target is to also build the back end[2] (or ends), but other other than that you and I are thinking along the same lines. [1] I've /only/ been working on it for like a year so I should be done soon ;b [2] What can I say, I'm writing a COMPILER for fun. Don't say it, I've all ready been told I'm nuts.
May 30 2007
parent reply Stephen Waits <steve waits.net> writes:
BCS wrote:
 
 It's just a lexer at this point[1] and the target is to also build the 
 back end[2] (or ends), but other other than that you and I are thinking 
 along the same lines.
With LLVM you needn't bother with the backend, as they exist for quite a few platforms. --Steve
May 31 2007
parent BCS <ao pathlink.com> writes:
Reply to Stephen,

 BCS wrote:
 
 It's just a lexer at this point[1] and the target is to also build
 the back end[2] (or ends), but other other than that you and I are
 thinking along the same lines.
 
With LLVM you needn't bother with the backend, as they exist for quite a few platforms. --Steve
Where would the fun be in that?
May 31 2007
prev sibling parent reply Tomas Lindquist Olsen <tomas famolsen.dk> writes:
Stephen Waits wrote:

 Has anyone looked at marrying the D front end to LLVM?
 
 --Steve
I have been playing around with merging the DMD frontend and LLVM for about a week now. It's not a really serious attempt, but it's going a lot better than I had thought it would. I had not planned to announce anything, but since this post has arrived I thought I'd let out the secret. I'm not a compiler guru, in fact this is my first attempt ever with anything compiler related. Also I'm just a hobbyist programmer and I'm doing this in my spare time just for fun. Maybe something useful will come out of it, maybe it will die in a week. Right now I just don't know... That being said I'm not going to stop yet as it's actually pretty fun so far :) To give an idea of how far I am (which isn't very far) I have the following working so far: * integral and floating types (real is double) * pointers to the working types (& and *) * casts * global variables * structs (no methods) * free functions (templated too) * = - * / += -= *= /= operators As you can see I've only implemented a tiny fraction of the specification so far, but it would definitely be nice to have a comlpete LLVM-D implementation. It's just a really nice feeling to run my test modules in the JIT compiler :P The main issue I've had so far is translating to the LLVM SSA form. As far as I have seen DMD does not provide any information about whether a variable needs storage or not. Before pointers I had some really nice code output, but when I got to pointers it all collapsed and now I use alloca for all variables and rely on the mem2reg optimization pass to figure out where it's really needed and not... -Tomas
May 31 2007
parent reply "Nick Sabalausky" <a a.a> writes:
"Tomas Lindquist Olsen" <tomas famolsen.dk> wrote in message 
news:f3mp43$235j$1 digitalmars.com...
 I have been playing around with merging the DMD frontend and LLVM for
 about
 a week now. It's not a really serious attempt, but it's going a lot better
 than I had thought it would. I had not planned to announce anything, but
 since this post has arrived I thought I'd let out the secret.
I've been working on writing stubs and such to at least get the DMD frontend to compile and I'm curious how you handled DMD's tocsym.c and todt.c files. Did you: 1. Rip them out (like I think I've heard DMC does)? 2. Keep them, but gut the function bodies? or 3. Leave them intact and recreate all of the backend stuff they reference? (Like I tried but ultimately gave up on)
Aug 03 2007
parent reply Tomas Lindquist Olsen <tomas famolsen.dk> writes:
Nick Sabalausky wrote:

 "Tomas Lindquist Olsen" <tomas famolsen.dk> wrote in message
 news:f3mp43$235j$1 digitalmars.com...
 I have been playing around with merging the DMD frontend and LLVM for
 about
 a week now. It's not a really serious attempt, but it's going a lot
 better than I had thought it would. I had not planned to announce
 anything, but since this post has arrived I thought I'd let out the
 secret.
I've been working on writing stubs and such to at least get the DMD frontend to compile and I'm curious how you handled DMD's tocsym.c and todt.c files. Did you: 1. Rip them out (like I think I've heard DMC does)? 2. Keep them, but gut the function bodies? or 3. Leave them intact and recreate all of the backend stuff they reference? (Like I tried but ultimately gave up on)
That would be number 2. The LLVM backend is fundamentally different from Walters, and I'm not using them at all. My compiler is based on the toElem and toObjFile backend functions only. Eventually I'll be moving away from those too and roll my own completely... But that is for the future... I anticipate having a pre-alpha release ready in a week or two, then you can take a look yourself. Also you might be interested in Gregor Richards DMDFE *[1] which is the DMD frontend with all the backend stuff removed, and it compiles out-of-the-box. [1]: http://dsource.org/projects/dsss/browser/branches/dmdfe
Aug 03 2007
parent Stephen Waits <steve waits.net> writes:
Thanks for reviving this thread - just wonder if you folks working 
toward this could provide a status update?

I'm getting close to starting my next project on PS3 and I'm looking 
squarely in the direction of D.

--Steve
Aug 03 2007