简体   繁体   English

我的Fortran编译器的中间代码生成:DAG或四倍

[英]Intermediate Code Generation for my Fortran compiler: DAG or quadruples

I'm writing a mini Fortran compiler using Flex and Bison. 我正在使用Flex和Bison编写一个小型Fortran编译器。 Up to now I've finished the lexical and syntax analysis. 到目前为止,我已经完成了词法和语法分析。 I'm in the semantic analysis in type checking and I must now choose an IR. 我正在进行类型检查的语义分析,现在必须选择一个IR。 My target machine is MIPS. 我的目标机器是MIPS。 So I want final code generation based on MIPS IAS. 所以我想要基于MIPS IAS的最终代码生成。 So a good IR I believe are quadruples. 因此,我认为好的IR是四倍的。 But I want to introduce some optimizations. 但是我想介绍一些优化。 For that reason I've built a DAG structure (using a hash table). 因此,我建立了一个DAG结构(使用哈希表)。 There are 2 paths for IR: quadruples or DAG and then quadruples. IR有2条路径:四倍或DAG,然后四倍。

If I go with DAG as my IR, how could I use the backpatching method for statements? 如果我将DAG用作IR,我如何使用backpatching方法处理语句? With quadruples it'd be easy. 使用四倍,这将很容易。 The DAG on the other way is more abstract. 另一方面,DAG更为抽象。 I'll be forced to convert it to quadruples. 我将不得不将其转换为四倍。 I know that. 我知道。 My fear is backpatching. 我的担心正在修补。

I believe you are worrying about low-level details when you should concentrate on high-level design. 我相信您在专注于高级设计时会担心低级细节。 Besides, current compilers don't use quadruples, but SSA (Static Single Asignment). 此外,当前的编译器不使用四倍,而使用SSA(静态单一分配)。 For final code generation, perhaps take a look at the LCC compiler, they use a simple way to emit locally optimal code by tree matching. 对于最终的代码生成,也许看看LCC编译器,他们使用一种简单的方法通过树匹配来发出局部最优代码。

A way to cheat is to just emit a high-level language (like C) and leave the heavy lifting to it's compiler (and you get portability for free ;-). 作弊的一种方法是只发出一种高级语言(如C),而将繁重的工作留给它的编译器(并且您可以免费获得可移植性;-)。

I don't know if the Usenet group comp.compilers lives on in some form, but it's FAQ would be my first stop. 我不知道Usenet小组的comp.compilers是否以某种形式存在,但是FAQ是我的第一站。 Possibly horribly dated, though. 不过,可能过时了。

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

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