1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 31: Building a Runnable Program COMP 144 Programming Language Concepts Spring 2002.

Slides:



Advertisements
Similar presentations
1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Advertisements

1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 2: Compilation and Interpretation COMP 144 Programming Language Concepts Spring.
CS 31003: Compilers Introduction to Phases of Compiler.
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
Program Representations. Representing programs Goals.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 36: Global Optimization, Loop Improvement and Profiling COMP 144 Programming Language.
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 33: Code Generation and Linking COMP 144 Programming Language Concepts Spring 2002.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 32: The Java Virtual Machine COMP 144 Programming Language Concepts Spring 2002.
CS189A/172 - Winter 2008 Lecture 7: Software Specification, Architecture Specification.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 34: Code Optimization COMP 144 Programming Language Concepts Spring 2002 Felix.
Topic 6 -Code Generation Dr. William A. Maniatty Assistant Prof. Dept. of Computer Science University At Albany CSI 511 Programming Languages and Systems.
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 35: In-line Expansion and Local Optimization COMP 144 Programming Language Concepts.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Precision Going back to constant prop, in what cases would we lose precision?
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
Lecture 17 Modern Programming Trends JVM, C#, .NET
COP4020 Programming Languages
Chapter 1. Introduction.
1 Binding Time and Storage Allocation (Section ) CSCI 431 Programming Languages Fall 2003 A modification of slides developed by Felix Hernandez-Campos.
10/1/2015© Hal Perkins & UW CSEG-1 CSE P 501 – Compilers Intermediate Representations Hal Perkins Autumn 2009.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 10, 10/30/2003 Prof. Roy Levow.
CSC 338: Compiler design and implementation
Principles of Programming Languages Asst. Prof. Dr. Ahmet Sayar Spring-2012 Kocaeli University Computer Engineering Department Introduction.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Joey Paquet, 2000, 2002, 2007, Concordia University Department of Computer Science COMP 442/6421 Compiler Design.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
1 Text Reference: Warford. 2 Computer Architecture: The design of those aspects of a computer which are visible to the programmer. Architecture Organization.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Introduction to Code Generation and Intermediate Representations
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
1 Compilation and Interpretation (Sections ) Compilation and Interpretation (Sections ) CSCI 431 Programming Languages Fall 2003 A modification.
Chap. 10, Intermediate Representations J. H. Wang Dec. 27, 2011.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Copyright © 2009 Elsevier Chapter 14 :: Building a Runnable Program Programming Language Pragmatics Michael L. Scott.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Lecture 12 Intermediate Code Generation Translating Expressions
INTERMEDIATE LANGUAGES SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Compiler Chapter 9. Intermediate Languages Sung-Dong Kim Dept. of Computer Engineering, Hansung University.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Advanced Computer Systems
Introduction to Compiler Construction
Compiler Chapter 9. Intermediate Languages
Compiler Construction
Course supervisor: Lubna Siddiqui
Intermediate Representations
Intermediate Representations
8 Code Generation Topics A simple code generator algorithm
Intermediate Code Generating machine-independent intermediate form.
Presentation transcript:

1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 31: Building a Runnable Program COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos April 10 The University of North Carolina at Chapel Hill

2 COMP 144 Programming Language Concepts Felix Hernandez-Campos 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. 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

3 COMP 144 Programming Language Concepts Felix Hernandez-Campos Phases of Compilation

4 COMP 144 Programming Language Concepts Felix Hernandez-Campos Compiler Structure Lexical, syntax and semantic analyses are the front- end of a compilerLexical, 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 compilerThe rest of the phases are considered part of the back-end of a compiler –They are responsible for the generation of the target program

5 COMP 144 Programming Language Concepts Felix Hernandez-Campos Phases of Compilation The first three phases are language- dependentThe first three phases are language- dependent The last two are machine- dependentThe last two are machine- dependent The middle two dependent on neither the language nor the machineThe middle two dependent on neither the language nor the machine

