let split_basic_block stmt =
let statement_list = match stmt.il0_t with
IL0stmtSequence is -> is
| _ -> [stmt] in
let rec get_label = function
[], [] -> []
| [], l -> get_body [] l
| result, [] -> [List.rev result]
| result, ({ il0_t = (IL0stmtLabel _) } as stmt)::l -> get_label( stmt::result, l )
| result, l -> get_body result l
and get_body result = function
[] -> [List.rev result]
| stmt::l ->
match stmt.il0_t with
IL0stmtLabel _ -> (List.rev result)::get_label( [stmt], l )
| IL0stmtIf _ |
IL0stmtSwitch _ |
IL0stmtGoto _ |
IL0stmtReturn _ -> (List.rev (stmt::result))::get_label( [], l )
| _ ->
assert stmt.il0_nobranch;
get_body (stmt::result) l
in
get_label( [], statement_list@[make_il0 (IL0stmtReturn None)] )