IR - Intermediate Representation Abstract syntax tree,...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
cs5363 1 Intermediate Representation Abstract syntax tree, control- flow graph, three-address code
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs5363 2 Intermediate Code Generation Intermediate language between source and target Multiple machines can be targeted Attaching a different backend for each machine Intel, AMD, IBM machines can all share the same parser for C/C++ Multiple source languages can be supported Attaching a different frontend (parser) for each language Eg. C and C++ can share the same backend Allow independent code optimizations Multiple levels of intermediate representation Supporting the needs of different analyses and optimizations
Background image of page 2
cs5363 3 IR In Compilers Internal representation of input program by compilers Source code of the input program Results of program analysis Control-flow graphs, data-flow graphs, dependence graphs Symbol tables Book-keeping information for translation (eg., types and addresses of variables and subroutines) Selecting IR --- depends on the goal of compilation Source-to-source translation: close to source language Parse trees and abstract syntax trees Translating to machine code: close to machine code Linear three-address code External format of IR Support independent passes over IR
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs5363 4 Abstraction Level in IR Source-level IR High-level constructs are readily available for optimization Array access, loops, classes, methods, functions Machine-level IR Expose low-level instructions for optimization Array address calculation, goto branches Subscript A i j loadI 1 => r1 sub rj, r1 => r2 loadI 10 => r3 mult r2, r3 => r4 sub ri, r1 => r5 add r4, r5 => r6 loadI @A => r7 add r7, r6 => r8 load r8 => rAij Source-level tree ILOC code
Background image of page 4
cs5363 5 Parse Tree And AST Graphically represent grammatical structure of input program Parse tree: tree representation of syntax derivations AST: condensed form of parse tree Operators and keywords do not appear as leaves Chains of single productions are collapsed If-then-else B S1 S2 S IF B THEN S1 ELSE S2 E E + T 5 T 3 + 3 5 Parse trees Abstract syntax trees
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs5363 6 Implementing AST in C Define different kinds of AST nodes typedef enum {PLUS, MINUS, ID, NUM} ASTNodeTag; Define AST node types typedef struct ASTnode { AstNodeTag kind; union { symbol_table_entry* id_entry; int num_value; struct ASTnode* opds[2]; } description; }; Define AST node construction routines ASTnode* mkleaf_id(symbol_table_entry* e); ASTnode* mkleaf_num(int n); ASTnode* mknode_plus(struct ASTnode* opd1, struct ASTNode* opd2); ASTnode* mknode_minus(struct ASTnode* opd1, struct ASTNode* opd2); E ::= E + T | E – T | T T ::= (E) | id | num Grammar:
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/29/2012 for the course CS 5363 taught by Professor Staff during the Spring '08 term at The University of Texas at San Antonio- San Antonio.

Page1 / 19

IR - Intermediate Representation Abstract syntax tree,...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online