lcc.NET: Targeting the .NET Common Intermediate Language from Standard C

  • David R. Hanson

MSR-TR-2002-112 |

Note: Revised April 2003

The core of the Microsoft .NET platform includes a new virtual machine, the Common Intermediate Language, also known as MSIL. Unlike most other VMs, including the Java VM, MSIL is designed specifically to support a wide range of languages. While it is designed primarily for type-safe, object-oriented languages, it also has facilities that support both low-level languages and very high-level languages. For example, it accommodates unsafe pointer arithmetic and tail calls. This paper describes the implementation of an MSIL back end for lcc, a retargetable compiler for Standard C. C is at one end of the range of languages that MSIL intends to support, and lcc is about the simplest “real” C compiler widely available. Porting lcc to MSIL thus provides a realistic test of how well MSIL supports this class of languages and provides a glimpse of its performance costs. This effort succeeded, but static initializations, function pointers, separate compilation, and address arithmetic were major problem areas. These problems also suggested improvements in lcc’s code-generation interface, and they exposed a long-standing error in the lcc front end. Programs compiled by the MSIL back end run 2-3 times slower than those compiled by lcc native Intel x86 back end, but the MSIL programs have some important diagnostic benefits.