Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the best resources for learning CIL (MSIL)

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)?

like image 260
TheSoftwareJedi Avatar asked Sep 30 '08 22:09

TheSoftwareJedi


People also ask

What is the difference between CIL and MSIL Il?

Both the terms are similar but with following difference: CIL – Common Intermediate Language – is the term used in the International Standard. MSIL – Microsoft Intermediate Language – is the product term for the Microsoft implementation of that standard.

Which of the following is read by CLR to understand the requirements of MSIL code?

CLR provides the services and runtime environment to the MSIL code. Internally CLR includes the JIT(Just-In-Time) compiler which converts the MSIL code to machine code which further executed by CPU. CLR also uses the . NET Framework class libraries.

What is MSIL explain in short how it works?

The Microsoft Intermediate Language (MSIL), also known as the Common Intermediate Language (CIL) is a set of instructions that are platform independent and are generated by the language-specific compiler from the source code.

What are CIL instructions?

CIL instructions are executed by a CLI-compatible runtime environment such as the Common Language Runtime. Languages which target the CLI compile to CIL. CIL is object-oriented, stack-based bytecode. Runtimes typically just-in-time compile CIL instructions into native code.


2 Answers

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.

like image 59
Nick Johnson Avatar answered Sep 22 '22 07:09

Nick Johnson


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.

like image 26
Darren Kopp Avatar answered Sep 20 '22 07:09

Darren Kopp