Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compiler Summary Mooly Sagiv html://www.math.tau.ac.il/~msagiv/courses/wcc03.html.

Similar presentations


Presentation on theme: "Compiler Summary Mooly Sagiv html://www.math.tau.ac.il/~msagiv/courses/wcc03.html."— Presentation transcript:

1 Compiler Summary Mooly Sagiv html://www.math.tau.ac.il/~msagiv/courses/wcc03.html

2 Lecture Format Compilation stages and techniques – Review Break Last year’s exam

3 Compiler Structure Input program Lexical analysis Tokens Parser AST Context Analysis Annotated AST Code Generation Assembly Assembler Assembled Binary code Syntax errors “Semantic” errors Executable code Library code Linker input output

4 Lexical Analysis Input: Text (input-file) Output: Tokens (with values) Jlex regular expressions input program scanner tokens

5 Techniques Convert regular expressions to finite automata Accepting states are associated with actions –Actions which are defined first take priority Scanner uses backtracking to find longest match

6 Syntax Analysis (Parsing) Input: Stream of tokens Output: Abstract Syntax Tree Jcup Context free grammar tokens parser AST

7 Recursive Descent (Top Down Parsing) Procedure for every non-terminal The procedure of every non-terminal identifies leftmost derivations –Consider a single token –Decide which production to apply Works for a limited class of grammars [The parser tables can be constructed algorithmically]

8 Bottom-Up Parsing Construct the tree from the leaves Store “states” on the stack Identifies rightmost derivations in reverse order Works for a limited class of grammars The parser tables can be constructed algorithmically (SLR(0)

9 Context Analysis Input: Abstract Syntax Tree Output: Annotated Abstract Syntax Trees –Semantic errors Several tree traversals [Can be declaratively defined using attribute grammar] Examples: –Name resolution –type checking –Consistency of usages Private fields, … –“Allocate” stack slots (offsets) for variables

10 Code Generation Input: AST Output Assembly

11 Code generation of procedures Generate prologue assembly code for opening a stack frame –Local (automatic) variables –callee-save registers Generate code for procedure body Generate epilog assembly code for closing the stack frame –Restore callee-save register Returns to the caller

12 Code generation for procedure body Code for control flow statements –Normal –Runtime checks –Exceptions Code for side-effect free expressions –2-phase Weighted tree (optimal) Code for basic blocks –Avoids store/loads –Construct dependency graphs –Optimize dependency graphs –Generate code with symbolic registers –Allocate architectural registers to symbolic Code for procedure invocation –Store caller-save registers –Transfer actual parameters –Actual call

13 Heap allocated data “Long” lived Duration can exceed procedure body Relies on Garbage collection –Library with the help of the compiler Garbage collection techniques –Stop the world vs. incremental –Generational Garbage collecting algorithms –Mark and sweep –Copying –Reference counts

14 Runtime descriptors Additional information on the stack/heap –Type information –Dynamic class binding –Dispatch tables –Array size Generate code to fill information

15 Assembler Convert assembly to binary Resolve labels –Two phase –Backpatch Simple overloading Produce relocation information

16 Linker Relocate code Address changes

17 Loader Part of the operating system Initializes runtime state

18 Tiger vs. TC Records Procedure nesting Object oriented –Classes –Virtual functions


Download ppt "Compiler Summary Mooly Sagiv html://www.math.tau.ac.il/~msagiv/courses/wcc03.html."

Similar presentations


Ads by Google