From 22822a0644d0884c80b4e56220ec5407f47181c6 Mon Sep 17 00:00:00 2001 From: Joss Date: Thu, 23 Mar 2023 12:22:38 +0000 Subject: [PATCH] feat(nargo) print-acir command --- crates/nargo/src/cli/mod.rs | 3 +++ crates/nargo/src/cli/print_acir_cmd.rs | 29 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 crates/nargo/src/cli/print_acir_cmd.rs diff --git a/crates/nargo/src/cli/mod.rs b/crates/nargo/src/cli/mod.rs index 27f98b33ba6..cf39d170664 100644 --- a/crates/nargo/src/cli/mod.rs +++ b/crates/nargo/src/cli/mod.rs @@ -17,6 +17,7 @@ mod execute_cmd; mod gates_cmd; mod new_cmd; mod preprocess_cmd; +mod print_acir_cmd; mod prove_cmd; mod test_cmd; mod verify_cmd; @@ -58,6 +59,7 @@ enum NargoCommand { Preprocess(preprocess_cmd::PreprocessCommand), Test(test_cmd::TestCommand), Gates(gates_cmd::GatesCommand), + PrintAcir(print_acir_cmd::PrintAcirCommand), } pub fn start_cli() -> eyre::Result<()> { @@ -77,6 +79,7 @@ pub fn start_cli() -> eyre::Result<()> { NargoCommand::Test(args) => test_cmd::run(args, config), NargoCommand::Gates(args) => gates_cmd::run(args, config), NargoCommand::CodegenVerifier(args) => codegen_verifier_cmd::run(args, config), + NargoCommand::PrintAcir(args) => print_acir_cmd::run(args, config), }?; Ok(()) diff --git a/crates/nargo/src/cli/print_acir_cmd.rs b/crates/nargo/src/cli/print_acir_cmd.rs new file mode 100644 index 00000000000..dbc0fea86de --- /dev/null +++ b/crates/nargo/src/cli/print_acir_cmd.rs @@ -0,0 +1,29 @@ +use clap::Args; +use noirc_driver::CompileOptions; +use std::path::Path; + +use crate::cli::compile_cmd::compile_circuit; +use crate::errors::CliError; + +use super::NargoConfig; + +/// Prints out the ACIR for a compiled circuit +#[derive(Debug, Clone, Args)] +pub(crate) struct PrintAcirCommand { + #[clap(flatten)] + compile_options: CompileOptions, +} + +pub(crate) fn run(args: PrintAcirCommand, config: NargoConfig) -> Result<(), CliError> { + print_acir_with_path(config.program_dir, &args.compile_options) +} + +fn print_acir_with_path>( + program_dir: P, + compile_options: &CompileOptions, +) -> Result<(), CliError> { + let compiled_program = compile_circuit(program_dir.as_ref(), compile_options)?; + println!("{}", compiled_program.circuit); + + Ok(()) +}