什么是LLVM? Swift,Rust,Clang等背后的力量

论坛 期权论坛     
选择匿名的用户   2021-5-23 02:01   187   0
<div class="cat" id="drr-container">
<p> 新语言以及对现有语言的改进在整个开发环境中如雨后春笋般冒出。 <a href="https://www.infoworld.com/article/3234929/application-development/get-started-with-rust-the-language-for-safer-code.html">Mozilla的Rust</a> , <a href="https://www.infoworld.com/article/3216546/application-development/what-to-expect-in-apples-swift-5.html">苹果的Swift</a> , <a href="https://www.infoworld.com/article/3224868/java/what-is-kotlin-the-java-alternative-explained.html">Jetbrains的Kotlin</a>以及许多其他语言为开发人员提供了速度,安全性,便利性,便携性和功能性方面的新选择。 </p>
<p> 为什么现在? 一个重要的原因是用于构建语言的新工具,特别是编译器。 其中最主要的是<a href="http://llvm.org/">LLVM</a> ,这是一个由Swift语言创建者Chris Lattner最初开发的开源项目,是伊利诺伊大学的一项研究项目。 </p>
<p class="fakesidebar"></p>
<h4> [ <u><a href="https://www.infoworld.com/article/3383246/should-we-be-worried-about-programming-languages.html">同样在InfoWorld上:我们应该担心“公司”编程语言吗?</a></u> ] </h4>
<p> LLVM不仅使创建新语言更加容易,而且使现有语言的开发更加容易。 它提供了用于自动执行语言创建任务中许多最令人不快的部分的工具:创建编译器,将输出的代码移植到多个平台和体系结构,生成特定于体系结构的优化(例如矢量化)以及编写代码以处理诸如通用语言隐喻之类的代码例外。 它的自由许可意味着它可以作为软件组件自由重用,也可以作为服务部署。 </p>
<p> 使用LLVM的语言花名册有许多熟悉的名称。 Apple的Swift语言使用LLVM作为其编译器框架,Rust使用LLVM作为其工具链的核心组件。 此外,许多编译器都有LLVM版本,例如Clang,C / C &#43;&#43;编译器(此名称为“ C-lang”),它本身就是与LLVM紧密相关的项目。 .NET实现Mono,可以选择<a href="http://www.mono-project.com/docs/advanced/runtime/docs/llvm-backend/">使用LLVM后端编译为本地代码</a> 。 而且Kotlin(名义上是JVM语言)正在开发一种称为<a href="https://www.infoworld.com/article/3187370/application-development/kotlin-compiles-directly-to-native-code-via-llvm.html">Kotlin Native</a>的语言版本,该版本使用LLVM编译为机器本地代码。 </p>
<h2> LLVM定义 </h2>
<p> LLVM的核心是用于以编程方式创建机器本地代码的库。 开发人员使用API以称为<em>中间表示</em> (IR)的格式生成指令。 然后,LLVM可以将IR编译为独立的二进制文件,或者对代码执行JIT(即时)编译,以在其他程序的上下文中运行,例如该语言的解释器或运行时。 </p>
<p> LLVM的API提供了用于开发许多常见语言和编程语言结构的原语。 例如,几乎每种语言都具有函数和全局变量的概念,并且许多语言都具有协程和C外部函数接口。 LLVM在其IR中将函数和全局变量作为标准元素,并且具有用于创建协程和与C库接口的隐喻。 </p>
<p class="nativo-promo nativo-promo-1 smartphone" id=""></p>
<p> 您无需花费时间和精力来重新设计那些特定的轮子,您只需使用LLVM的实现,并专注于需要注意的语言部分。 </p>
<div class="fakesidebar fakesidebar-auto fakesidebar-sponsored" id="sponsoredfakesidebardiv"></div>
<figure class="large" style="display:block;text-align:center;">
  <img alt="你好世界llvm" border="0" class="lazy" height="262" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-09db5e0f63389fbd86780fff03d3da75" style="display:block;margin:0 auto" width="700">
  <small class="credit">IDG</small>
  <figcaption>
   <p> LLVM的中间表示(IR)的示例。 右边是一个用C语言编写的简单程序。 左侧是Clang编译器翻译成LLVM IR的相同代码。 </p>
  </figcaption>
</figure>
<p class="sidebar medium"></p>
<h3 class="body"> 阅读有关Go,Kotlin,Python和Rust的更多信息 </h3>
<p> <strong>走:</strong> </p>
<ul><li> <a href="https://www.infoworld.com/article/3190210/application-development/tap-the-power-of-googles-go-language.html#tk.ifw-infsb">发挥Google Go语言的强大功能</a> </li><li> <a href="https://www.infoworld.com/article/3171158/application-development/the-best-go-language-ides-and-editors.html#tk.ifw-infsb">最好的Go语言IDE和编辑器</a> </li></ul>
<p> <strong>Kotlin:</strong> </p>
<ul><li> <a href="https://www.infoworld.com/article/3224868/java/what-is-kotlin-the-java-alternative-explained.html#tk.ifw-infsb">什么是Kotlin?</a> <a href="https://www.infoworld.com/article/3224868/java/what-is-kotlin-the-java-alternative-explained.html#tk.ifw-infsb">Java替代说明</a> </li><li> <a href="https://www.infoworld.com/article/3236419/kotlin-frameworks-a-survey-of-jvm-development-tools.html#tk.ifw-infsb">Kotlin框架:JVM开发工具概述</a> </li></ul>
<p> <strong>Pytho
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP