by jbevain · 12y ago · 0 comments
Fun fact, MonoTouch applications are built with a very similar pipeline, except that LLVM does the compilation in the end.
The steps 4 and 5 in the blog post map quite exactly to the Mono.Linker and the Mono.Tuner. Both tools are using a XML file format for whitelisting pieces of code that need to be included, that's useful if you're calling code with reflection at runtime which is not statically discoverable at build time.
I'm going to guess that in this case, their reason to not go with LLVM was the most compelling one possible: When Microsoft was designing the .NET toolchain, LLVM didn't exist yet.
Given the timing of when it came out, I wouldn't even be surprised if LLVM wasn't at least partially envisioned as an open-source answer to .NET. In which case there's a hint of NIH behind LLVM, with Mono being the non-NIH open source option.
.NET Native uses MDIL to create a looser coupling between NUTC and the runtime. This means NUTC doesn't have to understand the precise binary layout of the runtime. The binder takes care of fixing that up!
MDIL has more advanced capabilities too. For more background on MDIL, I highly recommend watching the video I linked to in the blog post: http://channel9.msdn.com/Shows/Going+Deep/Mani-Ramaswamy-and...
It comes from the Singularity OS compiler toolchain, which is older than LLVM.
It is also used to deploy .NET applications as native code on Windows Phone 8 devices.
http://en.wikipedia.org/wiki/Singularity_%28operating_system...
Although the first published papers are indeed from 2004.
MDIL is described to be the platform's native machine code + some extension tokens (to avoid direct encoding of pointers, for example).
A similar LLVM IR derivative would no longer be by a long shot something resembling LLVM IR, so the property of being "derivative" would not buy you anything.
.class public Foo
{
.method public static int32 Add(int32, int32) cil managed
{
.maxstack 2
ldarg.0 // load the first argument;
ldarg.1 // load the second argument;
add // add them;
ret // return the result;
}
}If you ever look at a disassembled CLR executable, expect to see a heap of lines like:
valuetype A* modopt([mscorlib]System.Runtime.CompilerServices.CallConvThiscall) 'A.{ctor}'(valuetype A* modopt([mscorlib]System.Runtime.CompilerServices.IsConst) modopt([mscorlib]System.Runtime.CompilerServices.IsConst))