Code Generation Example -- 1 source text: x:=1; z := y < x Abstract Syntax Tree: ; := < x 1 z y x assignment = vars ‘:=‘ exprs; stmts = stmts ‘;’ stmt;

Slides:



Advertisements
Similar presentations
Calling sequence ESP.
Advertisements

Chapter 8 Intermediate Code Generation. Intermediate languages: Syntax trees, three-address code, quadruples. Types of Three – Address Statements: x :=
1 Homework / Exam Turn in mp2 at start of class today Reading –PAL, pp 3-6, Exam #1 next class –Open Book / Open Notes –NO calculators or other.
Assembly Language for Intel-Based Computers Chapter 8: Advanced Procedures Kip R. Irvine.
University of Washington Last Time For loops  for loop → while loop → do-while loop → goto version  for loop → while loop → goto “jump to middle” version.
Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols.
Machine-Level Programming III: Procedures Apr. 17, 2006 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables CS213.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
ISBN Chapter 3 More Syntax –BNF –Derivations –Practice.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Accessing parameters from the stack and calling functions.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
– 1 – , F’02 ICS05 Instructor: Peter A. Dinda TA: Bin Lin Recitation 4.
Microprocessors Frame Pointers and the use of the –fomit-frame-pointer switch Feb 25th, 2002.
Chapter 2 A Simple Compiler
September 22, 2014 Pengju (Jimmy) Jin Section E
Stack Activation Records Topics IA32 stack discipline Register saving conventions Creating pointers to local variables February 6, 2003 CSCE 212H Computer.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
Recitation 2: Assembly & gdb Andrew Faulring Section A 16 September 2002.
6.828: PC hardware and x86 Frans Kaashoek
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 Carnegie Mellon Stacks : Introduction to Computer Systems Recitation 5: September 24, 2012 Joon-Sup Han Section F.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Code Generation Gülfem Savrun Yeniçeri CS 142 (b) 02/26/2013.
Fabián E. Bustamante, Spring 2007 Machine-Level Programming III - Procedures Today IA32 stack discipline Register saving conventions Creating pointers.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Recitation 2 – 2/11/02 Outline Stacks & Procedures Homogenous Data –Arrays –Nested Arrays Mengzhi Wang Office Hours: Thursday.
Target Code Generation Using the generated intermediate code, covert to instructions and memory characteristics of the target machine.
Derived from "x86 Assembly Registers and the Stack" by Rodney BeedeRodney Beede x86 Assembly Registers and the Stack Nov 2009.
Chapter 2. Design of a Simple Compiler J. H. Wang Sep. 21, 2015.
Procedures – Generating the Code Lecture 21 Mon, Apr 4, 2005.
Sahar Mosleh California State University San MarcosPage 1 Nested Procedure calls and Flowcharts.
CSC 221 Computer Organization and Assembly Language
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 21: Calling.
Machine-level Programming III: Procedures Topics –IA32 stack discipline –Register saving conventions –Creating pointers to local variables.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 11: Functions and stack frames.
Compiler Construction Code Generation Activation Records
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
1 Assembly Language: Function Calls Jennifer Rexford.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
Overview of Back-end for CComp Zhaopeng Li Software Security Lab. June 8, 2009.
1 Topic 4: Abstract Syntax Symbol Tables COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer.
Type Inference Example -- 1 source text: x:=1; z := y < x Abstract Syntax Tree: ; := < x 1 z y x assignment = vars ‘:=‘ exprs; stmts = stmts ‘;’ stmt;
Section 5: Procedures & Stacks
Recitation 3: Procedures and the Stack
CS 177 Computer Security Lecture 9
Assembly function call convention
Reading Condition Codes (Cont.)
Run-Time Environments Chapter 7
C function call conventions and the stack
Exploiting & Defense Day 2 Recap
Homework In-line Assembly Code Machine Language
Introduction to Compilers Tim Teitelbaum
Recitation 2 – 2/4/01 Outline Machine Model
Assembly Language Programming V: In-line Assembly Code
asum.ys A Y86 Programming Example
Discussion Section – 11/3/2012
Machine-Level Programming 4 Procedures
Stack Frames and Advanced Procedures
Procedures – Overview Lecture 19 Mon, Mar 28, 2005.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Assembly Language Programming II: C Compiler Calling Sequences
Machine-Level Programming III: Procedures Sept 18, 2001
Understanding Program Address Space
“Way easier than when we were students”
ICS51 Introductory Computer Organization
Presentation transcript:

Code Generation Example -- 1 source text: x:=1; z := y < x Abstract Syntax Tree: ; := < x 1 z y x assignment = vars ‘:=‘ exprs; stmts = stmts ‘;’ stmt; relation = sum ‘<‘ sum; b logical i integer r real

