1 / 22

Intermediate Code Representations

Intermediate Code Representations. Conceptual phases of compiler. Lexical Analysis (scanner). Semantic Analysis. Code generation. Syntax analysis (parser). Code optimization. Optimized code. Sequence of tokens. Intermediate code - IR 1. Intermediate code IR 2. Target code.

Télécharger la présentation

Intermediate Code Representations

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 Representations

  2. Conceptual phases of compiler Lexical Analysis (scanner) Semantic Analysis Code generation Syntax analysis (parser) Code optimization Optimized code Sequence of tokens Intermediate code - IR1 Intermediate code IR2 Target code Back End machine dependent language independent Middle Front End machine independent language dependent

  3. Why use an IR?

  4. IR – Encodes Compiler’s Program Knowledge • Thus, some IR PROPERTIES: • Ease of generation • Ease of manipulation • Size • Freedom of Expression • Level of Abstraction • Selecting IR is critical.

  5. 3 Categories of IRs • Structural/Graphical • - AST and Concrete ST • - call graph • - program dependence graph (PDG) • 2. Linear • - 3-address code • - abstract stack machine code • Hybrid • - control flow graph (CFG)

  6. Level of Abstraction Consider:A[j,i] = @A + j*10 + i [ ] A I J Loadi 1, R1 Sub RJ, R1, R2 Loadi 10, R3 Mult R2, R3, R4 Sub Ri, R1, r5 Add R4, R5, R6 Loadi @A, R7 Add R7, R6, R8 Load R8, RAIJ

  7. Some Design Issues for IRs • Questions to Ponder: • What is the minimum needed in the language’s set of • operators? • What is the advantage of a small set of operators? • What is the concern of designing the operations • Close to actual machine operations? • 4. What is the potential problem of having a small • Set of IR operations?

  8. High LevelGraphical Representations Consider: A -> V := E E -> E + E | E * E | - E | id String: a := b * - c + b * - c Exercise: Concrete ST? AST? DAG?

  9. Linear IRs: Three Address Code • Sequence of instructions of the form X := y op z where x, y and z are variable names, constants, or compiler generated variables (“temporaries”) • Only one operator is permitted on the RHS – expressions computed using temporaries

  10. Simple Linear IRs Write the 3 – address code for: a := b * - c + b * - c ? = -c = b * ? … complete the code from the ast? The dag?

  11. Exercise Give the 3 address code for: Z := x * y + a[j] / sum(b)

  12. More Simple Linear IRs Stack machine code: push, pop, ops Consider: x – 2 * y Advantages?

  13. Hybrid IRs

  14. Exercise – Construct the CFG

  15. Call Graph Representation Node = function or method Edge from A to B : A has a call site where B is potentially called

  16. Exercise: Construct a call graph

  17. Multiple IRs: WHIRL

  18. Key Highlights of IRs

More Related