From fc5848c7e24a3708ed8c3c378d081895997bfb54 Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Fri, 10 Jan 2025 15:58:48 +0000 Subject: [PATCH] feat(cli): Add CLI option to filter by contract function name (#7018) --- compiler/noirc_driver/src/lib.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 87da9cd658..a7e7e2d4e2 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -73,7 +73,11 @@ 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)] + pub show_contract_fn: Option, /// Emit the unoptimized SSA IR to file. /// The IR will be dumped into the workspace target directory, @@ -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_fn { + 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_fn { + let show = name == *name_filter; + options.show_ssa &= show; + options.show_ssa_pass = options.show_ssa_pass.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)); @@ -642,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 {