Sign in to follow this  
Decrius

What to export for a hobby compiler?

Recommended Posts

So, I want to play around building a mini-hobby compiler. The parser I can handle (though I might favor a library for that! suggestions?) however, what to export? Machine code? Sounds difficult and inflexible. ASM code? Is okay, but would limit myself to certain CPU families (unless I export multiple kinds of ASM, depending the demand...but it's only a hobby compiler :O). C code? Could do, but I rather would like to dive a little deeper and not be limited to C. Is there anything in between C and ASM I could export? Something like an intermediate file? What is it anyways? Or is ASM my best bet? Thanks!

Share this post


Link to post
Share on other sites
Okay thanks.

I do want to get a system dependent executable in the end of course, but that I would get after compiling the LLVM sources on a specific platform?

Share this post


Link to post
Share on other sites
Quote:
Original post by Decrius
Okay thanks.

I do want to get a system dependent executable in the end of course, but that I would get after compiling the LLVM sources on a specific platform?


Native code, and tons of optimisations for free. The LLVM machine is, unlike .net or Java VM, not intended to provide full platform independence, but to provide the best optimisations for the target machine, i.e. target machine adaption, lifelong optimization, and (not implemented yet) offline optimization (that means: intense optimisation when the machine is idling). On the other hand, you can use LLVM to provide native performance scripting functionality for your applications. E.g., I plan to use LLVM for a shader system for picogen, a full software ray tracer.

One big plus of LLVM is that it only has roughly 30 instructions, afair.

Basically, you build an abstract syntax tree, upon which LLVM will do his work. So, compared to Java VM and .net, it's damn easy to implement, plus, as said, you get native performance and a plethora of optimisation passes for free.

Share this post


Link to post
Share on other sites
Quote:
Original post by phresnel
Quote:
Original post by Decrius
Okay thanks.

I do want to get a system dependent executable in the end of course, but that I would get after compiling the LLVM sources on a specific platform?


Native code, and tons of optimisations for free. The LLVM machine is, unlike .net or Java VM, not intended to provide full platform independence, but to provide the best optimisations for the target machine, i.e. target machine adaption, lifelong optimization, and (not implemented yet) offline optimization (that means: intense optimisation when the machine is idling). On the other hand, you can use LLVM to provide native performance scripting functionality for your applications. E.g., I plan to use LLVM for a shader system for picogen, a full software ray tracer.

One big plus of LLVM is that it only has roughly 30 instructions, afair.

Basically, you build an abstract syntax tree, upon which LLVM will do his work. So, compared to Java VM and .net, it's damn easy to implement, plus, as said, you get native performance and a plethora of optimisation passes for free.


Sounds interesting, and with native code you mean an executable specifically for that certain platform? And would it be build by the developer, or do users automatically let it compile for their system (does the developer have to distribute executables for every platform, or just the LLVM script?)?

Share this post


Link to post
Share on other sites
It can generate native, executable code that runs straight on the metal. You don't need to distribute llvm with your code to get it to run your code that was compiled with llvm. On that note, llvm natively handles C and C++. In other words, if you are looking to make a LANGUAGE, then you need to be concerned with translating into LLVM. If you're looking to make a COMPILER, then LLVM is kind of redundant, as LLVM is a compiler.

If instead you are looking to make a COMPILER PASS, aka an optimization, then LLVM is likely pretty close to spot on what you're looking for [especially considering MS's Pheonix has just been sitting there for about a year].

It can also run in a JIT compiled mode, in which case you would have to distribute the LLVM JIT. It can be used for both purposes.

Share this post


Link to post
Share on other sites
If you want, think about LLVM as an optimizing assembler. Check this
beginners tutorial on LVM, it just uses the online llvm compiler.

So you just create llvm assembly, then llvm will optimize it and spit out the relevant x86/whatever optimized assembly, then you can create an executable out of it with GCC/whatever.

clang is the name of the llvm C compiler.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this