Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands.

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Compiler construction in4020 – lecture 2 Koen Langendoen Delft University of Technology The Netherlands.
Intermediate Code Generation
Compilation (Semester A, 2013/14) Lecture 14: Compiling Object Oriented Programs Noam Rinetzky Slides credit: Mooly Sagiv 1.
Programming Languages and Paradigms
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
1 Compiler Construction Intermediate Code Generation.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Compilation (Semester A, 2013/14) Lecture 13: Assembler, Linker & Loader Noam Rinetzky Slides credit: Eli Bendersky, Mooly Sagiv & Sanjeev Setia.
Compiler construction in4020 – lecture 12 Koen Langendoen Delft University of Technology The Netherlands.
Compiling Object Oriented Programs Mooly Sagiv Chapter
From AST to Code Generation Professor Yihjia Tsai Tamkang University.
Chapter 9 Imperative and object-oriented languages 1.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3.
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Run time vs. Compile time
An introduction to systems programming
CS 536 Spring Code Generation II Lecture 21.
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
Compiler Summary Mooly Sagiv html://
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Assembler, Linker and OO Paradigm Professor Yihjia Tsai Tamkang University.
Compiler construction in4020 – lecture 11 Koen Langendoen Delft University of Technology The Netherlands.
CIS Computer Programming Logic
MIPS coding. SPIM Some links can be found such as:
Runtime Environments Compiler Construction Chapter 7.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Compiler Construction
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Topic 2d High-Level languages and Systems Software
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Compiler Construction Dr. Noam Rinetzky and Orr Tamir School of Computer Science Tel Aviv University
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
11/12/2015© Hal Perkins & UW CSEL-1 CSE P 501 – Compilers Code Shape II – Objects & Classes Hal Perkins Winter 2008.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
CSE 351 Final Exam Review 1. The final exam will be comprehensive, but more heavily weighted towards material after the midterm We will do a few problems.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Compilation Lecture 13: Course summary: Advanced Topics Noam Rinetzky 1.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
RealTimeSystems Lab Jong-Koo, Lim
©2004 Joel Jones 1 CS 403: Programming Languages Lecture 3 Fall 2004 Department of Computer Science University of Alabama Joel Jones.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Windows Programming Lecture 03. Pointers and Arrays.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 3 Translation.
Lecture 9 Symbol Table and Attributed Grammars
Principles of programming languages 10: Object oriented languages
Assemblers, linkers, loaders
Compiler Construction (CS-636)
System Programming and administration
Naming and Binding A computer system is merely a bunch of resources that are glued together with names Thus, much of system design is merely making choices.
Linking & Loading.
Compiler Design 18. Object Oriented Semantic Analysis (Symbol Tables, Type Checking) Kanat Bolazar March 30, 2010.
Procedural Programming
PZ09A - Activation records
The Assembly Language Level
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
An introduction to systems programming
Presentation transcript:

Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands

Summary of lecture 9 dependency graphs code generation for basic blocks [instruction selection: BURS] register allocation: graph coloring instruction ordering: ladder sequences annotated AST assembly code generator assembler object file linker executable library

Quiz 4.17 Show that there is always at least one available ladder sequence when linearizing the dependency graph.

Overview assemblers & linkers imperative and object-oriented programming context handling code generation annotated AST assembly code generator assembler object file linker executable library

Assemblers, linkers & loaders assembler symbolic object code  binary object file linker multiple objects (libraries)  executable loader load executable into memory assembly assembler object file linker executable library

Assemblers symbolic code  binary machine code handle addresses internal: resolve external: store in relocation table addl %edx, %ecx opcode addl reg-reg edxecx

Handling internal addresses two passes compute addresses generate object file one pass backpatch list.data.align 8 var1:.long text main: addl var1, %eax... jmp L1;... L1:

Handling external addresses relocation information entry points (text + data) unresolved references char fmt[] = “x=%d, y=%d\n"; int x = 11; extern int y; int main() { printf(fmt, x, y); return globj; } symboltypeaddress _fmtentry000000data _xentry00000cdata _yD ref00000ftext _mainentry000000text _printfT ref00001ftext

Source language data representation and handling basic types enumeration types set types record types union types array types pointer types object types routine types – map to target hardware – map to integers – map to bitset – field alignment field 1 field 2 int double – union tag? – descriptors + precomputation – check scope rules

Object types data representation features inheritance method overriding polymorphism dynamic binding (dependent) multiple inheritance

