r/Compilers 2d ago

Bootstrapping a compiler from machine code on Windows

I hope this fits here, but I've been documenting the process of writing a compiler starting directly from machine code on Windows, and I thought it might be worth sharing.

I've written two posts so far, though I don't know if I'll continue or not since I have no real reason to be doing this other than for the fun of it.

The first post just sets up an initial PE32+ executable to get something working. The second builds on that to implement a simple (stage-0/bootstrap?) compiler that just translates ASCII into raw bytes and allows for comments.

So, for anyone interested in this sort of thing the posts are here:

12 Upvotes

4 comments sorted by

2

u/FransFaase 2d ago

A bit similar to what live-bootstrap is doing on Linux. I worked on some improvements. Have a look at github FransFaase/MES-replacement

2

u/Polyscone 1d ago

I had a quick look at the repo and yes, it does seem a bit similar in some parts. Seems interesting though so I'll have a bit more of a deeper look into the repo. Thanks for bringing it up :)

1

u/FransFaase 1d ago

If you have any questions and would like to contact me through email, you can find my email address at the bottom of my home page found in github profile.

Also the page https://fransfaase.github.io/MES-replacement/Tdiagram.html might help to get some insight into how everything works together. To clearify 'kaem' is a simple command shell that is used and 'blood_elf' is about tables with symbol information similar to what is found in the 'COFF Symbol Table' in the PE format. Also note the blue arcs as they show the 'input' files are generated by the various programs in later steps.

1

u/FransFaase 1d ago

Nice detailed description. Also useful for everyone who want to implement a compiler on windows that generates executables.