1 / 13

An Overview to Compiler Design

An Overview to Compiler Design. Outline. An Overview of Compiler Structure Front End Middle End Back End. Reading. Slides and Lecture Notes Aho,Lam,Sethi,Ullman: Chapter 1.4 ~ 1.5 Chapter 2.1 ~ 2.7 Chapter 3.1 ~ 3.5 Chapter 4.1 ~ 4.5.

aleron
Download Presentation

An Overview to Compiler Design

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. An Overview toCompiler Design \course\cpeg421-08s\Topic-1a.ppt

  2. Outline • An Overview of Compiler Structure • Front End • Middle End • Back End \course\cpeg421-08s\Topic-1a.ppt

  3. Reading Slides and Lecture Notes Aho,Lam,Sethi,Ullman: Chapter 1.4 ~ 1.5 Chapter 2.1 ~ 2.7 Chapter 3.1 ~ 3.5 Chapter 4.1 ~ 4.5 \course\cpeg421-08s\Topic-1a.ppt

  4. A Review on CompilerStructure/Design • Overall structure • Front-end: lexical and syntax analysis • Middle-end: machine independent code analysis and (scalar, and sometimes loop nest ) optimization • Back-end: Machine dependent code analysis and optimization \course\cpeg421-08s\Topic-1a.ppt

  5. int foo( ) { int x; return (x + x) ; } Motivation for Compiler optimization COMPILER Source Program Machine Code Input program example: \course\cpeg421-08s\Topic-1a.ppt

  6. foo: sub $sp, $sp, 8 sw $fp, 8($sp) add $fp, $sp, 8 sw $ra, -4($fp) add $t0, $a0 $a0 move $v0, $t0 lw $ra, -4($fp) lw $fp, 0($fp) add $sp, $sp, 8 jr $ra Output Assembly Code (non-optimized) \course\cpeg421-08s\Topic-1a.ppt

  7. foo: sub $sp, $sp, 8 % Push stack frame sw $fp, 8($sp) % Save old frame pointer add $fp, $sp, 8 % Set new frame pointer sw $ra, -4($fp) % Save return address add $t0, $a0 $a0 % Addition move $v0, $t0 % Copy return value lw $ra, -4($fp) % Restore return address lw $fp, 0($fp) % Restore frame pointer add $sp, $sp, 8 % Pop stack frame jr $ra % Jump to return address Output Assembly Code (non-optimized) \course\cpeg421-08s\Topic-1a.ppt

  8. Output Assembly Code -- Revisited (non-optimized) foo: sub $sp, $sp, 8 % Push stack frame (for what?) sw $fp, 8($sp) % Save old frame pointer (for what?) add $fp, $sp, 8 % Set new frame pointer sw $ra, -4($fp) % Save return address (for what?) add $t0, $a0, $a0 % Addition move $v0, $t0 % Copy return value lw $ra, -4($fp) % Restore return address lw $fp, 0($fp) % Restore frame pointer add $sp, $sp, 8 % Pop stack frame jr $ra % Jump to return address \course\cpeg421-08s\Topic-1a.ppt

  9. foo: add $v0, $a0, $a0 % Set result jr $ra % Jump to return address Output Assembly Code(optimized) \course\cpeg421-08s\Topic-1a.ppt

  10. Runtime Memory Organization frame-1 code for procedure 1 Entry point for procedure 1 Space for arguments (parameters) frame-2 code area Space for bookkeeping Information, including Return address frame-3 code for procedure 2 global/static area Entry point for procedure 2 … stack Space in local data … free space Space for local temporaries code for procedure n Runtime stack Entry point for procedure n A stack frame heap Code memory Address space \course\cpeg421-08s\Topic-1a.ppt

  11. Phases of a Compiler Source program Intermediate-code Generator Lexical Analyzer (Scanner) Non-optimized Intermediate Code Tokens Intermediate-code Optimizer Syntax Analyzer (Parser) Optimized Intermediate Code Parsetree Target-code Generator/Opt Semantic Analyzer Target machine code Abstract Syntax Tree w/ Attributes \course\cpeg421-08s\Topic-1a.ppt

  12. String of characters String of characters String of tokens String of tokens Parse tree Parse tree Abstract Syntax tree Abstract syntax tree Medium-level intermediate code Low-level intermediate code Medium-level intermediate code Low-level intermediate code Low-level intermediate code Relocatable object module or runnable machine code Relocatable object module or runnable machine code Low-level Model Mixed-level Model Lexical analyzer Lexical analyzer Parser Parser Semantic analyzer Semantic analyzer Intermediate-code generator Translator Optimizer Optimizer Code generator Final assembly Postpass optimizer Two models of compiler structures (Muchnick, pp. 08) \course\cpeg421-08s\Topic-1a.ppt

  13. A Good Compiler Infrastructure Needed – A modern View Front end Interprocedural Analysis and Optimization Good IR Loop Nest Optimization and Parallelization Global (Scalar) Optimization Middle-End Backend Code Generation \course\cpeg421-08s\Topic-1a.ppt

More Related