Skip to content

Commit 27b36d2

Browse files
committed
wip
1 parent c4dbcab commit 27b36d2

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

avm-transpiler/src/opcodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// All AVM opcodes
22
/// Keep updated with TS, cpp, and docs protocol specs!
33
#[allow(clippy::upper_case_acronyms, dead_code)]
4-
#[derive(PartialEq, Copy, Clone, Debug)]
4+
#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash)]
55
pub enum AvmOpcode {
66
// Compute
77
ADD,

avm-transpiler/src/transpile_contract.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl From<CompiledAcirContractArtifact> for TranspiledContractArtifact {
100100
let acir_program = function.bytecode;
101101
let brillig_bytecode = extract_brillig_from_acir_program(&acir_program);
102102
let assert_messages = extract_static_assert_messages(&acir_program);
103+
info!("Extracted Brillig program has {} instructions", brillig_bytecode.len());
103104

104105
// Map Brillig pcs to AVM pcs (index is Brillig PC, value is AVM PC)
105106
let brillig_pcs_to_avm_pcs = map_brillig_pcs_to_avm_pcs(brillig_bytecode);
@@ -118,7 +119,7 @@ impl From<CompiledAcirContractArtifact> for TranspiledContractArtifact {
118119
let _ = encoder.read_to_end(&mut compressed_avm_bytecode);
119120

120121
log::info!(
121-
"{}::{}: compressed {} to {} bytes ({}% reduction)",
122+
"{}::{}: bytecode size of {} was compressed to {} ({}% reduction)",
122123
contract.name,
123124
function.name,
124125
avm_bytecode.len(),

avm-transpiler/src/utils.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use fxhash::FxHashMap as HashMap;
22

33
use acvm::acir::circuit::brillig::BrilligFunctionId;
44
use acvm::FieldElement;
5-
use log::debug;
5+
use log::{debug, info, trace};
66

77
use acvm::acir::brillig::Opcode as BrilligOpcode;
88
use acvm::acir::circuit::{AssertionPayload, Opcode, Program};
99

1010
use crate::instructions::AvmInstruction;
11+
use crate::opcodes::AvmOpcode;
1112

1213
/// Extract the Brillig program from its `Program` wrapper.
1314
/// Noir entry point unconstrained functions are compiled to their own list contained
@@ -67,16 +68,25 @@ pub fn extract_static_assert_messages(program: &Program<FieldElement>) -> HashMa
6768

6869
/// Print inputs, outputs, and instructions in a Brillig program
6970
pub fn dbg_print_brillig_program(brillig_bytecode: &[BrilligOpcode<FieldElement>]) {
70-
debug!("Printing Brillig program...");
71+
trace!("Printing Brillig program...");
7172
for (i, instruction) in brillig_bytecode.iter().enumerate() {
72-
debug!("\tPC:{0} {1:?}", i, instruction);
73+
trace!("\tPC:{0} {1:?}", i, instruction);
7374
}
7475
}
7576

7677
/// Print each instruction in an AVM program
7778
pub fn dbg_print_avm_program(avm_program: &[AvmInstruction]) {
78-
debug!("Printing AVM program...");
79+
info!("Transpiled AVM program has {} instructions", avm_program.len());
80+
trace!("Printing AVM program...");
81+
let mut counts = std::collections::HashMap::<AvmOpcode, usize>::new();
7982
for (i, instruction) in avm_program.iter().enumerate() {
80-
debug!("\tPC:{0}: {1}", i, &instruction.to_string());
83+
trace!("\tPC:{0}: {1}", i, &instruction.to_string());
84+
*counts.entry(instruction.opcode).or_insert(0) += 1;
85+
}
86+
debug!("AVM opcode counts:");
87+
let mut sorted_counts: Vec<_> = counts.into_iter().collect();
88+
sorted_counts.sort_by_key(|(_, count)| -(*count as isize));
89+
for (opcode, count) in sorted_counts {
90+
debug!("\t{0:?}: {1}", opcode, count);
8191
}
8292
}

0 commit comments

Comments
 (0)