1 / 19

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421). William Mansky http://courses.engr.illinois.edu/cs421/. Based in part on slides by Mattox Beckman, as updated by Vikram Adve, Gul Agha, Elsa Gunter, and Dennis Griffith. The Big Picture. OCaml/Functional Programming Continuation Passing Style

julian-best
Download Presentation

Programming Languages and Compilers (CS 421)

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. Programming Languages and Compilers (CS 421) William Mansky http://courses.engr.illinois.edu/cs421/ Based in part on slides by Mattox Beckman, as updated by Vikram Adve, Gul Agha, Elsa Gunter, and Dennis Griffith

  2. The Big Picture • OCaml/Functional Programming • Continuation Passing Style • Type checking/inference • Unification • Lexing • Parsing • Operational Semantics • Lambda Calculus • Hoare Logic

  3. Anatomy of an Interpreter Program Text Lexing regular expressions/lex Token Buffer Parsing BNF grammar/yacc AST Static Semantics type checking/inference, unification possibly Hoare Logic! Correct AST Dynamic Semantics operational semantics Program Output

  4. Anatomy of a Compiler Program Text Lexing regular expressions/lex Token Buffer Parsing BNF grammar/yacc AST Static Semantics type checking/inference, unification possibly Hoare Logic! Correct AST Translation denotational semantics possibly CPS! } IR Optimization CS 426 Optimized IR Code Generation (denotational semantics again) Assembly/Machine Code (or lambda calculus!)

  5. What can we do now? • Write functional programs (which parallelize well and compute math quickly) • Build compilers and interpreters • Specify and implement programming languages • Prove programs correct • Compare various approaches to PL syntax and semantics

  6. Formal Methods • The study of proving programs correct • But what is a program? • Anything we can model formally/mathematically • Computer programs, machines, workflows • Compilers, air traffic control protocols, security protocols, simulators, Java programs • And how do we prove it correct? • Syntax, semantics, formal logic, automatic/interactive provers

  7. Verifying a Compiler Program Text Lexing Token Buffer Parsing AST “do the same thing” Static Semantics Correct AST Translation IR Optimization Optimized IR Code Generation Assembly/Machine Code

  8. Verifying a Compiler Program Text Lexing Token Buffer Parsing AST have the same semantics? Static Semantics Correct AST Translation IR Optimization Optimized IR Code Generation Assembly/Machine Code

  9. Verifying a Compiler Program Text Lexing Token Buffer Parsing AST Static Semantics Correct AST have the same semantics Translation IR Optimization Optimized IR Code Generation Assembly/Machine Code

  10. Verifying a Compiler Semantics Input AST Input Meaning prove this! Translation Semantics Output AST Output Meaning

  11. Verifying a Compiler – Example PicoML SOS PicoML AST PicoML Value prove this! Denotation LC SOS Lambda-term LC Value

  12. Verifying a Compiler – Example PicoML SOS PicoML AST PicoML Value prove this! Denotation LC SOS Lambda-term LC Value Can we prove this for every program?

  13. Verifying a Compiler – Example PicoML SOS PicoML AST PicoML Value prove this! Denotation LC SOS Lambda-term LC Value Can we prove this for every program? Yes.

  14. Verifying a Compiler – Harder Case Semantics Compiler IR Input Meaning prove this! Optimization Semantics Compiler IR Output Meaning Can we prove this for every program?

  15. Control Flow Graphs • ASTs are good for complex expressions • What if we care more about control flow than expression structure? • Graphs with commands on nodes, edges showing control flow

  16. Control Flow Graphs 0: x := 1 1: if x > 0 goto 4 2: x := x + 1 3: goto 5 4: x := x - 1 5: y := x 6: return y Entry seq x := 1 seq if x > 0 seq branch x := x + 1 x := x - 1 seq goto seq branch y := x seq return y seq Exit

  17. Semantics on Control Flow Graphs • Configurations are (G, n, m), where G is a graph and n is the currently executing node • Small-step for moving between nodes, big-step within a single node • E.g. (Assignment Rule): label(G, n) = I := E (E, m) v out(n) = n' (G, n, m)  (G, n', m[x  v])

  18. Verifying a Compiler – Harder Case CFG Semantics Input CFG Input Value prove this! Optimization CFG Semantics Output CFG Output Value

  19. Questions?

More Related