如何为自定义CPU创建C编译器? [英] How to create a C compiler for custom CPU?

查看:154
本文介绍了如何为自定义CPU创建C编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经有一个汇编器,那么为自定义CPU创建C编译器的最简单方法是什么?

What would be the easiest way to create a C compiler for a custom CPU, assuming of course I already have an assembler for it?

由于C编译器生成了汇编,是否有某种方法可以为各种C习惯用法定义标准的汇编代码,重新构建编译器,从而获得用于目标硬件的交叉编译器?

Since a C compiler generates assembly, is there some way to just define standard bits and pieces of assembly code for the various C idioms, rebuild the compiler, and thereby obtain a cross compiler for the target hardware?

最好将编译器本身用C编写,并构建为Linux或Windows的本机可执行文件。

Preferably the compiler itself would be written in C, and build as a native executable for either Linux or Windows.

请注意: not 询问如何编写编译器本身。我确实在大学里上过那门课,我了解一般的编译器等。在这种情况下,我只想配置一些现有的框架。我不想修改语言,只希望能够针对任意架构。如果答案是这样行不通,则 信息将对我自己和可能做出类似假设的其他人有用。

Please note: I am not asking how to write the compiler itself. I did take that course in college, I know about general compiler-compilers, etc. In this situation, I'd just like to configure some existing framework if at all possible. I don't want to modify the language, I just want to be able to target an arbitrary architecture. If the answer turns out to be "it doesn't work that way", that information will be useful to myself and anyone else who might make similar assumptions.

推荐答案

快速撰写概述/教程


该文档介绍了为LLVM编写后端的技术,这些技术将LLVM表示形式转换为机器汇编代码或其他语言。

[。 。 。 ]

要创建一个静态编译器(一个会发出文本汇编的编译器),您需要实现以下内容:

To create a static compiler (one that emits text assembly), you need to implement the following:


  • 描述寄存器集。

  • 描述指令集。

  • 描述目标机器。

  • 实现

  • 为该架构实现指令选择器。

  • Describe the register set.
  • Describe the instruction set.
  • Describe the target machine.
  • Implement the assembly printer for the architecture.
  • Implement an instruction selector for the architecture.

这篇关于如何为自定义CPU创建C编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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