Archived

This topic is now archived and is closed to further replies.

Mithrandir

Compiler Gurus need only apply...

Recommended Posts

Mithrandir    607
Okay, so in the past month I''ve developed a really stable and functional virtual machine on my own. That''s great and all, but there''s one problem: doing anything useful in it takes way too much time. I now remember why no-one codes in ASM anymore My question is, is anyone familiar with GCC? Supposedly GCC offers a whole range of language front-ends which are all compiled to the same object code, and from there, anyone can write a back-end which converts the O-code into ASM for a particular machine. Am I correct with this notion? So, does anyone know anything about object code? I cannot find any resources on the GNU page, other than the badly documented and fugly source code of GCC itself... I figured that my other option would be to make a simple language from scratch. I have some experience with compiling directly from a parse-tree into assembly, so this shouldn''t be too difficult. Anyone have any hints on the ease of either method?

Share this post


Link to post
Share on other sites
NuffSaid    122
I don''t know much about GCC, but have you tried lcc? Its supposed to be pretty good and well documented. Here''s the link on Amazon.

Don''t know if that''s what you''re looking for though...

Share this post


Link to post
Share on other sites
Mithrandir    607
Well, the appeal of GCC is that it''s become a general compiler collection, rather than a C compiler alone. GCC now has front-ends for C, C++, Objective C, Chill, Fortran, Java, and soon they will have Ada support as well.

The obvious benefit is that all of these languages are compiled to a common form, and then that form can be assembled into machine-specific binaries.

Share this post


Link to post
Share on other sites
EvilCrap    134
hi!
for a long time ive had a great interest in writting scriptors and things, in order to write your own language; do you need to directly write asm values to a file? or is there like some api that will write the correct codes depending on the machine?

how does mvc++ do this? it does compile code that will work on various machines/processors, doesnt it?

Share this post


Link to post
Share on other sites
Truckhunter    122
Well, here''s another answer that doesn''t really answer your question. I can''t tell you for sure about GCC, but another similar option would be to look at the new Microsoft .NET stuff. If you haven''t read much on it, the basic gist is that all languages compile to an intermediate language (IL) which is then JIT compiled as it needs to be run. The IL is very well documented in the .NET platform sdk docs, so you''d have easy access to information on it. The downside would be that IL is a bit more complicated than most intermediate languages; it''s like a sort of object-oriented assembly. (PCode is the only other one I have any experience with, and it was much simpler to undertand.)
Anyway, if you could make a backend that goes from MSIL to your VM code, then in theory any of the .NET compilers should be able to compile for it.
The .NET platform SDK with C# and VB compilers is a free download at MSDN.

Share this post


Link to post
Share on other sites
Oluseyi    2111
quote:
Original post by Mithrandir
The obvious benefit is that all of these languages are compiled to a common form, and then that form can be assembled into machine-specific binaries.


GCC does not convert to a "common form." GCC parses the filenames (or command-line parameters) to determine what specific compiler to pass the file on to. It then uses the linker to combine all the object files into an executable (or static/dynamic library). For C programs (*.c) it calls ''cc''; for C++ (*.C, *.cc, *.cpp, *.cxx, ...) it calls g++; g77 for FORTRAN77 programs; gcj for Java programs, and so forth.

.NET is the closest thing to what you''re interested, and since being submitted to ECMA it should be possible to implement what you''re interested in. Also look into Mono, an attempt at an Open Source implementation of .NET for Linux.

Share this post


Link to post
Share on other sites
Dactylos    122
Well, you are both right in a way. GCC doesn''t compile it''s programs to a common form, but it does use a common intermediate form for all the languages it supports, this enables different languages to use the same optimizers and backends.

What you want to do is write GCC machine description macros for your VM.

Look at the GCC manual (that''s for GCC 3.0.1), specifically at chapters 20 ("Machine Descriptions") and 21 ("Target Description Macros").

Hope this helps at least a little...

Share this post


Link to post
Share on other sites