[−][src]Module c2rust_transpile::cfg
Control Flow Graph analysis
Through switch
/case
/default
and labels/goto
, the C language supports jumping directly
from one position in the code to another. Rust supports on structured control flow constructs.
This means that during translation, we need to somehow eliminate the unstructured control-flow
constructs C has. This module is where that happens.
In a nutshell, here are the steps:
- given an entry point C statement, translate it into a CFG consisting of
BasicBlock<Label>
- simplify this CFG (by eliminating empty blocks that jump unconditionally to the next block)
- use the Relooper algorithm to convert this CFG into a sequence of
Structure<StmtOrDecl>
s - place the declarations in the right place and produce a sequence of
Structure<Stmt>
s - simplify that sequence of
Structure<Stmt>
s into another such sequence - convert the
Vec<Structure<Stmt>>
back into aVec<Stmt>
Modules
loops | This module contains stuff related to choosing better loops in Relooper. The problem is simple:
there is a point in the relooper algorithm where we commit to making a |
multiples | This module contains stuff related to preserving and using information from the initial C
source to better decide when to produce |
relooper | This modules handles converting a a control-flow graph |
structures | This modules handles converting |
Structs
BasicBlock | Generalized basic block. |
Cfg | A CFG graph of regular basic blocks. |
DeclStmtInfo | This contains the information one needs to convert a C declaration in all the possible ways: |
DeclStmtStore | Stores information about translating C declarations to Rust statements. When seeing a C
declaration, we often don't know if it is already in the right place. The fix is to punt: we
put into a |
SwitchCases | The sole purpose of this structure is to accumulate information about what cases/default have been seen which translating the body of the switch. |
Enums
GenTerminator | Represents the control flow choices one can make when at the end of a |
ImplicitReturnType | Reaching the end of a body without encountering a |
Label | These labels identify basic blocks in a regular CFG. |
StmtOrComment | A Rust statement, or a comment |
StmtOrDecl | A Rust statement, or a C declaration, or a comment |
Structure | These are the things that the relooper algorithm produces. |
StructureLabel | These labels identify structure basic blocks in a structure CFG. |