No description
Find a file
2009-09-23 15:55:25 -07:00
asm [CHANGED] updated comments, removed some unnecessary code 2009-06-26 15:37:48 -07:00
test [CHANGED] default test suite now includes big_test 2009-06-26 11:22:48 -07:00
.gitignore [CHANGED] added trash to .gitignore 2009-06-26 11:39:52 -07:00
build.rb [NEW] Binary assembler outputs working machine code and Mach-O object files that can be linked into working executables. 2009-06-25 09:42:56 -07:00
compiler.rb [CHANGED] Removed use of the LOOP instruction. 2009-06-26 11:37:45 -07:00
cradle.rb Initial commit of a compiler in Ruby. 2009-05-13 20:56:46 -07:00
interpreter.rb [NEW] Added the bare-bones interpreter with i/o primitives. 2009-05-15 09:38:16 -07:00
Makefile [NEW] Binary assembler outputs working machine code and Mach-O object files that can be linked into working executables. 2009-06-25 09:42:56 -07:00
min.code [FIXED] compiler appends _exit code to binary output 2009-05-19 18:09:28 -07:00
min.darwin.asm [NEW] First hints of cross-platform support. Compiles to Mach-O on Darwin with nasm and gcc. 2009-05-25 16:26:21 -07:00
min.linux.asm [NEW] First hints of cross-platform support. Compiles to Mach-O on Darwin with nasm and gcc. 2009-05-25 16:26:21 -07:00
README added README 2009-09-23 15:55:25 -07:00
template.darwin.asm [NEW] First hints of cross-platform support. Compiles to Mach-O on Darwin with nasm and gcc. 2009-05-25 16:26:21 -07:00
template.linux.asm [NEW] First hints of cross-platform support. Compiles to Mach-O on Darwin with nasm and gcc. 2009-05-25 16:26:21 -07:00

sjs
sami.samhuri@gmail.com
2009-09-22

A compiler for fun and education.  Written (mostly) in Ruby and based
on the tutorial "Let's Build a Compiler" by Jack Crenshaw.  I wasn't
satisfied using an external assembler and outputing assembly text so I
wrote an x86 assembler in Ruby.  It assembles just the instructions I
need for this compiler, so it is by no means complete.  32-bit only
and no prefixes are supported.  It's basically just a handful of
instructions and mod-rm encoding.  I use the system's linker and have
no intention of writing my own, don't worry!

The code currently consists of a recursive descent parser that outputs
x86 code in ELF binaries* on Linux and Mach-O binaries on Darwin.
Most of the code for outputing executables is Ruby, but ELF support is
still in C and not published in the repository.  Classes to output
Mach-O and ELF binaries are found in asm/(elf|macho)writer.rb, but ELF
support is not implemented yet so binaries only compile and run on OS
X right now. ELF should come soon as I now have lights in my den. :)

Some major refactoring is needed as the project grew organically and
in order to keep up with the tutorials I have not yet made radical
changes.  The asm/ directory holds the assembler but also the MachO
and ELF code, for now.  The assembler is a from-scratch implementation
in Ruby. This is my first assembler and first time working with the
x86 ISA, so it probably isn't great.  It outputs horribly inefficient
code and there are no optimizations.

Hopefully I can reduce the number of lines by factoring more, but it's
pretty slim at ~3000 LOC.  About 2100 of those are actual code.  I did
not write this compiler with the intention of anyone else reading it
but there are a reasonable about of comments.


 Real   Total  Filename
 Lines  Lines
 -----  -----  --------
   87  /  112  build.rb
  617  /  891  compiler.rb
   12  /   29  asm/asm.rb
  569  /  843  asm/binary.rb
  197  /  319  asm/cstruct.rb
    4  /    6  asm/elfsymtab.rb
    4  /    8  asm/elfwriter.rb
  170  /  374  asm/machofile.rb
   95  /  163  asm/macho.rb
   19  /   28  asm/machosym.rb
   48  /   77  asm/machosymtab.rb
   19  /   25  asm/machowriter.rb
   16  /   25  asm/objwriter.rb
   20  /   31  asm/registers.rb
   42  /   66  asm/regproxy.rb
   56  /   89  asm/symtab.rb
  131  /  183  asm/text.rb
 2097  / 3269  total


Happy hacking!
-sjs