8.1.2 Data Structures for the Implementation of Three-Address code
8.1.2 Data Structures for the Implementation of Three-Address Code
The most common implementation is to implement three-address code as quadruple, which means that four fields are necessary One for the operation and three for the addresses a different implementation of three-address code s called a triple Use the instructions themselves to represent the temporaries It requires that each three-address instruction be reference-able, either as an index in an array or as a pointer in a linked list
• The most common implementation is to implement three-address code as quadruple, which means that four fields are necessary: – One for the operation and three for the addresses • A different implementation of three-address code is called a triple: – Use the instructions themselves to represent the temporaries. • It requires that each three-address instruction be reference-able, either as an index in an array or as a pointer in a linked list
Quadruple implementation for the three address code of the previous example X (gt,x,0, tI) (if f, tl, LI (asn (lab, L2 (mul, fact, x, t2 (asn, t2, fact,) (sub, x, l, t3) (eq, x, 0, t4) (if f, t4, L2,) wri. fact Cab. LI (halt
• Quadruple implementation for the threeaddress code of the previous example (rd, x , _ , _ ) (gt, x, 0, t1 ) (if_f, t1, L1, _ ) (asn, 1,fact, _ ) (lab, L2, _ , _ ) (mul, fact, x, t2 ) (asn, t2, fact, _ ) (sub, x, 1, t3 ) (asn, t3, x, _ ) (eq, x, 0, t4 ) (if_f, t4, L2, _) (wri, fact, _, _ ) (lab, L1, _ , _ ) (halt, _, _, _ )
C code defining data structures for the quadruples Typedef enum i rd, gt, if f, asn, lab, mul, sub, eq, wri, halt,.) OpKind Typedef enum Empty, IntConst, String) AddrKind Typedef struct f AddrKind kind; nion f int val char name 3 contents 3 Address pede struct f OpKind op Address addr1. addr2 addr3 3 Quad
• C code defining data structures for the quadruples Typedef enum { rd, gt, if_f, asn, lab, mul, sub, eq, wri, halt, …} OpKind; Typedef enum { Empty, IntConst, String } AddrKind; Typedef struct { AddrKind kind; Union { int val; char * name; } contents; } Address Typedef struct { OpKind op; Address addr1, addr2, addr3; } Quad