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

Fergus Henderson fjh@cs.mu.oz.au
Thu, 27 Nov 2003 12:32:56 +1100


On 26-Nov-2003, Chris Lattner <sabre@nondot.org> wrote:
> > > 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.
> 
> Ah, ok.  I thought the unverifiable CIL was basically just machine code.
> I didn't know it used the stack machine: cool!

You have to distinguish between _unverifiable_ code, and _unmanaged_ code.
The former uses the stack machine, the latter is just machine code.

> > 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.
> 
> Ok.  There are _inherently_ difficult parts though.  For example, you
> can't really translate '#ifdef BIG_ENDIAN' style code into a portable
> representation, no matter what it is.

That's true.  But code which uses #ifdef BIG_ENDIAN is not
standard-conforming C code.

> The hardest part is probably handling all of the libc functions that
> everyone expects: signals, stdio, etc.

Right.  For most of that, you can implement it using PInvoke to invoke
the underlying (run-time) platform's libc.  However, because there are
a lot of macros that the C standard specifies are (compile-time) constant
expressions, you would have to wrap a lot of the functionality.
That is, you'd need to define your own set of C header files that define
the constants in a platform-independent way, and then have the implementation
of the C functions work by PInvoking your own C wrapper functions which
convert these constants to the appropriate platform-specific values and
then invoke the wrapped libc function.

-- 
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.