[antlr-interest] C# vs MSIL Output

Robin Debreuil robin at debreuil.com
Sun Mar 7 16:04:15 PST 2004


> Upon further investigation, CodeDom is not as cool as I first thought.
> Unless I don't understand, CodeDom structures cannot be compiled directly
to
> MSIL.  Instead they are transformed to C# or VB and then sent to the
command
> line compiler for transformation to MSIL.  This is equivalent to option B.
> However, CodeDom is much more attractive than generating C# (or VB) by
hand!

Actually you can generate IL once you have a CodeDom tree - there are
classes in the Microsoft.CSharp namespace:

CSharpCodeProvider.CreateCompiler
CSharpCodeProvider.CreateGenerator
CSharpCodeProvider.CreateParser

Note: CreateParser isn't implemented, it always returns null. The antlr C#
project I've been working on will essentially be the missing parser. Other
useful areas to look into if you haven't already are Reflection.Emit (for
emitting IL), and the CodeDom.Compilers namespace. That may be a given, just
the framework is so huge it is easy to overlook stuff (mostly you find it
after two weeks of work implementing it!).

The downside of the CodeDom is there are a few areas missing (eg unary
operators), so you have to get into some ugly workarounds with snippets or
something. If your language needs aren't too demanding though, it will
hopefully fall all into the bounds of the CodeDom. I wrote a bit about what
is missing here/possible workarounds (err, ignore the sarcasm):

http://blog.debreuil.com/posts/190.aspx
http://blog.debreuil.com/posts/195.aspx

To be clear, I haven't done a lot of IL stuff yet - I mostly generate for
graphic/pcode formats (like swf/svg). A lot of my opinions come from
extrapolating a few test files - they are probably in for a bit of a reality
check in the next few weeks ; ).

Cheers,
Robin

>
> Regardless of this limitation, I think I am going to go down the CodeDom
> path.  If compilation performance becomes a problem down the road, I will
> then research converting CodeDom directly to MSIL.
>
> Mike Bresnahan
>
> > -----Original Message-----
> > From: Mike Bresnahan [mailto:mbresnah at visi.com]
> > Sent: Sunday, March 07, 2004 3:08 PM
> > To: antlr-interest at yahoogroups.com
> > Subject: RE: [antlr-interest] C# vs MSIL Output
> >
> >
> > > You should throw in an option d) there, parse into a CodeDom
> > > structure. That
> > > way you can generate il (pre-generate or at runtime), or source code
for
> > > other languages that implement it (C#, vb, etc). You can also use that
> > > sturcture from any .net language. Depends on your needs I guess, but
> > > something to consider...
> >
> > Most cool!  I was not aware of CodeDom.  Thank you very much!
> >
> > Mike Bresnahan
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list