Assembler, Linker and OO Paradigm Professor Yihjia Tsai Tamkang University.

Slides:



Advertisements
Similar presentations
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Advertisements

Chapter 10 Linking and Loading. Separate assembly creates “.mob” files.
Chapter 11 Implementing an Assembler and a Linker Using C++ and Java.
Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
Compilation (Semester A, 2013/14) Lecture 14: Compiling Object Oriented Programs Noam Rinetzky Slides credit: Mooly Sagiv 1.
Programming Languages and Paradigms
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands.
1 Compiler Construction Intermediate Code Generation.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Linking & Loading CS-502 Operating Systems
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
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.
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code.
Compiling Object Oriented Programs Mooly Sagiv Chapter
Chapter 9 Imperative and object-oriented languages 1.
Lecture 13 – Compiling Object-Oriented Programs Eran Yahav 1 Reference: MCD
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
CS 536 Spring Code Generation II Lecture 21.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
Compiler Summary Mooly Sagiv html://
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Compiler construction in4020 – lecture 11 Koen Langendoen Delft University of Technology The Netherlands.
Compiling Object Oriented Programs Mooly Sagiv Chapter 6.2.9, 6.5.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
CIS Computer Programming Logic
MIPS coding. SPIM Some links can be found such as:
Programming Language C++ Xulong Peng CSC415 Programming Languages.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
Topic 2d High-Level languages and Systems Software
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.
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.
Compiling Objects in Class-Based Languages CS 153: Compilers.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Compilation /16a Lecture 10 Compiling Object-Oriented Programs Noam Rinetzky 1.
C++ for Java Programmers Chapter 2. Fundamental Daty Types Timothy Budd.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Compilation Lecture 13: Course summary: Advanced Topics Noam Rinetzky 1.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Advanced Programming Constants, Declarations, and Definitions Derived Data Types.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
©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.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Lecture 3 Translation.
Lecture 9 Symbol Table and Attributed Grammars
Principles of programming languages 10: Object oriented languages
Assemblers, linkers, loaders
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.
Loaders and Linkers: Features
The Assembly Language Level
Linking & Loading CS-502 Operating Systems
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
Presentation transcript:

Assembler, Linker and OO Paradigm Professor Yihjia Tsai Tamkang University

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

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