Object representation class A { public: int a1, a2; void m1(int i) { a1 = i; } void m2(int i) { a2 = a1 + i; } C++ object data a1 a2 m1_A m2_A method table

Object representation typedef struct { int a1, a2; } class_A; void m1_A(class_A *this, int i) { this->a1 = i; } void m2_A(class_A *this, int i) { this->a2 = this->a1 + i; } class A a;... a.m1(3); class_A a;... m1_A( &a, 3); C class A { public: int a1, a2; void m1(int i) { a1 = i; } void m2(int i) { a2 = a1 + i; } C++

Inheritance object data m1_A m2_A method table a1 a2 b1 m3_B class B : public A { public: int b1; void m3(void) { b1 = a1 + a2; }

Method overriding object data m1_A_A m2_A_B method table a1 a2 b1 m3_B_B class B : public A { public: int b1; void m3(void) { b1 = a1 + a2; } void m2(int i) { a2 = b1 + i; } declareddefined

Exercise (4 min.) abstract class Shape { boolean IsShape() {return true;} boolean IsRectangle() {return false;} boolean IsSquare() {return false;} abstract double SurfaceArea(); } class Rectangle extends Shape { double SurfaceArea {... } boolean IsRectangle() {return true;} } class Squrae extends Rectangle { boolean IsSquare() {return true;} } Give the method tables for Rectangle and Square

Answers

Method table for Rectangle IsShape_Shape_Shape IsRectangle_Shape_Rectangle IsSquare_Shape_Shape SurfaceArea_Shape_Rectangle Method table for Square IsShape_Shape_Shape IsRectangle_Shape_Rectangle IsSquare_Shape_Square SurfaceArea_Shape_Rectangle

Break

Polymorphism a pointer to class C may actually refer to an object of class C or any of its extensions implementation requires pointer supertyping class B *b =...; class A *a = b; class_B *b =...; class_A *a = convert_ptrB_to_ptrA(b); a1 a2 b1 ptr to B ptr to A inside B

Dynamic typing which method to invoke on overloaded polymorphic types? class B *b =...; class A *a = b; a->m2(3); m2_A_A(a, 3); static m2_A_B(a, 3); dynamic

Dynamic typing implementation: dispatch tables B-objectB-class ptr to B ptr to A inside B a1 a2 b1 m1_A_A m2_A_B m3_B_B *(a->dispatch_table[1])(a, 3); class B *b =...; class A *a = b; a->m2(3);

Dynamic typing implementation requires pointer subtyping void m2_A_B(class_A *this_A, int i) { class_B *this = convert_ptrA_to_ptrB(this_A); this->a2 = this->b1 + i; }

Multiple inheritance class C { public: int c1, c2; void m1() {...} void m2() {...} } class E : public C, D { public: int e1; void m2() {...} void m4() {...} void m5() {...} } class D { public: int d1; void m3() {...} void m4() {...} }

convert_ptrC_to_ptrE(c)  c convert_ptrD_to_ptrE(d)  d - sizeof(Class_C) convert_ptrC_to_ptrE(c)  c convert_ptrD_to_ptrE(d)  d - sizeof(Class_C) convert_ptrE_to_ptrC(e)  e convert_ptrE_to_ptrD(e)  e + sizeof(Class_C) convert_ptrE_to_ptrC(e)  e convert_ptrE_to_ptrD(e)  e + sizeof(Class_C) Multiple inheritance supertyping subtyping E-objectE-class ptr to E ptr to C inside E c1 c2 m1_C_C m2_C_E m3_D_D d1 e1 ptr to D inside E m4_D_E m5_E_E

Exercise (4 min.) given an object e of class E, give the compiled code for the calls e.m1() e.m3() e.m4()

Answers

e.m1() (*(e->dispatch_table[0]))((Class_C *) e) e.m3() (*(e->dispatch_table[2]))( (class_D *)((char *)e + sizeof(Class_C))) e.m4() (*(e->dispatch_table[3]))( (class_D *)((char *)e + sizeof(Class_C)))

Dependent multiple inheritance Does an object of class E contain 1 or 2 objects of class A? 1: dependent inheritance 2: independent inheritance class E: public C,D { public: int e1; void m2() {...} void m4() {...} void m5() {...} } class C: public A { public: int c1, c2; void m1() {...} void m2() {...} } class D: public A { public: int d1; void m3() {...} void m4() {...} } class A { public: int a1, a2; void m1() {...} void m3() {...} }

Dependent multiple inheritance E-objectE-class ptr to E ptr to C inside E a1 a2 m1_A_C m3_A_A m2_C_E c1 c2 ptr to D inside E m1_A_A m3_A_D d1 e field offsets m4_D_E m5_E_E

Summary assemblers & linkers object-oriented programming translation to C method tables annotated AST assembly code generator assembler object file linker executable library

Homework study sections: Array types assignment 2: make Asterix OO deadline June 4 08:59 print handout for next week [blackboard]