@@ -2,12 +2,13 @@ use fxhash::FxHashMap as HashMap;
22
33use acvm:: acir:: circuit:: brillig:: BrilligFunctionId ;
44use acvm:: FieldElement ;
5- use log:: debug;
5+ use log:: { debug, info , trace } ;
66
77use acvm:: acir:: brillig:: Opcode as BrilligOpcode ;
88use acvm:: acir:: circuit:: { AssertionPayload , Opcode , Program } ;
99
1010use 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
6970pub 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 ! ( "\t PC:{0} {1:?}" , i, instruction) ;
73+ trace ! ( "\t PC:{0} {1:?}" , i, instruction) ;
7374 }
7475}
7576
7677/// Print each instruction in an AVM program
7778pub 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 ! ( "\t PC:{0}: {1}" , i, & instruction. to_string( ) ) ;
83+ trace ! ( "\t PC:{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