制作一门语言,需要一个好的后端
我想制作一种编译语言。 我目前正在评估后端。 到目前为止,我之所以关注 C,是因为它的执行速度、编译速度以及一个名为 TCC 的小型且易于使用的编译器。
阅读了这里关于将其用作中间语言的讨论后,我正在尝试思考如何使其与垃圾收集兼容并处理异常。 到目前为止,我认为我可以解决这两个问题,但开销很大。
以下是我对其他可能的后端的一些想法:
- 程序集:不可移植,并且在 .NET 中编程非常痛苦
- 。 .NET:感觉非常慢。 Ironpython 和 Boo 上 5 秒启动,5 秒评估 1+2。 没有大库就无法运行。
- JVM:感觉有点慢。 无法访问二进制库。 没有大库就无法运行。
- LLVM:不支持 Windows。 我听说编译后的可执行文件大小为 16 mb+
- C--: 看起来不发达。
- C++:可能。 找不到一个可以捆绑的漂亮的小型免费产品。
你们中有人可以改变我的想法或者有更多内容可以添加到此列表中吗?
编辑
我最近一直在尝试 LLVM。 我发现他们有预编译的二进制文件,并且可以编译为本机程序集。
http://www.antlr.org/wiki /display/CS652/Generate+machine+executable+binaries+with+LLVM
步骤如下:
- 在 LLVM 程序集上运行 llvm-as,这会生成 LLVM 字节码文件。
- 在 LLVM 字节码文件上运行 llc 以生成汇编文件。
- 对汇编文件运行汇编程序以生成目标文件。 (或者运行 llvm-ld ,它似乎依赖于外部安装的 c 编译器)
- 使用 gcc 等编译为可执行文件。
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:
- Assembly: unportable and a total pain to program in.
- .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.
- JVM: Feels a bit slow. No access to binary libraries. Unable to run without large library.
- LLVM: No windows support. I hear that compiled executable size is 16 mb+
- C--: looks underdeveloped.
- 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:
- Run llvm-as on LLVM Assembly, which yields a LLVM bytecode file.
- Run llc on the LLVM bytecode file to yield an assembly file.
- 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)
- Compile to executable with gcc etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您是否考虑过为 GCC 编写前端? 我提到这一点只是为了完整起见——据我所知,后端接口相当复杂,代码库庞大且难以理解。
另一方面,GCC 是一个成熟的产品,有许多专家程序员在开发它。 至少,它可能提供了所有替代方案中最坚实的基础。
就我个人而言,我更喜欢 LLVM(令人兴奋的架构)或 .NET 的 IL:非常非常容易使用,具有强大的工具支持(反射器,塞西尔,Reflexil 以及最后但并非最不重要的,.NET 反射 API)和两个非常高效的实现(即 Microsoft 的规范实现和 Mono)。
但我不能声称自己拥有任何架构方面的专业知识,因此对这个答案持保留态度。
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.
在这种情况下,LLVM 可能是更好的选择。
LLVM有Windows支持,只是编译需要一些时间
In that case LLVM is probably a better choice.
LLVM has Windows support, it just takes some time to compile
对于 SmartEiffel,我们使用 C 作为后端。
Tcc 对于开发来说是一个非常好的选择 - 尽管不是最终版本(生成的对象相当于 gcc -O0)
For SmartEiffel we use C as a back-end.
Tcc is a very good option for development- though not for final release (the produced object is equivalent to gcc -O0)
C++ 不会给你太多,请使用 C。 但是,如果您希望您的语言在 Web 中使用,请使用 .NET 或 Java,当然它们加载速度很慢,但当它们加载时,它们与 C 一样快。
C++ won't give you much, use C instead. But if you want you language to be used in the Web, use .NET or Java, sure they slow to load but when they are, they as fast as C.
TCC是最好的选择。 它是可移植的,并且有一个库,因此可以很容易地用作后端,称为 libtcc。 可执行文件比 gcc 小,并且是 ANSI C。
TCC is the best choice. It is portable and it has a library so it can easily be used as a backend which is called libtcc. The executables are smaller than gcc and it is ANSI C.
另一个要添加到列表中的是:Slava 最近在 因素后端。 我自己没有尝试过,但我感觉它会提供更多您想要的高级功能的功能,并且更像低级功能的尺寸/性能。
Another to add to the list: Slava recently implemented Smalltalk on a Factor backend. I haven't tried this myself, but I have the feeling it would offer more of the features you want from the higher-level ones with more like the size/performance from the lower-level ones.