6 COMP 144 Programming Language Concepts Felix Hernandez-Campos 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. 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.

7 COMP 144 Programming Language Concepts Felix Hernandez-Campos Example Syntax Tree and Symbol Table

8 COMP 144 Programming Language Concepts Felix Hernandez-Campos Phases of Compilation Intermediate code generation transforms the abstract syntax tree into a less hierarchical representation: a control flow graphIntermediate code generation transforms the abstract syntax tree into a less hierarchical representation: a control flow graph

9 COMP 144 Programming Language Concepts Felix Hernandez-Campos Example Control Flow Graph Basic blocks are maximal-length set of sequential operationsBasic blocks are maximal-length set of sequential operations –Operations on a set of virtual registers »Unlimited »A new one for each computed value Arcs represent interblock control flowArcs represent interblock control flow

10 COMP 144 Programming Language Concepts Felix Hernandez-Campos Phases of Compilation Machine- independent code improvement performs a number of transformations:Machine- independent code improvement performs a number of transformations: –Eliminate redundant loads stores and arithmetic computations –Eliminate redundancies across blocks

11 COMP 144 Programming Language Concepts Felix Hernandez-Campos Phases of Compilation Target Code Generation translates block into the instruction set of the target machine, including branches for the arcTarget 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 registersIt still relies in the set of virtual registers

12 COMP 144 Programming Language Concepts Felix Hernandez-Campos Phases of Compilation Machine- specific code improvement consists of:Machine- specific code improvement consists of: –Register allocation (mapping of virtual register to physical registers and multiplexing) –Instruction scheduling (fill the pipeline)

13 COMP 144 Programming Language Concepts Felix Hernandez-Campos Compilation Passes A pass of compilation is a phase or sequence of phases that is serialized with respect to the rest of the compilationA 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 commonTwo-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 passMost compilers generate assembly, so the assembler behaves as an extra pass Assembly requires linking that may take place at compilation, load or run-timeAssembly requires linking that may take place at compilation, load or run-time

14 COMP 144 Programming Language Concepts Felix Hernandez-Campos Compilation Passes Why are compilers divided in passes?Why are compilers divided in passes? Sharing the front-end among the compilers of more than one machineSharing the front-end among the compilers of more than one machine Sharing the back-end among the compilers of more than one languageSharing the back-end among the compilers of more than one language Historically, passes help reducing memory usageHistorically, passes help reducing memory usage

15 COMP 144 Programming Language Concepts Felix Hernandez-Campos Intermediate Forms Front-end and back-end are linked using an abstract representation known as the Intermediate Format (IF)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 dependenceThey classified according to their level of machine dependence High-level IFs are usually trees or directed acyclic graphs that capture the hierarchy of the programHigh-level IFs are usually trees or directed acyclic graphs that capture the hierarchy of the program –They are useful for machine-independent code improvement, interpretation and other operations

16 COMP 144 Programming Language Concepts Felix Hernandez-Campos Intermediate Forms Stack-based Language Stack-based language are another type of IFsStack-based language are another type of IFs –E.g. JVM, Pascal’s P-code They are simple and compactThey are simple and compact –They resemble post-order tree enumeration OperationsOperations –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 compactThese languages tend to make language easy to port and the result code is very compact –Ideal for network transfer of applets

17 COMP 144 Programming Language Concepts Felix Hernandez-Campos Java Virtual Machine JVM specJVM spec – edition/html/VMSpecTOC.doc.html edition/html/VMSpecTOC.doc.htmlhttp://java.sun.com/docs/books/vmspec/2nd- edition/html/VMSpecTOC.doc.html TutorialTutorial – haggar_bytecode/index.html haggar_bytecode/index.htmlhttp://www-106.ibm.com/developerworks/library/it- haggar_bytecode/index.html

18 COMP 144 Programming Language Concepts Felix Hernandez-Campos Reading Assignment Read ScottRead Scott –Sect. 9 Intro –Sect. 9.1 –Sect. 9.2 intro, and glance at IDL and RTL