Code Generation Example -- 2 source text: x:=1; z := y < x Abbreviate As stmts_stmtsSEMIstmt ; assignment_varsCOLONEQexprs := relation_sumLTsum < tree.getRoot() root() tree.getNode(nd,k) node(k)

Code Generation Example -- 3 source text: x:=1; z := y < x initial state: ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code

Code Generation Example -- 4 source text: x:=1; z := y < x genWalk(): emit.prolog() ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i 55: pushR EBP # save x86 frame pointer 89e5: movRR EBP,ESP # new x86 frame 8b7508: movRP ESI,8 # point at X frame 60:pushA # callee save 55 89e5 8b

Code Generation Example -- 5 source text: x:=1; z := y < x genWalk(): stmtWalk(getRoot()) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i 55 89e5 8b x86 code

Code Generation Example -- 6 source text: x:=1; z := y < x stmtWalk(): assignWalk(getKid(1)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i 55 89e5 8b x86 code

Code Generation Example -- 7 source text: x:=1; z := y < x assignWalk(): lhs=varsWalk(getKid(1)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i 55 89e5 8b x86 code

Code Generation Example -- 8 source text: x:=1; z := y < x varsWalk(): opd=emit.var(tok) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i 55 89e5 8b x86 code

Code Generation Example -- 9 source text: x:=1; z := y < x assignWalk(): rhs=exprsWalk(getKid(3)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i lhs x 55 89e5 8b x86 code

Code Generation Example source text: x:=1; z := y < x exprsWalk(): t=exprWalk(getKid(1)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i lhs x 55 89e5 8b x86 code

Code Generation Example source text: x:=1; z := y < x exprWalk(): opd=emit.expr0(rule,tok) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i lhs rhs 1 x 55 89e5 8b x86 code

Code Generation Example source text: x:=1; z := y < x assignWalk(): emit.store(lhs, rhs) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i 55 89e5 8b b lhs x rhs1 b : movRC EAX,=1=0x : movMR 0,EAX (x)

Code Generation Example – 13 source text: x:=1; z := y < x stmtWalk(): stmtWalk(getKid(2)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i 55 89e5 8b b x86 code

Code Generation Example – 14 source text: x:=1; z := y < x stmtWalk(): assignWalk(getKid(3)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code 55 89e5 8b b

Code Generation Example – 15 source text: x:=1; z := y < x assignWalk(): lhs =varsWalk(getKid(1)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code 55 89e5 8b b

Code Generation Example – 16 source text: x:=1; z := y < x varsWalk(): opd=emit.var(tok) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code 55 89e5 8b b

Code Generation Example – 17 source text: x:=1; z := y < x assignWalk(): rhs =exprsWalk(getKid(3)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code lhs z 55 89e5 8b b

Code Generation Example – 18 source text: x:=1; z := y < x exprWalk(): lft=exprWalk(getKid(1)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code lhs z 55 89e5 8b b

Code Generation Example – 19 source text: x:=1; z := y < x exprWalk(): res=emit.expr0(tok) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code lhs z 55 89e5 8b b

Code Generation Example – 20 source text: x:=1; z := y < x exprWalk(): rgt=exprWalk(getKid(3)) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code lhs z lft y 55 89e5 8b b

Code Generation Example – 21 source text: x:=1; z := y < x exprWalk(): res = emit.expr0(r, tok) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i x86 code lhs z y lft 55 89e5 8b b

Code Generation Example – 22 source text: x:=1; z := y < x exprWalk(): emit.expr2(rule,lft,rgt) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i lhs z lft rgt y x 8b b8e bc1 8b : movRM EAX,8 (y) 8b8e : movRM ECX,0 (x) 3bc1: cmpRR EAX,ECX 55 89e5 8b b

Code Generation Example – 23 source text: x:=1; z := y < x assignWalk(): emit.store(lhs,rhs) ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i lhs z rhs F 0f9cc0: setlR EAX 81e : andRC EAX,=1=0x : movMR 4,EAX (z) 8b b8e bc1 0f9cc0 81e e5 8b b

Code Generation Example – 24 source text: x:=1; z := y < x stmtWalk(): ; := < x 1 z y x symbol table y/right/i z/left/b x/leftright/i 8b b8e bc1 0f9cc0 81e e5 8b b x86 code

Code Generation Example – 25 source text: x:=1; z := y < x genWalk(): emit.epilog() ; := < x 1 z y x 8b b8e bc 0f9cc0 81e C0 c9 c3 61: popA # callee restore 33C0: xorRR EAX,EAX # 0 means no error c9: leave # restore stack c3: ret # restore EIP 55 89e5 8b b