Figure 28.1 Position of the Code generator
|
|
- Cameron Austin
- 5 years ago
- Views:
Transcription
1 Module 28 Code Generator Introduction and Basic Blocks After discussing the various semantic rules necessary to convert every programming construct into three-address code, in this module, we will discuss the next phase of the compiler Code generation. We will start this module by understanding the issues in generating code. As a first step in code generation, we will discuss the concept of basic blocks and flow graphs 28.1 Code Generation Introduction The position of the code generation module is shown in figure As shown in figure 28.1, the front-end of the compiler delivers intermediate code as output after processing the lexical, syntactic and semantic phases. This intermediate code is used for code generation. The intermediate code could also be optimized and the optimized intermediate code could also be fed to the code generator. Figure 28.1 Position of the Code generator The following are the expectations of the code generator: Code produced by compiler must be correct The conversion from the source to the target language should preserve the semantics of the source program. Code produced by compiler should be of high quality The code generation algorithm should be aware of the instructions set of the target language. The code should be generated, by effectively using these target machine resources. Normally, heuristic techniques are used to generate good but suboptimal code, as optimal code generation is an undecidable problem Issues in the Code Generator The code generator needs to address so many issues before actually generating the code. The following are some of the issues and let us discuss each one of them in brief.
2 Input to the code generator: The code generator gets the three-address code as input. The format in which this three-address code is fed as input need to be decided. The following are some of the ways of feeding input to the code generator. Linear The input could be a string of characters where we use postfix notation to express the input. Tables As discussed in the previous modules, the three-address code is typically represented using Quadruples, Triples or Indirect triples and this table could be served as input Non-linear Abstract Syntax tree (AST) or Directed Acyclic Graph (DAG) could be used as input to the code generator after converting the input into AST or DAG representation In addition to the input, symbol table information need to be given to the code generator. The format in which symbol table needs to be available to the code generator needs to be decided. Target Program Code: The back-end code generator of a compiler may generate different forms of code, depending on the requirements. The target program code needs to be specified as assembly language or machine language. The following are some of the forms Absolute machine code This code is directly executable Relocatable machine code This is a relocatable machine language and is normally available as an object files Assembly language This is available in any assembly language which depends on the target machine and later an assembler converts this to machine language. Byte code forms for interpreters Java virtual machine has the write once and run anywhere concept where the output should be in Byte code. Target Machine: Implementing code generation requires thorough understanding of the target machine architecture and its instruction set. Consider a hypothetical machine with the following features: The instructions are byte-addressable where a word is 4 bytes Has n general purpose registers R0, R1,, Rn-1 Instructions are of Two-address, ones of the form op source, destination where op stands for op-codes.
3 For example MOV (move content of source to destination) ADD (add content of source to destination) SUB (subtract content of source from destination) It is also assumed that the hypothetical target Machine supports the addressing modes as given in Table 28.1 Table 28.1 Assumed addressing modes Mode Form Address Added Cost Explanation Absolute M M 1 Register R R 0 Indexed c(r) c+contents(r) 1 Indirect register *R contents(r) 0 Indirect indexed *c(r) contents(c+contents(r)) 1 Literal #c N/A 1 This is absolute addressing and involves one memory unit and incurs an additional cost of 1 Register based addressing and involves no cost Indexed addressing where the register holds the address to operate upon and is offset by a value c The contents of a register are looked upon to find the address of a location to operate upon Combination of indexed and indirect register Uses the value of the variable as part of the instruction Instruction Selection After understanding the types of addressing modes, the choice of an instruction depends on the cost effectiveness of the instruction. The target machine is a simple, non-super-scalar processor with fixed instruction costs. Realistic machines have deep pipelines, I-cache, D-cache, etc. The cost of an instruction is defined as : 1 + cost(source-mode) + cost(destination-mode)
4 To know the cost of source and destination mode, Table 28.1 is referred. Table 28.2 shows some example instructions and the cost associated with it. Table 28.2 Example instruction costs Instruction Operation Cost Cost computation MOV R0,R1 Store content(r0) into register R1 1 R0, R1 involves 0 cost and cost of 1 is incurred for MOV MOV R0,M Store content(r0) into memory location M 2 MOV costs 1 + one memory address in the instruction costs 1 thus totaling to 2 MOV M,R0 Store content(m) into register R0 2 MOV costs 1 + one memory address in the instruction costs 1 thus totaling to 2 MOV 4(R0),M MOV *4(R0),M Store contents(4+contents(r0)) into M Store contents(contents(4+contents(r0))) into M 3 4(R0) costs 1, memory costs 1 and MOV costs 1 thus totaling to a cost of 3 3 *4(R0) costs 1, memory costs 1 and MOV costs 1 thus totaling to a cost of 3 MOV #1,R0 Store 1 into R0 2 #1 costs 1, MOV costs 1 which totals to a cost of 2 ADD 4(R0),*12(R1) Add contents(4+contents(r0)) to contents(12+contents(r1)) 3 ADD costs 1, 4(R0) costs 1, *12(R1 costs 1 thus totaling to 3 Instruction Selection: Instruction selection is important to obtain efficient code. Suppose we need to translate the following three-address code x:=y+z The procedure is to move the value y into a register and add with that register the value z and store the result back in the variable x.
5 The following would be the instructions with a total cost of 6 (2+2+2): MOV y,r0 ADD z,r0 MOV R0,x Consider another instruction a:=a+1 and if we adopt the same strategy to convert this instruction to target code, the following would be the result with a cost of 6 (2+2+2) MOV a,r0 ADD #1,R0 MOV R0,a If we replace this with the following instruction, the cost would be 3 ( ) which is 1 each for ADD, #1, a ADD #1,a On the other hand, if this is replaced by the following instruction the cost would be 2 (1 for INC and 1 for a ) INC a Instruction Selection The choice of instructions also could change based on the addressing Modes Suppose we translate a:=b+c into MOV b,r0 ADD c,r0 MOV R0,a The cost of this would be 6 ( ) On the other hand, assuming addresses of a, b, and c are stored in R0, R1, and R2 MOV *R1,*R0 ADD *R2,*R0 The cost of this would be 2 (1 +1) which is just due to the MOV and ADD instructions Consider, R1 and R2 contain values of b and c ADD R2,R1 MOV R1,a Would incur a cost of 3 (1 + 2) for ADD, MOV.
6 Need for Global Code optimization This is the next issue in code generation. Consider the instruction and its corresponding three-address code as given in the table 28.3(a): Table 28.3 a Instruction and code Instruction Code x:=y+z MOVy,R0 ADD z,r0 MOV R0,x Consider the following sequence of instructions and supposing we use the same logic to translate, then we will end up in the table 28.3 (b). Table 28.3 (b) Sequence of Instructions and code Instruction a:=b+c d:=a+e Code MOVa,R0 ADD b,r0 MOV R0,a MOV a,r Redundant as R0 is used ADD e,r0 MOV R0,d As given in the Table 28.3 (b), register R0 already had the value of a according to the previous computation and hence this MOV instruction as indicated is redundant and this calls for Global code optimization. Register allocation and Assignment One of the important issues in code generation is register allocations. The number of registers in any architecture is limited to match the number of variable in a high-level program. Efficient utilization of the limited set of registers is important to generate good code. Registers are assigned by Register allocation to select the set of variables that will reside in registers at a point in the code Register assignment to pick the specific register that a variable will reside in However, finding an optimal register assignment in general is NP-complete. Consider the table 28.3 (c) that has the sequence of instructions and their corresponding three-address code.
7 Table 28.3 (c) Sequence of Instruction and code Instructions Code Inference t := a+b t := t * c t := t / d MOV a, R1 ADD b, R1 MUL c, R1 DIV d, R1 Only R1 is used for generating code t:=a*b t:=t+a t:=t/d MOV R1, t MOV a,r0 MOV R0,R1 MUL b,r1 ADD R0,R1 DIV d,r1 MOV R1,t Two registers are used for almost the same sequence of instructions Choice of Evaluation order When instructions are independent, their evaluation order can be changed to utilize registers and save on instruction cost. Consider the following instruction: a+b-(c+d)*e The three-address code, the corresponding code and its reordered instruction are given in Table 28.4 Table 28.4 Necessity for Reordering instruction Threeaddress code t1:=a+b t2:=c+d t3:=e*t2 t4:=t1-t3 Code MOV a,r0 ADD b,r0 MOV R0,t1 MOV c,r1 ADD d,r1 MOV e,r0 MUL R1,R0 MOV t1,r1 SUB R0,R1 MOV R1,t4 Reordered three-address code t2:=c+d t3:=e*t2 t1:=a+b t4:=t1-t3 Code MOV c,r0 ADD d,r0 MOV e,r1 MUL R0,R1 MOV a,r0 ADD b,r0 SUB R1,R0 MOV R0,t4 Inference The reordered instructions reduced the number of final code by 2 and thus saved in cost. The threeaddress code is reordered so that t1 is computed after computing t2 and t3. This reordering has saved in the instruction cost. The methodology to reorder instructions will be discussed in subsequent modules
8 28.3 Basic Blocks and Flowgraphs To handle all the issues in the code generation process, we need to construct basic blocks and flow graphs from the sequence of three-address code. Basic blocks are computation sequences and they form the node of a flow graph. Flow graph is a graphical representation of three-address code where nodes are the basic blocks and edges indicate the flow of control between basic blocks. The primary objective of flow graphs is code optimization include optimal register allocation. A flow graph is a graphical depiction of a sequence of instructions. A flow graph can be defined at the intermediate code level or target code level. Consider the following example at the final code level and the corresponding flow graph of Figure MOV 1,R0 MOV n,r1 JMP L2 L1: MUL 2,R0 SUB 1,R1 L2: JMPNZ R1,L1 Figure 28.2 flow graph From figure 28.2 there is an indication of arrow which indicates control flow. The flow of control can be in both directions. A basic block is a sequence of consecutive instructions with exactly one entry point and one exit point (with natural flow or a branch instruction). The same flow graph of figure 28.2 in grouped and the same is given in figure 28.3
9 Figure 28.3 Flow graph with basic blocks highlighted In a flow graph, suppose there is an edge from basic block B 1 to B 2 as B 1 B 2, then B 1 is a predecessor of B 2 and B 2 is a successor of B 1 In figure 28.3, we have grouped the statements into basic blocks 1, 2, 3 and the manner to do it is given algorithm 28.1 Algorithm 28.1 Basic block construction Input: A sequence of three-address statements Output: A list of basic blocks with each three-address statement in exactly one block 1. Determine the set of leaders, the first statements if basic blocks a) The first statement is the leader b) Any statement that is the target of a goto is a leader c) Any statement that immediately follows a goto is a leader 2. For each leader, its basic block consist of the leader and all statements up to but not including the next leader or the end of the program From algorithm 28.1, it is evident that the first step is to identify the set of leaders and group the statements between a pair of leaders into a basic block. An example of this is given in the next module
10 Summary: In this module, we understood the need for code generation and the various issues that need to be handled in code generation. Basic block and algorithm for basic block creation from three address / final code was discussed.
tokens parser 1. postfix notation, 2. graphical representation (such as syntax tree or dag), 3. three address code
Intermediate generation source program lexical analyzer tokens parser parse tree generation intermediate language The intermediate language can be one of the following: 1. postfix notation, 2. graphical
More informationPrinciples of Compiler Design
Principles of Compiler Design Code Generation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Intermediate Code Code Generation Target Program
More informationG Compiler Construction Lecture 12: Code Generation I. Mohamed Zahran (aka Z)
G22.2130-001 Compiler Construction Lecture 12: Code Generation I Mohamed Zahran (aka Z) mzahran@cs.nyu.edu semantically equivalent + symbol table Requirements Preserve semantic meaning of source program
More informationCODE GENERATION Monday, May 31, 2010
CODE GENERATION memory management returned value actual parameters commonly placed in registers (when possible) optional control link optional access link saved machine status local data temporaries A.R.
More informationCode Generation (#')! *+%,-,.)" !"#$%! &$' (#')! 20"3)% +"#3"0- /)$)"0%#"
Code Generation!"#$%! &$' 1$%)"-)',0%)! (#')! (#')! *+%,-,.)" 1$%)"-)',0%)! (#')! (#')! /)$)"0%#" 20"3)% +"#3"0- Memory Management returned value actual parameters commonly placed in registers (when possible)
More informationCSE 504: Compiler Design. Code Generation
Code Generation Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Introducing basic concepts in code generation phase Code Generation Detailed Steps The problem of generating an optimal target program
More informationGeneral issues. Section 9.1. Compiler Construction: Code Generation p. 1/18
General issues Section 9.1 Target language: absolute machine language all addresses refer to actual addresses program placed in a fixed location in memory relocatable machine language (object modules)
More informationGroup 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 informationIntermediate 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 informationUNIT 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 informationCompiler 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 informationPSD3A 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 informationCSE 401/M501 Compilers
CSE 401/M501 Compilers Intermediate Representations Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 G-1 Agenda Survey of Intermediate Representations Graphical Concrete/Abstract Syntax Trees (ASTs)
More informationVIVA QUESTIONS WITH ANSWERS
VIVA QUESTIONS WITH ANSWERS 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the
More informationThe analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.
COMPILER DESIGN 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the target
More informationOptimization. ASU Textbook Chapter 9. Tsan-sheng Hsu.
Optimization ASU Textbook Chapter 9 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Introduction For some compiler, the intermediate code is a pseudo code of a virtual machine.
More informationCSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1
CSE P 501 Compilers Intermediate Representations Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 G-1 Administrivia Semantics/types/symbol table project due ~2 weeks how goes it? Should be caught up on
More informationCompiler Architecture
Code Generation 1 Compiler Architecture Source language Scanner (lexical analysis) Tokens Parser (syntax analysis) Syntactic structure Semantic Analysis (IC generator) Intermediate Language Code Optimizer
More informationCompiler Optimization Techniques
Compiler Optimization Techniques Department of Computer Science, Faculty of ICT February 5, 2014 Introduction Code optimisations usually involve the replacement (transformation) of code from one sequence
More informationCopyright 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 informationIntermediate 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 informationCode Generation. CS 540 George Mason University
Code Generation CS 540 George Mason University Compiler Architecture Intermediate Language Intermediate Language Source language Scanner (lexical analysis) tokens Parser (syntax analysis) Syntactic structure
More information1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]
Code No: R05311201 Set No. 1 1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8] 2. Compute the FIRST and FOLLOW sets of each
More informationCS415 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 informationCOMPUTER ORGANIZATION & ARCHITECTURE
COMPUTER ORGANIZATION & ARCHITECTURE Instructions Sets Architecture Lesson 5a 1 What are Instruction Sets The complete collection of instructions that are understood by a CPU Can be considered as a functional
More informationIntermediate representation
Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing HIR semantic analysis HIR intermediate code gen.
More informationIntermediate 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 informationProf. 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 informationDixita 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 informationA Simple Syntax-Directed Translator
Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called
More informationNARESHKUMAR.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 informationCSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall
CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http://www.cse.buffalo.edu/faculty/alphonce/sp17/cse443/index.php https://piazza.com/class/iybn4ndqa1s3ei Announcements Be sure to
More informationChallenges in the back end. CS Compiler Design. Basic blocks. Compiler analysis
Challenges in the back end CS3300 - Compiler Design Basic Blocks and CFG V. Krishna Nandivada IIT Madras The input to the backend (What?). The target program instruction set, constraints, relocatable or
More informationUNIT-V. Symbol Table & Run-Time Environments Symbol Table
1 P a g e UNIT-V Symbol Table & Run-Time Environments Symbol Table Symbol table is a data structure used by compiler to keep track of semantics of variable. i.e. symbol table stores the information about
More informationArchitectures. Code Generation Issues III. Code Generation Issues II. Machine Architectures I
CSc 553 Principles of Compilation 7 : Code Generation I Introduction Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2011 Christian Collberg Lexing, Parsing Semantic
More informationTerminology & Basic Concepts
Terminology & Basic Concepts Language Processors The basic model of a language processor is the black box translator (or transducer) Has one input stream, one output stream, and a black box (program) that
More informationCSc 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 informationCode generation and optimization
Code generation and timization Generating assembly How do we convert from three-address code to assembly? Seems easy! But easy solutions may not be the best tion What we will cover: Peephole timizations
More informationLECTURE NOTES ON COMPILER DESIGN P a g e 2
LECTURE NOTES ON COMPILER DESIGN P a g e 1 (PCCS4305) COMPILER DESIGN KISHORE KUMAR SAHU SR. LECTURER, DEPARTMENT OF INFORMATION TECHNOLOGY ROLAND INSTITUTE OF TECHNOLOGY, BERHAMPUR LECTURE NOTES ON COMPILER
More informationVETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY
VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS6660 COMPILER DESIGN III year/ VI sem CSE (Regulation 2013) UNIT I -INTRODUCTION TO COMPILER PART A
More informationAcknowledgement. 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 informationIntermediate Representations Part II
Intermediate Representations Part II Types of Intermediate Representations Three major categories Structural Linear Hybrid Directed Acyclic Graph A directed acyclic graph (DAG) is an AST with a unique
More informationCode Generation. M.B.Chandak Lecture notes on Language Processing
Code Generation M.B.Chandak Lecture notes on Language Processing Code Generation It is final phase of compilation. Input from ICG and output in the form of machine code of target machine. Major issues
More informationComputer 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 informationDEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI UNIT I - LEXICAL ANALYSIS 1. What is the role of Lexical Analyzer? [NOV 2014] 2. Write
More informationMidterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 21, 2016
Name: Midterm 2 CMSC 430 Introduction to Compilers Fall 2016 November 21, 2016 Instructions This exam contains 7 pages, including this one. Make sure you have all the pages. Write your name on the top
More informationPESIT Bangalore South Campus
INTERNAL ASSESSMENT TEST I Date: 30/08/2017 Max Marks: 40 Subject & Code: Computer Organization 15CS34 Semester: III (A & B) Name of the faculty: Mrs.Sharmila Banu.A Time: 8.30 am 10.00 am Answer any FIVE
More informationLESSON 13: LANGUAGE TRANSLATION
LESSON 13: LANGUAGE TRANSLATION Objective Interpreters and Compilers. Language Translation Phases. Interpreters and Compilers A COMPILER is a program that translates a complete source program into machine
More informationIntermediate 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 information2.2 Syntax Definition
42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions
More informationCS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014
B CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014 DUE : March 3, 2014 READ : - Related sections of Chapter 2 - Related sections of Chapter 3 - Related sections of Appendix A - Related sections
More informationWhat Compilers Can and Cannot Do. Saman Amarasinghe Fall 2009
What Compilers Can and Cannot Do Saman Amarasinghe Fall 009 Optimization Continuum Many examples across the compilation pipeline Static Dynamic Program Compiler Linker Loader Runtime System Optimization
More informationSemantic 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 informationCA Compiler Construction
CA4003 - Compiler Construction David Sinclair Overview This module will cover the compilation process, reading and parsing a structured language, storing it in an appropriate data structure, analysing
More informationRui Wang, Assistant professor Dept. of Information and Communication Tongji University.
Instructions: ti Language of the Computer Rui Wang, Assistant professor Dept. of Information and Communication Tongji University it Email: ruiwang@tongji.edu.cn Computer Hierarchy Levels Language understood
More informationIntermediate Representations
Intermediate Representations Where In The Course Are We? Rest of the course: compiler writer needs to choose among alternatives Choices affect the quality of compiled code time to compile There may be
More informationCSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall
CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall Phases of a compiler Target machine code generation Figure 1.6, page 5 of text B1 i = 1 B2 j = 1 B3 t1 = 10 * i t2 = t1 + j t3 = 8
More informationVariables vs. Registers/Memory. Simple Approach. Register Allocation. Interference Graph. Register Allocation Algorithm CS412/CS413
Variables vs. Registers/Memory CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 33: Register Allocation 18 Apr 07 Difference between IR and assembly code: IR (and abstract assembly) manipulate
More informationCSc 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 informationUNIT-II. Part-2: CENTRAL PROCESSING UNIT
Page1 UNIT-II Part-2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:
More informationIntroduction. 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 informationIntermediate 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 informationWinter Compiler Construction T10 IR part 3 + Activation records. Today. LIR language
Winter 2006-2007 Compiler Construction T10 IR part 3 + Activation records Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University Today ic IC Language Lexical Analysis Syntax Analysis
More informationLevels of Programming. Registers
Levels of Programming COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1. Arithmetic Instructions 2.
More informationopt. 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 informationSardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization
Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES (2018-19) (ODD) Code Optimization Prof. Jonita Roman Date: 30/06/2018 Time: 9:45 to 10:45 Venue: MCA
More informationInstruction Set Architecture
Computer Architecture Instruction Set Architecture Lynn Choi Korea University Machine Language Programming language High-level programming languages Procedural languages: C, PASCAL, FORTRAN Object-oriented
More informationCompilers. 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 informationCompiler Design (40-414)
Compiler Design (40-414) Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007 Evaluation: Midterm Exam 35% Final Exam 35% Assignments and Quizzes 10% Project
More informationLecture 3 Machine Language. Instructions: Instruction Execution cycle. Speaking computer before voice recognition interfaces
Lecture 3 Machine Language Speaking computer before voice recognition interfaces 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very
More informationProgram Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 )
Program Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 ) lizheng@mail.buct.edu.cn Lexical and Syntax Analysis Topic Covered Today Compilation Lexical Analysis Semantic Analysis Compilation Translating from high-level
More informationOverview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer
Overview EE 4504 Computer Organization Section 7 The Instruction Set Much of the computer s architecture / organization is hidden from a HLL programmer In the abstract sense, the programmer should not
More information6. Intermediate Representation!
6. Intermediate Representation! Prof. O. Nierstrasz! Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.! http://www.cs.ucla.edu/~palsberg/!
More informationQUESTION BANK CHAPTER 1 : OVERVIEW OF SYSTEM SOFTWARE. CHAPTER 2: Overview of Language Processors. CHAPTER 3: Assemblers
QUESTION BANK CHAPTER 1 : OVERVIEW OF SYSTEM SOFTWARE 1) Explain Analysis-synthesis model/fron end backend model of compiler 2) Explain various phases of compiler and symbol table. Consider the statement
More informationChapter 10 Language Translation
Chapter 10 Language Translation A program written in any of those high-level languages must be translated into machine language before execution, by a special piece of software, the compilers. Compared
More informationCOMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]
More informationCSE 378 Midterm 2/12/10 Sample Solution
Question 1. (6 points) (a) Rewrite the instruction sub $v0,$t8,$a2 using absolute register numbers instead of symbolic names (i.e., if the instruction contained $at, you would rewrite that as $1.) sub
More informationSOURCE LANGUAGE DESCRIPTION
1. Simple Integer Language (SIL) SOURCE LANGUAGE DESCRIPTION The language specification given here is informal and gives a lot of flexibility for the designer to write the grammatical specifications to
More informationUnderstand the factors involved in instruction set
A Closer Look at Instruction Set Architectures Objectives Understand the factors involved in instruction set architecture design. Look at different instruction formats, operand types, and memory access
More informationECE232: Hardware Organization and Design. Computer Organization - Previously covered
ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Computer Organization
More informationComputer Hardware and System Software Concepts
Computer Hardware and System Software Concepts Introduction to concepts of System Software/Operating System Welcome to this course on Computer Hardware and System Software Concepts 1 RoadMap Introduction
More informationUNIT I INTRODUCTION TO COMPILING
UNIT I INTRODUCTION TO COMPILING 1. Define compiler? A compiler is a program that reads a program written in one language (source language) and translates it into an equivalent program in another language
More informationGroup A Assignment 3(2)
Group A Assignment 3(2) Att (2) Perm(3) Oral(5) Total(10) Sign Title of Assignment: Lexical analyzer using LEX. 3.1.1 Problem Definition: Lexical analyzer for sample language using LEX. 3.1.2 Perquisite:
More informationIntermediate 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 informationLife Cycle of Source Program - Compiler Design
Life Cycle of Source Program - Compiler Design Vishal Trivedi * Gandhinagar Institute of Technology, Gandhinagar, Gujarat, India E-mail: raja.vishaltrivedi@gmail.com Abstract: This Research paper gives
More informationAlternatives 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 informationUNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes
8051 Software Overview: 1. Addressing Modes 2. Instruction Set 3. Programming 8051 Addressing Modes: UNIT-III ASSEMBLY LANGUAGE PROGRAMMING The CPU can access data in various ways, which are called addressing
More informationCIS 341 Midterm February 28, Name (printed): Pennkey (login id): SOLUTIONS
CIS 341 Midterm February 28, 2013 Name (printed): Pennkey (login id): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing this
More informationThree address representation
Three address representation A typical inetrnal representation is three address ce. In many cases, the compound statements (e.g. for or do loops and if statements) are transformed into sequences of instructions
More information6. Intermediate Representation
6. Intermediate Representation Oscar Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes. http://www.cs.ucla.edu/~palsberg/
More informationCS5363 Final Review. cs5363 1
CS5363 Final Review cs5363 1 Programming language implementation Programming languages Tools for describing data and algorithms Instructing machines what to do Communicate between computers and programmers
More informationModel-based Software Development
Model-based Software Development 1 SCADE Suite Application Model in SCADE (data flow + SSM) System Model (tasks, interrupts, buses, ) SymTA/S Generator System-level Schedulability Analysis Astrée ait StackAnalyzer
More informationCSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes
CSC 488S/CSC 2107S Lecture Notes These lecture notes are provided for the personal use of students taking CSC488H1S or CSC2107S in the Winter 2012/2013 term at the University of Toronto Copying for purposes
More informationIntermediate 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 informationArchitecture II. Computer Systems Laboratory Sungkyunkwan University
MIPS Instruction ti Set Architecture II Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Making Decisions (1) Conditional operations Branch to a
More informationConcepts 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 informationCS606- compiler instruction Solved MCQS From Midterm Papers
CS606- compiler instruction Solved MCQS From Midterm Papers March 06,2014 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 Final Term MCQ s and Quizzes CS606- compiler instruction If X is a
More informationCOMPILER DESIGN. Intermediate representations Introduction to code generation. COMP 442/6421 Compiler Design
1 COMPILER DESIGN Intermediate representations Introduction to code generation Concordia University Introduction to code generation 2 Front end: Lexical Analysis Syntactic Analysis Intermediate Code/Representation
More informationEC 413 Computer Organization
EC 413 Computer Organization Review I Prof. Michel A. Kinsy Computing: The Art of Abstraction Application Algorithm Programming Language Operating System/Virtual Machine Instruction Set Architecture (ISA)
More informationCS 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