ng/
ng.rs

1//! An example of a program that uses strop to generate machine code computing a given function
2
3use strop::Disassemble;
4use strop::RunError;
5use strop::RunResult;
6use strop::ToBruteForce;
7use strop::ToTrace;
8
9fn zero(i: u8) -> RunResult<u8> {
10    i.checked_add(5).ok_or(RunError::NotDefined)
11}
12
13fn main() {
14    let target_function = zero as fn(u8) -> RunResult<u8>;
15
16    // do a bruteforce search for Z80 machine code programs implementing the same function
17    let mut bruteforce = strop::mips::O32::default()
18        .trace()
19        .to_bruteforce(target_function);
20
21    let bf = bruteforce.search().unwrap();
22
23    println!("An equivalent subroutine we found by bruteforce search,");
24    println!("after {} iterations.", bruteforce.count);
25    bf.dasm();
26}