简体   繁体   English

从汇编器到C编译器

[英]From Assembler to C-Compiler

i designed a small RISC in verilog. 我在verilog中设计了一个小型RISC。 Which steps do I have to take to create ac compiler which uses my assembler-language? 创建使用汇编语言的交流编译器时,我必须采取哪些步骤? Or is it possible to modify a conventional compiler like gcc, cause I don't want to make things like linker, ... 或者有可能修改像gcc这样的常规编译器,因为我不想做类似链接器的事情,...

Thanks 谢谢

You need to use an unmodified C lexer+parser (often called the front end), and a modified code generation component (the back end) to do that. 您需要使用未经修改的C lexer + parser(通常称为前端)和经过修改的代码生成组件(后端)来执行此操作。

Eli Bendersky's pycparser can be used as the front end, and Atul's mini C compiler can be used as inspiration for the code generating back end: http://people.cs.uchicago.edu/~varmaa/mini_c/ Eli Bendersky的pycparser可以用作前端,而Atul的mini C编译器可以用作生成后端代码的灵感: http : //people.cs.uchicago.edu/~varmaa/mini_c/

With Eli Bendersky's pycparser, all you need to do is convert the AST to a Control Flow Graph (CFG) and generate code from there. 使用Eli Bendersky的pycparser,您所需要做的就是将AST转换为控制流图(CFG),并从那里生成代码。 It is easier to start with supporting a subset of C than the full shebang. 从支持C的子集开始要比完整的shebang更容易。

The two tools are written in Python, but you didn't mention any implementation language preferences :) 这两个工具是用Python编写的,但是您没有提到任何实现语言首选项:)

I have found most open sourcen compilers (except clang it seems) too tightly coupled to easily modify the back end. 我发现大多数开放源代码编译器(似乎不是clang)耦合得太紧密,无法轻松修改后端。 Clang and especially GCC are not easy to dive into, nowhere NEAR as easy as the two above. Clang尤其是GCC并不容易涉足,没有NEAR可以像上述两者一样容易。 And since Eli's parser does full C99 (it parses everything I've thrown at it) it seem like a nice front end to use for further development. 而且由于Eli的解析器执行完整的C99(它解析了我抛出的所有内容),因此它似乎是用于进一步开发的不错的前端。 The examples on the Github project demonstrates most of the features of the project and it's easy to get started. Github项目上的示例演示了该项目的大多数功能,并且很容易上手。 The example that parses C to literal English is worth taking a look at, but may take a while to fully grok. 将C解析为文字英语的示例值得一看,但可能需要一段时间才能完全理解。 It basically handles any C expression, so it is a good reference for how to handle the different nodes of the AST. 它基本上可以处理任何C表达式,因此对于如何处理AST的不同节点提供了很好的参考。

I also recommended the tools above, in my answer to this question: Build AST from C code 在回答这个问题时,我还推荐了上述工具: 从C代码构建AST

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM