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 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.
 

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

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
next sibling parent reply Stephen Waits <steve waits.net> writes:
Tomas Lindquist Olsen wrote:
 
 Has anyone looked at marrying the D front end to LLVM?

a week now. It's not a really serious attempt, but it's going a lot better

Thomas, that's GREAT to hear!
 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

Is LLVM's SSA structure the same as gcc's? I know they've interface gcc and g++ onto LLVM. This is why I figured GDC might be a viable front-end for LLVM; however, I obviously haven't looked into it yet. --Steve
May 31 2007
parent Tomas Lindquist Olsen <tomas famolsen.dk> writes:
Stephen Waits wrote:
 
 Is LLVM's SSA structure the same as gcc's?

Last week I didn't even know what SSA was, so I really have no clue.
May 31 2007
prev sibling 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 "Nick Sabalausky" <a a.a> writes:
Sorry, disregard this, my newsgroup reader seems to have replied to the 
wrong forum (Should have been D.gnu).

"Nick Sabalausky" <a a.a> wrote in message 
news:f8vl7s$9k8$1 digitalmars.com...
 "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