Creating IL for the .NET platform.

I am writing a small compiler in C # and plan to generate IL statements for the .NET platform using System.Reflection.Emit . My question is: it is recommended to use System.Reflection.Emit to generate IL for compilers.

If it is not recommended to use System.Reflection.Emit to generate IL for production compilers, do we have alternative libraries / tools for this purpose?

+4
source share
4 answers

System.Reflection.Emit great for compilers, although you can take a look at mono-cecil .

+7
source

Here is a blog article describing some issues with Reflection.Emit , which are probably not serious limitations for your project, but you can be the judge:

If these problems do not bother you, you can use this SO question for tips in generating using Reflection.Emit and writing the assembly to disk:

+2
source

So far, System.Reflection.Emit allows you to generate code, which is the oldest of the code APIs in the .NET platform, and requires an understanding of IL. Expression trees introduced in .NET 3.5 and extended in .NET 4.0 (cannot create new types), but they can be used to build complete method bodies.

+2
source

Reflection.Emit is generally fine, but IKVM.Reflection.Emit (available from Mono) may have more options if the assembly you generate is not for the same platform (i.e. you want to build a silverlight dll from your compiler, written in "full" .NET).

+1
source

All Articles