Compiler Principles Fall 2015-2016 Compiler Principles Exercise Set: Lowering and Formal Semantics Roman Manevich Ben-Gurion University of the Negev.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Intermediate Code Generation
Chapter 8 ICS 412. Code Generation Final phase of a compiler construction. It generates executable code for a target machine. A compiler may instead generate.
Formal Semantics of Programming Languages 虞慧群 Topic 6: Advanced Issues.
Lecture 08a – Backpatching & Recap Eran Yahav 1 Reference: Dragon 6.2,6.3,6.4,6.6.
Short circuit code for boolean expressions: Boolean expressions are typically used in the flow of control statements, such as if, while and for statements,
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
8 Intermediate code generation
1 Compiler Construction Intermediate Code Generation.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
Compiler Principles Fall Compiler Principles Lecture 7: Intermediate Representation Roman Manevich Ben-Gurion University.
CS412/413 Introduction to Compilers Radu Rugina Lecture 16: Efficient Translation to Low IR 25 Feb 02.
Programming Language Semantics Inductive Definitions Mooly SagivEran Yahav Schrirber 317Open space
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
CS 536 Spring Code Generation II Lecture 21.
The If/Else Statement, Boolean Flags, and Menus Page 180
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Boolean Algebra أ. زينب آل كاظم 1. Boolean Functions In Boolean algebra we work with the set {0,1}, where: 0 ≡ F (False) & 1 ≡ T (True). The 3 Operations.
Compilation /15a Lecture 7 Getting into the back-end Noam Rinetzky 1.
XOR and XNOR Logic Gates. XOR Function Output Y is TRUE if input A OR input B are TRUE Exclusively, else it is FALSE. Logic Symbol  Description  Truth.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
Chapter 8 Intermediate Code Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Compiler Chapter# 5 Intermediate code generation.
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
We are learning to write expressions using variables. (8-1)
Semantics (1).
Boolean Algebra M. AL- Towaileb1. Boolean Functions In Boolean algebra we work with the set {0,1}, where: 0 ≡ F (False) & 1 ≡ T (True). The 3 Operations.
Compiler Principles Fall Compiler Principles Lecture 7: Lowering Correctness Roman Manevich Ben-Gurion University of the Negev.
CMSC 330: Organization of Programming Languages Operational Semantics.
1 Structure of a Compiler Source Language Target Language Semantic Analyzer Syntax Analyzer Lexical Analyzer Front End Code Optimizer Target Code Generator.
Compiler Principles Fall Compiler Principles Lecture 8: Intermediate Representation Roman Manevich Ben-Gurion University.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Compiler Principles Fall Compiler Principles Lecture 6: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Semantics(1). 2 Symantec(1)  To provide an authoritative definition of the meaning of all language constructs for: 1.Programmers 2.Compiler writers 3.Standards.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Compiler Principles Fall Compiler Principles Lecture 8: Dataflow & Optimizations 1 Roman Manevich Ben-Gurion University of the Negev.
Program Analysis and Verification Noam Rinetzky Lecture 2: Operational Semantics 1 Slides credit: Tom Ball, Dawson Engler, Roman Manevich, Erik.
Lecture 3 Selection Statements
Propositional Calculus: Boolean Functions and Expressions
Selection (also known as Branching) Jumail Bin Taliba by
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Graph-Based Operational Semantics
Propositional Calculus: Boolean Functions and Expressions
Intermediate Code Generation
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Fall Compiler Principles Lecture 5: Intermediate Representation
Fall Compiler Principles Lecture 8: Loop Optimizations
Spring 2017 Program Analysis and Verification Operational Semantics
Computers & Programming Languages
Chapter 6 Intermediate-Code Generation
Three-address code A more common representation is THREE-ADDRESS CODE . Three address code is close to assembly language, making machine code generation.
Pages:51-59 Section: Control1 : decisions
Compiler Design 21. Intermediate Code Generation
Getting into the back-end Noam Rinetzky
Fall Compiler Principles Lecture 5: Intermediate Representation
Evaluating Boolean expressions
Pages:51-59 Section: Control1 : decisions
Spring 2016 Program Analysis and Verification Operational Semantics
Compiler Design 21. Intermediate Code Generation
Controlling Program Flow
Presentation transcript:

Compiler Principles Fall Compiler Principles Exercise Set: Lowering and Formal Semantics Roman Manevich Ben-Gurion University of the Negev

Q1: Extending Boolean expressions We would like to extend the set of Boolean expressions with an expression of the form B  B ? A : A The idea is that in ‘b ? a 1 : a 2 ’ is that if b is true then the result is that of a 1 and otherwise the result is that of a 2 Define the formal semantics for evaluating these expressions Define a corresponding lowering rule (cgen) 2

Q2: Boolean short-cuts We would like to extend the set of Boolean expressions with an expression of the form B  B && B The idea is that in ‘b 1 && b 2 ’ if b 1 is true then the result is that of b 2, and otherwise it is false 1.Define the formal semantics for evaluating these expressions 3

Q2: Boolean short-cuts 2.Consider the two following translations. Are they equivalent? Explain what is the formal definition of equivalence that you consider. 4 cgen(b 1 && b 2 ) = cgen(b 1  b 2 ) where l1, l2, lend and t are fresh cgen(b 1 ) = (P 1, t 1 ) cgen(b 2 ) = (P 2, t 2 ) cgen(b 1 && b 2 ) = (P 1 · l1: t:=t 1 · IfZ t Goto lend · P 2 · l2: t:=t 2 · lend: skip, t) 1 2

Extending IL with memory 5

Q3: Extending IL with memory We would like to support two additional types of commands, as shown in the next page 1.Explain how the states of the revised language should be defined 2.Write the rules for the new commands 6

Q3: Extended syntax V  n | x R  V Op V Op  - | + | * | / | = |  | > | … C  l: skip | l: x := R | l: x := [y] | l: [x] := y | l: Goto l’ | l: IfZ x Goto l’ | l: IfNZ x Goto l’ IR  C + 7 n  NumNumerals l  Num Labels x  Temp  VarTemporaries and variables

solution 8

A1: Extending Boolean expressions  b ? a 1 : a 2   = if  b   = tt then  a 1   else  a 2   9 cgen(b) = (P b, t b ) cgen(a 1 ) = (P 1, t 1 ) cgen(a 2 ) = (P 2, t 2 ) cgen(b ? a 1 : a 2 ) = ( Pb IfZ t Goto label(P 2 ) P 1 t := t 1 l finish : Goto L after P 2 t := t 2 l after : skip, t )

A2: Boolean short-cuts The two translations are indeed equivalent according to the truth table of conjunction We consider equivalence by projecting states on the variables (and temporaries) used in the sub-expression b 1 and b 2 and the output temporary t 10

A3: Extending program states Z Integers {0, 1, -1, 2, -2, …} IState (Var  Temp  {pc})  Z  Z  Z Intermediate states are pairs: – The first component, the stack, gives values to variables – The second component, the heap, maps addresses to values 11

A3: adding memory access rules 12 s(pc) = lP(l) = x:=[y] (s,h)  (s[pc  l+1, x  h(s(y))], h) s(pc) = lP(l) = [x]:=y (s,h)  (s[pc  l+1], h[s(x)  s(y)])