From 07391e76ae5a3290efcd42aa3122b70b2754ca11 Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Fri, 10 Jan 2025 14:27:08 +0000 Subject: [PATCH 1/3] Add CLI option to filter by contract function name --- compiler/noirc_driver/src/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 87da9cd658..b8a5b17629 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -75,6 +75,10 @@ pub struct CompileOptions { #[arg(long, hide = true)] pub show_ssa_pass_name: Option, + /// Only show the SSA and ACIR for the contract function with a given name. + #[arg(long, hide = true)] + pub show_contract_function_name: Option, + /// Emit the unoptimized SSA IR to file. /// The IR will be dumped into the workspace target directory, /// under `[compiled-package].ssa.json`. @@ -442,6 +446,11 @@ pub fn compile_contract( if options.print_acir { for contract_function in &compiled_contract.functions { + if let Some(ref name) = options.show_contract_function_name { + if name != &contract_function.name { + continue; + } + } println!( "Compiled ACIR for {}::{} (unoptimized):", compiled_contract.name, contract_function.name @@ -486,7 +495,15 @@ fn compile_contract_inner( continue; } - let function = match compile_no_check(context, options, function_id, None, true) { + let mut options = options.clone(); + + if let Some(ref name_filter) = options.show_contract_function_name { + let show = name == *name_filter; + options.show_ssa &= show; + options.show_ssa_pass_name = options.show_ssa_pass_name.filter(|_| show); + }; + + let function = match compile_no_check(context, &options, function_id, None, true) { Ok(function) => function, Err(new_error) => { errors.push(FileDiagnostic::from(new_error)); From 7bacc7d2fa2a2a2cd353d7fe7678e38e27cb333b Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Fri, 10 Jan 2025 15:46:58 +0000 Subject: [PATCH 2/3] Shorten it to show_contract_fn --- compiler/noirc_driver/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index b8a5b17629..2970027c98 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -77,7 +77,7 @@ pub struct CompileOptions { /// Only show the SSA and ACIR for the contract function with a given name. #[arg(long, hide = true)] - pub show_contract_function_name: Option, + pub show_contract_fn: Option, /// Emit the unoptimized SSA IR to file. /// The IR will be dumped into the workspace target directory, @@ -446,7 +446,7 @@ pub fn compile_contract( if options.print_acir { for contract_function in &compiled_contract.functions { - if let Some(ref name) = options.show_contract_function_name { + if let Some(ref name) = options.show_contract_fn { if name != &contract_function.name { continue; } @@ -497,7 +497,7 @@ fn compile_contract_inner( let mut options = options.clone(); - if let Some(ref name_filter) = options.show_contract_function_name { + if let Some(ref name_filter) = options.show_contract_fn { let show = name == *name_filter; options.show_ssa &= show; options.show_ssa_pass_name = options.show_ssa_pass_name.filter(|_| show); From 979eaa52e649735f6a690db1a87005dd9e10540d Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Fri, 10 Jan 2025 15:48:35 +0000 Subject: [PATCH 3/3] Shorten it to show_ssa_pass --- compiler/noirc_driver/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 2970027c98..a7e7e2d4e2 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -73,7 +73,7 @@ pub struct CompileOptions { /// Only show SSA passes whose name contains the provided string. /// This setting takes precedence over `show_ssa` if it's not empty. #[arg(long, hide = true)] - pub show_ssa_pass_name: Option, + pub show_ssa_pass: Option, /// Only show the SSA and ACIR for the contract function with a given name. #[arg(long, hide = true)] @@ -500,7 +500,7 @@ fn compile_contract_inner( if let Some(ref name_filter) = options.show_contract_fn { let show = name == *name_filter; options.show_ssa &= show; - options.show_ssa_pass_name = options.show_ssa_pass_name.filter(|_| show); + options.show_ssa_pass = options.show_ssa_pass.filter(|_| show); }; let function = match compile_no_check(context, &options, function_id, None, true) { @@ -659,7 +659,7 @@ pub fn compile_no_check( let return_visibility = program.return_visibility; let ssa_evaluator_options = noirc_evaluator::ssa::SsaEvaluatorOptions { - ssa_logging: match &options.show_ssa_pass_name { + ssa_logging: match &options.show_ssa_pass { Some(string) => SsaLogging::Contains(string.clone()), None => { if options.show_ssa {