如何写GCC自己的code发电机后端? [英] How to write your own code generator backend for gcc?

查看:128
本文介绍了如何写GCC自己的code发电机后端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造我自己的(很简单)字节code语言和虚拟机来执行它。它工作正常,但现在我想使用gcc(或任何其他免费提供的编译器)从一个普通的C程序生成字节code这台机器。所以,问题是,我该如何修改或扩展的gcc,以便它可以输出自己的字节code?请注意,我不希望编译我的字节code机器code,我想编译的C code到(我自己)字节code。

I have created my very own (very simple) byte code language, and a virtual machine to execute it. It works fine, but now I'd like to use gcc (or any other freely available compiler) to generate byte code for this machine from a normal c program. So the question is, how do I modify or extend gcc so that it can output my own byte code? Note that I do NOT want to compile my byte code to machine code, I want to "compile" c-code to (my own) byte code.

我意识到这是一个潜在的大问题,它可能是最好的答案是去看看gcc的源$ C ​​$ C。我只是需要一些帮助,如何让这个开始。我估计,必须有关于这个问题,可以描述的过程中添加自定义生成器gcc的一些文章或书籍,但我还没有使用Google所发现任何东西。

I realize that this is a potentially large question, and it is possible that the best answer is "go look at the gcc source code". I just need some help with how to get started with this. I figure that there must be some articles or books on this subject that could describe the process to add a custom generator to gcc, but I haven't found anything by googling.

推荐答案

这是艰苦的工作。

例如我还设计我自己的建筑与我自己的字节code和想要生成C / C ++ code。与GCC它。这是我的方式怎么做的:

For example I also design my own "architecture" with my own byte code and wanted to generate C/C++ code with GCC for it. This is the way how I make it:


  1. 在首先应该阅读有关href=\"http://gcc.gnu.org/onlinedocs/gcc/\" rel=\"nofollow\"> GCC的手动的
  2. 也不忘过阅读 GCC内幕

  3. 阅读有关编译器很多东西。

  4. 另外,也要看看这个问题和答案在这里。

  5. 谷歌获取更多信息。

  6. 问问自己,如果你真的准备好了。

  7. 确保有一个很好的网吧机器......你会需要它。

  8. 启动机器dependet文件添加到GCC。

  9. 在跨主机目标的方式GCC编译

  10. 检查code结果的十六进制编辑器。

  11. 请更多的测试。

  12. 现在,有乐趣与自己的架构:D

  1. At first you should read everything about porting in the manual of GCC.
  2. Also not forget too read GCC Internals.
  3. Read many things about Compilers.
  4. Also look at this question and the answers here.
  5. Google for more information.
  6. Ask yourself if you are really ready.
  7. Be sure to have a very good cafe machine... you will need it.
  8. Start to add machine dependet files to gcc.
  9. Compile gcc in a cross host-target way.
  10. Check the code results in the Hex-Editor.
  11. Do more tests.
  12. Now have fun with your own architecture :D

当你完成,你可以使用C或C ++只是没OS-dependet库(您目前对你的架构没有运行OS),你现在应该(如果你需要的话)编译许多其他库与交叉编译器有一个良好的框架。

When you are finished you can use c or c++ only without os-dependet libraries (you have currently no running OS on your architecture) and you should now (if you need it) compile many other libraries with your cross compiler to have a good framework.

PS: LLVM (的)更容易端口...也许你想从那里开始?

PS: LLVM (Clang) is easier to port... maybe you want to start there?

这篇关于如何写GCC自己的code发电机后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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