1 / 18

Compiler Summary

Compiler Summary. Mooly Sagiv html://www.math.tau.ac.il/~msagiv/courses/wcc03.html. Lecture Format. Compilation stages and techniques – Review Break Last year’s exam. “Semantic” errors. Syntax errors. Context Analysis. Lexical analysis. Parser. Tokens. AST. Code Generation.

sora
Download Presentation

Compiler Summary

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. 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. “Semantic” errors Syntax errors Context Analysis Lexical analysis Parser Tokens AST Code Generation Annotated AST Assembler Assembly Assembled Binary code input Library code Executable code Linker output Compiler Structure Input program

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

  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. Context free grammar AST parser tokens Syntax Analysis (Parsing) • Input: Stream of tokens • Output: Abstract Syntax Tree Jcup

  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. Records Procedure nesting Object oriented Classes Virtual functions Tiger vs. TC

More Related