[Mono-list] Gcc summit...interesting stuff

Fergus Henderson fjh@cs.mu.OZ.AU
Wed, 26 Nov 2003 23:26:14 +1100

On 25-Nov-2003, Chris Lattner <sabre@nondot.org> wrote:
> On Tue, 25 Nov 2003 pbaena@uol.com.ar wrote:
> > Well, I guess the most important question would be: How hard could it be
> > to make it [LLVM] target IL code?
> Here's the response I sent to Miguel:
> While possible, it would be _very_ difficult.  LLVM code is more
> expressive/low-level than CIL code: for example array bounds checks are
> not implicit, and there is no object model.  I'm not sure exactly how you
> would map general C programs onto the managed runtime at least, much less
> general LLVM programs.

LLVM should map to *unverifiable* CIL without too much difficulty, I think.
Well, actually you'd map to a subset of that: you wouldn't use the
object model instructions at all.

It's mostly fairly straight-forward to map general C programs onto
unverifiable CIL.  Casting a pointer to int or vice versa is easy, just
push as one type and pop as another.  Pointer arithmetic is just integer
addition.  The C heap is unmanaged memory which can be allocated either
as a global array or using OS-specific code.  There are some tricky parts,
such as volatile and setjmp/longjmp, but these are not insurmountable
hurdles -- they can be handled, it just requires a little more cleverness.

> The best way to do this would be to make a _new_ C/C++ compiler like
> Microsoft did, which adds language restrictions for managed mode.

Microsoft's C++ compiler, and lcc, and the C compiler in Portable.NET
can all compile almost every C construct to unverifiable IL.  I don't
know if any of them handle volatile properly, and AFAIK none of them
handle setjmp/longjmp.  But that's just lack of development resources.

Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.