Lecture 31: Building a Runnable Program

Similar documents
Intermediate Representations

Lecture 15: Iteration and Recursion

Lecture 13: Expression Evaluation

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Intermediate Representations

Intermediate Representations

Concepts Introduced in Chapter 3

Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

Intermediate Representation (IR)

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

Principles of Compiler Design

Compiler Code Generation COMP360

CS415 Compilers. Intermediate Represeation & Code Generation

1 Little Man Computer

CSCI 3136 Principles of Programming Languages

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Application Specific Signal Processors S

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

Lecture08: Scope and Lexical Address

Compiler Construction

A simple syntax-directed

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

CA Compiler Construction

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Intermediate Code Generation

Compilers and Interpreters

CSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1

Compiler Construction

CSE 401/M501 Compilers

Compiler Construction

Compiler Construction

Intermediate Code, Object Representation, Type-Based Optimization

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Code Generation. Frédéric Haziza Spring Department of Computer Systems Uppsala University

Compiler Construction

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

55:132/22C:160, HPCA Spring 2011

opt. front end produce an intermediate representation optimizer transforms the code in IR form into an back end transforms the code in IR form into

Compiling Techniques

Lecture 4: Syntax Specification

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CSc 453 Interpreters & Interpretation

Compiler construction

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

CMPSC 160 Translation of Programming Languages. Three-Address Code

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Compiler Construction

Front End. Hwansoo Han

ICS 252 Introduction to Computer Design

Major Advances (continued)

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

Formal Languages and Compilers Lecture IX Semantic Analysis: Type Chec. Type Checking & Symbol Table

Intermediate Representations

0. Overview of this standard Design entities and configurations... 5

Programming Languages

Soot A Java Bytecode Optimization Framework. Sable Research Group School of Computer Science McGill University

CSE P 501 Exam 8/5/04

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

CST-402(T): Language Processors

Introduction. Interpreters High-level language intermediate code which is interpreted. Translators. e.g.

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Compiler Construction

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

Intermediate Representations & Symbol Tables

Intermediate Representations

ECE232: Hardware Organization and Design

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

1 Lexical Considerations

Compilers and interpreters

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Instruction Set Architecture

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Chapter 2 First Java Programs

Building a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano

Compiler Optimization

Programming Languages FILS Andrei Vasilateanu

ECE 486/586. Computer Architecture. Lecture # 7

Ruby: Introduction, Basics

Languages and Compiler Design II IR Code Optimization

Today's Topics. CISC 458 Winter J.R. Cordy

Where we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers

Introduction to Java Programming

A Simple Syntax-Directed Translator

Chapter 04: Instruction Sets and the Processor organizations. Lesson 20: RISC and converged Architecture

Control Flow Analysis

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Intermediate Code & Local Optimizations

The View from 35,000 Feet

G Programming Languages - Fall 2012

IR Lowering. Notation. Lowering Methodology. Nested Expressions. Nested Statements CS412/CS413. Introduction to Compilers Tim Teitelbaum

5. Semantic Analysis!

LECTURE 3. Compiler Phases

Transcription:

The University of North Carolina at Chapel Hill Spring 2002 Lecture 31: Building a Runnable Program April 10 1 From Source Code to Executable Code program gcd(input, output); var i, j: integer; begin read(i, j); while i <> j do if i > j then i := i j; else j := j i; writeln(i) end. Compilation 2 1

3 Compiler Structure Lexical, syntax and semantic analyses are the front- end of a compiler These phases serve to figure out the meaning of the program The rest of the phases are considered part of the back-end of a compiler They are responsible for the generation of the target program 4 2

The first three phases are language- dependent The last two are machine- dependent The middle two dependent on neither the language nor the machine 5 Example program gcd(input, output); var i, j: integer; begin read(i, j); while i <> j do if i > j then i := i j; else j := j i; writeln(i) end. 6 3

Example Syntax Tree and Symbol Table 7 Intermediate code generation transforms the abstract syntax tree into a less hierarchical representation: a control flow graph 8 4

Example Control Flow Graph Basic blocks are maximal-length length set of sequential operations Operations on a set of virtual registers» Unlimited» A new one for each computed value Arcs represent interblock control flow 9 Machine- independent code improvement performs a number of transformations: Eliminate redundant loads stores and arithmetic computations Eliminate redundancies across blocks 10 5

Target Code Generation translates block into the instruction set of the target machine, including branches for the arc It still relies in the set of virtual registers 11 Machine- specific code improvement consists of: Register allocation (mapping of virtual register to physical registers and multiplexing) Instruction scheduling (fill( the pipeline) 12 6

Compilation Passes A pass of compilation is a phase or sequence of phases that is serialized with respect to the rest of the compilation It may be written as separate program that relies on files for input and output Two-pass compilers are very common Front-end and back-end passes, or intermediate code generation and global code improvement Most compilers generate assembly, so the assembler behaves as an extra pass Assembly requires linking that may take place at compilation, load or run-time 13 Compilation Passes Why are compilers divided in passes? Sharing the front-end among the compilers of more than one machine Sharing the back-end among the compilers of more than one language Historically, passes help reducing memory usage 14 7

Intermediate Forms Front-end and back-end are linked using an abstract representation known as the Intermediate Format (IF) The IF is propagated through the back-end phases They classified according to their level of machine dependence High-level IFs are usually trees or directed acyclic graphs that capture the hierarchy of the program They are useful for machine-independent independent code improvement, interpretation and other operations 15 Intermediate Forms Stack-based Language Stack-based language are another type of IFs E.g. JVM, Pascal s P-codeP They are simple and compact They resemble post-order order tree enumeration Operations Take their operands from an implicit stack Return their result to an implicit stack These languages tend to make language easy to port and the result code is very compact Ideal for network transfer of applets 16 8

Java Virtual Machine JVM spec http://java.sun.com/docs/books/vmspec/2nd- edition/html/vmspectoc.doc.html Tutorial http://www-106.ibm.com/developerworks/library/it 106.ibm.com/developerworks/library/it- haggar_bytecode/index.html 17 Reading Assignment Read Scott Sect. 9 Intro Sect. 9.1 Sect. 9.2 intro, and glance at IDL and RTL 18 9