mechanized semantics for clight
play

Mechanized semantics for Clight Sandrine Blaxy, Xavier Leroy Pim - PowerPoint PPT Presentation

Mechanized semantics for Clight Sandrine Blaxy, Xavier Leroy Pim Jager - Type Theory and Coq The CompCert C project Formally proving a compiler The CompCert project investigates the formal verification of realistic compilers usable


  1. Mechanized semantics for Clight Sandrine Blaxy, Xavier Leroy Pim Jager - Type Theory and Coq

  2. The CompCert C project – Formally proving a compiler • ” The CompCert project investigates the formal verification of realistic compilers usable for critical embedded software” • Goal: Formally verify the transformation of C programs to machine executable assembly.

  3. Today we focus on Clight, a large subset of C

  4. Clight is a (very large) subset of C Including: Differences: • Most of C types • No GOTO statement • Most C operators • Pointers (and pointer arithmetic) • Expressions must be pure - Ensures termination • Function pointers - Ensures deterministic evaluation • Structs • Unions • Almost all control structures a = print(..) + print(..);

  5. Clight Syntax: Types

  6. Clight Syntax : Expressions

  7. Clight syntax: Statements

  8. C: calculating a least common multiple int n1, n2; int main() { int lcm; n1 = 42; n2 = 34; lcm = (n1>n2) ? n1 : n2; while(1) { if(lcm%n1==0 && lcm%n2==0){ break; } lcm++; } return lcm; }

  9. Clight: calculating a least common multiple int(I32, Signed) n1; int(I32, Signed) n2; int f() { int(I32, Signed) lcm; n1 = 42; n2 = 34; lcm = (n1>n2) ? n1 : n2; while(1) { if(lcm%n1==0 ? (lcm%n2==0 ? 1 : 0) : 0){ break; } else { skip; } lcm = lcm + 1; } return lcm; } main = f

  10. Semantics of Clight Big step semantics: 𝑑,𝑡 ⟹ 𝑡 % • Expression in left position Expression in right position Execution of terminating statement Execution of diverging statement

  11. Judgment of terminating statements • G: Global environment • E: Local environment • s: statement to be executed • M: Current state of memory • t: trace of IO events • out: statement outcomes: - Normal - Continue - Break - Return - Return(v) • M’: new state of memory

  12. Semantics of statements (except loops) Coq

  13. Recall: Semantics for IMP statements • Assignment: • Sequencing:

  14. Semantics of while loops Coq

  15. Recall: while in IMP

  16. Judgment of diverging statements • G: Global environment • E: Local environment • s: statement to be executed • M: Current state of memory • T: (infinite) trace of IO events

  17. A statement diverges if any of its components diverges. Coq

  18. Just like commands in IMP diverge when any of their components diverge

  19. Semantics are defined by 8 10 judgments Calling of terminating functions Calling of diverging functions

  20. Function calls Coq

  21. Function invocation

  22. 2009 to 2016 Big step to Small step • CompCert changed semantics model to small step: 𝑡, 𝑛 → (𝑡 % , 𝑛 % ) • Small step based on continuations • Coq

  23. Questions?

  24. Judgment for expressions (in right position) • G: Global environment • E: Local environment • a: expression to be evaluated • M: Current state of memory • v: result value, either: - int(n) - float(f) - ptr(l) - undef

  25. Semantics for expressions in right position

  26. Semantics for ( a1 op a2) a1 op a2)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend