views:

511

answers:

5

I'm an expert C# 3 / .NET 3.5 programmer looking to start doing some runtime codegen using System.Reflection.Emit.DynamicMethod. I'd love to move up to the next level by becoming intimately familiar with IL.

Any pointers (pun intended)?

+2  A: 

The best way to learn it, is to write something you understand, then look at the IL it created. Also, depending on what you are doing, you can use expression trees instead of emitting IL, and then when you compile the expression trees, those smart guys at microsoft create the IL for ya.

Darren Kopp
Expression trees FTW!Hadn't thought about that! Thanks!
TheSoftwareJedi
+2  A: 

Expert .NET 2.0 IL Assembler. Although this book may be a little dated now, it was still a great overview for me.

Nescio
+3  A: 

.NET Reflector is great for examining the IL produced by C#/VB.NET.

It's a wonderful learning tool.

Michael Burr
I use that all the time, but have it decompiling to C# - great advice, thanks!
TheSoftwareJedi
+1  A: 

The ECMA 335 specification is freely available for download here: http://www.ecma-international.org/publications/standards/Ecma-335.htm

Partition III is the most relevant for dealing with MSIL, but I'd strongly recommend partition I as well for any .NET developer as it will greatly solidify understanding of the platform.

+3  A: 

In addition to Darren's answer, I'd suggest picking or inventing a toy language, and writing a simple compiler for it. Pick something that requires little parsing, like BF or a stack-based language, and you'll find that writing a compiler is actually simpler than it seems.

Nick Johnson