6
Most read
7
Most read
8
Most read
INTERMEDIATE CODE
GENERATION
INTRODUCTION
• In computing, code generation is the process by which a
compiler's code generator converts some intermediate
representation of source code into a form (e.g., machine code)
that can be readily executed by a machine.
• The front end of a compiler translates a source program into an
independent intermediate code,
• Then the back end of the compiler uses this intermediate code to
generate the target code (which can be understood by the
MACHINE INDEPENDENT INTERMEDIATE
CODE:
• Because of the machine independent intermediate code,
portability will be enhanced.
• It is easier to apply source code modification to improve the
performance of source code by optimizing the intermediate
code.
Intermediate code
INTERMEDIATE
REPRESENTATION
HIGH LEVEL IR
• High-level intermediate
code representation is very
close to the source
language itself.
• Not preferred for target
machine optimization
LOW LEVEL IR
• This one is close to the
target machine.
• It is good for machine-
dependent optimizations.
COMMONLY USED INTERMEDIATE
CODE REPRESENTATION
POSTFIX NOTATION
• The postfix notation for the expression “a + b” places the
operator at the right end as ab +.
• No parentheses are needed in postfix notation because the
position and arity (number of arguments) of the operators
permit only one way to decode a postfix expression.
• In postfix notation the operator follows the operand.
THREE ADDRESS CODE
• A statement involving no more than three references(two for
operands and one for result) is known as three address
statement.
• Three address statement is of the form x = y op z , here x, y, z
will have address (memory location).
• Can be represented in 3 forms : Quadruples, Triples, Indirect
type.
QUADRUPLES
• Each instruction in quadruples presentation is divided into four
fields: operator, arg1, arg2, and result.
Operator Argument
1
Argument
2
Resul
t
(1) * C D R1
(2) + B R1 R2
(3) = R2 A
Previous example of a = b + c * d
TRIPLES
• Each instruction in triples presentation has three fields :
op, arg1, and arg2.
• The results of respective sub-expressions are denoted by
the position of expression.
Operator Argument
1
Argument
2
(1) * C D
(2) + B (1)
(3) = (2)
Previous example of a = b + c * d
INDIRECT TRIPLES
• This representation is an enhancement over triples
representation. It uses pointers instead of position to
store results.
• This enables the optimizers to freely re-position the
sub-expression to produce an optimized code.
SYNTAX TREE
• Syntax tree is nothing more than condensed form of a parse
tree.
• The operator and keyword nodes of the parse tree are moved
to their parents and a chain of single productions is replaced
by single link in syntax tree.
• The internal nodes are operators and child nodes are
operands.
SYNTAX TREE
THANK YOU

More Related Content

PPTX
Intermediate code generator
PPT
Intermediate code generation (Compiler Design)
PDF
Language processors
PDF
Intermediate code generation in Compiler Design
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PPT
Passes of compilers
PPTX
Compiler Chapter 1
PPTX
Operator precedance parsing
Intermediate code generator
Intermediate code generation (Compiler Design)
Language processors
Intermediate code generation in Compiler Design
Type Checking(Compiler Design) #ShareThisIfYouLike
Passes of compilers
Compiler Chapter 1
Operator precedance parsing

What's hot (20)

PPTX
Code generation
PPTX
PPT
Jumps in Assembly Language.
PPTX
Basic blocks - compiler design
PDF
Syntax analysis
PDF
Code generation in Compiler Design
PDF
Deterministic Finite Automata (DFA)
PPTX
Automata Theory - Turing machine
PPT
Introduction to Compiler design
PPTX
Reduction & Handle Pruning
PPTX
Lexical analyzer generator lex
PDF
Token, Pattern and Lexeme
PPTX
Specification-of-tokens
PDF
Syntax directed translation
DOC
Dma transfer
PPTX
Introduction to loaders
PPTX
Access to non local names
PPTX
Bootstrapping in Compiler
PPTX
Syntax Analysis in Compiler Design
PDF
Compiler Design- Machine Independent Optimizations
Code generation
Jumps in Assembly Language.
Basic blocks - compiler design
Syntax analysis
Code generation in Compiler Design
Deterministic Finite Automata (DFA)
Automata Theory - Turing machine
Introduction to Compiler design
Reduction & Handle Pruning
Lexical analyzer generator lex
Token, Pattern and Lexeme
Specification-of-tokens
Syntax directed translation
Dma transfer
Introduction to loaders
Access to non local names
Bootstrapping in Compiler
Syntax Analysis in Compiler Design
Compiler Design- Machine Independent Optimizations
Ad

Similar to Intermediate code (20)

PDF
Chapter 11 - Intermediate Code Generation.pdf
PPTX
Intermediate code generator.pptx
PPTX
CSC 204 PASSES IN COMPILER CONSTURCTION.pptx
PPTX
Chapter 6 - Intermediate Languages.pptxjfjgj
PPTX
Intermediate code- generation
PPTX
Programming the basic computer
PPTX
gayathri.p.pptx
PDF
Issues in the design of Code Generator
PPTX
Assembly Language for as level computer science
PPT
Compiler chapter six .ppt course material
PPTX
Three address code In Compiler Design
PPTX
Three Address code
PPT
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
PPT
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
PPTX
Lecture 12 intermediate code generation
PPTX
UNIT-3.pptx
PPTX
Code optimization
PPTX
Code optimization
PPT
Lcdf4 chap 03_p2
PDF
Intermediate code generation
Chapter 11 - Intermediate Code Generation.pdf
Intermediate code generator.pptx
CSC 204 PASSES IN COMPILER CONSTURCTION.pptx
Chapter 6 - Intermediate Languages.pptxjfjgj
Intermediate code- generation
Programming the basic computer
gayathri.p.pptx
Issues in the design of Code Generator
Assembly Language for as level computer science
Compiler chapter six .ppt course material
Three address code In Compiler Design
Three Address code
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
Lecture 12 intermediate code generation
UNIT-3.pptx
Code optimization
Code optimization
Lcdf4 chap 03_p2
Intermediate code generation
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access-Surgery.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
PDF
International_Financial_Reporting_Standa.pdf
PDF
advance database management system book.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
PDF
English Textual Question & Ans (12th Class).pdf
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Complications of Minimal Access-Surgery.pdf
My India Quiz Book_20210205121199924.pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
International_Financial_Reporting_Standa.pdf
advance database management system book.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Environmental Education MCQ BD2EE - Share Source.pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Core Concepts of Personalized Learning and Virtual Learning Environments
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
English Textual Question & Ans (12th Class).pdf
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
FORM 1 BIOLOGY MIND MAPS and their schemes
Hazard Identification & Risk Assessment .pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...

Intermediate code

  • 2. INTRODUCTION • In computing, code generation is the process by which a compiler's code generator converts some intermediate representation of source code into a form (e.g., machine code) that can be readily executed by a machine. • The front end of a compiler translates a source program into an independent intermediate code, • Then the back end of the compiler uses this intermediate code to generate the target code (which can be understood by the
  • 3. MACHINE INDEPENDENT INTERMEDIATE CODE: • Because of the machine independent intermediate code, portability will be enhanced. • It is easier to apply source code modification to improve the performance of source code by optimizing the intermediate code.
  • 5. INTERMEDIATE REPRESENTATION HIGH LEVEL IR • High-level intermediate code representation is very close to the source language itself. • Not preferred for target machine optimization LOW LEVEL IR • This one is close to the target machine. • It is good for machine- dependent optimizations.
  • 7. POSTFIX NOTATION • The postfix notation for the expression “a + b” places the operator at the right end as ab +. • No parentheses are needed in postfix notation because the position and arity (number of arguments) of the operators permit only one way to decode a postfix expression. • In postfix notation the operator follows the operand.
  • 8. THREE ADDRESS CODE • A statement involving no more than three references(two for operands and one for result) is known as three address statement. • Three address statement is of the form x = y op z , here x, y, z will have address (memory location). • Can be represented in 3 forms : Quadruples, Triples, Indirect type.
  • 9. QUADRUPLES • Each instruction in quadruples presentation is divided into four fields: operator, arg1, arg2, and result. Operator Argument 1 Argument 2 Resul t (1) * C D R1 (2) + B R1 R2 (3) = R2 A Previous example of a = b + c * d
  • 10. TRIPLES • Each instruction in triples presentation has three fields : op, arg1, and arg2. • The results of respective sub-expressions are denoted by the position of expression. Operator Argument 1 Argument 2 (1) * C D (2) + B (1) (3) = (2) Previous example of a = b + c * d
  • 11. INDIRECT TRIPLES • This representation is an enhancement over triples representation. It uses pointers instead of position to store results. • This enables the optimizers to freely re-position the sub-expression to produce an optimized code.
  • 12. SYNTAX TREE • Syntax tree is nothing more than condensed form of a parse tree. • The operator and keyword nodes of the parse tree are moved to their parents and a chain of single productions is replaced by single link in syntax tree. • The internal nodes are operators and child nodes are operands.

Editor's Notes

  • #3: In computing, code generation is the process by which a compiler's code generator converts some intermediate representation of source code into a form (e.g., machine code) that can be readily executed by a machine. n the analysis-synthesis model of a compiler, the front end of a compiler translates a source program into an independent intermediate code, then the back end of the compiler uses this intermediate code to generate the target code (which can be understood by the machine).
  • #4: If a compiler translates the source language to its target machine language without having the option for generating intermediate code, then for each new machine, a full native compiler is required. Intermediate code eliminates the need of a new full compiler for every unique machine by keeping the analysis portion same for all the compilers. The second part of compiler, synthesis, is changed according to the target machine. It becomes easier to apply the source code modifications to improve code performance by applying code optimization techniques on the intermediate code.
  • #5: If we generate machine code directly from source code then for n target machine we will have n optimisers and n code generators but if we will have a machine independent intermediate code, we will have only one optimiser. Intermediate code can be either language specific (e.g., Bytecode for Java) or language. independent (three-address code).
  • #6: High Level IR - High-level intermediate code representation is very close to the source language itself. They can be easily generated from the source code and we can easily apply code modifications to enhance performance. But for target machine optimization, it is less preferred. Low Level IR - This one is close to the target machine, which makes it suitable for register and memory allocation, instruction set selection, etc. It is good for machine-dependent optimizations. Intermediate code can be either language specific (e.g., Byte Code for Java) or language independent (three-address code).
  • #8: The ordinary (infix) way of writing the sum of a and b is with operator in the middle : a + b The postfix notation for the same expression places the operator at the right end as ab +. In general, if e1 and e2 are any postfix expressions, and + is any binary operator, the result of applying + to the values denoted by e1 and e2 is postfix notation by e1e2 +. No parentheses are needed in postfix notation because the position and arity (number of arguments) of the operators permit only one way to decode a postfix expression. In postfix notation the operator follows the operand. Example – The postfix representation of the expression (a – b) * (c + d) + (a – b) is :   ab – cd + *ab -+.
  • #9: A statement involving no more than three references(two for operands and one for result) is known as three address statement. A sequence of three address statements is known as three address code. Three address statement is of the form x = y op z , here x, y, z will have address (memory location). Sometimes a statement might contain less than three references but it is still called three address statement. Example – The three address code for the expression a = b + c * d: r1 = c * d; r2 = b + r1; a = r2 r1,r2 are temporary variables. Can be represented in 3 forms : Quadruples, Triples, Indirect type.
  • #13: Syntax tree is nothing more than condensed form of a parse tree. The operator and keyword nodes of the parse tree are moved to their parents and a chain of single productions is replaced by single link in syntax tree the internal nodes are operators and child nodes are operands. To form syntax tree put parentheses in the expression, this way it's easy to recognize which operand should come first.
  • #14: Syntax tree is nothing more than condensed form of a parse tree. The operator and keyword nodes of the parse tree are moved to their parents and a chain of single productions is replaced by single link in syntax tree the internal nodes are operators and child nodes are operands. To form syntax tree put parentheses in the expression, this way it's easy to recognize which operand should come first.