15
90
Fork
You've already forked dozer
14
WIP rust compiler
C 95.3%
Shell 2.2%
Dockerfile 1.2%
Rust 0.8%
CMake 0.5%
John Nunley d326dc9e99
All checks were successful
ci/woodpecker/pr/test/1 Pipeline was successful
ci/woodpecker/pr/test/2 Pipeline was successful
ci/woodpecker/pr/test/3 Pipeline was successful
ci/woodpecker/pr/test/4 Pipeline was successful
ci/woodpecker/push/test/1 Pipeline was successful
ci/woodpecker/push/test/2 Pipeline was successful
ci/woodpecker/push/test/3 Pipeline was successful
ci/woodpecker/push/test/4 Pipeline was successful
m: Change strategy for flexible arrays
Previously we were using the U_Array structure to handle flexible
arrays, which had a number of issues. Namely, the fact that it encodes
no type information and is very easy to misuse. This commit replaces it
with a new flexible array type. It is represented by "T*", which aims to
make it easier to index and iterate through.
Signed-off-by: John Nunley <dev@notgull.net>
2025年01月19日 16:05:21 -08:00
.woodpecker ci: Use Dockerfile to pre-install deps 2024年10月18日 12:40:20 -07:00
ci Fix ci/test.sh outputting mega diffs 2025年01月15日 14:45:23 +01:00
src m: Change strategy for flexible arrays 2025年01月19日 16:05:21 -08:00
tests Fix test paths in blocklist 2025年01月16日 14:33:09 +01:00
.gitignore m: Replace typemap with symbol table 2024年10月24日 20:21:25 -07:00
.gitmodules Add and test files in dozer-rustc-1.0.0 submodule 2025年01月10日 13:51:03 +01:00
ARCHITECTURE.md Move byteops/map/util into util/ 2025年01月19日 09:35:59 +01:00
build.sh Do not move libdozerrt.a output 2025年01月19日 09:35:59 +01:00
clean.sh Update build/clean scripts and add CMakeLists.txt ( #28 ) 2024年10月02日 02:02:43 +00:00
CMakeLists.txt Move byteops/map/util into util/ 2025年01月19日 09:35:59 +01:00
compile.sh Update build/clean scripts and add CMakeLists.txt ( #28 ) 2024年10月02日 02:02:43 +00:00
LICENSE-APACHE m: Initial commit 2024年08月02日 17:04:20 -07:00
LICENSE-MIT m: Initial commit 2024年08月02日 17:04:20 -07:00
README.md fix typo 2024年10月19日 20:32:42 +00:00

dozer

WIP Rust compiler, written in C

Motivation

The goal is to be able to compile an early version of the Rust compiler, without needing to go through the following:

  • C++; this is the current canonical bootstrap strategy via mrustc. This way Rust can be used as a viable bootstrap language for C++.
    • Note that this means we can't use the LLVM backend, as LLVM is written in C++.
  • The entire Rust bootstrap chain starting from OCaml in rustc v0.7 and going forwards from there. This takes a significant amount of time and we would like to avoid this.

See my blogpost announcing Dozer for more information.

Goals

As part of this goal dozer should be able to be compiled with very simple C compilers, like TinyCC and cproc. Care should be taken to avoid more complicated GNU extensions.

Eventually I would like the compiler to be able to compile an earlier version of rustc. I hope that it is possible to compile a version of rustc that supports the Cranelift backend, but this may be infeasible with a simple compiler. So for now we are targeting rustc v1.0.

Build

The build process for dozer aims to be very simple. We don't even use a Makefile, just to open the door to the possibility that make could be implemented in Rust. We only assume that we have a C compiler (which depends on an assembler, archiver and linker) as well as a very basic scripting tool (at the moment we are targeting kaem).

Thankfully kaem scripts are POSIX-shell compatible, so we can just use bash to run the build script.

$ bash build.sh

This script builds three important targets:

  • dozer, the bootstrap compiler.
  • dozer-qbe, the QBE backend for Dozer's intermediate language.
  • libdozerrt.a, a small runtime that is linked into programs compiled with Dozer.

Running

Note: dozer is still in an early state so the command line interface is heavily subject to change.

To compile a Rust program, call Dozer with the path to the root Rust module and the path to the output file.

$ ./dozer hello.rs hello.nhad

The "nhad" file contains metadata and bytecode for the compiled program. Use dozer-qbe to strip metadata and translate the bytecode to QBE IR.

$ ./dozer-qbe hello.nhad > hello.qbe

At this point QBE and the system C compiler can be used to translate the QBE IR to an executable. Make sure that libdozerrt.a is linked into the final executable.

$ qbe hello.qbe > hello.S
$ cc hello.S ./src/libdozerrt.a -o hello

Things left to do

  • The parser is still incomplete. Expanding the parser is probably the lowest-hanging fruit for new contributors.
  • We only support typechecking and emitting basic i32 operations. We need to be able to support more of Rust.
    • My current plan is to "eat the frog" and get trait resolution working as soon as possible, as most of Rust's language features require traits to work.
  • The rest of the owl.

License

MIT/Apache2