1 / 13

Intermediate Code Generation

Intermediate Code Generation. Prepared By: Abhisekh Biswas - 04CS3002. Intermediate Code. Intermediate Code is generated using the Parse rule Producing a language from the input language. Utility of Intermediate Code Generation.

pauline
Télécharger la présentation

Intermediate Code Generation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intermediate Code Generation Prepared By: Abhisekh Biswas - 04CS3002

  2. Intermediate Code Intermediate Code is generated using the Parse rule Producing a language from the input language.

  3. Utility of Intermediate Code Generation 1. Suppose We have n-source languages and m-Target languages. Without Intermediate code we will change each source language into target language directly. So, for each source-target pair we will need a compiler. Hence we will require (n*m) Compilers, one for each pair. If we Use Intermediate code We will require n-Compilers to convert each source language into Intermediate code and m-Compilers to convert Intermediate code into m-target languages. Thus We require only (n+m) Compilers.

  4. Retargeting is facilitated; a compiler for a different machine can be created by attaching a Back-end (which generate Target Code) for the new machine to an existing Front-end (which generate Intermediate Code). • A machine Independent Code-Optimizer can be applied to the Intermediate code. • Intermediate code is simple enough to be easily converted to any target code. • Complex enough to represent all the complex structure of high level language.

  5. Types of Intermediate Code • High Level Representation. • Low level Representation.

  6. Code Optimization • See the total intermediate instruction and optimize. • Find Redundancy in Code.

  7. -find common subexpression • -check for dependency • -detect dead codes • TWO BASIC TYPES OF OPTIMIZATION: • 1>machine dependent i.e utilizing hardware specification for max efficiency.but range of compatibility is small. • 2>machine independent,

  8. Syntax Tree is optimization of high level language. Suppose we have following code: if(x<0) then x=3*(y+1) else y=y+1;

  9. ifstat if assign then exp elsestat ; id relop id = exp id exp exp * exp ) ( exp + exp id id

  10. elsestat exp else id exp = exp exp + id id

  11. We Can see A DAG gives the same information but in a more compact manner because common sub-expression are identified. • PostFix Notation can be used to represent tree in linearized manner.In PostFix Notation edges of tree do not appear explicitly.

  12. Three Address Code • Another way to represent tree in lenearized form is Three-address-code Notation. • In Three Address Code method internal nodes are given names. It is a low level Intermediate code representation.

  13. Example x=y op z where x, y and z are names, constants or Compiler generated temporaries. where op stands for any operator.

More Related