O'Reilly logo

Compilers: Principles and Practice by Himanshu B. Dave, Parag H. Dave

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.9 Converting the 4-Tuple and RPN into Assembly Code

Although generating an assembly language code directly by the semantic phase is not only possible, but also comparatively easy, we have taken the path of the IR in anticipation of later possibility of machine independent optimization.

Considerable string matching and manipulation are involved in converting a 4-tuple code into an assembly code, so we chose to write the code generator in Perl script. We use an auxiliary file, called codebase.mat which contains the templates for the conversion, and its initial version for converting 4-tuple IR is given below:

DCL# A2: .A1 0 LD# movl A1, A2 =# movl A1, A2 ADD# addl A1, A2 nl movl A2, A3 SUB# subl A2, A1 nl movl A1, A3 MUL# imull A1, A2 nl movl ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required