Common Intermediate Language (CIL, pronounced either "sil" or "kil") (formerly called Microsoft Intermediate Language or MSIL) is the lowest-level human-readable programming language in the Common Language Infrastructure and in the .NET Framework. Languages which target the .NET Framework compile to CIL, which is assembled into bytecode. CIL is an object-oriented assembly language, and is entirely stack-based. It is executed by a virtual machine. MSIL-wa MicroSoft Intermediate Language da. 通用中间语言(CIL,发音为"sill"或"kill")(曾经被称为微软中间语言或MSIL)是一种属于通用语言架构.NET Framework的低级的人类可读编程语言。目标为.NET Framework的语言被编译成CIL,然后汇编成字节码。CIL类似一个面向对象的汇编语言,并且它是完全基于堆栈的。它运行在虚拟机上,其主要的语言有C#Visual Basic .NETC++/CLI以及 J#
CIL was originally known as Microsoft Intermediate Language (MSIL) during the beta releases of the .NET languages. Due to standardization of C# and the Common Language Infrastructure, the bytecode is now officially known as CIL. Because of this legacy, CIL is still frequently referred to as MSIL, especially by long-standing users of the .NET languages. 在.NET语言的测试版中,CIL原本叫做微软中间语言(MSIL)。由于C#和通用语言架构的标准化,字节码现在已经官方地成为了CIL。因此,CIL仍旧经常与MSIL相提并论,特别是那些.NET语言的老用户。

General information / Jenerol informeiçion / 概述

During compilation of .NET programming languages, the source code is translated into CIL code rather than platform or processor-specific object code. CIL is a CPU- and platform-independent instruction set that can be executed in any environment supporting the .NET framework (either the .NET runtime on Microsoft Windows operating system, or the independently derived Mono, which can be used to execute some bytecode on Linux or Unix-based operating systems). CIL code is verified for safety during runtime, providing better security and reliability than natively compiled binaries[來源請求]. 在编译.NET编程语言时,源代码被翻译成CIL码,而不是基于特定平台或处理器的目标代码。CIL是一种独立于具体CPU和平台的指令集,它可以在任何支持.NET framework的环境下运行。CIL码在运行时被检查并提供比二进制代码更好的安全性和可靠性。

Bytecode instructions

CIL bytecode has instructions for the following groups of tasks: CIL bytecode has instructions for the following groups of tasks:

Just-in-time compilation / Jùst-in-taim kompaileiçion / 即时编译 (JIT)

Just-in-time compilation involves turning the byte-code into code immediately executable by the CPU. The conversion is performed gradually during the program's execution. JIT compilation provides environment-specific optimization, runtime type safety, and assembly verification. To accomplish this, the JIT compiler examines the assembly metadata for any illegal accesses and handles violations appropriately. 即时编译是指字节码在CPU执行时被立即转换成机器码。转换是在程序执行的过程中逐渐进行的。JIT编译技术提供了特定环境下的优化、运行时类型安全以及汇编验证。为此,JIT编译器检查程序集元数据中是否有非法访问和句柄的冲突。

Native image generator compilation

The native image generator (NGEN) produces a native binary image for the current environment. The byte-code is either skipped entirely or converted into native CPU instructions completely before runtime. This eliminates the JIT overhead at the expense of portability; whenever an NGEN-generated image is run in an incompatible environment, .NET framework automatically reverts to using JIT. Once NGEN is run against an assembly, the resulting native image is placed into the Native Image Cache for use by all other .NET assemblies. This makes it possible, for example, to use NGEN to process .NET assemblies at installation time, saving processor time later on, when the end-user invokes the application on their system.

NGEN is intended to make the assembly execute faster by removing the JIT compilation process at runtime, but this does not always improve performance because some optimizations can be done only by a JIT compiler (i.e. if the JIT compiler knows that the code is already running with full trust, it can skip certain expensive security checks). Because of this fact, it makes sense to use NGEN only after benchmarking the application performance before and after it.


Mein artikol: .NET metadata

.NET records information about compiled classes as Metadata. Like the type library in the Component Object Model, this enables applications to support and discover the interfaces, classes, types, methods, and fields in the assembly. The process of reading such metadata is called reflection.

Executing CIL

  • Source code is converted to Common Intermediate Language, .NET’s equivalent to Assembly language for a CPU.
  • CIL is then assembled into bytecode and a .NET assembly is created.
  • Upon execution of a .NET assembly, its bytecode is passed through the Common Language Runtime's JIT compiler to generate native code. (NGEN compilation eliminates this step at run time.)
  • The native code is executed by the computer's processor.

External links


da:Common Intermediate Language de:Common Intermediate Language es:MSIL id:Microsoft Intermediate Language fr:Common Intermediate Language it:Common Intermediate Language he:CIL hu:Common Intermediate Language ja:共通中間言語 pl:Common Intermediate Language ru:Microsoft Intermediate Language zh:通用中间语言

Community content is available under CC-BY-SA unless otherwise noted.