Complete the code to identify the start of a basic block in a flow graph.
if instruction.is_leader(): start_block = [1]
The start of a basic block is marked by a leader instruction, so we assign the current instruction as the start.
Complete the code to create edges between basic blocks in a flow graph.
for block in basic_blocks: for successor in block.[1]: graph.add_edge(block, successor)
Edges in a flow graph connect a block to its successors, representing possible next blocks in execution.
Fix the error in the code that checks if a block ends with a jump instruction.
if block.instructions[-1].[1] == 'jump': handle_jump(block)
The opcode field of an instruction tells what operation it performs, such as 'jump'.
Fill both blanks to build a dictionary mapping block leaders to their successors.
block_map = {leader: block[1] for leader, block in blocks.items() if block[2]We map each leader to its block's successors only if the block exists (is not None).
Fill all three blanks to create a flow graph with nodes and edges from basic blocks.
flow_graph = FlowGraph() for block in [1]: flow_graph.add_node(block.[2]) for succ in block.[3]: flow_graph.add_edge(block.[2], succ.[2])
We iterate over basic_blocks, add nodes using each block's leader, and add edges to their successors.