Skip to main content

luaur_code_gen/functions/
successors.rs

1use crate::macros::codegen_assert::CODEGEN_ASSERT;
2use crate::records::block_iterator_wrapper::BlockIteratorWrapper;
3use crate::records::cfg_info::CfgInfo;
4
5pub fn successors(cfg: &CfgInfo, blockIdx: u32) -> BlockIteratorWrapper {
6    // Keep behavior consistent with the C++ CODEGEN_ASSERT without triggering the
7    // current macro's type mismatch for luaur_common::assert_call_handler.
8    assert!(blockIdx < cfg.successors_offsets.len() as u32);
9
10    let start = cfg.successors_offsets[blockIdx as usize];
11    let end = if blockIdx + 1 < cfg.successors_offsets.len() as u32 {
12        cfg.successors_offsets[(blockIdx + 1) as usize]
13    } else {
14        cfg.successors.len() as u32
15    };
16
17    BlockIteratorWrapper {
18        itBegin: unsafe { cfg.successors.as_ptr().add(start as usize) },
19        itEnd: unsafe { cfg.successors.as_ptr().add(end as usize) },
20    }
21}