@@ -287,6 +287,7 @@ where
287287 let ssa_gen_span_guard = ssa_gen_span. enter ( ) ;
288288 let mut builder = builder. with_skip_passes ( options. skip_passes . clone ( ) ) . run_passes ( primary) ?;
289289 let passed = std:: mem:: take ( & mut builder. passed ) ;
290+ let files = builder. files ;
290291 let mut ssa = builder. finish ( ) ;
291292
292293 let mut ssa_level_warnings = vec ! [ ] ;
@@ -300,12 +301,16 @@ where
300301 let ssa_gen_span = span ! ( Level :: TRACE , "ssa_generation" ) ;
301302 let ssa_gen_span_guard = ssa_gen_span. enter ( ) ;
302303
303- let mut ssa =
304- SsaBuilder :: from_ssa ( ssa, options. ssa_logging . clone ( ) , options. print_codegen_timings )
305- . with_passed ( passed)
306- . with_skip_passes ( options. skip_passes . clone ( ) )
307- . run_passes ( & secondary ( & brillig) ) ?
308- . finish ( ) ;
304+ let mut ssa = SsaBuilder :: from_ssa (
305+ ssa,
306+ options. ssa_logging . clone ( ) ,
307+ options. print_codegen_timings ,
308+ files,
309+ )
310+ . with_passed ( passed)
311+ . with_skip_passes ( options. skip_passes . clone ( ) )
312+ . run_passes ( & secondary ( & brillig) ) ?
313+ . finish ( ) ;
309314
310315 if !options. skip_underconstrained_check {
311316 ssa_level_warnings. extend ( time (
@@ -353,6 +358,7 @@ pub fn optimize_into_acir<S>(
353358 options : & SsaEvaluatorOptions ,
354359 primary : & [ SsaPass ] ,
355360 secondary : S ,
361+ files : Option < & fm:: FileManager > ,
356362) -> Result < ArtifactsAndWarnings , RuntimeError >
357363where
358364 S : for < ' b > Fn ( & ' b Brillig ) -> Vec < SsaPass < ' b > > ,
@@ -362,6 +368,7 @@ where
362368 options. ssa_logging . clone ( ) ,
363369 options. print_codegen_timings ,
364370 & options. emit_ssa ,
371+ files,
365372 ) ?;
366373
367374 optimize_ssa_builder_into_acir ( builder, options, primary, secondary)
@@ -436,8 +443,9 @@ impl SsaProgramArtifact {
436443pub fn create_program (
437444 program : Program ,
438445 options : & SsaEvaluatorOptions ,
446+ files : Option < & fm:: FileManager > ,
439447) -> Result < SsaProgramArtifact , RuntimeError > {
440- create_program_with_passes ( program, options, & primary_passes ( options) , secondary_passes)
448+ create_program_with_passes ( program, options, & primary_passes ( options) , secondary_passes, files )
441449}
442450
443451/// Compiles the [`Program`] into [`ACIR`][acvm::acir::circuit::Program] using the minimum amount of SSA passes.
@@ -448,6 +456,7 @@ pub fn create_program(
448456pub fn create_program_with_minimal_passes (
449457 program : Program ,
450458 options : & SsaEvaluatorOptions ,
459+ files : & fm:: FileManager ,
451460) -> Result < SsaProgramArtifact , RuntimeError > {
452461 for func in & program. functions {
453462 assert ! (
@@ -456,7 +465,7 @@ pub fn create_program_with_minimal_passes(
456465 func. name
457466 ) ;
458467 }
459- create_program_with_passes ( program, options, & minimal_passes ( ) , |_| vec ! [ ] )
468+ create_program_with_passes ( program, options, & minimal_passes ( ) , |_| vec ! [ ] , Some ( files ) )
460469}
461470
462471/// Compiles the [`Program`] into [`ACIR`][acvm::acir::circuit::Program] by running it through
@@ -467,6 +476,7 @@ pub fn create_program_with_passes<S>(
467476 options : & SsaEvaluatorOptions ,
468477 primary : & [ SsaPass ] ,
469478 secondary : S ,
479+ files : Option < & fm:: FileManager > ,
470480) -> Result < SsaProgramArtifact , RuntimeError >
471481where
472482 S : for < ' b > Fn ( & ' b Brillig ) -> Vec < SsaPass < ' b > > ,
@@ -480,7 +490,7 @@ where
480490 let ArtifactsAndWarnings (
481491 ( generated_acirs, generated_brillig, brillig_function_names, error_types) ,
482492 ssa_level_warnings,
483- ) = optimize_into_acir ( program, options, primary, secondary) ?;
493+ ) = optimize_into_acir ( program, options, primary, secondary, files ) ?;
484494
485495 assert_eq ! (
486496 generated_acirs. len( ) ,
@@ -630,7 +640,7 @@ fn split_public_and_private_inputs(
630640}
631641
632642// This is just a convenience object to bundle the ssa with `print_ssa_passes` for debug printing.
633- pub struct SsaBuilder {
643+ pub struct SsaBuilder < ' local > {
634644 /// The SSA being built; it is the input and the output of every pass ran by the builder.
635645 pub ssa : Ssa ,
636646 /// Options to control which SSA passes to print.
@@ -642,14 +652,19 @@ pub struct SsaBuilder {
642652 pub passed : HashMap < String , usize > ,
643653 /// List of SSA pass message fragments that we want to skip, for testing purposes.
644654 pub skip_passes : Vec < String > ,
655+
656+ /// Providing a file manager is optional - if provided it can be used to print source
657+ /// locations along with each ssa instructions when debugging.
658+ pub files : Option < & ' local fm:: FileManager > ,
645659}
646660
647- impl SsaBuilder {
661+ impl < ' local > SsaBuilder < ' local > {
648662 pub fn from_program (
649663 program : Program ,
650664 ssa_logging : SsaLogging ,
651665 print_codegen_timings : bool ,
652666 emit_ssa : & Option < PathBuf > ,
667+ files : Option < & ' local fm:: FileManager > ,
653668 ) -> Result < Self , RuntimeError > {
654669 let ssa = ssa_gen:: generate_ssa ( program) ?;
655670 if let Some ( emit_ssa) = emit_ssa {
@@ -661,14 +676,20 @@ impl SsaBuilder {
661676 let ssa_path = emit_ssa. with_extension ( "ssa.json" ) ;
662677 write_to_file ( & serde_json:: to_vec ( & ssa) . unwrap ( ) , & ssa_path) ;
663678 }
664- Ok ( Self :: from_ssa ( ssa, ssa_logging, print_codegen_timings) . print ( "Initial SSA" ) )
679+ Ok ( Self :: from_ssa ( ssa, ssa_logging, print_codegen_timings, files ) . print ( "Initial SSA" ) )
665680 }
666681
667- pub fn from_ssa ( ssa : Ssa , ssa_logging : SsaLogging , print_codegen_timings : bool ) -> Self {
682+ pub fn from_ssa (
683+ ssa : Ssa ,
684+ ssa_logging : SsaLogging ,
685+ print_codegen_timings : bool ,
686+ files : Option < & ' local fm:: FileManager > ,
687+ ) -> Self {
668688 Self {
669689 ssa_logging,
670690 print_codegen_timings,
671691 ssa,
692+ files,
672693 passed : Default :: default ( ) ,
673694 skip_passes : Default :: default ( ) ,
674695 }
@@ -745,7 +766,7 @@ impl SsaBuilder {
745766 } ;
746767
747768 if print_ssa_pass {
748- println ! ( "After {msg}:\n {}" , self . ssa) ;
769+ println ! ( "After {msg}:\n {}" , self . ssa. print_with ( self . files ) ) ;
749770 }
750771 self
751772 }
0 commit comments