[antlr-interest] RE: C# vs MSIL Output

Ney, Richard richard.ney at aspect.com
Mon Mar 8 22:36:05 PST 2004


As always, it really comes down to a matter of preference and how often
your application needs to do it. To list examples of Microsoft libraries
that uses the two methods. The XML attributes for serializing and
deserializing XML files uses the CodeDom API since creating the classes
to load a XML schema is usually only done once so the cost of pausing
your application and invoking CSC.exe isn't really and issue. Now the
regular expression evaluator library uses the Reflection.Emit API since
it is often placed in GUIs and you don't want the GUI to become
unresponsive while CSC is brought in. 

Both methods should generate code that performs the same since they both
end up as MSIL. In my application using the Emit API is faster since I
generate a custom class to handle each unique request during the
lifetime of my application and they come in large groups. I can't afford
to have 10+ copies of CSC running to convert generated C# into MSIL. But
I do use the XML attributes to load my startup meta-data.

-Richard

-----Original Message-----
From: Daniel Gackle [mailto:gackle at shaw.ca] 
Sent: Monday, March 08, 2004 10:04 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] RE: C# vs MSIL Output

> As far as I can tell, the ICompiler object created by
> CSharpCodeProvider.CreateCompiler converts the CodeDom
> to C# and invokes csc.exe.

That's right. Even if you ask the CodeDom for an in-memory assembly, it
still generates C# source code and parses it all over again before
turning
it into IL. It's not possible to use the CodeDom to generate IL
directly.
That's what Reflection.Emit does. However, we did some performance tests
and
found that, once you get past the compilation of the C#, code generated
via
the CodeDom doesn't run significantly slower than code generated via
Reflection.Emit. As a result, we opted for the convenience of the
higher-level CodeDom API.

Daniel

________________________________________________________________________

Message: 6
   Date: Sun, 7 Mar 2004 18:28:08 -0600
   From: "Mike Bresnahan" <mbresnah at visi.com>
Subject: RE: C# vs MSIL Output

> 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

As far as I can tell, the ICompiler object created by
CSharpCodeProvider.CreateCompiler converts the CodeDom to C# and invokes
csc.exe.  I'm guessing CodeDom is not transformed directly to MSIL
because
csc.exe uses a different data structure for storing the parsed source
code.
Until this internal data structure and CodeDom are the same or someone
writes a new compiler, we will be stuck transforming CodeDom to source
code
as an intermediate step.

What's interesting is that there is an option to create the compiled
assembly in-memory instead of in a temporary file.  I'm guessing this
means
that csc.exe outputs the assembly to stdout or through some other IPC
mechanism, however "csc.exe -help" does not list such and option.

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