From 432e6f5fffa3ad7b78070c06f1d91bd7128e73c0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 15 Nov 2024 16:22:19 +0000 Subject: [PATCH] generate another function in gen: example --- examples/gen.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/gen.rs b/examples/gen.rs index 9157f60d..f0c98070 100644 --- a/examples/gen.rs +++ b/examples/gen.rs @@ -8,8 +8,7 @@ fn zero(_hex: u8) -> Result { Ok(b'0') } -/* -fn target_function(hex: u8) -> Result { +fn dec_to_hex(hex: u8) -> Result { match hex { 0x0 => Ok(b'0'), 0x1 => Ok(b'1'), @@ -30,11 +29,26 @@ fn target_function(hex: u8) -> Result { _ => Err(StropError::Undefined), } } -*/ fn main() { let target_function = zero as fn(u8) -> Result; + // you can do a bruteforce search for Z80 machine code programs implementing the same function + let mut bruteforce = SdccCall1::::new() + // By specifying that we want a pure function, and that the function is a leaf function, we + // can constrain the search space even further + .pure() + .leaf() + .bruteforce(target_function); + + let bf = bruteforce.search().unwrap(); + + println!("An equivalent subroutine we found by bruteforce search,"); + println!("after {} iterations.", bruteforce.count); + bf.dasm(); + + let target_function = dec_to_hex as fn(u8) -> Result; + // you can do a bruteforce search for Z80 machine code programs implementing the same function let mut bruteforce = SdccCall1::::new() // By specifying that we want a pure function, and that the function is a leaf function, we @@ -46,6 +60,7 @@ fn main() { let bf = bruteforce.search().unwrap(); - println!("An equivalent subroutine we found by bruteforce search:"); + println!("An equivalent subroutine we found by bruteforce search,"); + println!("after {} iterations.", bruteforce.count); bf.dasm(); }