Want to Write a Compiler?

Slides:



Advertisements
Similar presentations
An Overview Of Virtual Machine Architectures Ross Rosemark.
Advertisements

Compilation by Program Transformation : Programming Languages Spring 2004.
8. Code Generation. Generate executable code for a target machine that is a faithful representation of the semantics of the source code Depends not only.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.2: Language Processors Spring 2010 Marco.
T-diagrams “Mommy, where do compilers come from?” Adapted from:
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
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”
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
Programming Languages: Scratch Intro to Scratch. Lower level versus high level Clearly, lower level languages can be tedious Higher level languages quickly.
Language processors (Chapter 2) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Which Language is Better?
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 2.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
 Chapter 2 Language Processors Fall Chart 2  Translators and Compilers  Interpreters  Real and Abstract Machines  Interpretive Compilers 
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
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.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
COMP 3002: Compiler Construction Pat Morin School of Computer Science.
Review Pat Morin COMP What is a Compiler A compiler translates – from a source language S – to a target language T – while preserving the meaning.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
COMP Compilers Lecture 1: Introduction
Why don’t programmers have to program in machine code?
Advanced Computer Systems
Using Ada-C/C++ Changer as a Converter Automatically convert to C/C++ to reuse or redeploy your Ada code Eliminate the need for a costly and.
Compiler Design (40-414) Main Text Book:
Introduction Chapter : Introduction.
Overview of Compilers and Language Translation
High or Low Level Programming Language? Justify your decision.
Compiler, Interpreter, and Bootstrapping
Introduction to Compiler Construction
Language Translation Compilation vs. interpretation.
Programming Language Hierarchy, Phases of a Java Program
Overview of Compilation The Compiler BACK End
课程名 编译原理 Compiling Techniques
History of compiler development
CISC 7120X Programming Languages and Compilers
Introduction to Compiler Construction
Assembler, Compiler, Interpreter
Programming Languages
Compiler Construction
COMP Compilers Lecture 1: Introduction
CSCE 531 Compiler Construction Ch.2
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
Overview of Compilation The Compiler BACK End
Assembler, Compiler, Interpreter
Compiler Writing Source Language Issues
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Introduction to Compiler Construction
CISC 7120X Programming Languages and Compilers
Chapter 1 Introduction.
Introduction Chapter : Introduction.
Reasons To Study Programming Languages
Compiler Structures 1. Overview Objective
Programming language translators
Intermediate Code Generating machine-independent intermediate form.
Introduction to Compiler Construction
Week 1 - Friday COMP 1600.
Presentation transcript:

Want to Write a Compiler? Pat Morin COMP 3002

What is a Compiler? From Day 1: A compiler is a program that translates from a source language S into a target language T while preserving semantics Often (but not always) S is a programming language T is a machine language

Want to Write a Compiler? A compiler has 3 main parameter Source language (S) What kind of input does the compiler take? C, C++, Java, Python, .... Implementation language (I) What language is the compiler written in? C, Java, i386, x84_64 Target language (T) What is the compiler's target language i386, x86_64, PPC, MIPS, ... S T I

Source Language Issues Complexity Is a completely handwritten compiler feasible? Stability Is the language definition still changing? Novelty Do there already exist compilers for this language? Complicated, or still-changing languages promote the use of compiler generation tools

Target Language Issues Novelty Is this a new architecture? Are there similar architectures/instruction sets? Available tools Is there an assembler for this language? Are there other compilers for this language?

Performance criteria Speed Does it have to be a fast compiler? Does it have to be a small compiler? Does it have to generate fast code? Portability Should the compiler run on many different architectures (rehostability) Should the compiler generate code for many different architectures (retargetability)

Possible Workarounds Rewrite an existing front end when the source is new reuse back (code generation) end of the compiler Rewrite an existing back end when the target architecture is new retarget an existing compiler to a new architecture What happens when both the source language and target language are new? Write a compiler from scratch? Do we have other options?

Composing Compilers Java JVM Java JVM C C i386 i386 i386 Java JVM Java Compilers can be composed and used to compile each other Example: We have written a Java to JVM compiler in C and we want to make it to run on two different platforms i386 and x86_64 both platforms have C compilers Java JVM Java JVM C C i386 i386 i386 Java JVM Java JVM C C x64 i386 x64

Example PRM JVM PRM PRM JVM JVM Java Java JVM JVM JVM i386 JVM JVM' Assignment 3: Assignment 4: Java JVM JVM' Java PRM JVM fib.prm PRM PRM JVM JVM a.j Java Java JVM JVM JVM i386 JVM JVM' a.j JVM PRM JVM' JVM a.j' Java Java JVM JVM JVM i386

Example Show how to To take your PRM compiler and make it faster To take your Jasmin optimizer and make it faster PRM JVM Java PRM PRM' Java Java JVM i386

Bootstrapping by cross-compiling Sometimes the source and implementation language are the same E.g. A C compiler written in C In this case, cross compiling can be useful C 4 x64 C 5 x64 C 1 x64 C C 3 x64 x64 C C C 2 i386 i386 i386 i386 i386

Bootstrapping Cont'd Bootstrapping by reduced functionality Implement, in machine language, a simplified compiler A subset of the target language No optimizations Write a compiler for the full language in the reduced language C i386 C i386 C-- C-- i386 i386 asm

Bootstrapping for Self-Improvement If we are writing a good optimizing compiler with I=S then We can compile the compiler with itself We get a fast compiler gcc does this (several times) C gcc i386 C gcc i386 C gcc i386 C C gcc i386 i386 C C C cc i386 i386 i386 i386 i386

Summary When writing a compiler there are several techniques we can use to leverage existing technology Reusing front-ends or back ends Cross-compiling Starting from reduced instruction sets Self-compiling