Skip to content
4 changes: 2 additions & 2 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ pub fn compile_main(
}

if options.print_acir {
println!("Compiled ACIR for main (unoptimized):");
println!("{}", compiled_program.program);
noirc_errors::println_to_stdout!("Compiled ACIR for main (unoptimized):");
noirc_errors::println_to_stdout!("{}", compiled_program.program);
}

Ok((compiled_program, warnings))
Expand Down
30 changes: 30 additions & 0 deletions compiler/noirc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,33 @@
pub mod reporter;
pub use position::{Located, Location, Position, Span, Spanned};
pub use reporter::{CustomDiagnostic, DiagnosticKind};
use std::io::Write;

/// Print the input to stdout, and exit gracefully if `SIGPIPE` is received.

Check warning on line 12 in compiler/noirc_errors/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (SIGPIPE)
/// Rust ignores `SIGPIPE` by default, converting pipe errors into `ErrorKind::BrokenPipe`

Check warning on line 13 in compiler/noirc_errors/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (SIGPIPE)
pub fn print_to_stdout(args: std::fmt::Arguments) {
let mut stdout = std::io::stdout();
if let Err(e) = stdout.write_fmt(args) {
if e.kind() == std::io::ErrorKind::BrokenPipe {
// Gracefully exit on broken pipe
std::process::exit(0);
} else {
panic!("Unexpected error: {e}");
}
}
}

/// Macro to print formatted output to stdout
#[macro_export]
macro_rules! print_to_stdout {
($($arg:tt)*) => {
noirc_errors::print_to_stdout(format_args!($($arg)*))
};
}

#[macro_export]
macro_rules! println_to_stdout {
($($arg:tt)*) => {
noirc_errors::print_to_stdout(format_args!("{}\n", format!($($arg)*)))
};
}
5 changes: 3 additions & 2 deletions compiler/noirc_evaluator/src/ssa/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::Write;
use std::path::Path;
use std::{collections::HashMap, path::PathBuf};

use noirc_errors::println_to_stdout;
use noirc_frontend::monomorphization::ast::Program;

use crate::errors::RuntimeError;
Expand Down Expand Up @@ -201,7 +202,7 @@ impl<'local> SsaBuilder<'local> {
};

if print_ssa_pass {
println!("After {msg}:\n{}", self.ssa.print_with(self.files));
println_to_stdout!("After {msg}:\n{}", self.ssa.print_with(self.files));
}
self
}
Expand All @@ -214,7 +215,7 @@ pub(super) fn time<T>(name: &str, print_timings: bool, f: impl FnOnce() -> T) ->

if print_timings {
let end_time = chrono::Utc::now().time();
println!("{name}: {} ms", (end_time - start_time).num_milliseconds());
println_to_stdout!("{name}: {} ms", (end_time - start_time).num_milliseconds());
}

result
Expand Down
10 changes: 7 additions & 3 deletions tooling/artifact_cli/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ pub fn save_and_check_witness(
witness_dir: Option<&Path>,
witness_name: Option<&str>,
) -> Result<(), CliError> {
println!("[{circuit_name}] Circuit witness successfully solved");
noirc_errors::println_to_stdout!("[{circuit_name}] Circuit witness successfully solved");
// Save first, so that we can potentially look at the output if the expectations fail.
if let Some(witness_dir) = witness_dir {
save_witness(&results.witness_stack, circuit_name, witness_dir, witness_name)?;
}
if let Some(ref return_value) = results.return_values.actual_return {
println!("[{circuit_name}] Circuit output: {return_value:?}");
noirc_errors::println_to_stdout!("[{circuit_name}] Circuit output: {return_value:?}");
}
check_witness(circuit, results.return_values)
}
Expand All @@ -112,7 +112,11 @@ pub fn save_witness(
}
}

println!("[{}] Witness saved to {}", circuit_name, witness_path.display());
noirc_errors::println_to_stdout!(
"[{}] Witness saved to {}",
circuit_name,
witness_path.display()
);
Ok(())
}

Expand Down
Loading