@@ -30,10 +30,17 @@ use crate::get_encoder_config;
3030
3131const VAL_LVL : ValidateLevel = ValidateLevel :: Weak ;
3232
33+ #[ non_exhaustive]
34+ #[ derive( Clone , Debug , Default ) ]
35+ pub struct Config {
36+ pub show_patch_on_error : bool ,
37+ }
38+
3339pub fn process_file (
3440 yaml_file : & Path ,
3541 out_path : Option < & Path > ,
3642 format_config : Option < & Path > ,
43+ config : & Config ,
3744) -> Result < ( ) > {
3845 // Load the specified YAML root file
3946 let f = File :: open ( yaml_file) ?;
@@ -61,16 +68,25 @@ pub fn process_file(
6168 let f = File :: open ( svdpath) ?;
6269 let mut contents = String :: new ( ) ;
6370 ( & f) . read_to_string ( & mut contents) ?;
64- let mut config = svd_parser:: Config :: default ( ) ;
65- config . validate_level = ValidateLevel :: Disabled ;
66- let mut svd = svd_parser:: parse_with_config ( & contents, & config ) ?;
71+ let mut parser_config = svd_parser:: Config :: default ( ) ;
72+ parser_config . validate_level = ValidateLevel :: Disabled ;
73+ let mut svd = svd_parser:: parse_with_config ( & contents, & parser_config ) ?;
6774
6875 // Load all included YAML files
6976 yaml_includes ( root) ?;
7077
7178 // Process device
72- svd. process ( root, true )
73- . with_context ( || format ! ( "Processing device `{}`" , svd. name) ) ?;
79+ svd. process ( root, true ) . with_context ( || {
80+ let name = & svd. name ;
81+ let mut out_str = String :: new ( ) ;
82+ let mut emitter = yaml_rust:: YamlEmitter :: new ( & mut out_str) ;
83+ emitter. dump ( & Yaml :: Hash ( root. clone ( ) ) ) . unwrap ( ) ;
84+ if config. show_patch_on_error {
85+ format ! ( "Processing device `{name}`. Patches looks like:\n {out_str}" )
86+ } else {
87+ format ! ( "Processing device `{name}`" )
88+ }
89+ } ) ?;
7490
7591 // SVD should now be updated, write it out
7692 let config = get_encoder_config ( format_config) ?;
0 commit comments