0

I'm writing a mini Fortran compiler using Flex and Bison. 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. My target machine is MIPS. So I want final code generation based on MIPS IAS. So a good IR I believe are quadruples. But I want to introduce some optimizations. For that reason I've built a DAG structure (using a hash table). There are 2 paths for IR: quadruples or DAG and then quadruples.

If I go with DAG as my IR, how could I use the backpatching method for statements? With quadruples it'd be easy. The DAG on the other way is more abstract. I'll be forced to convert it to quadruples. I know that. My fear is backpatching.

gon1332
  • 1,930
  • 1
  • 24
  • 30

1 Answers1

0

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). 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.

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 ;-).

I don't know if the Usenet group comp.compilers lives on in some form, but it's FAQ would be my first stop. Possibly horribly dated, though.

vonbrand
  • 11,412
  • 8
  • 32
  • 52
  • I know about SSA..LLVM GCC and more. I am building a compiler for my class project. It's open in matter of implementation. And for final code I have to choose between MIPS and x86. I'll go with MIPS cause I know it really well. I'm confussed about the order of things. Should I go immediately with quads and then with DAGs, or immediately with DAGs? In the second case, how could I use backpatching? – gon1332 Mar 14 '14 at 01:22