Advanced Computer Systems

Slides:



Advertisements
Similar presentations
1 CIS 461 Compiler Design and Construction Fall 2014 Instructor: Hugh McGuire slides derived from Tevfik Bultan, Keith Cooper, and Linda Torczon Lecture-Module.
Advertisements

Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Compiler Construction by Muhammad Bilal Zafar (AP)
CPSC Compiler Tutorial 9 Review of Compiler.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
Chapter 1. Introduction.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
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 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
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.
Introduction to Compiling
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Chapter# 6 Code generation.  The final phase in our compiler model is the code generator.  It takes as input the intermediate representation(IR) produced.
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 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
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.
Dr. Mohamed Ramadan Saady 314ALL CH1.1 Chapter 1: Introduction to Compiling.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
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.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
DDC 2223 SYSTEM SOFTWARE DDC2223 SYSTEM SOFTWARE.
Compiler Design (40-414) Main Text Book:
Introduction Chapter : Introduction.
Visit for more Learning Resources
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
CSCI-235 Micro-Computer Applications
Compiler Construction (CS-636)
Introduction.
Chapter 1 Introduction.
-by Nisarg Vasavada (Compiled*)
课程名 编译原理 Compiling Techniques
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Compiler Construction
Introduction to Compiler Construction
Course supervisor: Lubna Siddiqui
Introduction CI612 Compiler Design CI612 Compiler Design.
Compiler Construction
Compiler 薛智文 TH 6 7 8, DTH Spring.
Introduction to Compiler Construction
CISC 7120X Programming Languages and Compilers
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 1 Introduction.
Chapter 10: Compilers and Language Translation
Compiler Construction
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Introduction Chapter : Introduction.
Introduction to Compiler Construction
Presentation transcript:

Advanced Computer Systems COMPILER DESIGN & IMPLEMENTATION 5th Computer at Modern Academy Dr. Osama Mohamed Mowafy

1. Compiler : Introduction Programming languages are notations for describing computations to people and to machines. The world as we know it depends on programming languages, because all the software running on all the computers was written in some programming language. But, before a program can be run, it first must be translated into a form in which it can be executed by a computer. The software systems that do this translation are called compilers. This course is about how to design and implement compilers. We shall discover that a few basic ideas can be used to construct translators for a wide variety of languages and machines. Besides compilers, the principles and techniques for compiler design are applicable to so many other domains that they are likely to be reused many times in the career of a computer scientist. The study of compiler writing touches upon programming languages, machine architecture, language theory, algorithms, and software engineering.

1. Compiler : Introduction Why Study Compilers? Central role of compilers in software development. Prime importance of compilers in determining performance. The microcosm of computer science found in compilers.

1. Compiler : Introduction Fundamentals of Compiling The compiler must preserve the meaning of the program. The compiler must improve the source code in some noticeable manner.

1. Compiler : Introduction Desirable Properties Correct output code Compile-time efficiency Better code (Optimized) Minimum Space Feedback Debugging

1. Compiler : Introduction Fundamentals of Compiling The compiler must preserve the meaning of the program. The compiler must improve the source code in some noticeable manner.

1.1 Language Processors Simply stated, a compiler is a program that can read a program in one language - the source language - and translate it into an equivalent program in another language - the target language; see Fig. 1.1. An important role of the compiler is to report any errors in the source program that it detects during the translation process. If the target program is an executable machine-language program, it can then be called by the user to process inputs and produce outputs; see Fig. 1.2. .

1.1 Language Processors An interpreter is another common kind of language processor. Instead of producing a target program as a translation, an interpreter appears to directly execute the operations specified in the source program on inputs supplied by the user, as shown in Fig. 1.3. The machine-language target program produced by a compiler is usually much faster than an interpreter at mapping inputs to outputs . An interpreter, however, can usually give better error diagnostics than a compiler, because it executes the source program statement by statement.

1.1 Language Processors Example 1.1 : Java language processors combine compilation and interpretation, as shown in Fig. 1.4. A Java source program may first be compiled into an intermediate form called bytecodes. The bytecodes are then interpreted by a virtual machine. A benefit of this arrangement is that bytecodes compiled on one machine can be interpreted on another machine, perhaps across a network. In order to achieve faster processing of inputs to outputs, some Java compilers, called just-in-time compilers, translate the bytecodes into machine language immediately before they run the intermediate program to process the input.

