Intermediate Code Generation

Slides:



Advertisements
Similar presentations
Intermediate Code Generation
Advertisements

CSNB143 – Discrete Structure
Chapter Matrices Matrix Arithmetic
1 Compiler Construction Intermediate Code Generation.
Compiler Designs and Constructions
Passing Parameters. Different Techniques Pass by Value Pass by Reference Pass by Result Pass by Value-Result Pass by Name.
CSE 803 Using images in C++ Computing with images Applications & Methods 2D arrays in C++ Programming project 4.
1 Chapter 7: Runtime Environments. int * larger (int a, int b) { if (a > b) return &a; //wrong else return &b; //wrong } int * larger (int *a, int *b)
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Ada Declarations Declarations ID Offsets i, 0 j; 2 type r is record x, 0 y: integer; 2 end; arecord: r; 4 a1: array (1..10) of r 8 a2: array (4..6) of.
Building Java Programs Chapter 7.5
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
Chapter 4 – Matrix CSNB 143 Discrete Mathematical Structures.
Review: –What is an activation record? –What are the typical fields in an activation record? –What are the storage allocation strategies? Which program.
ITI 1120 Lab #9 Slides by: Diana Inkpen and Alan Williams.
ECE 103 Engineering Programming Chapter 23 Multi-Dimensional Arrays Herbert G. Mayer, PSU CS Status 6/24/2014 Initial content copied verbatim from ECE.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
CS 285- Discrete Mathematics Lecture 11. Section 3.8 Matrices Introduction Matrix Arithmetic Transposes and Power of Matrices Zero – One Matrices Boolean.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Umm Al-Qura University
CSE 504 Discrete Mathematics & Foundations of Computer Science
CSNB 143 Discrete Mathematical Structures
Sections 2.4 and 2.5 Matrix Operations
Properties and Applications of Matrices
Linear Algebra review (optional)
Lecture 8: 2D Arrays and Nested Loops
Two-Dimensional Arrays
Discrete Structures – CNS2300
Java Array Object Chuen-Liang Chen Department of Computer Science
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
C Tutorial (part 5) CS220, Spring 2012
Compiler Construction
Compiler Optimization and Code Generation
Pointers.
Intermediate Code Generation Part I
Intermediate Code Generation Part II
Chapter 6 Intermediate-Code Generation
Intermediate Code Generation Part II
Intermediate Code Generation Part I
Compilers B V Sai Aravind (11CS10008).
Matrices Elements, Adding and Subtracting
Multidimensional Arrays
Intermediate Code Generation Part II
Three-address code A more common representation is THREE-ADDRESS CODE . Three address code is close to assembly language, making machine code generation.
Section 2.4 Matrices.
Compiler Design 21. Intermediate Code Generation
Homework Assignment Suppose a 96x96 array S is distributed by blocks across four processors, so that each contains a 48x48 subarray. At each position S[i,j]
Matrices Introduction.
Intermediate Code Generation Part I
Dr Tripty Singh Arrays.
INC 161 , CPE 100 Computer Programming
Intermediate Code Generation Part II
L19. Two-Dimensional Arrays
Intermediate Code Generation
Runtime Environments What is in the memory?.
14.1 Vectors in Two Dimensions
Intermediate Code Generation Part II
Review: For array a[2,5], how would the memory for this array looks like using row major layout? What about column major layout? How to compute the address.
Intermediate Code Generation Part I
Compiler Design 21. Intermediate Code Generation
Arrays and Matrices Prof. Abdul Hameed.
Slides by: Diana Inkpen and Alan Williams
ENERGY 211 / CME 211 Lecture 11 October 15, 2008.
Applied Discrete Mathematics Week 4: Functions
Variable Storage Memory Locations (Logical) Variable Classes Stack
Arrays and Pointers.
CS Problem Solving and Object Oriented Programming Spring 2019
Chapter 6 - Arrays Outline Multiple-Subscripted Arrays.
Presentation transcript:

Intermediate Code Generation Part II Chapter 6

Addressing Array Elements In C and Java, A[i] i=0,1,…,n-1 … =A[i] =base+i*w; Where base is the relative address of the storage allocated for the array ,i.e.,base is the relative address of A[0] Two dimensions, base +i1 * w1 +i2 * w2 k dimensions, base +i1 * w1 +i2 * w2 +…+ik * wk

Addressing Array Elements In C and Java, int A[2][3]; BaseA A[0][0] A[0][0] A[0][1] A[1][0] A[0][2] A[0][1] A[1][0] A[1][1] A[1][1] A[0][2] A[1][2] A[1][2] Row-major Column-major

Translation of Array References S  id= E; {gen(top.get(id.lexeme)’=‘ E.addr } |L=E; {gen(L.array.base’[‘L.addr’]’’=‘ E.addr } E E1+ E2 { E.addr := new Temp(); gen (E.addr’=‘ E1.addr’+’ E2.addr);} |id {E.addr =top.get(id.lexeme);} |L {E.addr = new Temp(); gen (E.addr’=‘L.array.base’[’L.addr’]’);} L  id[E] {L.array=top.get(id.lexeme); L.type=L.array.type.elem; L.addr=new Temp(); gen(L.addr’=‘E.addr’*’L.type.width);} |L1[E] {L.array=L1.array; L.type=L1.type.elem; t=new Temp(); gen(t’=‘E.addr’*’L.type.width);} gen(L.addr’=‘L1.addr’+’t);}

Translation of Array References L.addr denotes a temporary that is used while computing the offset for the array reference by summing the terms ij * wj L.array is a pointer to the symbol-table entry for the array name. The base address of the array ,say ,L.array.base. L.type is the type of the subarray generated by L. For any type t, we assume that its width is given by t.width.

Translation of Array References Example 6.12, let a denote a 2*3 array of integers, and let c,i and j all denote integers. Then the type of a is array(2,array(3,integer)).Its width w is 24,assuming that the width of an integer is 4. the type of a[i] is array (3,integer),of width w1=12. the type of a[i][j] is integer. Three address code of c+a[i][j] is t1=i*12 t2=j*4 t3=t1+t2 t4=a[t3] t5=c+t4