CFG
TODOs
-
CFG AST Each of the functions has a separate CFG, hence the AST could be something like this: pub type CFG = Vec<CFGFunction>; pub type CFGFunction = Vec<CFGBlock>; pub type BlockIndex = usize; pub struct CFGBlock{ instructions: Vec<Instruction>, prev: BlockIndex, next: Vec<BlockIndex> // either 0 (fn end), 1 or 2 (jmpif) successors }; impl CFGBlock { pub fn instructions(&self) -> &Vec<Instruction> {} pub fn predecessors(&self) -> Vec<BlockIndex> {} pub fn successors(&self) -> Vec<BlockIndex> {} }
-
IR -> CFG Could be implemented roughly as follows: - loop over IR and collect Functions/Blocks
- a FnLabel starts a new CFGFunction (and Block) and ends the previous one
- a Label starts a new Block and ends the previous one
- Jmp adds an edge to the Block of the jump target
- JmpIf adds an edge to the next Block and the target Block
-
CFG traversal/visitor methods I.e. each function provides a block visitor and each block an instruction visitor. -
CFG -> IR -
CFG -> DOT