Modern Compiler Design

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Modern Compiler Design - Presentation Transcript

    1. Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University [email_address] http://www.cs.tau.ac.il/~gretay Modern Compiler Design T1 - Overview
    2. Who
      • Greta Yorsh
      • Schrieber Open-space
      • Tel: 640-5358
      • [email_address]
      • Wednesday 16:00-17:00
      • http://www.cs.tau.ac.il/~gretay
    3. What Semantic Representation Backend (synthesis) Compiler Frontend (analysis) Executable code exe Source text txt
    4. Say What? Semantic Representation Backend (synthesis) Compiler Frontend (analysis) Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Gen. Executable code exe Source text txt Cool Language txt Executable code exe
    5. How Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Gen. flex bison C++ Cool GC MIPS assembly SPIM Cool Language txt Executable code exe
    6. Project - a complete compiler
      • Cool to MIPS assembly language
      • Implemented in C++
      • Split into assignments
    7. Grading
      • 50% exam
      • 10% theoretical assignment
      • 40% project
        • 5 assignments – different weights
        • code checked both automatically and manually
      today exam teams PA1 PA2 TA1 PA3 PA4 PA5
    8. Project Guidelines
      • Teams of 3 students
        • email me before next practice
        • team account
      • In case of doubt – ask questions in the Forum
      • There is adequate time to complete assignments
      • Start early and please follow directions
      • Submit assignments on schedule
      • Goals:
        • Understand the scope of the project
        • How to write a Cool program
      Today Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Gen. Cool Language txt Executable code exe
    9. Cool Overview
      • Classroom Object Oriented Language
      • Implementation of modern
        • abstraction
        • static typing
        • reuse (inheritance)
        • memory management
        • and more…
    10. Good News
      • No arrays
      • No floating point operations
      • No “static” modifier
      • No interfaces
      • No method overloading (but still allow overriding)
      • No exceptions
      • No packages
    11. Better News
      • Cool language is still rich enough for doing interesting things
    12. A Simple Example
      • class Point {
      • x : Int  0;
      • y : Int  0;
      • };
      • Cool programs are sets of class definitions
      • class = a collection of attributes and methods
        • A special class Main with a special method main
        • No separate notion of subroutine
      • Instance of a class are objects
    13. Cool Objects
      • class Point {
      • x : Int  0;
      • y : Int ; (* use default value *)
      • };
      • The expression “new Point” creates a new object of class Point
      • An object can be thought of as a struct (record) with a slot for each attribute
      0 0 x y
    14. Methods
      • class Point {
      • x : Int  0;
      • y : Int  0;
      • movePoint (newx : Int, newy : Int) : Point {
      • { x  newx;
      • y  newy;
      • self;
      • } – close block expression
      • }; -- close method
      • }; -- close class
      • A class can also define methods for manipulating the attributes
      • Methods can refer to the current object using self
    15. Information Hiding in Cool
      • Methods are global (public)
      • Attributes are local to a class (private)
        • they can only be accessed by the class’s methods
      • Example
      • class Point {
      • getx () : Int { x };
      • setx (newx : Int) : Int { x  newx };
      • };
    16. Methods
      • Each object knows how to access the code of a method
      • As if the object contains a slot pointing to the node
      • In reality implementations save space by sharing these pointers among instances of the same class
      0 0 x y * movePoint methods 0 0 x y * movePoint
    17. Inheritance
      • We can extend points to colored points using subclass (class hierarchy)
      • class ColorPoint inherits Points {
      • color : Int  0;
      • movePoint(newx : Int, newy : Int) : Point {
      • { color  0;
      • x  newx; y  newy;
      • self;
      • }
      • };
      • };
      0 0 y color * movePoint 0 x
    18. Cool Types
      • Every class is a type
      • Base classes:
        • Int
        • Bool (true, false)
        • String
        • Object (root of the class hierarchy)
      • All variables must be declared
        • compiler infers types for expressions
    19. Cool Type Checking
      • x : A;
      • x  new B;
      • Is well typed if A is an ancestor of B in the class hierarchy
        • anywhere an A is expected a B can be used
      • Type safety
        • A well-typed program cannot result in runtype type errors
    20. Method Invocation and Ingeritance
      • Methods are invoked by dispatch
      • Understanding dispatch in the presence of inheritance is a subtle aspect of OO languages
      • p : Point ;
      • p  new ColorPoint;
      • p.movePoint(1,2);
        • p has static type Point
        • p has dynamic type ColorPoint
        • p.movePoint must invoke the ColorPoint version
    21. Method Invokation
      • Example: invoke one-argument method m
      • e.m(e’)
      • Eval e
      • Find class of e
      • Find code of m
      • Eval argument
      • Bind self and x
      • Run method
    22. Other Expressions
      • Expression language
        • every expression has a type and a value
        • Loops: while E loop E pool
        • Conditionals: if E then E else E fi
        • Case statement: case E of x: Type  E; esac
        • Arithmetic operations
        • Logical operations
        • Assignment x  E
    23. Cool Memory Management
      • Memory is allocated every time new is invoked
      • Memory is deallocated automatically when an object is not reachable anymore
        • done by the garbage collector (GC)
        • There is a Cool GC
    24. Cool Language - Main features
      • Object oriented
        • Objects, virtual method calls, but no overloading
      • Strongly typed
        • Primitives for int, boolean, string
        • Reference types
      • Dynamic allocation and Garbage Collection
        • Heap allocation, automatic deallocation
      • Many things are left out
        • short time implementation
      • Adapted with permission from Prof. Alex Aiken (Berkeley,Standford)

    + nextlibnextlib, 3 years ago

    custom

    1128 views, 1 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1128
      • 1128 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 56
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories