Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tooling/ssa_executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ acvm.workspace = true
bn254_blackbox_solver.workspace = true
thiserror.workspace = true
nargo.workspace = true
base64.workspace = true

[features]
nargo = ["nargo/rpc"]
bls12_381 = []

[[example]]
name = "compilation"
path = "examples/compilation.rs"
22 changes: 22 additions & 0 deletions tooling/ssa_executor/examples/compilation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use noir_ssa_executor::compiler::compile_to_bytecode_base64;
use noirc_driver::CompileOptions;
use noirc_evaluator::ssa::ssa_gen::Ssa;

/// Compiles the given SSA program into an Brillig program and prints the bytecode
fn main() {
let ssa = "brillig(inline) predicate_pure fn main f0 {
b0(v0: u16, v1: Field, v2: Field, v3: Field, v4: Field, v5: u1, v6: u1):
v9 = call to_le_radix(v3, u32 256) -> [u8; 102]
v10 = call to_le_radix(v4, u32 256) -> [u8; 16]
v11 = call to_le_radix(v2, u32 256) -> [u8; 16]
v12 = call to_le_radix(v1, u32 256) -> [u8; 16]
v13 = call to_le_radix(v3, u32 256) -> [u8; 16]
v14 = cast v5 as u8
return v14
}
";
let program_bytecode =
compile_to_bytecode_base64(Ssa::from_str(ssa).unwrap(), &CompileOptions::default())
.unwrap();
println!("Bytecode: {program_bytecode}");
}
12 changes: 12 additions & 0 deletions tooling/ssa_executor/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use acvm::acir::circuit::Program;
use base64::Engine;
use noirc_abi::Abi;
use noirc_driver::{CompileError, CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING};
use noirc_errors::call_stack::CallStack;
Expand Down Expand Up @@ -100,3 +102,13 @@ pub fn compile_from_ssa(
let artifacts = optimize_ssa_into_acir(ssa, options.as_ssa_options(PathBuf::new()))?;
Ok(compile_from_artifacts(artifacts))
}

pub fn compile_to_bytecode_base64(
ssa: Ssa,
options: &CompileOptions,
) -> Result<String, CompileError> {
let compiled_program = compile_from_ssa(ssa, options)?;
let bytecode = Program::serialize_program(&compiled_program.program);
let bytecode_b64 = base64::engine::general_purpose::STANDARD.encode(bytecode);
Ok(bytecode_b64)
}
Loading