Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

SlimC

The slimC self-compiling compiler

Documentation

Tbd.

For a detailed reference on many of the implemented concepts, see

N. Wirth
Compiler Construction
Addison Wesley, 1996

Demonstration

The following demonstration was tested on a Macbook Pro running MacOS X (10.10.5) with homebrew. To compile the compiler for the first time, checkout the repository and use cmake to compile the compiler.

git clone https://github.com/rkwitt/slimc.git
cd slimc
mkdir build
cmake ..
make

This bootstrapping is requires some tricks (to remove the added language constructs) which can be found in bs.h. Next, we compile the compiler using the just generated executable slimc. This executable is in the native format of your machine and does not need the VM to execute.

cd build
./slimc slimc.c > slimc-native-vm

The compiler outputs RISC instructions which we just piped into the file slimc-native-vm. As you might have guessed, this file can now be used by the VM. In fact, we will use it to compile the compiler another time, but now using the compiler in the form of the collection of RISC instructions (as opposed to the compiler available as an executable on your machine as before):

./vm slimc-gcc-vm slimc.c > slimc-vm-vm

You will also get some additional output which might look like

Total VM execution time (usec): 5162276
Executed instructions per second: 9.390646e+07

This is a little statistic on how many VM instructions were executed per second. The total runtime, on the test system, is about 5 seconds. Finally, we compare the generated RISC instructions with the instructions generated by our compiler (but initially compiled via clang or GCC):

diff slimc-native-vm slimc-vm-vm

If everything went well, there should be no difference.

About

The slimC self-compiling compiler

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages