compiler development cmpsc 401
play

Compiler Development (CMPSC 401) Janyl Jumadinova January 17, 2018 - PowerPoint PPT Presentation

Compiler Development (CMPSC 401) Janyl Jumadinova January 17, 2018 Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 1 / 34 What is a compiler? Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 2 / 34


  1. Compiler Development (CMPSC 401) Janyl Jumadinova January 17, 2018 Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 1 / 34

  2. What is a compiler? Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 2 / 34

  3. What is a compiler? Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 3 / 34

  4. Compilers are translators Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 4 / 34

  5. Compilers are optimizers Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 5 / 34

  6. Why Study Compilers? Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 6 / 34

  7. Why Study Compilers? Compilers provide portability Compilers enable high performance and productivity Techniques used for compiler design are also useful for other things Compilers and interpreters for domain-specific languages are popular Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 7 / 34

  8. Why Study Compilers? Compilers provide portability Compilers enable high performance and productivity Techniques used for compiler design are also useful for other things Compilers and interpreters for domain-specific languages are popular Bring together : Data structures and Algorithms, Formal Languages, Computer Architecture Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 7 / 34

  9. Why Study Compilers? Compilers provide portability Compilers enable high performance and productivity Techniques used for compiler design are also useful for other things Compilers and interpreters for domain-specific languages are popular Bring together : Data structures and Algorithms, Formal Languages, Computer Architecture Influence : Language Design, Architecture (influence is bi-directional), Techniques used influence other areas (program analysis, testing, ...) Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 7 / 34

  10. Common compiler types High level language → assembly language (e.g., gcc) Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 8 / 34

  11. Common compiler types High level language → assembly language (e.g., gcc) High level language → machine independent bytecode (e.g., javac) Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 8 / 34

  12. Common compiler types High level language → assembly language (e.g., gcc) High level language → machine independent bytecode (e.g., javac) Bytecode → native machine code (e.g., java’s JIT compiler) Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 8 / 34

  13. Common compiler types High level language → assembly language (e.g., gcc) High level language → machine independent bytecode (e.g., javac) Bytecode → native machine code (e.g., java’s JIT compiler) High level language → high level language (e.g., domain specific languages, many research languages) Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 8 / 34

  14. View from 50,000 feet Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 9 / 34

  15. Analysis-Synthesis Model of Compilation There are two parts to compilation: 1 Analysis 2 Synthesis Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 10 / 34

  16. Analysis-Synthesis Model of Compilation There are two parts to compilation: 1 Analysis: determines the operations implied by the source program which are recorded in a tree structure 2 Synthesis Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 11 / 34

  17. Analysis-Synthesis Model of Compilation There are two parts to compilation: 1 Analysis: determines the operations implied by the source program which are recorded in a tree structure 2 Synthesis: takes the tree structure and translates the operations therein into the target program Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 12 / 34

  18. Common Compiler Phases Lexical Analysis (scanning) Syntax Analysis (parsing) Semantic Analysis (type checking) Intermediate Code Generation Machine Code Generation Optimization Memory Management Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 13 / 34

  19. Grouping of phases Compiler front and back ends: Front-end: analysis (machine independent) Back-end: synthesis (machine dependent) Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 14 / 34

  20. Grouping of phases Compiler front and back ends: Front-end: analysis (machine independent) Back-end: synthesis (machine dependent) Compiler passes: - A collection of phases is done only once (single pass) or multiple times (multi pass) Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 14 / 34

  21. Grouping of phases Compiler front and back ends: Front-end: analysis (machine independent) Back-end: synthesis (machine dependent) Compiler passes: - A collection of phases is done only once (single pass) or multiple times (multi pass) Single pass: usually requires everything to be defined before being used in source program Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 14 / 34

  22. Grouping of phases Compiler front and back ends: Front-end: analysis (machine independent) Back-end: synthesis (machine dependent) Compiler passes: - A collection of phases is done only once (single pass) or multiple times (multi pass) Single pass: usually requires everything to be defined before being used in source program Multi pass: compiler may have to keep entire program representation in memory Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 14 / 34

  23. Compiler Construction Tools Software development tools are available to implement one or more compiler phases Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 15 / 34

  24. Compiler Construction Tools Software development tools are available to implement one or more compiler phases Scanner generators Parser generators Syntax-directed translation engines Automatic code generators Data-flow engines Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 15 / 34

  25. Traditional Two-Pass Compiler Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 16 / 34

  26. The Front-End Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 17 / 34

  27. Scanner Compiler starts by seeing only program text Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 18 / 34

  28. Scanner Compiler starts by seeing only program text Scanner converts program text into string of tokens Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 19 / 34

  29. Scanner Compiler starts by seeing only program text Scanner converts program text into string of tokens But we still don’t know what the syntactic structure of the program is Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 20 / 34

  30. Parser Converts string of tokens into a parse tree or an abstract syntax tree Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 21 / 34

  31. Parser Converts string of tokens into a parse tree or an abstract syntax tree Captures syntactic structure of the code Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 21 / 34

  32. Parser Converts string of tokens into a parse tree or an abstract syntax tree Captures syntactic structure of the code Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 21 / 34

  33. Parser Converts string of tokens into a parse tree or an abstract syntax tree Captures syntactic structure of code Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 22 / 34

  34. Semantic actions Interpret the semantics of syntactic constructs Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 23 / 34

  35. Semantic actions Interpret the semantics of syntactic constructs Up to now we have been only concerned with what the syntax of the code is Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 23 / 34

  36. Semantic actions Interpret the semantics of syntactic constructs Up to now we have been only concerned with what the syntax of the code is What’s the difference? Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 23 / 34

  37. Syntax vs. Semantics Syntax: “grammatical” structure of a language Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 24 / 34

  38. Syntax vs. Semantics Syntax: “grammatical” structure of a language What symbols, in what order, is a legal part of the language? Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 24 / 34

  39. Syntax vs. Semantics Syntax: “grammatical” structure of a language What symbols, in what order, is a legal part of the language? But something that is syntactically correct may not mean anything! Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 24 / 34

  40. Syntax vs. Semantics Syntax: “grammatical” structure of a language What symbols, in what order, is a legal part of the language? But something that is syntactically correct may not mean anything! “colorless green ideas sleep furiously” Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 24 / 34

  41. Syntax vs. Semantics Semantics: meaning of the language Janyl Jumadinova Compiler Development (CMPSC 401) January 17, 2018 25 / 34

Recommend


More recommend