Chibil: A C compiler targeting .NET IL
Chibil is an intriguing project that re-implements a C compiler in C#, specifically targeting .NET IL. It demonstrates impressive capabilities, such as compiling and running a pure C version of DOOM, and offers robust debugging features within the .NET ecosystem. This technical feat of cross-language compilation and runtime integration makes it a compelling exploration for developers interested in compiler design and interop solutions.
The Lowdown
Chibil is an ambitious open-source project that re-implements a C compiler in C# to target the .NET Intermediate Language (IL). Based on the well-known chibicc compiler, Chibil aims to bridge the gap between traditional C programming and the modern .NET runtime, offering a unique approach to integrating C code into .NET applications.
- Core Functionality: Chibil translates C source files into COFF OBJ files that are binary-compatible with those generated by MSVC's
/clrmode. - Execution Pipeline: It leverages standard Visual Studio's
link.exefor linking, allowing for the creation of executables and even enabling interoperability with C++/CLI object files. The creator plans to develop a custom linker to remove the dependency on Windows. - Debugging Capabilities: A key feature is the ability to debug C code compiled by Chibil directly within a .NET debugger, complete with line numbers and local variable inspection.
- Runtime Support: While a full standard C library is not provided, a minimal C runtime stub (
crt) handles themainfunction, allowing compiled C programs to execute. - .NET Interop: Consuming compiled C code from .NET is currently possible via reflection, although this functionality is still under development for more seamless integration.
- Developer Tools: The project includes a
coffobjdumper.csutility to inspect .NET OBJ files, offering a specialized tool that complements existing utilities like ILDASM and dumpbin.exe.
In essence, Chibil demonstrates a sophisticated method for bringing C code into the .NET world, showcasing the potential for powerful cross-language integration and providing valuable tools for developers exploring this niche.