-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
317 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "noir_inspector" | ||
description = "Inspector for noir build artifacts" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
rust-version.workspace = true | ||
repository.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[[bin]] | ||
name = "noir-inspector" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
clap.workspace = true | ||
serde.workspace = true | ||
serde_json.workspace = true | ||
color-eyre.workspace = true | ||
const_format.workspace = true | ||
acir.workspace = true | ||
noirc_artifacts.workspace = true | ||
noirc_artifacts_info.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Args; | ||
use color_eyre::eyre; | ||
use noirc_artifacts::program::ProgramArtifact; | ||
use noirc_artifacts_info::{count_opcodes_and_gates_in_program, show_info_report, InfoReport}; | ||
|
||
#[derive(Debug, Clone, Args)] | ||
pub(crate) struct InfoCommand { | ||
/// The artifact to inspect | ||
artifact: PathBuf, | ||
|
||
/// Output a JSON formatted report. Changes to this format are not currently considered breaking. | ||
#[clap(long, hide = true)] | ||
json: bool, | ||
} | ||
|
||
pub(crate) fn run(args: InfoCommand) -> eyre::Result<()> { | ||
let file = std::fs::File::open(args.artifact.clone())?; | ||
let artifact: ProgramArtifact = serde_json::from_reader(file)?; | ||
|
||
let package_name = args | ||
.artifact | ||
.with_extension("") | ||
.file_name() | ||
.map(|s| s.to_string_lossy().to_string()) | ||
.unwrap_or_else(|| "artifact".to_string()); | ||
|
||
let program_info = count_opcodes_and_gates_in_program(artifact, package_name.to_string(), None); | ||
|
||
let info_report = InfoReport { programs: vec![program_info] }; | ||
show_info_report(info_report, args.json); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use clap::{command, Parser, Subcommand}; | ||
use color_eyre::eyre; | ||
use const_format::formatcp; | ||
|
||
mod info_cmd; | ||
mod print_acir_cmd; | ||
|
||
const INSPECTOR_VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
|
||
static VERSION_STRING: &str = formatcp!("version = {}\n", INSPECTOR_VERSION,); | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(name="Noir inspector", author, version=VERSION_STRING, about, long_about = None)] | ||
struct InspectorCli { | ||
#[command(subcommand)] | ||
command: InspectorCommand, | ||
} | ||
|
||
#[non_exhaustive] | ||
#[derive(Subcommand, Clone, Debug)] | ||
enum InspectorCommand { | ||
Info(info_cmd::InfoCommand), | ||
PrintAcir(print_acir_cmd::PrintAcirCommand), | ||
} | ||
|
||
pub(crate) fn start_cli() -> eyre::Result<()> { | ||
let InspectorCli { command } = InspectorCli::parse(); | ||
|
||
match command { | ||
InspectorCommand::Info(args) => info_cmd::run(args), | ||
InspectorCommand::PrintAcir(args) => print_acir_cmd::run(args), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Args; | ||
use color_eyre::eyre; | ||
use noirc_artifacts::program::ProgramArtifact; | ||
|
||
#[derive(Debug, Clone, Args)] | ||
pub(crate) struct PrintAcirCommand { | ||
/// The artifact to print | ||
artifact: PathBuf, | ||
} | ||
|
||
pub(crate) fn run(args: PrintAcirCommand) -> eyre::Result<()> { | ||
let file = std::fs::File::open(args.artifact.clone())?; | ||
let artifact: ProgramArtifact = serde_json::from_reader(file)?; | ||
|
||
println!("Compiled ACIR for main:"); | ||
println!("{}", artifact.bytecode); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod cli; | ||
|
||
fn main() { | ||
if let Err(report) = cli::start_cli() { | ||
eprintln!("{report:?}"); | ||
std::process::exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.