Intermediate Code Generation

Size: px
Start display at page:

Download "Intermediate Code Generation"

Transcription

1 Intermediate Code Generation Basic Approach and Application to Assignment and xpressions Array xpressions Boolean xpressions Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission to make copies of these materials for their personal use.

2 Structure of a Compiler O(n) O(n) O(n log n) Scanner words Parser IR Analysis & Optimization IR Intermediate Code Generation O(n) IR regs Code Generation Very Fast or Very Hard NP Complete asm k regs A compiler is a lot of fast stuff followed by some hard problems The hard stuff is mostly in Code Generation and Optimization For super-scalars, its Allocation & Scheduling that counts

3 Intermediate Code Generation IR Parse tree AST Intermediate Code Generation O(n) IR Three-Address Instructions regs Direct Translation Using SDT scheme Parse Tree to Three-Address Instructions Can be done while Parsing in a Single Pass Needs to be able to deal with Syntactic rrors and Recovery Indirect Translation First valate parsing constructing of AST Uses SDT scheme to build AST Traverse the AST and generate Three Address Instructions This Lecture Same but asier

4 Three-Address Instructions IR High-level Constructs mapped to Three-Address Instructions Register-based IR for xpression valuation Infinite Number of Virtual Registers Still Independent of Target Architecture Parameter Passing Discipline either on Stack or via Registers Addresses and Instructions Symbolic Names are addresses of the corresponding source-level variable. Various constants, such as numeric and offsets (known at compile time) Generic Instruction Format: Label: x = y op z or if exp goto L Statements can have Symbolic Labels Compiler inserts Temporary Variables (any variable with t prefix) Type and Conversions dealt in other Phases of the Code Generation

5 Assignments: Three-Address Instructions x = y op z (binary operator) x = op y (unary) x = y (copy) x = y[i] and x[i] = y (array indexing assignments) x = phi y z (Static Single Assignment instruction) Memory Operations: x = &y; x = *y and *x = y; for assignments via pointer variables.

