LLVM Europe 2012: A Portable C++/CLI Compiler
This afternoon I’m giving a brief talk on the Nuanti C++/CLI compiler built on Clang at the LLVM European Conference, London.
We started this project a couple of years ago to cover the language specification in ECMA-372, having found it a pain to integrate applications and SDK written in C and C++ with .NET. Since then, the compiler has developed into a self-hosting toolchain that’s been used to port entire applications to run on Mono, Silverlight, Mac OS X and Linux.
There are two codegen modes: (1) fully managed .NET bytecode, and (2) native optimized machine code with hooks into the Mono runtime for invocations. There’s some flexibility to mix and match the two. Sometimes it’s handy to call into an existing managed library from your C++ application and this use case is simple as adding an import header and calling the methods you need. No bindings or wrappers, and if using a runtime like Mono the stack is garbage collected behind the scenes.
The frontend has all the parser support you’d expect plus CLR metadata import. Meanwhile there’s a CIL backend using the LLVM codegen infrastructure. The two work together to generate native-looking SDK-quality assemblies out of all kinds of unmanaged code.
The implementation embraces and extends the ECMA spec with dynamic types from C# 4.0, LINQ for C++, expression trees and full-blown DLR syntax trees, going beyond the original specification in many ways. This is the real interesting part, since it’s what we use to bootstrap the compiler (so it can compile itself).
We were able to port User Mode Linux and WebKit to Silverlight using this with a certain amount of patching. There are other fascinating integration points like a pretty neat Objective-C++/CLI bridge.
See you there!
WOW! Terrific work, this is very promising.
This was my favorite talk at the dev meeting, both engaging and technical, made my trip to the UK worthwhile.
It’s clear the C++/CLI specification is significant and Nuanti has taken and run with it from some of the things you showed in your presentation. Is this work funded by Microsoft?
If I could add one thing, it’s that the technology is only just maturing from our POV. A lot of companies have an investment in established .NET / C++ code and are waiting for something like this to unlock the potential, especially server-side and on tablets or mobiles. Applies particularly to those trying to embed Mono in a product today.
So best of luck with your language research at Nuanti and I hope it’ll find a place alongside your WebKit work which we already follow closely.
Comments are closed.