L10-IR - Introduction to Compiler Design Intermediate-Code...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Compiler Design Intermediate-Code Generation Professor Yi-Ping You Department of Computer Science http://www.cs.nctu.edu.tw/~ypyou/ Page 1 Introduction to Compiler Design, Spring 2010 Outline Outline Overview of Intermediate Representation termediate Representation Intermediate Representation Syntax Trees hree- ddress Code Three Address Code Intermediate-Code Generation ypes and Declarations Types and Declarations Translation of Expressions Type Checking Control Flow Backpatching Switch-Statements and Procedures Page 2 Introduction to Compiler Design, Spring 2010 Recall: The Structure of a Compiler Recall: The Structure of a Compiler Lexical Analyzer Source Code y (scanner) Syntax Analyzer (parser) Semantic Analyzer Front End Details of source language Intermediate Code enerator (Analysis) Code Optimizer Generator etails of Code Generator Back End ynthesis) Details of target machine Page 3 Introduction to Compiler Design, Spring 2010 Target Code (Synthesis) A Sequence of Intermediate Representations A Sequence of Intermediate Representations ource rget Intermediate Representation … Source Program Target Code High-level IR Low-level IR High-level representations Syntax trees (graphical representations) y (g p p ) Closer to source language uitable for static type checking Suitable for static type checking Low-level representations hree ddress code Three-address code Closer to target machine uitable for machine ependent tasks like register Page 4 Introduction to Compiler Design, Spring 2010 Suitable for machine-dependent tasks like register allocation and instruction selection Recall: Syntax Trees Recall: Syntax Trees A syntax tree shows the structure of a program y abstracting away irrelevant details from a by abstracting away irrelevant details from a parse tree ach node represents a computation to be performed Each node represents a computation to be performed The children of the node represents what that computation is performed on T igit * T F * digit digit F 5 3 5 Page 5 Introduction to Compiler Design, Spring 2010 3 Parse Tree Syntax Tree Variant of Syntax Trees Variant of Syntax Trees Directed acyclic graph (DAG) ommons to syntax trees Commons to syntax trees Leaves: atomic operands Interior nodes: operators Differences to syntax trees Common subexpressions are not replicated E.g., a + a * ( b – c ) + ( b – c ) * d + + + * + * d – a – a * c b d – a * Page 6 Introduction to Compiler Design, Spring 2010 Syntax Tree c b c b DAG Construction of DAG: An Example Construction of DAG: An Example Production Semantic Rules 1) E → E 1 + T E.node = new Node (‘+’, E 1 .node, T.node ) 2) E → E 1 – T E.node = new Node (‘–’, E 1 .node, T.node ) 3) E → E 1 * T E.node = new Node (‘*’, E 1 .node, T.node ) ) d d Before creating a new node, we 4) E → T E.node = T.node 5) T → ( E ) T.node = E.node 6) T → id T.node = new Leaf( id , id .entry) check whether the node exists teps for constructing the DAG for + a *...
View Full Document

Page1 / 101

L10-IR - Introduction to Compiler Design Intermediate-Code...

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

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