Constructs a randomly-generated `GenericFunction`. This function is guaranteed to pass validation with the given (valid) [`RegInfo`] implementation.
(
reginfo: &impl RegInfo,
u: &mut Unstructured<'_>,
config: ArbitraryFunctionConfig,
)
| 71 | /// This function is guaranteed to pass validation with the given (valid) |
| 72 | /// [`RegInfo`] implementation. |
| 73 | pub fn arbitrary_with_config( |
| 74 | reginfo: &impl RegInfo, |
| 75 | u: &mut Unstructured<'_>, |
| 76 | config: ArbitraryFunctionConfig, |
| 77 | ) -> Result<Self> { |
| 78 | let mut builder = FunctionBuilder::new(u, reginfo, config); |
| 79 | builder.gen_cfg_skeleton()?; |
| 80 | builder.block_insts.grow_to(builder.func.num_blocks()); |
| 81 | builder.defs_by_blocks.grow_to(builder.func.num_blocks()); |
| 82 | |
| 83 | let postorder = PostOrder::for_function(&builder.func); |
| 84 | builder.domtree.compute(&builder.func, &postorder); |
| 85 | |
| 86 | builder.add_blockparams()?; |
| 87 | |
| 88 | for block in postorder.cfg_postorder() { |
| 89 | builder.func.blocks[block].immediate_dominator = |
| 90 | builder.domtree.immediate_dominator(block).into(); |
| 91 | builder.gen_block_insts(block)?; |
| 92 | } |
| 93 | |
| 94 | // Generate some unused values. |
| 95 | for _ in 0..builder.u.int_in_range(0..=10)? { |
| 96 | let bank = RegBank::new(builder.u.choose_index(reginfo.num_banks())?); |
| 97 | builder.new_value(bank)?; |
| 98 | } |
| 99 | |
| 100 | builder.finalize()?; |
| 101 | |
| 102 | Ok(builder.func) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | struct FunctionBuilder<'a, 'b, R> { |
nothing calls this directly
no test coverage detected