0
0
Compiler Designknowledge~10 mins

Basic blocks and flow graphs in Compiler Design - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to identify the start of a basic block in a flow graph.

Compiler Design
if instruction.is_leader():
    start_block = [1]
Drag options to blanks, or click blank then click option'
Ainstruction
BFalse
CNone
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a boolean value instead of the instruction.
Using None which does not represent a block start.
2fill in blank
medium

Complete the code to create edges between basic blocks in a flow graph.

Compiler Design
for block in basic_blocks:
    for successor in block.[1]:
        graph.add_edge(block, successor)
Drag options to blanks, or click blank then click option'
Apredecessors
Bleaders
Csuccessors
Dinstructions
Attempts:
3 left
💡 Hint
Common Mistakes
Using predecessors which point backward.
Using leaders or instructions which are not related to edges.
3fill in blank
hard

Fix the error in the code that checks if a block ends with a jump instruction.

Compiler Design
if block.instructions[-1].[1] == 'jump':
    handle_jump(block)
Drag options to blanks, or click blank then click option'
Aopcode
Boperand
Clabel
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Checking operand or label which are not operation types.
Using address which is unrelated here.
4fill in blank
hard

Fill both blanks to build a dictionary mapping block leaders to their successors.

Compiler Design
block_map = {leader: block[1] for leader, block in blocks.items() if block[2]
Drag options to blanks, or click blank then click option'
A.successors
B.predecessors
Cis not None
Dis None
Attempts:
3 left
💡 Hint
Common Mistakes
Using predecessors instead of successors.
Checking if block is None instead of not None.
5fill in blank
hard

Fill all three blanks to create a flow graph with nodes and edges from basic blocks.

Compiler Design
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])
Drag options to blanks, or click blank then click option'
Abasic_blocks
Bleader
Csuccessors
Dinstructions
Attempts:
3 left
💡 Hint
Common Mistakes
Using instructions instead of basic blocks.
Using instructions or predecessors instead of successors.
Using block instead of leader for node identity.