Search the web
Sign In
New User? Sign Up
compilers101 · Compilers 101
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
I got my intel code generator working!   Message List  
Reply | Forward Message #1314 of 1320 |
It took about 2 days of programming and 2 days of debugging (one of which was
Rainer's :-) ) to get an x86 code generator working for the toy compiler I wrote
last year.

There were two bugs in the generated code; Rainer caught the first one, to do
with comparisons. The second was that I was failing to assign to any array
elements. Turned out to be simple: I had "mov eax,[ecx]" when I should have had
"mov [ecx], eax"

It now runs my test program, Ecce, perfectly. (Ecce is an old line-based text
editor; I actually still use a later variant of it, embedded within emacs, as my
main editor)

I defined a very simple stack machine, and then wrote a program that read the
stack-machine assembly code and macro expanded each instruction into a
functionally equivalent set of x86 instructions.

The generated code is something like a third the speed and three times the size
of 'proper' x86 code, but it works.

What I'll be doing in the long term is making my toy language look more like a
cut down version of C (rather than a lot like Rainer's "LC", which is what it
started out to be based on), and I'll simplify the source code of my compiler
until it can compile itself, at which point it's officially not a toy compiler
any more :-) (Toy being defined as any compiler that cannot compile itself)

Then with this virtual stack machine as an intermediate code, I have a way to
rapidy bootstrap the compiler to any other architecture.

I still have a fair bit of work to do, eg to make sure that I can cross-call C
etc, but the hard part is now done. Now that I can write solid reliable simple
code, expanding the features supported should happen quickly.

The test program is here:

http://www.gtoal.com/compilers101/intro/gtoal/interp/ecce.t.txt (source)
http://www.gtoal.com/compilers101/intro/gtoal/interp/ecce.asm.txt (stack
machine)
http://www.gtoal.com/compilers101/intro/gtoal/interp/ecce.S.txt (x86 code)
http://www.gtoal.com/compilers101/intro/gtoal/interp/ecce (linux executable)

I even have some documentation:
http://history.dcs.ed.ac.uk/archive/apps/ecce/hwhitfield/ecce.txt (man page)
http://history.dcs.ed.ac.uk/archive/apps/ecce/hmd/ecce8.txt (primer)

This version doesn't have any file I/O yet, it just starts with an empty buffer,
and throws everything away on exit. I expect that will probably be improved
before the weekend is over :-)

G





Sat Jun 6, 2009 2:39 pm

graham_toal
Offline Offline
Send Email Send Email

Forward
Message #1314 of 1320 |
Expand Messages Author Sort by Date

It took about 2 days of programming and 2 days of debugging (one of which was Rainer's :-) ) to get an x86 code generator working for the toy compiler I wrote...
Graham Toal
graham_toal
Offline Send Email
Jun 6, 2009
2:40 pm

... Graham, as usual, you are THE MAN. This is really cool! For extra bonus points, you should work in register calling conventions. ;-) -->Neil ... C. Neil...
Neil Bradley
cneilbradley
Offline Send Email
Jun 6, 2009
6:02 pm

... When I do a native code generator, I'll do that and throw all the optimising tricks at it, but as long as I'm treating the x86 as a simple stack machine,...
Graham Toal
graham_toal
Offline Send Email
Jun 6, 2009
8:10 pm

... next development - I'm using the stack-based code as an intermediate code from which to generate more traditional x86 instructions in a load/store format;...
Graham Toal
graham_toal
Offline Send Email
Jun 11, 2009
7:07 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help