Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework 4 Basic Blocks and Control Flow Graphs CS4430 Spring 2012 Due: April 2 nd by 2pm* * There will be absolutely no extensions for this assignment.

Similar presentations


Presentation on theme: "Homework 4 Basic Blocks and Control Flow Graphs CS4430 Spring 2012 Due: April 2 nd by 2pm* * There will be absolutely no extensions for this assignment."— Presentation transcript:

1 Homework 4 Basic Blocks and Control Flow Graphs CS4430 Spring 2012 Due: April 2 nd by 2pm* * There will be absolutely no extensions for this assignment.

2 The Tuple Language Tuple  Asn | Add | Sub | Jmp | Label | Read | Write | Exit Asn  (ASSIGN,RegArg,Arg) Add  (ADDI,RegArg,Arg,Arg) Sub  (SUBI,RegArg,Arg,Arg) Jmp  (JUMP,Arg) Branch  (JNZ,RegArg,Arg) Label  (LABEL,Num) /* N.b., labels are Num ’s */ Read  (READI,RegArg) Write  (WRITEI,Arg) Exit  (EXIT) Arg  RegArg | Num Register  ‘R’ Num | SP | FP | BP RegArg  Register | M[Register] | M[Register + Num] Num  [1-9] Digit*

3 Homework 4, Question 1 Input: the abstract syntax for a Tuple program Input: the tuple parser in TuplePrettyPrinter.tar.gz Output: – Basic blocks for input program Extend it to produce a linked list of basic blocks. – You MUST define a new type called BasicBlock to represent each BB. – The code within the block MUST be represented as an array (and not a linked list) – Include in the definition of BasicBlock whatever else you need (i.e., figure that out). I suggest giving each block a unique id. – Difference from lecture slides: include any jump/branch instructions within the code array To check your results, print out a GraphViz representation of your basic blocks. Each node must contain the code in the block.

4 Tuple Pretty Printer Compile with Makefile in the tarball TuplePrettyPrinter.tar.gz – Available on the class webpage. Run it with file redirection; e.g., –./tuplec test1.gv – Takes a tuple file as input and produces GraphViz output file Requires bison and flex – you do not need to alter these files at all. – Just use the Makefile.

5 Question 2 Input: the output from problem 1 Construct a control flow graph representation for an input program. To check your work, produce a GraphViz representation of the control flow graph.

6 Review: Basic Block basic block is a instruction sequence with – one entry point only EP may be dest. of a jump/branch EP may be target of multiple jump/branch’s – one exit point, and – no jump instructions between EP and exit Last instruction in basic block may be a – jump instruction or – Instruction right before destination of jump instruction.

7 Review: Control Flow Graph Control flow graph (CFG) is a directed graph showing all possible paths during program execution – each node is a basic block/instruction – directed edges are control flow changes Entry block through which control enters into the flow graph, and the Exit block from which control flow leaves.

8 Given input on left, your solution should produce the graph on the right (READI, A) (READI, B) (GT,A,B,t1) (JUMP0,t1,L1) (ADDI,A,5,C) (JUMP,L2) (LABEL,L1) (ADDI,B,5,C) (LABEL,L2) (SUBI,C,1,t2) (MULTI,2,t2,t3) (WRITEI,t3) Control Flow Graph (CFG) generated by Graphviz Input Tuple program

9 Here’s the GraphViz code Cosmetic issues (color, font, etc.) don’t matter in your output graph N.b., if two different basic blocks have the same code, then you’ll have to ensure that they are different nodes in the GraphViz graph. N.b., also that the branch instruction is in the block (this differs from the lecture slides). Your solution must also retain the jumps and branches. digraph cfg { size="6,6"; node [color=yellow, style=filled, shape = box, fontname = "Courier New"]; "(READI, A)\l(READI, B)\l(GT,A,B,t1)\l(JUMP0,t1,L1)" -> "(ADDI,A,5,C)" [label="t1=0",len=1.00] ; "(READI, A)\l(READI, B)\l(GT,A,B,t1)\l(JUMP0,t1,L1)" -> "(LABEL,L1)\l(ADDI,B,5,C)" [label="t1!=0",len=1.00] ; "(ADDI,A,5,C)" -> "(LABEL,L2)\l(SUBI,C,1,t2)\l(MULTI,2,t2,t3)\l(WRITEI,t3)"; "(LABEL,L1)\l(ADDI,B,5,C)" -> "(LABEL,L2)\l(SUBI,C,1,t2)\l(MULTI,2,t2,t3)\l(WRITEI,t3)"; }


Download ppt "Homework 4 Basic Blocks and Control Flow Graphs CS4430 Spring 2012 Due: April 2 nd by 2pm* * There will be absolutely no extensions for this assignment."

Similar presentations


Ads by Google