Python bytecode CFG added to compiler-explorer

Hi
We just added control-flow-graph support to compiler-explorer:

Hopefully it is useful to you guys. Please report any problems you find - and maybe even further enhancement suggestions!
Toy example: Compiler Explorer

Thanks,
-Ofek

15 Likes

I guess match statements are quickly too much for it :sweat_smile:

More relevant bug, and maybe the cause of the above:

def square(num):
    while num>5:
        print("A")
        if num % 4 == 0:
            break
    else:
        print("B")
    print("C")

Results in an incomplete graph. It appears the CFG can’t point inside of longer blocks, and the block splitting algorithm doesn’t split at all labels, so there is a jump that doesn’t point anywhere.

1 Like

I’ve moved this to the Help Category, which is also the place for general project announcements. compiler-explorer does not appear to be part of the core workflow, so it shouldn’t be in that category. If that’s not accurate, please indicate how compiler-explorer is officially associated to the core dev workflow.

1 Like

We actually do process match successfully up to python 3.12:

I’ll get it fixed for 3.13+ too. (dis output had changed slightly).
Thanks for noticing.

6 Likes

A fix is under way: Fix for py-cfg by OfekShilon · Pull Request #7922 · compiler-explorer/compiler-explorer · GitHub

4 Likes

Forgot to update here: fix is live for ~1w

2 Likes

Nice. Is there a desktop version?

A small suggestion maybe: the branching arrows from branching instructions (e.g. POP_JUMP_IF_FALSE) are not on the same level, and it would be nice if they were labelled, e.g. True/False.

@sr-murthy You can relatively easily run your own local CE instance. Here’s a guide , feel very free to reach me (or the CE discord) if you’re having problems.

1 Like