1.1 Language Processors In addition to a compiler, several other programs may be required to create an executable target program, as shown in Fig. 1.5. A source program may be divided into modules stored in separate files. The task of collecting the source program is sometimes entrusted to a separate program, called a preprocessor. The preprocessor may also expand shorthands, called macros, into source language statements. The modified source program is then fed to a compiler. The compiler may produce an assembly-language program as its output, because assembly language is easier to produce as output and is easier to debug. The assembly language is then processed by a program called an assembler that produces relocatable machine code as its output. Large programs are often compiled in pieces, so the relocatable machine code may have to be linked together with other relocatable object files and library files into the code that actually runs on the machine. The linker resolves external memory addresses, where the code in one file may refer to a location in another file. The loader then puts together all of the executable object files into memory for execution.

1.1 Language Processors 1.11 Exercises for Section 1.1 Exercise 1.1.1 : What is the difference between a compiler and an interpreter? Exercise 1.1.2 : What are the advantages of (a) a compiler over an interpreter (b) an interpreter over a compiler? Exercise 1.1.3 : What advantages are there to a language- processing system in which the compiler produces assembly language rather than machine language? Exercise 1.1.4 : A compiler that translates a high-level language into another high-level language is called a source-to-source translator. What advantages are there to using C as a target language for a compiler? Exercise 1.1.5 : Describe some of the tasks that an assembler needs to perform.

1.2 The Structure of a Compiler Up to this point we have treated a compiler as a single box that maps a source program into a semantically equivalent target program. If we open up this box a little, we see that there are two parts to this mapping: analysis and synthesis. The analysis part breaks up the source program into constituent pieces and imposes a grammatical structure on them. It then uses this structure to create an intermediate representation of the source program. If the analysis part detects that the source program is either syntactically ill formed or semantically unsound, then it must provide informative messages, so the user can take corrective action. The analysis part also collects information about the source program and stores it in a data structure called a symbol table, which is passed along with the intermediate representation to the synthesis part.

1.2 The Structure of a Compiler The synthesis part constructs the desired target program from the intermediate representation and the information in the symbol table. The analysis part is often called the front end of the compiler; the synthesis part is the back end. If we examine the compilation process in more detail, we see that it operates as a sequence of phases, each of which transforms one representation of the source program to another. A typical decomposition of a compiler into phases is shown in Fig. 1.6. In practice, several phases may be grouped together, and the intermediate representations between the grouped phases need not be constructed explicitly. The symbol table, which stores information about the entire source program, is used by all phases of the compiler.

1.2 The Structure of a Compiler Jobs for a Compiler… Determine whether input is a well constructed sentence in the language. Lexical analysis or Scanning Break the input into tokens (words) Syntax analysis or Parsing Analyze the phrase or sentence structure of the input Determine whether the program (input) has a well-defined meaning. Semantic or context-sensitive analysis Perform type checking, analyze the hierarchical structure of statements and report errors W W*2*X*Y*Z

1.2 The Structure of a Compiler Jobs for a Compiler… Improve the code. Optimization Improve some important aspect of the code, e.g., speed or size. W W*2*2 becomes W W*4 Generate an executable program. Code Generation Select the instructions to implement the transformed code on the target machine. Allocate program values to the limited set of registers. Order or schedule the selected instructions to minimize the execution time.

1.2 The Structure of a Compiler Simplified Modern Compiler Organization Modern Optimizing Compiler

1.2 The Structure of a Compiler

1.2 The Structure of a Compiler Lexical Analysis Determine the words (token) in the input. What are words in computer programs? How do we separate the input string into words? How does this facilitate compilation? Syntactic Analysis Determine the sentences in the input. What are sentences in computer programs? How do we group the words into sentences?

1.2 The Structure of a Compiler Intermediate Representations Represent the program in an easily transformable manner. Representation strongly tied to the algorithms trees ➫ recursion linear ➫ iteration How do IRs support compilation? Abstract Syntax Trees Form of intermediate representation. Tree basis for representing the essence of the computer program being translated. Form reflects the form of the program. Representation for each programming structure mimics the language.

1.2 The Structure of a Compiler Semantic Analysis Determine the meaning of the input. What are sentences in computer program supposed to do? Are all of the interactions valid? How does this support compilation? Code Generation Translate the internal representation into a form that can be executed by a machine. Optimization Improve the generated code in some measurable way (speed, size, …)