为何进行中间语言转换 [英] Why intermediate language conversion

查看:72
本文介绍了为何进行中间语言转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

We know in Dot Net Framework , Compiler compiles the managed Code to Intermediate Code and then to machine code.
 
Now my Question why Compiler straighforward compiles from Manage code to Machine Code. Why It has to first convert to Intermediate Language ? 





我的尝试:





What I have tried:

Tried Googling but didnt find anything specific

推荐答案

有两个优点。编译器可以将不同的语言转换为相同的CIL,因此多种语言可以利用框架,c#和vb.net是最知名的。但是任何想要创建.net语言的人都只需要知道如何生成CIL。



第二个优点是在平台上运行.net只需要能够将CIL转换为自己的特定平台。所以我可以将我的c#应用程序编译为CIL,然后任何启用CIL的环境都可以运行,因此Windows使用.net框架,或使用Mono的Linux,或任何其他了解CIL的东西。如果您直接从c#转到机器代码,那么您必须为特定平台编译程序。使用CIL编译为CIL,然后目标平台担心转换为机器特定的代码。
There are two advantages. The compiler can convert different languages to the same CIL so multiple languages can leverage the framework, c# and vb.net being the best known. But anyone who wants to create a .net language only needs to know how to generate CIL.

The second advantage is that to run .net on a platform, that platform only needs the ability to convert CIL to it's own specific platform. So I can compile my c# app to CIL, then any CIL enabled environment can run that, so Windows using .net framework, or Linux using Mono, or anything else that understands CIL. If you went direct from c# to machine code then you would have to compile your program for a specific platform. With CIL you compile to CIL then the target platform worries about converting to machine-specific code.


cil - 为什么.NET代码编译成MSIL? - Stack Overflow [ ^ ]



主要是因为MSIL与平台无关。如果您直接编译为本机代码,则必须为要支持的每个平台重新编译它。
cil - Why .NET code compiles to MSIL? - Stack Overflow[^]

Primarily because MSIL is platform-agnostic. If you compiled straight to native code, you'd have to recompile it for every platform you wanted to support.


这篇关于为何进行中间语言转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