6 Three-Address Instructions Control Transfer and Function Calls: goto L (unconditional); if (a relop b) goto L (conditional) where relop is a relational operator consistent with the type of the variables a and b; y = call p, n for a function or procedure call instruction to the name or variable p p might be a variable holding a set of possible symbolic names (a function pointer) the value n specifies that before this call there were n putparam instructions to load the values of the arguments. the param x instruction specifies a specific value in reverse order (i.e, the param instruction closest to the call is the first argument value. Later we will talk about parameter passing disciplines (Run-Time nv.)

7 Function Call xample Source Code Three Address Instructions y = p(a, b+1) int p(x,z){ return x+z; } t1 = a t2 = b + 1 putparam t1 putparam t2 y = call p, 2 p: getparam z getparam x t3 = x + z return t3 return

8 Function Call xample Source Code Three Address Instructions y = p(a, b+1) int p(x,z){ return x+z; } argument evaluation passing args on the stack getting values from the stack t1 = a t2 = b + 1 putparam t1 putparam t2 y = call p, 2 p: getparam z getparam x t3 = x + z return t3 return

9 Loop xample Source Code do i = i + 1; while (a[i] < v); Three Address Instructions L: t1 = i + 1 i = t1 t2 = i * 8 t3 = a[t2] if t3 < v goto L

10 Loop xample Source Code do i = i + 1; while (a[i] < v); Three Address Instructions L: t1 = i + 1 i = t1 t2 = i * 8 t3 = a[t2] if t3 < v goto L Where d this come from?

11 SDT for Three Address Code Generation Attributes for the Non-Terminals, and S Location (in terms of temporary variable) of the value of an expression:.place. If.place is t1 it means that the value of is saved in t1. The Code that valuates the xpressions or Statement:.code Markers for beginning and end of sections of the code S.begin, S.end For simplicity these are symbolic labels. Semantic Actions in Productions of the Grammar Functions to create temporaries newtemp, and labels newlabel Auxiliary functions to enter symbols and lookup types corresponding to declarations in a symbol table. To generate the code we use the function gen which creates a list of instructions to be emitted later and can generate symbolic labels corresponding to next instruction of a list. Use of append function on lists of instructions. Make use of Synthesized and Inherited Attributes

12 Assignment Statements S = { p = lookup(.name); if (p!= NULL){ S.code = gen(p =.place); } else } error; S.code = nulllist; } } {.place = newtemp();.code = append( 1.code, 2.code, gen(.place = 1.place + 2.place); } 1 * 2 {.place = newtemp();.code = append( 1.code, 2.code, gen(.place = 1.place * 2.place); } - 1 {.place = newtemp();.code = append( 1.code,gen(.place = - 1.place)); } ( 1 ) {.place = 1.place;.code = 1.code; } { p = lookup(.name); if (p!= NULL).place = p; else error;.code = nulllist; }

13 Assignment: xample x = a * b + c * d - e * f; S = + x * - * * a b c d e f

14 Assignment: xample x = a * b + c * d - e * f; S = + Production: { p = lookup(.name); if (p!= NULL).place = p; else error;.code = null list; } x * - * * a b c d e f

15 Assignment: xample x = a * b + c * d - e * f; S = + Production: { p = lookup(.name); if (p!= NULL).place = p; else error;.code = null list; } x * - * * place = loc(e) code = null place = loc(f) code = null a b c d e f

16 Assignment: xample x = a * b + c * d - e * f; S Production: 1 * 2 {.place = newtemp();.code = gen(.place = 1.place * 2.place);} = + x * - place = loc(t1) code = {t1 = e * f;} * * place = loc(e) code = null place = loc(f) code = null a b c d e f

17 Assignment: xample x = a * b + c * d - e * f; S Production: 1 * 2 {.place = newtemp();.code = gen(.place = 1.place * 2.place);} = + x * place = loc(t2) - code = {t2 = c + d;} place = loc(t1) code = {t1 = e * f;} * place = loc(c) code = null place = loc(d) code = null * place = loc(e) code = null place = loc(f) code = null a b c d e f

18 x = a * b + c * d - e * f; place = loc(x) S = code = null x a Assignment: xample * b + * Production: S = { p = lookup(.name); if (p!= NULL).code = append(.code, gen(p =.place)); code = {t1 = e * f; t2 = c * d; t3 = t2 - t1; t4 = a * b; t5 = t4 + t3; x = t5; } else error; place = loc(t5) } place = loc(a) code = null place = loc(t4) code = {t4 = a * b;} place = loc(b) code = null code = {t1 = e * f; t2 = c * d; t3 = t2 - t1; t4 = a * b; t5 = t4 + t3; } place = loc(c) code = null place = loc(t2) - code = {t2 = c + d;} place = loc(d) code = null place = loc(t3) code = {t1 = e * f; t2 = c * d; t3 = t2 - t1; } * place = loc(e) code = null place = loc(t1) code = {t1 = e + f;} place = loc(f) code = null c d e f

19 Assignment: xample x = a * b + c * d - e * f; S = + x * - t1 = e * f; t2 = c * d; t3 = t2 - t1; t4 = a * b; t5 = t4 + t3; x = t5; * * a b c d e f

20 Reusing Temporary Variables Temporary Variables Short lived Used for valuation of xpressions Clutter the Symbol Table Change the newtemp Function Keep track of when a value created in a temporary is used Use a counter to keep track of the number of active temporaries When a temporary is used in an expression decrement counter When a temporary is generated by newtemp increment counter Initialize counter to zero (0) Alternatively, can be done as a post-processing pass

21 Assignment: xample x = a * b + c * d - e * f; // c = 0 S t1 = e * f; // c = 1 t2 = c * d; // c = 2 = t1 = t2 - t1; // c = 1 x + * - t2 = a * b; // c = 2 t1 = t2 + t1; // c = 1 * * x = t1; // c = 0 a b c d e f Only 2 Temporary Variables and hence only 2 registers are Needed

22 Code Generation for Array Accesses x = A[y,z];; S L = Questions: What is the Base Type of A? What are the Dimensions of A? What is the layout of A? x L list ] Where to Get Answers? Use Symbol Table list, Check Array Layout A [ L L z? t1 = y * 20 t1 = t1 * z t2 = basea - 84 t3 = 4 * t1 t4 = t2[t3] y X = t4

23 How does the Compiler Handle A[i,j]? First, we must agree on a Storage Scheme or Layout Row-major order Lay out as a sequence of consecutive rows Rightmost subscript varies fastest A[1,1], A[1,2], A[1,3], A[2,1], A[2,2], A[2,3] Column-major order Lay out as a sequence of columns Leftmost subscript varies fastest A[1,1], A[2,1], A[1,2], A[2,2], A[1,3], A[2,3] Indirection vectors Vector of pointers to pointers to to values Takes much more space, trades indirection for arithmetic Not amenable to analysis (most languages) (Fortran) (Java)

24 The Concept A Row-major order 1,1 1,2 1,3 1,4 2,1 2,2 2,3 2,4 Laying Out Arrays These have distinct & different cache behavior A 1,1 1,2 1,3 1,4 2,1 2,2 2,3 2,4 Column-major order A 1,1 2,1 1,2 2,2 1,3 2,3 1,4 2,4 Indirection vectors 1,1 1,2 1,3 1,4 A 2,1 2,2 2,3 2,4

25 Accessing an Array lement How to access A[ i ]? Computing the Address of a 1-D Array lement: basea + ( i low ) x sizeof(basetype(a)) In General: base(a) + ( i low ) x sizeof(basetype(a))

26 Computing an Array Address Computing the Address of A[ i ]: Computing the Address of a 1-D Array lement: basea + ( i low ) x sizeof(basetype(a)) In General: base(a) + ( i low ) x sizeof(basetype(a)) Almost always a power of 2, known at compile-time and use a shift for speed Defined by the storage class of the array. int A[1:10] where low is 1; Make low 0 for faster access (saves a ) as in the C language

27 A[ i ] basea + ( i low ) x sizeof(basetype(a)) In general: base(a) + ( i low ) x sizeof(basetype(a)) What about A[i 1,i 2 ]? Computing an Array Address Row-major order, two dimensions basea + (( i 1 low 1 ) x (high 2 low 2 + 1) + i 2 low 2 ) x sizeof(basetype(a)) Column-major order, two dimensions basea + (( i 2 low 2 ) x (high 1 low 1 + 1) + i 1 low 1 ) x sizeof(basetype(a)) Indirection vectors, two dimensions *(A[i 1 ])[i 2 ] where A[i 1 ] is, itself, a 1-d array reference This stuff looks expensive! Lots of implicit +, -, x ops

28 Optimizing Address Calculation for A[i,j] In row-major order where w = sizeof(basetype(a)) basea + (i low 1 )(high 2 low 2 +1) x w + (j low 2 ) x w Which can be factored into basea + i x (high 2 low 2 +1) x w + j x w (low 1 x (high 2 low 2 +1) x w) + (low 2 x w) If low i, high i, and w are known, the last term is a constant Define basea 0 as basea (low 1 x (high 2 low 2 +1)) x w + low 2 x w and len 2 as (high 2 -low 2 +1) Then, the address expression becomes basea 0 + (i x len 2 + j ) x w Compile-time constants

29 Address Calculation for A[i 1,i 2,,i k ] A[i 1,i 2,,i k ] Addressing generalizes to (( ((i 1 n 2 +i 2 )n 3 +i 3 ) )n k +i k ) x w + +basea - (( ((low 1 n 2 +low 2 )n 3 +low 3 ) )m k +low k ) x w where n j = high j - low j + 1 and w = sizeof(basetype(a)) First term can be computed using the recurrence e 1 = i 1 e m = e m-1 x n m + i m at the end multiply by w and add compile-time constant term Compile-time constants

30 SDT for Addressing Arrays lements Three Attributes place: just the name or base address of the array offset: the index value into the array ndim: the number of dimensions Use the Recurrence to Compute Offset offset 1 = i 1 offset m = offset m-1 x n m + i m At the end multiply by w = sizeof(basetype(a)) Add the compile-time constant term Keep track of which dimension at each level Use the auxiliary function n m = numlem(a,m) as the number of elements along the m th dimension of A

31 SDT for Addressing Arrays lements L list ] { L.place = newtemp(); L.offset = newtemp(); code1 = gen(l.place = constterm(list.array)); code2 = gen(l.offset = list.place * sizeof(basetype(list.array))); L.code = append(list.code,code1,code2); } list list 1, { t = newtemp(); m = list 1.ndim + 1; x = A[y,z]; code1 = gen(t = list 1.place * numlem(list 1.array,m)); code2 = gen(t = t +.place); list.array = list 1.array; list.place = t; list.ndim = m; list.code = append(list 1.code,.code,code1,code2); } S L = x list list, A [ L L L z ] list [ { list.array =.place; list.place =.place; list.ndim = 1; List.code =.code; } y

32 SDT for Addressing Arrays lements L { if (L.offset = NULL) then.place = L.place; else.place = newtemp;.code = gen(.place = L.place[L.offset]); } S L = } { if L.offset = NULL then.code = gen(l.place =.place); else S.code = append(.code,gen(l.place[l.offset] =.place); L { L.place =.place; } L.offset = null;

33 SDT for Addressing Arrays lements x = A[y,z]; S A is 10 x 20 array with low 1 = low 2 = 1 sizeof(basetype(a)) = sizeof(int) = 4 bytes L = x list L ] list, A [ L L z y

34 SDT for Addressing Arrays lements x = A[y,z]; S A is 10 x 20 array with low 1 = low 2 = 1 sizeof(basetype(a)) = sizeof(int) = 4 bytes L.place = x L.offset = null =.place = t4 L.place = t2 x list.place = t1 list.ndim = 2 list.array = A L.offset = t3 ] t1 = y * 20 // numlem(a,2) = 20 t1 = t1 + z //.place is z A [ list.place = y list.ndim = 1 list.array = A.place = y,.place = z L.place = z L.offset = null t2 = c // c = base(a) - (20+1)*4 t3 = t1 * 4 // sizeof(int) = 4 t4 = t2[t3] L.place = y L.offset = null z x = t4 y

35 Array References What about Arrays as Actual Parameters? Whole arrays, as call-by-reference parameters Need dimension information build a dope vector Store the values in the calling sequence Pass the address of the dope vector in the parameter slot Generate complete address at each reference Some improvement is possible Save len i and low i rather than low i and high i Pre-compute the fixed terms in prologue sequence basea low 1 high 1 low 2 high 2

36 Array References What about A[12] as an actual parameter? If corresponding parameter is a scalar, it s easy Pass the address or value, as needed Must know about both formal & actual parameter Language definition must force this interpretation What is corresponding parameter is an array? Must know about both formal & actual parameter Meaning must be well-defined and understood Cross-procedural checking of conformability

37 Array References What about Variable-Sized Arrays? Local arrays dimensioned by actual parameters Same set of problems as parameter arrays Requires dope vectors (or equivalent) dope vector at fixed offset in activation record Different access costs for textually similar references This presents a lot of opportunity for a good optimizer Common sub-expressions in the address Contents of dope vector are fixed during each activation Handle them like parameter arrays

38 Array Address Calculations in a Loop DO J = 1, N A[I,J] = A[I,J] + B[I,J] ND DO Naïve: Perform the address calculation twice DO J = 1, N R1 = basea 0 + (J x len 1 + I ) x floatsize R2 = baseb 0 + (J x len 1 + I ) x floatsize MM(R1) = MM(R1) + MM(R2) ND DO

39 Array Address Calculations in a Loop DO J = 1, N A[I,J] = A[I,J] + B[I,J] ND DO Sophisticated: Move common calculations out of loop R1 = I x floatsize c = len 1 x floatsize! Compile-time constant R2 = basea 0 + R1 R3 = baseb 0 + R1 DO J = 1, N a = J x c R4 = R2 + a R5 = R3 + a MM(R4) = MM(R4) + MM(R5) ND DO

40 Array Address Calculations in a Loop DO J = 1, N A[I,J] = A[I,J] + B[I,J] ND DO Very sophisticated: Convert multiply to add (Operator Strength Reduction) R1 = I x floatsize c = len 1 x floatsize! Compile-time constant R2 = basea 0 + R1 ; R3 = baseb 0 + R1 DO J = 1, N R2 = R2 + c R3 = R3 + c MM(R2) = MM(R2) + MM(R3) ND DO

41 SDT Scheme for Boolean xpressions Two Basic Code Generation Flavors Use boolean and, or and not instructions (like arithmetic). Control-flow (or positional code) defines true or false of predicate. Arithmetic valuation Simpler to generate code as just eagerly evaluate the expression. Associate 1 or 0 with outcome of predicates and combine with logic instructions. Use the same SDT scheme explained for arithmetic operations. Control Flow valuation (short circuit evaluation) More efficient in many cases. Complications: Need to Know Address to Jump To in Some Cases Solution: Two Additional Attributes nextstat (Inherited) Indicates the next symbolic location to be generated laststat (Synthesized) Indicates the last location filled As code is generated down and up the tree attributes are filled with the correct values

42 Arithmetic Scheme: Grammar and Actions false.place = newtemp().code = {gen(.place = 0)}.laststat =.nextstat + 1 true.place = newtemp().code = {gen(.place = 1)}.laststat =.nextstat + 1 ( 1 ).place = 1.place;.code = 1.code; 1.nextstat =.nextstat.laststat = 1.laststat not 1.place = newtemp().code = append( 1.code,gen(.place = not 1.place)) 1.nextstat =.nextstat.laststat = 1.laststat + 1

43 Arithmetic Scheme: Grammar and Actions 1 or 2.place = newtemp().code = append( 1.code, 2.code,gen(.place = 1.place or 2.place) 1.nextstat =.nexstat 2.nextstat = 1.laststat.laststat = 2.laststat and 2.place = newtemp() 2.place).code = append( 1.code, 2.code,gen(.place = 1.place and 1.nextstat =.nexstat 2.nextstat = 1.laststat.laststat = 2.laststat relop 2.place = newtemp().code = gen(if 1.place relop 2.place goto.nextstat+3).code = append(.code,gen(.place = 0)).code = append(.code,gen(goto.nextstat+2)).code = append(.code,gen(.place = 1)).laststat =.nextstat + 4

44 Boolean xpressions: xample a < b or c < d and e < f relop a < b or relop and relop c < d e < f 00: if a < b goto 03 01: t1 = 0 02: goto 04 03: t1 = 1 04: if c < d goto 07 05: t2 = 0 06: goto 08 07: t2 = 1 08: if e < f goto 11 09: t3 = 0 10: goto 12 11: t3 = 1 12: t4 = t2 and t3 13: t5 = t1 or t4

45 Summary Intermediate Code Generation Using Syntax-Directed Translation Schemes xpressions and Assignments Array xpressions and Array References Boolean xpressions (Arithmetic Scheme)

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Basic Approach and Application to Assignment and xpressions Array xpressions Boolean xpressions Copyright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in the

More information

Code Shape II Expressions & Assignment

Code Shape II Expressions & Assignment Code Shape II Expressions & Assignment Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make

More information

Intermediate Representations & Symbol Tables

Intermediate Representations & Symbol Tables Intermediate Representations & Symbol Tables Copyright 2014, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission

More information

(just another operator) Ambiguous scalars or aggregates go into memory

(just another operator) Ambiguous scalars or aggregates go into memory Handling Assignment (just another operator) lhs rhs Strategy Evaluate rhs to a value (an rvalue) Evaluate lhs to a location (an lvalue) > lvalue is a register move rhs > lvalue is an address store rhs

More information

& Simulator. Three-Address Instructions. Three-Address Instructions. Three-Address Instructions. Structure of an Assembly Program.

& Simulator. Three-Address Instructions. Three-Address Instructions. Three-Address Instructions. Structure of an Assembly Program. & Simulator Copyright 2011, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California (USC) have explicit permission to make copies of these

More information

Compiler Design. Code Shaping. Hwansoo Han

Compiler Design. Code Shaping. Hwansoo Han Compiler Design Code Shaping Hwansoo Han Code Shape Definition All those nebulous properties of the code that impact performance & code quality Includes code, approach for different constructs, cost, storage

More information

Generating Code for Assignment Statements back to work. Comp 412 COMP 412 FALL Chapters 4, 6 & 7 in EaC2e. source code. IR IR target.

Generating Code for Assignment Statements back to work. Comp 412 COMP 412 FALL Chapters 4, 6 & 7 in EaC2e. source code. IR IR target. COMP 412 FALL 2017 Generating Code for Assignment Statements back to work Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights

More information

CS2210: Compiler Construction. Code Generation

CS2210: Compiler Construction. Code Generation Modern Compiler Project Fortran program Fortran s Lexer, Parser, and Static Checker Intermediate Code Generator IR MIPS Code Generator MIPS code C program C s Lexer, Parser, and Static Checker Intermediate

More information

Principle of Compilers Lecture VIII: Intermediate Code Generation. Alessandro Artale

Principle of Compilers Lecture VIII: Intermediate Code Generation. Alessandro Artale Free University of Bolzano Principles of Compilers. Lecture VIII, 2003/2004 A.Artale (1 Principle of Compilers Lecture VIII: Intermediate Code Generation Alessandro Artale Faculty of Computer Science Free

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Rupesh Nasre. CS3300 Compiler Design IIT Madras Aug 2015 Character stream Lexical Analyzer Machine-Independent Code Optimizer F r o n t e n d Token stream Syntax Analyzer Syntax

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Intermediate codes are machine independent codes, but they are close to machine instructions The given program in a source language is converted to an equivalent program in

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Rupesh Nasre. CS3300 Compiler Design IIT Madras July 2018 Character stream Lexical Analyzer Machine-Independent Code Code Optimizer F r o n t e n d Token stream Syntax Analyzer

More information

Formal Languages and Compilers Lecture X Intermediate Code Generation

Formal Languages and Compilers Lecture X Intermediate Code Generation Formal Languages and Compilers Lecture X Intermediate Code Generation Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/

More information

Handling Assignment Comp 412

Handling Assignment Comp 412 COMP 412 FALL 2018 Handling Assignment Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Control-Flow tatements hort-circuit Predicate valuation Back-Patching Copyright 2011, Pedro C. Diniz, all rights reserved. tudents enrolled in the Compilers class at the University

More information

CMPSC 160 Translation of Programming Languages. Three-Address Code

CMPSC 160 Translation of Programming Languages. Three-Address Code CMPSC 160 Translation of Programming Languages Lectures 16: Code Generation: Three- Address Code Three-Address Code Each instruction can have at most three operands Each operand corresponds to a memory

More information

Arrays and Functions

Arrays and Functions COMP 506 Rice University Spring 2018 Arrays and Functions source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled

More information

Intermediate Code Generation Part II

Intermediate Code Generation Part II 1 Intermediate Code Generation Part II Chapter 6 (1 st ed Chapter 8) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009 2 Advanced Intermediate Code Generation

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Control-Flow tatements hort-circuit Predicate valuation Back-Patching Copyright 2015, Pedro C. Diniz, all rights reserved. tudents enrolled in the Compilers class at the University

More information

Module 27 Switch-case statements and Run-time storage management

Module 27 Switch-case statements and Run-time storage management Module 27 Switch-case statements and Run-time storage management In this module we will discuss the pending constructs in generating three-address code namely switch-case statements. We will also discuss

More information

CSCI Compiler Design

CSCI Compiler Design University of Southern California CSCI565 Compiler Design Mterm Exam Solution - Spring 2014 CSCI 565 - Compiler Design Spring 2014 Mterm Exam - Solution Problem 1: Context-Free-Grammars and Parsing Algorithms

More information

CSCI565 Compiler Design

CSCI565 Compiler Design CSCI565 Compiler Design Fall 2015 Homework 2 - Solution Problem 1: Attributive Grammar and Syntax-Directed Translation [30 points] In this problem you ned to develop a grammar for array variable expressions

More information

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Language Processing Systems Prof. Mohamed Hamada Software ngineering Lab. The University of Aizu Japan Intermediate/Code Generation Source language Scanner (lexical analysis) tokens Parser (syntax analysis)

More information

UNIT-3. (if we were doing an infix to postfix translator) Figure: conceptual view of syntax directed translation.

UNIT-3. (if we were doing an infix to postfix translator) Figure: conceptual view of syntax directed translation. UNIT-3 SYNTAX-DIRECTED TRANSLATION: A Grammar symbols are associated with attributes to associate information with the programming language constructs that they represent. Values of these attributes are

More information

CMPT 379 Compilers. Anoop Sarkar. 11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC

CMPT 379 Compilers. Anoop Sarkar.  11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC CMPT 379 Compilers Anoop Sarkar http://www.cs.sfu.ca/~anoop 11/13/07 1 TAC: Intermediate Representation Language Specific Language + Machine Independent Machine Dependent Front End AST Intermediate Code

More information

CSc 453 Intermediate Code Generation

CSc 453 Intermediate Code Generation CSc 453 Intermediate Code Generation Saumya Debray The University of Arizona Tucson Overview Intermediate representations span the gap between the source and target languages: closer to target language;

More information

TACi: Three-Address Code Interpreter (version 1.0)

TACi: Three-Address Code Interpreter (version 1.0) TACi: Three-Address Code Interpreter (version 1.0) David Sinclair September 23, 2018 1 Introduction TACi is an interpreter for Three-Address Code, the common intermediate representation (IR) used in compilers.

More information

Alternatives for semantic processing

Alternatives for semantic processing Semantic Processing Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies

More information

Acknowledgement. CS Compiler Design. Intermediate representations. Intermediate representations. Semantic Analysis - IR Generation

Acknowledgement. CS Compiler Design. Intermediate representations. Intermediate representations. Semantic Analysis - IR Generation Acknowledgement CS3300 - Compiler Design Semantic Analysis - IR Generation V. Krishna Nandivada IIT Madras Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation 1 Intermediate Code Generation Translating source program into an intermediate language" Simple CPU Independent, yet, close in spirit to machine language Benefits Retargeting

More information

Intermediate Representa.on

Intermediate Representa.on IR Intermediate Representa.on CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class Intermediate Representation Language Specific Language + Machine Independent Machine Dependent

More information

CS415 Compilers. Intermediate Represeation & Code Generation

CS415 Compilers. Intermediate Represeation & Code Generation CS415 Compilers Intermediate Represeation & Code Generation These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Review - Types of Intermediate Representations

More information

CS 432 Fall Mike Lam, Professor. Code Generation

CS 432 Fall Mike Lam, Professor. Code Generation CS 432 Fall 2015 Mike Lam, Professor Code Generation Compilers "Back end" Source code Tokens Syntax tree Machine code char data[20]; int main() { float x = 42.0; return 7; } 7f 45 4c 46 01 01 01 00 00

More information

THEORY OF COMPILATION

THEORY OF COMPILATION Lecture 09 IR (ackpatching) THEORY OF COMPILATION Eran Yahav www.cs.technion.ac.il/~yahave/tocs2011/compilers-lec09.pptx Reference: Dragon 6.2,6.3,6.4,6.6 1 Recap Lexical analysis regular expressions identify

More information

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Intermediate representations and code generation Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Today Intermediate representations and code generation Scanner Parser Semantic

More information

Principles of Compiler Design

Principles of Compiler Design Principles of Compiler Design Intermediate Representation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Unambiguous Program representation

More information

Intermediate Representations

Intermediate Representations Intermediate Representations Intermediate Representations (EaC Chaper 5) Source Code Front End IR Middle End IR Back End Target Code Front end - produces an intermediate representation (IR) Middle end

More information

UNIT IV INTERMEDIATE CODE GENERATION

UNIT IV INTERMEDIATE CODE GENERATION UNIT IV INTERMEDIATE CODE GENERATION 2 Marks 1. Draw syntax tree for the expression a=b*-c+b*-c 2. Explain postfix notation. It is the linearized representation of syntax tree.it is a list of nodes of

More information

Front End. Hwansoo Han

Front End. Hwansoo Han Front nd Hwansoo Han Traditional Two-pass Compiler Source code Front nd IR Back nd Machine code rrors High level functions Recognize legal program, generate correct code (OS & linker can accept) Manage

More information

Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit

Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies

More information

Time : 1 Hour Max Marks : 30

Time : 1 Hour Max Marks : 30 Total No. of Questions : 6 P4890 B.E/ Insem.- 74 B.E ( Computer Engg) PRINCIPLES OF MODERN COMPILER DESIGN (2012 Pattern) (Semester I) Time : 1 Hour Max Marks : 30 Q.1 a) Explain need of symbol table with

More information

Intermediate Representations

Intermediate Representations Intermediate Representations A variety of intermediate representations are used in compilers Most common intermediate representations are: Abstract Syntax Tree Directed Acyclic Graph (DAG) Three-Address

More information

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design PSD3A Principles of Compiler Design Unit : I-V 1 UNIT I - SYLLABUS Compiler Assembler Language Processing System Phases of Compiler Lexical Analyser Finite Automata NFA DFA Compiler Tools 2 Compiler -

More information

CSCI565 Compiler Design

CSCI565 Compiler Design CSCI565 Compiler Design Spring 2015 Homework 2 - Solution Problem 1: Attributive Grammar and Syntax-Directed Translation [25 points] Conser the grammar fragment below. It allows for the declaration of

More information

Chapter 6 Intermediate Code Generation

Chapter 6 Intermediate Code Generation Chapter 6 Intermediate Code Generation Outline Variants of Syntax Trees Three-address code Types and declarations Translation of expressions Type checking Control flow Backpatching Introduction Intermediate

More information

NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY Page 1

NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY Page 1 SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT III INTERMEDIATE CODE GENERATION PART A 1. What are the benefits of intermediate code generation? (A.U May 2008) A Compiler for different

More information

Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known.

Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known. SEMANTIC ANALYSIS: Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known. Parsing only verifies that the program consists of tokens

More information

Dixita Kagathara Page 1

Dixita Kagathara Page 1 2014 Sem-VII Intermediate Code Generation 1) What is intermediate code? Intermediate code is: The output of the parser and the input to the Code Generator. Relatively machine-independent: allows the compiler

More information

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres dgriol@inf.uc3m.es Compiler Architecture Source language Scanner (lexical analysis) tokens Parser (syntax

More information

COMP 181. Prelude. Intermediate representations. Today. High-level IR. Types of IRs. Intermediate representations and code generation

COMP 181. Prelude. Intermediate representations. Today. High-level IR. Types of IRs. Intermediate representations and code generation Prelude COMP 181 Lecture 14 Intermediate representations and code generation October 19, 2006 Who is Seth Lloyd? Professor of mechanical engineering at MIT, pioneer in quantum computing Article in Nature:

More information

Concepts Introduced in Chapter 6

Concepts Introduced in Chapter 6 Concepts Introduced in Chapter 6 types of intermediate code representations translation of declarations arithmetic expressions boolean expressions flow-of-control statements backpatching EECS 665 Compiler

More information

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview COMP 181 Compilers Lecture 2 Overview September 7, 2006 Administrative Book? Hopefully: Compilers by Aho, Lam, Sethi, Ullman Mailing list Handouts? Programming assignments For next time, write a hello,

More information

Three-address code (TAC) TDT4205 Lecture 16

Three-address code (TAC) TDT4205 Lecture 16 1 Three-address code (TAC) TDT4205 Lecture 16 2 On our way toward the bottom We have a gap to bridge: Words Grammar Source program Semantics Program should do the same thing on all of these, but they re

More information

Syntax-Directed Translation

Syntax-Directed Translation Syntax-Directed Translation 1 Syntax-Directed Translation 2 Syntax-Directed Translation 3 Syntax-Directed Translation In a syntax-directed definition, each production A α is associated with a set of semantic

More information

Syntactic Directed Translation

Syntactic Directed Translation Syntactic Directed Translation Translation Schemes Copyright 2016, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission

More information

Syntactic Directed Translation

Syntactic Directed Translation Syntactic Directed Translation Attribute Grammars & Syntax-Directed Definitions Copyright 206, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern

More information

CS 406/534 Compiler Construction Instruction Scheduling beyond Basic Block and Code Generation

CS 406/534 Compiler Construction Instruction Scheduling beyond Basic Block and Code Generation CS 406/534 Compiler Construction Instruction Scheduling beyond Basic Block and Code Generation Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on

More information

Compilers and computer architecture: A realistic compiler to MIPS

Compilers and computer architecture: A realistic compiler to MIPS 1 / 1 Compilers and computer architecture: A realistic compiler to MIPS Martin Berger November 2017 Recall the function of compilers 2 / 1 3 / 1 Recall the structure of compilers Source program Lexical

More information

intermediate-code Generation

intermediate-code Generation intermediate-code Generation }sequence of intermediate representations source program High Level intermediate Representation Low Level intermediate Representation Target Code e.g. C programming language

More information

Semantic analysis and intermediate representations. Which methods / formalisms are used in the various phases during the analysis?

Semantic analysis and intermediate representations. Which methods / formalisms are used in the various phases during the analysis? Semantic analysis and intermediate representations Which methods / formalisms are used in the various phases during the analysis? The task of this phase is to check the "static semantics" and generate

More information

Semantic actions for declarations and expressions

Semantic actions for declarations and expressions Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

CSE 504: Compiler Design. Runtime Environments

CSE 504: Compiler Design. Runtime Environments Runtime Environments Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Procedure Abstractions Mechanisms to manage procedures and procedure calls from compiler s perspective Runtime Environment Choices

More information

COMPILER CONSTRUCTION (Intermediate Code: three address, control flow)

COMPILER CONSTRUCTION (Intermediate Code: three address, control flow) COMPILER CONSTRUCTION (Intermediate Code: three address, control flow) Prof. K R Chowdhary Email: kr.chowdhary@jietjodhpur.ac.in Campus Director, JIET, Jodhpur Thursday 18 th October, 2018 kr chowdhary

More information

CS 2210 Programming Project (Part IV)

CS 2210 Programming Project (Part IV) CS 2210 Programming Project (Part IV) April 25, 2018 Code Generation This project is intended to give you experience in writing a code generator as well as bring together the various issues of code generation

More information

Object Code (Machine Code) Dr. D. M. Akbar Hussain Department of Software Engineering & Media Technology. Three Address Code

Object Code (Machine Code) Dr. D. M. Akbar Hussain Department of Software Engineering & Media Technology. Three Address Code Code Generation Intermediate Code? Assembly Code Object Code (Machine Code) 1 Intermediate Code P-Code Three Address Code 2 Compiler Construction F6S 1 Intermediate Representation Abstract Syntax Tree

More information

Compiler Construction 2009/2010: Intermediate Representation

Compiler Construction 2009/2010: Intermediate Representation Compiler Construction 2009/2010: Intermediate Representation Annette Bieniusa November 24, 2009 Outline 1 Contexts 2 Canonical Trees Using Expressions in different Contexts Compare the translation for

More information

Control Structures. Boolean Expressions. CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV

Control Structures. Boolean Expressions. CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV CSc 453 Compilers and Systems Software 16 : Intermediate Code IV Control Structures Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Control Structures

More information

Concepts Introduced in Chapter 6

Concepts Introduced in Chapter 6 Concepts Introduced in Chapter 6 types of intermediate code representations translation of declarations arithmetic expressions boolean expressions flow-of-control statements backpatching EECS 665 Compiler

More information

Static Checking and Intermediate Code Generation Pat Morin COMP 3002

Static Checking and Intermediate Code Generation Pat Morin COMP 3002 Static Checking and Intermediate Code Generation Pat Morin COMP 3002 Static Checking and Intermediate Code Generation Parser Static Checker Intermediate Code Generator Intermediate Code Generator Parse

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Front-end intermediate code generation source program Lexical Analyzer Syntax Analyzer Semantic Analyzer Int. Code Generator intermediate representation Symbol Table Advantages

More information

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev Fall 2015-2016 Compiler Principles Lecture 6: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation

More information

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree.

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree. Group B Assignment 9 Att (2) Perm(3) Oral(5) Total(10) Sign Title of Assignment: Code generation using DAG. 9.1.1 Problem Definition: Code generation using DAG / labeled tree. 9.1.2 Perquisite: Lex, Yacc,

More information

Computing Inside The Parser Syntax-Directed Translation. Comp 412 COMP 412 FALL Chapter 4 in EaC2e. source code. IR IR target.

Computing Inside The Parser Syntax-Directed Translation. Comp 412 COMP 412 FALL Chapter 4 in EaC2e. source code. IR IR target. COMP 412 FALL 2017 Computing Inside The Parser Syntax-Directed Translation Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights

More information

CSE 504: Compiler Design. Intermediate Representations Symbol Table

CSE 504: Compiler Design. Intermediate Representations Symbol Table Intermediate Representations Symbol Table Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Intermediate Representations Graphical IRs Linear IRs Symbol Table Information in a Program Compiler manages

More information

Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction

Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction Procedure Abstraction Run Time Environment Records Procedure Linkage Name Translation and Variable Access Copyright 2010, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at

More information

Overview of a Compiler

Overview of a Compiler High-level View of a Compiler Overview of a Compiler Compiler Copyright 2010, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have

More information

CSc 453. Code Generation I Christian Collberg. Compiler Phases. Code Generation Issues. Slide Compilers and Systems Software.

CSc 453. Code Generation I Christian Collberg. Compiler Phases. Code Generation Issues. Slide Compilers and Systems Software. Slide 16 2 Lexing, Parsing Semantic Analysis, Intermediate Code Generation Peephole Optimization Assembly Code Assembler Machine Code Register Allocation Intermediate Code Selection Scheduling Register

More information

LECTURE 3. Compiler Phases

LECTURE 3. Compiler Phases LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent

More information

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev Fall 2016-2017 Compiler Principles Lecture 5: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

Introduction. CSc 453. Compilers and Systems Software. 19 : Code Generation I. Department of Computer Science University of Arizona.

Introduction. CSc 453. Compilers and Systems Software. 19 : Code Generation I. Department of Computer Science University of Arizona. CSc 453 Compilers and Systems Software 19 : Code Generation I Introduction Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Compiler Phases Optimize

More information

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem: Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd

More information

Semantic actions for declarations and expressions

Semantic actions for declarations and expressions Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

The Processor Memory Hierarchy

The Processor Memory Hierarchy Corrected COMP 506 Rice University Spring 2018 The Processor Memory Hierarchy source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved.

More information

CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV. Department of Computer Science University of Arizona

CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV. Department of Computer Science University of Arizona CSc 453 Compilers and Systems Software 16 : Intermediate Code IV Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Control Structures Control Structures

More information

Compilers. Lecture 2 Overview. (original slides by Sam

Compilers. Lecture 2 Overview. (original slides by Sam Compilers Lecture 2 Overview Yannis Smaragdakis, U. Athens Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Last time The compilation problem Source language High-level abstractions Easy

More information

Semantic actions for declarations and expressions. Monday, September 28, 15

Semantic actions for declarations and expressions. Monday, September 28, 15 Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

Intermediate Representation (IR)

Intermediate Representation (IR) Intermediate Representation (IR) Components and Design Goals for an IR IR encodes all knowledge the compiler has derived about source program. Simple compiler structure source code More typical compiler

More information

Intermediate Representations

Intermediate Representations COMP 506 Rice University Spring 2018 Intermediate Representations source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

Undergraduate Compilers in a Day

Undergraduate Compilers in a Day Question of the Day Backpatching o.foo(); In Java, the address of foo() is often not known until runtime (due to dynamic class loading), so the method call requires a table lookup. After the first execution

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

CSc 453. Compilers and Systems Software. 13 : Intermediate Code I. Department of Computer Science University of Arizona

CSc 453. Compilers and Systems Software. 13 : Intermediate Code I. Department of Computer Science University of Arizona CSc 453 Compilers and Systems Software 13 : Intermediate Code I Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Introduction Compiler Phases

More information

Intermediate Representations

Intermediate Representations Compiler Design 1 Intermediate Representations Compiler Design 2 Front End & Back End The portion of the compiler that does scanning, parsing and static semantic analysis is called the front-end. The translation

More information

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

More information

Module 25 Control Flow statements and Boolean Expressions

Module 25 Control Flow statements and Boolean Expressions Module 25 Control Flow statements and Boolean Expressions In this module we learn to generate three address code for control flow statements. We will also try to incorporate short circuit information in

More information

Compiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code)

Compiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code) Compiler Theory (Intermediate Code Generation Abstract S yntax + 3 Address Code) 006 Why intermediate code? Details of the source language are confined to the frontend (analysis phase) of a compiler, while

More information

opt. front end produce an intermediate representation optimizer transforms the code in IR form into an back end transforms the code in IR form into

opt. front end produce an intermediate representation optimizer transforms the code in IR form into an back end transforms the code in IR form into Intermediate representations source code front end ir opt. ir back end target code front end produce an intermediate representation (IR) for the program. optimizer transforms the code in IR form into an

More information

Semantic Actions and 3-Address Code Generation

Semantic Actions and 3-Address Code Generation Compiler Design 1 Semantic Actions and 3-Address Code Generation Compiler Design 2 Introduction We start with different constructs of the given grammar (laboratory assignment-5) and discuss semantic actions

More information