Compilation by Program Transformation 600.426: Programming Languages Spring 2004.

Slides:



Advertisements
Similar presentations
FAA-Qualifiable Ada Subset Compiler V. Santhanam Boeing.
Advertisements

CSc 453 Compilers & Systems Software Saumya Debray The University of Arizona Tucson, AZ
Compiler Construction by Muhammad Bilal Zafar (AP)
UNIT-III By Mr. M. V. Nikum (B.E.I.T). Programming Language Lexical and Syntactic features of a programming Language are specified by its grammar Language:-
Java.  Java is an object-oriented programming language.  Java is important to us because Android programming uses Java.  However, Java is much more.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
COE Computer Organization & Assembly Language Introduction HLL vs. Assembly Programming Languages.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.2 Spring 2007 Marco Valtorta
1.1 Introduction to Language Processor
3/24/2004COSC4301 assignment 31 Compiler, Interpreter, and Bootstrapping Motivation: When we are asked to write a  Compiler for a complex source language.
3-1 3 Compilers and interpreters  Compilers and other translators  Interpreters  Tombstone diagrams  Real vs virtual machines  Interpretive compilers.
Source Code Basics. Code For a computer to execute instructions, it needs to be in binary Each instruction is given a number Known as “operation code”
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 1www.idc.ac.il/tecs Assembler Elements of Computing.
Chapter 1. Introduction.
Language processors (Chapter 2) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Pirouz Bazargan SabetDecember 2003 Outline Architecture of a RISC Processor Implementation.
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
Compilers for Embedded Systems Ram, Vasanth, and VJ Instructor : Dr. Edwin Sha Synthesis and Optimization of High-Performance Systems.
CS 614: Theory and Construction of Compilers Lecture 8 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
The course. Description Computer systems programming using the C language – And possibly a little C++ Translation of C into assembly language Introduction.
CSc 453 Compilers & Systems Software Saumya Debray The University of Arizona Tucson, AZ
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
 Chapter 2 Language Processors Fall Chart 2  Translators and Compilers  Interpreters  Real and Abstract Machines  Interpretive Compilers 
CS2100 Computer Organisation MIPS Part I: Introduction (AY2015/6) Semester 1.
Language Implementation Methods David Woolbright.
Object Oriented Software Development 4. C# data types, objects and references.
The Instruction Set Architecture. Hardware – Software boundary Java Program C Program Ada Program Compiler Instruction Set Architecture Microcode Hardware.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
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.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
CS 614: Theory and Construction of Compilers Lecture 8 Fall 2002 Department of Computer Science University of Alabama Joel Jones.
Introduction To Software Development Environment.
Chapter 1. Introduction.
CS2100 Computer Organisation
Why don’t programmers have to program in machine code?
Advanced Computer Systems
Component 1.6.
Overview of Compilers and Language Translation
SYSTEM SOFTWARE & COMPILER DESIGN
Language Translation Compilation vs. interpretation.
Chapter 9 – Real Memory Organization and Management
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Want to Write a Compiler?
Compiler Lecture 1 CS510.
CSc 453 Compilers & Systems Software 00. Background
and Executing Programs
Programming Languages
Compiler 薛智文 TH 6 7 8, DTH Spring.
High Level Programming Languages
CSCE 531 Compiler Construction Ch.2
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
The Purpose of this Course
C021TV-I3-S2.
Programming Languages and Compilers (CS 421)
Compiler Structures 1. Overview Objective
Programming language translators
Presentation transcript:

Compilation by Program Transformation : Programming Languages Spring 2004

To understand the most basic, fundamental concepts behind compilation: how a high-level program can be mapped to machine code  By writing a DSR compiler To appreciate the gap between high- and low-level code, and understanding how the gaps may be bridged Goal DSR Full DSR No Nested Functions DSR Primitive Operations Only Primitive C Machine Language OCaml gcc DSR C-like Program Structure OCaml

Why Study Compilation? Compilers are an important technology because code produced by a compiler is faster than interpreted code by several orders of magnitude Atleast 95% of the production software running is compiled code Compiled code is sometimes even better than hand-crafted assembly code because of the complexity of modern processors 1.Speed 2.Speed 3.Speed

Outline We will outline a compiler of DSR to a very limited subset of C (“pseudo-assembly”) You will later implement a DSR compiler in Caml by filling in the holes left out Compiling: Series of Program Transformations  Closure Conversion  A-Translation  Function Hoisting & finally, Translation into C DSR Full DSR No Nested Functions DSR Primitive Operations Only Primitive C Machine Language Closure Conversion A–Trans- lation gcc DSR C-like Program Structure Translation into C Function Hoisting

Program Transformation Approach Map programs to equivalent programs, removing high-level features one at a time The idea is:  To make the program’s expressiveness more and more primitive  Making it closer and closer to the target (machine) language, and  Hence bridging gaps gradually

Program Transformation Approach Real production compilers such as gcc and Sun’s javac do not use a trandformation process  Primarily because the speed of the compilation itself is too slow It is in fact possible to produce very good code by transformation.  E.g., The SML/NJ ML compiler uses a transformational approach Most production compilers transform the program to an intermediate form which is neither source nor target language (“intermediate language”) and do numerous optimizing transformations on this intermediate code

Example of PT-Approach for (i=0 ; i<10 ; i++) a = a+i; i=0; while (i<10) { a = a+i; i++; } i=0; loop_entry: if (i>=10) GOTO loop_exit; a = a+i; i++; GOTO loop_entry; loop_exit: [next_statement]… 1 2

Example of PT-Approach MOV, $0 loop_entry: CMP, $10 JGE loop_exit ADD, INC JMP loop_entry loop_exit: [next_statement]…

Soundness Property Programs before and after translation have the same execution behavior  In our case, termination and same numerical output  But in general, the same I/O behavior Note that the programs that are output by the translation are not necessarily operationally equivalent to the originals  Context

What we will not be covering Lexical Analysis and Parsing Optimizations Compilation of low-level languages such as C/C++  Our focus is on the compilation of higher-order languages Our executables will not  Try to catch run-time type errors  Garbage collect unused memory We are not being Realistic!

Closure Conversion: Why? Transformation which eliminates nonlocal variables in functions  To obtain an equivalent program where all variables used in functions are parameters of the function The problematic nonlocals which must be removed are those that are parameters of other functions, where function definitions have been nested