Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Overview to Compiler Design

Similar presentations


Presentation on theme: "An Overview to Compiler Design"— Presentation transcript:

1 An Overview to Compiler Design
2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

2 Outline An Overview of Compiler Structure Front End Middle End
Back End 2018/9/20 \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 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

4 A Review on Compiler Structure/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 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

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

6 Output Assembly Code (non-optimized)
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 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

7 Output Assembly Code (non-optimized)
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 2018/9/20 \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 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

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

10 Runtime Memory Organization
frame-1 Entry point for procedure 1 code for procedure 1 Space for arguments (parameters) frame-2 code area Space for bookkeeping Information, including Return address code for procedure 2 frame-3 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 2018/9/20 \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 Parse tree Target-code Generator/Opt Semantic Analyzer Target machine code Abstract Syntax Tree w/ Attributes 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt

12 Two models of compiler structures
Low-level Model Mixed-level Model String of characters String of tokens Parse tree Abstract Syntax tree Medium-level intermediate code Low-level intermediate code Relocatable object module or runnable machine code Lexical analyzer Abstract syntax tree Low-level intermediate code Relocatable object module or runnable machine code String of characters String of tokens Parse tree 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) 2018/9/20 \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 2018/9/20 \course\cpeg421-08s\Topic-1a.ppt


Download ppt "An Overview to Compiler Design"

Similar presentations


Ads by Google