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

Get Compilers: Principles and Practice now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.