Chibil: A C compiler targeting .NET IL

Hacker News Top Tools

Summary

Chibil is a C compiler written in C# that targets .NET IL, allowing C code to be compiled into .NET executables. It is based on chibicc and can run DOOM.

No content available
Original Article
View Cached Full Text

Cached at: 05/31/26, 04:35 PM

MichalStrehovsky/chibil

Source: https://github.com/MichalStrehovsky/chibil

Chibil C compiler

What is chibil

Chibil is a C compiler based on chibicc rewritten in C# and updated to target .NET IL (MSIL).

It is complete enough to run DOOM (PureDOOM).

Pipeline

Chibil takes C source files and generates COFF OBJ files. These OBJ files are binary-compatible with OBJ files produced by the MSVC compiler in /clr mode. link.exe from Visual Studio is used to link the object files together and produce final executables. One can actually mix and match C++/CLI and chibil-produced object files.

Chibil will probably have its own linker later, if for no other reason, just so we don’t need Windows.

Debugging

Line numbers and locals work as expected. You can step through the C code in a .NET debugger.

Standard C library

There isn’t one.

There is a minimal stub of a C runtime library in the crt directory. This provides a runnable main that takes string[] of arguments and dispatches to the C-standard main with argc and argv. The produced assembly is converted to a COFF object file using the asm2obj utility and can be linked together with the C code to form something with a runnable main.

Consuming C code from .NET code

This is not complete yet. The code is generated into global namespace so if you want to consume the compiled code from elsewhere (i.e. don’t intend to just run the EXE), you’ll need to use reflection such as Module.GetMethod to find the methods and reflection-invoke them.

Useful tools

The tools/coffobjdumper.cs file contains a COFF OBJ dumper that dumps .NET OBJ files. It’s a good complement for ILDASM (the desktop CLR ILDASM!) that can dump the .NET metadata from COFF OBJ files, but doesn’t show method bodies, and dumpbin.exe that can dump various things from COFF objects, but not much in terms of .NET metadata.

Similar Articles

QBE - Compiler Backend: Version 1.3

Lobsters Hottest

QBE 1.3 is a significant compiler backend release with 7k new lines of code, featuring a new IL matching algorithm, optimizations for coremark benchmark (improving from 40% to over 63% of gcc -O2 performance), Windows ABI support, and position-independent code generation.

56,000 lines of DOOM, in a language I made up

Hacker News Top

The author built a joke programming language called bet that compiles via LLVM, uses arena-based memory management, and successfully runs the full DOOM game (56,000 lines) without code review, relying only on tests.

Show HN: Nibble

Hacker News Top

Nibble is a C-like systems programming language implemented in 3000 lines of C that generates LLVM IR without external dependencies or heap allocations. It supports defer, recursion, various types, structs, pointers, and includes graphical demos.