Search code examples
c#.netcompilationclrjit

What are the processes that the .net compiler does in order to compile code?


first I want to say that I'm not sure if this is the best stack-exchange site to post this type of question but I'm not sure where it would fit the best. Anyway as the questions title's says I want to know the steps the .net compiler does when converting my C# code to a machine language one. I've watched some videos however there are some stuff that I still don't quite understand. I will leave all my question's at the bottom and I will try to be as specific as possible.

Here's my understanding of how the .net compiler works

My C# code -> IL -> JIT -> Assembler code

  1. What is the exact term of "My C# code" ?
  2. What is the use of CLR in here ?
  3. Is this entire process handled by the CLR or where does it even comes in ?
  4. What is Metadata ?
  5. Is there something additional that happens in between those transition from step 1 to step 2 and from step 2 to step 3 or it's just some code being translated to a lower-level language ?

Solution

    1. Just C# (C# -> Roslyn (or csc) -> IL -> JIT -> Native)
    2. The CLR is what reads your IL, JIT's it and holds the GC (and much, much more that doesn't pertain to this question)
    3. The CLR only runs your compiled code. C# compilation is done through a normal compiler (which was csc.exe, but is now deprecated by Roslyn).
    4. There are plenty of examples that state what Metadata is
    5. There is a lot that goes on in those steps, but that is the primary flow.