[Mono-list] C# or IL to C cross compiler

benc@cinematix.com benc@cinematix.com
Wed, 24 Apr 2002 19:01:42 -0800


> On a related note.  For serious game development using C#
> for core code, there needs to be a C# to C compiler that
> would allow engine C# code to be compiled to C code that
> could be run through the vectorizing and optimizing
> compilers for the various platforms.

Or you could write your performance critical code in C or
assembler. 
And P/Invoke it from the higher levels of code that do not
need the
performance.

Hmmm.. not every bit of a game is time critical, but many
of the bits that would benefit from a "safer" language like
C# are.  If C# could only be used for non-time critical
portions of the game code, that would eliminate its use
from a large portion of the game, as games tend to be
chocked full of time critical code.  

Still, writing certain portions of the engine which deal
specifically with DirectX, etc. in C is a good idea.  The
more narrow and smaller scope of the code, the easier it is
to ensure it's reliability.  

> Is anyone else interested in a C# to c compiler that
could
> be used to build precompiled heavily optimized code that
> would integrate well with the JIT code?

There will be few places where you could actually get a
gain from the
optimized C code, and that will be places where you can
infer things
about the data you are operating on (in unsafe contexts for
example), 

Vectorizing arrays, code motion, global optimization, and
other compile time expensive optimizations that static
compilers do actually 'do' make a big difference in game
code.  Much of the code you write in a game must execute at
or close to 60hz.  You'd be suprised at the breadth of
time-critical code that exists in most games.  Certain
seemingly minor optimizing or inlining rules of certain
compilers (i.e. Codewarrior) repeated across many modules
can really add up to significant time.

In any case, there's a warm safe feeling you get when you
statically compile a module with non-time sensitive extreme
static optimization for performance critical static apps.
 You want to keep the ability to load and integrate with
JIT game modules (i.e. level code), but the core game app
statically compiled with a vectorising, highly optimizing,
compiler is pretty important.  

>> But you are welcome to try ;-)
>> Miguel.

I think I just might if I have any time.  If I do the C
code generation, it would be separate from the main code
tree, inserted into the compiler passes after the parsing
and object instantiation.  

An IL to C compiler would be completely separate, but as I
stated in another post, information from the GCJ docs leads
me to believe that the IL C code might be somewhat inferior
to the direct C# to C conversion.

Thanks for the response.