Conversation
This introduces a type for control-flow graphs made up of basic blocks that can include the same sorts of commands that structured statements do. It includes a translation from structured statements to unstructured CFGs.
tautschnig
left a comment
There was a problem hiding this comment.
What will be the semantics of jumping into a block while skipping over a declaration? In C one can do:
goto lab;
int x = 42;
lab: ++x; // x is considered declared, but is uninitialisedI believe programs like the above can now be represented, but we also need to be clear on their semantics.
You caught one of the key reasons I hadn't moved this from a draft yet! My current plan is to require that declarations be procedure-level when translating to CFG, but I haven't yet decided how best to enforce that. As you've probably noticed, the example you commented on with the errant comma has an |
Labels exist only in CFGs now, not blocks themselves.
Fewer `[] .goto l` blocks
On further thought, I'm happy with how the semantics for this work out (as specified in the new |
MikaelMayer
left a comment
There was a problem hiding this comment.
A few things that could make our life easier down the road. My strong recommendation to have only non deterministic blocks since deterministic blocks are a subset of them.
I love to see that there are semantics as well, haven't checked them though.
Add Control-Flow Graph (CFG) Support to Imperative Dialect
This PR introduces unstructured control-flow graph representation to the
Imperative dialect, enabling transformation from structured statements to
basic blocks with explicit control flow.
Key Changes
New Core Components:
BasicBlock.lean - Defines CFG structure with deterministic and non-
deterministic basic blocks
CFGSemantics.lean - Small-step operational semantics for CFGs
Transformation:
Testing:
Implementation Details
By submitting this pull request, I confirm that you can use, modify, copy,
and redistribute this contribution, under the terms of your choice.