做一门语言,需要一个好的后端 [英] Making a language, need a good backend

查看:217
本文介绍了做一门语言,需要一个好的后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要编译语言。我目前正在评估后端。
到目前为止,我正在寻找C,因为它的执行速度,编译和一个小的,易于使用的编译器称为TCC。



阅读讨论这里关于使用它作为一种中间语言,我想想如何使它兼容垃圾收集和处理异常。



以下是我对其他可能的后端的一些想法:


  1. 装配:不可移植,总体疼痛。

  2. .NET:感觉真的很慢。 5秒启动,5秒评估1 + 2在Ironpython和Boo。无法在没有大图书馆的情况下运行。

  3. JVM:感觉有点慢。无法访问二进制库。无法在没有大图书馆的情况下运行。

  4. LLVM:没有Windows支持。我听说编译的可执行文件大小是16 mb +

  5. C--:看起来欠发达。

  6. 找不到一个很好的小自由,我可以捆绑。

任何人都可以改变主意或有更多的添加此列表?



编辑



我最近一直在试验LLVM。我发现他们有预编译的二进制文件,可以编译为本机程序集。



http://www.antlr.org/wiki/display/CS652/Generating+machine+executable+binaries+with+LLVM



以下是步骤:


  1. 在LLVM汇编上运行llvm-生成LLVM字节码文件。

  2. 在LLVM字节码文件上运行llc以生成汇编文件。

  3. 在汇编文件上运行汇编器以生成目标文件。 (或运行llvm-ld,这似乎取决于外部安装的c编译器)

  4. 使用gcc等编译为可执行文件。


解决方案

您是否考虑为 GCC ?我提到这是为了完整性的缘故 - 只要我知道后端接口是相当复杂,代码库是巨大的,很难理解。



另一方面, GCC是一个成熟的产品,许多专家程序员在其上工作。至少,它可能为所有的选择提供最坚实的基础。



我个人喜欢LLVM(令人兴奋的架构)或.NET的IL:非常,非常易于使用,拥有强大的工具支持( Reflector Cecil Reflexil 和最后但并非最不重要的,.NET反射API)和两个非常有效的实现(即微软的规范实现和单声道)。



但是我不能要求在任何架构的专业知识,所以请把这个答案与一粒盐。


I want to make a compiled language. I am currently evaluating backends. So far I am looking at C because of its speed of execution, compiling, and a small, easy to use compiler called TCC.

Having read the discussions here about using it as an intermediate language, I am trying to think about how to make it compatible with garbage collection, and handling exceptions. So far, I think I can solve both, but with much overhead.

Here are some of my thoughts on the other possible backends:

  1. Assembly: unportable and a total pain to program in.
  2. .NET: Feels really slow. 5 seconds to start up and 5 seconds to evaluate 1+2 on Ironpython and Boo. Unable to run without large library.
  3. JVM: Feels a bit slow. No access to binary libraries. Unable to run without large library.
  4. LLVM: No windows support. I hear that compiled executable size is 16 mb+
  5. C--: looks underdeveloped.
  6. C++: possibly. Can't find a nice small free one I can bundle with.

Can any of you change my mind or have more to add to this list?

Edit

I've been experimenting with LLVM recently. I found out that they have precompiled binaries and that it is possible to compile to native assembly.

http://www.antlr.org/wiki/display/CS652/Generating+machine+executable+binaries+with+LLVM

Here are the steps:

  1. Run llvm-as on LLVM Assembly, which yields a LLVM bytecode file.
  2. Run llc on the LLVM bytecode file to yield an assembly file.
  3. Run an assembler on the assembly file to yield an object file. (or run llvm-ld which seems to depend on an externally installed c compiler)
  4. Compile to executable with gcc etc.

解决方案

Have you considered writing a frontend for GCC? I mention this for completeness’ sake only – as far as I know the backend interface is quite complicated and the codebase is huge and hard to comprehend.

On the other hand, GCC is a mature product with many expert programmers working on it. At the very least, it probably provides the most solid basis of all the alternatives.

Personally, I would prefer LLVM (exciting architecture) or .NET’s IL: very, very easy to use, has great tool support (Reflector, Cecil, Reflexil and last but not least, the .NET reflection API) and two very efficient implementations (namely Microsoft’s canonical implementation and Mono).

But I can’t claim expertise in any of the architectures so take this answer with a grain of salt.

这篇关于做一门语言,需要一个好的后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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