Questions tagged [cil]

Common Intermediate Language is the object-oriented assembly language used by the .NET Framework, .NET Core, and Mono. .NET languages compile to CIL, which is assembled into an object code that has a bytecode-style format.

Common Intermediate Language (CIL, pronounced either "sil" or "kil") (formerly called Microsoft Intermediate Language or MSIL, and sometimes informally called IL) is the lowest-level human-readable programming language defined by the Common Language Infrastructure (CLI) specification and is used by the .NET Framework, .NET Core, and Mono.

Languages which target a CLI-compatible runtime environment compile to CIL, which is assembled into an object code that has a bytecode-style format. CIL is an object-oriented assembly language, and is stack-based. Its bytecode is translated into native code or executed by a virtual machine.

For CIL the C Intermediate Language (a subset of C), use .

1064 questions
18
votes
4 answers

Why is it so easy to decompile .NET IL code?

Why is it so easy to decompile .NET IL-code into source code, compared to decompiling native x86 binaries? (Reflector produces quite good source code most of the time, while decompiling the output of a C++ compiler is almost impossible.) Is it…
compie
  • 10,135
  • 15
  • 54
  • 78
18
votes
2 answers

Converting SSA to stack machine

It is well known how to convert code from SSA representation to a register machine. (Basically, graph coloring register allocation is the core of such conversion.) But what's the general method for converting from SSA to a stack machine? (CIL byte…
rwallace
  • 31,405
  • 40
  • 123
  • 242
18
votes
3 answers

C# Property with no setter - how can it get set from constructor?

How come you can set a get-only auto-property from a constructor? The code below shows how you can set the property from the constructor but using reflection shows that there really isn't a setter behind the scenes. How does it get set from the…
thisextendsthat
  • 1,266
  • 1
  • 9
  • 26
18
votes
1 answer

Does PowerShell compile scripts?

Suppose I have a simple PowerShell script: 1..3 | Write-Host How does PowerShell process it? Does it build in-memory assembly or some temporary .dll file? Can I examine this assembly and MSIL using some tools (e.g. ILSpy, VS, WinDbg)? Does…
user2341923
  • 4,537
  • 6
  • 30
  • 44
17
votes
3 answers

Why does this very simple C# method produce such illogical CIL code?

I've been digging into IL recently, and I noticed some odd behavior of the C# compiler. The following method is a very simple and verifiable application, it will immediately exit with exit code 1: static int Main(string[] args) { return…
lpmitchell
  • 181
  • 6
17
votes
2 answers

How is LINQ compiled into the CIL?

For example: var query = from c in db.Cars select c; foreach(Car aCar in query) { Console.WriteLine(aCar.Name); } How would this translate once it is compiled? What happens behind the scenes?
Liggi
  • 744
  • 8
  • 22
17
votes
1 answer

Can/does the (forward) pipe operator prevent tail call optimization?

For a parameter optimization problem at work I wrote a genetic algorithm to find some good settings because a brute-force solution is unfeasible. Unfortunately, when I return in the morning, most of the time I'm presented with a…
primfaktor
  • 2,831
  • 25
  • 34
17
votes
2 answers

The curiosity of the let_ property method

Every .net developer knows about the concept of properties. A rough 99.99%, it's just a piece of metadata gluing together two methods, a getter, and a setter. Same thing usually goes for events, with their add, remove, and invoke method. The…
Jb Evain
  • 17,319
  • 2
  • 67
  • 67
17
votes
3 answers

Do I understand this MSIL code correctly?

I have the following code in C# // test.Program private static void Main() { int x = 5; int y = 100; Console.WriteLine(y + ", " + x); } And I'm reading the IL code, I've never programmed assembly before so I'm asking if what I each line…
NomenNescio
  • 2,899
  • 8
  • 44
  • 82
16
votes
2 answers

MSIL Reference Manual

Is there any readable, up to date (.net 4) MSIL Reference Manual?
Max Yaffe
  • 1,317
  • 1
  • 14
  • 26
16
votes
6 answers

Modifying Existing .NET Assemblies

Is there a way to modify existing .NET assemblies without resorting to 3rd party tools? I know that PostSharp makes this possible but I find it incredibly wasteful that the developler of PostSharp basically had to rewrite the functionality of the…
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
15
votes
4 answers

Is there an API for verifying the MSIL of a dynamic assembly at runtime?

When using Reflection.Emit to build an assembly at runtime, I'd like to verify the assembly MSIL before saving to disc. Like PEVerify but at runtime. Is there such an API?
Stephen Swensen
  • 22,107
  • 9
  • 81
  • 136
15
votes
2 answers

LLVM CIL and Java Bytecode backend

I saw the http://vmkit.llvm.org/ project but it's not quite what I'm looking for. Don't want my code to run on yet another VM but on .NET's and Java's VM. Are there any compiler backends for LLVM that generate .NET CIL and/or Java Bytecode?
15
votes
3 answers

Compiler generates infinite loop after finally block when

I'm using standard VS2015 compiler targeted for .Net 4.6.2. Compilator emits infinite loop after failing finally block. Some examples: Debug: IL_0000: nop .try { IL_0001: nop IL_0002: nop IL_0003: leave.s IL_000c } // end .try finally { …
Pixello
  • 191
  • 2
  • 7
15
votes
3 answers

MS C# compiler and non-optimized code

Note: I noticed some errors in my posted example - editing to fix it The official C# compiler does some interesting things if you don't enable optimization. For example, a simple if statement: int x; // ... // if (x == 10) // do…