17-06-2013, 02:04 PM
Representing MIR, HIR and LIR in ICAN
Representing MIR.docx (Size: 16.92 KB / Downloads: 25)
INTRODUCTION
Up to now, we’ve seen external representations of MIR, HIR and LIR. So as to be able to conveniently manipulate MIR, HIR and LIR code in ICAN programs, we next present an internal representation for them.
To represent the code in ICAN, we have to choose an appropriate data structure. The structure we have chosen to use is an abstract syntax tree. An abstract syntax tree can be made either flat or very hierarchical. For instance, we may define different node types for different operators, with the node’s sons containing the operands. Or we may define a single node type, containing the type of the operator as well as the operands. We have chosen the latter approach, as it facilitates generalization: we can use the same code to deal with several different operators, if they require similar manipulation.
Representing MIR
Each kind of MIR instruction is represented by an ICAN tuple. The list of all possible tuples serves as an implicit declaration of the type MIRInst. We will bring here several examples of these tuples. The reader is referred to table 4.7 (page 83) for a complete list.
Representing HIR
To represent HIR in ICAN, we proceed essentially as for MIR. We implicitly define the type HIRInst, which maps HIR instructions to ICAN tuples. The definition of this type is given in table 4.8.
HIR needs no additional operands, so we use the type IROper defined earlier to represent the type of its operands. Several other enumerated types, as well as the function HIR_Exp_Kind and HIR_Has_Left are different for HIR, and are defined in figure 4.10.
The only thing worth noting is that for and endfor are represented as separate nodes, as are if, else and endif. This flattening of the tree allows the compiler greater flexibility when reordering instructions.
Representing LIR
To represent LIR in ICAN, we proceed essentially as for MIR. The implicit definition of the type LIRInst is given in table 4.9. The other enumerated types, and the functions LIR_Exp_Kind and LIR_Has_Left are declared in figure 4.11.