Intermediate Code (3-Address Quadruples)

Total Page:16

File Type:pdf, Size:1020Kb

Intermediate Code (3-Address Quadruples)

CS 5300 Compiler Design Fall 2003

Intermediate Code (3-address quadruples) 1. Additional token codes (not found in the source by the scanner); BUNC unconditional jump 30 CALL return jump or function CALL 31 IR indexed reference 32 IA indexed assignment 33 PUSH push a value onto the runtime stack 34 POP pop a value from the runtime stack 35 2. Arithmetic operators; ( ADD, SUB, MULT, DIV ) op arg1 arg2 dest Perform the operation upon the two args and place the result in dest. 3. Conditional transfer of control; (BEQ, BLE, BGT, BLE, BGE, BNE – reuse token codes 40-45) op arg1 arg2 quadnum Using the relational operation op, compare arg1 with arg2 and jump to quadruple indicated by quadnum if the comparison is true. 4. Unconditional transfers; (BUNC, CALL) BUNC 00 quadnum Unconditional jump to quadnum. CALL arg 0 quadnum Returnable jump or function CALL to quadnum 5. Assignment; (ASGN, IR, IA) = arg 0 dest Assign the value of arg to the variable dest. IR arg1 arg2 dest Assign the value of (arg1 indexed by arg2) to dest. IA arg1 arg2 dest Assign the value of arg1 to (dest indexed by arg2). 6. I/O; (READ, WRITE) READ 0 0 dest Perform an input and assign result to dest. WRITE arg 0 0 Perform an output from arg. 7. Arguments, destinations; Variables, constants, and literals are all referenced using the appropriate symbol-table slot number. To avoid confusion, we will assign the slot range 1-199 for variables, 200-299 for integer constants, 300-399 for real constants, and 400-499 for literals. Intermediate code may assume an unlimited number of readily-available temporary variables which we will reference using negative numbers. For example, temporary #5 might be represented by -5.

EXAMPLES: 20 5 201 -13 ;add (PLUS) the value of the variable in SBT slot #5 to the constant in slot 201 and place the result in temporary #13. 40 -7 0 3 ;assign (=) the value of temp #7 to the variable in slot #3. 44 310 2 356 ;jump (GEQ) to quadnum 356 if the constant in slot #310 is >= to the variable in slot #2. 70 0 0 2 ;read (READ) a value into the variable of slot #2.

Recommended publications