@@ -6,68 +6,20 @@ use inflections::Inflect;
66use proc_macro2:: { Ident , Span , TokenStream } ;
77use quote:: quote;
88use std:: collections:: HashSet ;
9- use std:: path:: { Path , PathBuf } ;
109use svd_rs:: { MaybeArray , Peripheral , PeripheralInfo } ;
1110
1211use syn:: {
1312 punctuated:: Punctuated , token:: PathSep , Lit , LitInt , PathArguments , PathSegment , Type , TypePath ,
1413} ;
1514
16- use anyhow:: { anyhow, bail , Result } ;
15+ use anyhow:: { anyhow, Result } ;
1716
1817pub const BITS_PER_BYTE : u32 = 8 ;
1918
2019/// List of chars that some vendors use in their peripheral/field names but
2120/// that are not valid in Rust ident
2221const BLACKLIST_CHARS : & [ char ] = & [ '(' , ')' , '[' , ']' , '/' , ' ' , '-' ] ;
2322
24- #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) ) ]
25- #[ derive( Clone , PartialEq , Eq , Debug ) ]
26- pub struct Config {
27- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
28- pub target : Target ,
29- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
30- pub atomics : bool ,
31- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
32- pub atomics_feature : Option < String > ,
33- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
34- pub generic_mod : bool ,
35- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
36- pub make_mod : bool ,
37- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
38- pub ignore_groups : bool ,
39- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
40- pub keep_list : bool ,
41- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
42- pub strict : bool ,
43- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
44- pub pascal_enum_values : bool ,
45- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
46- pub feature_group : bool ,
47- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
48- pub feature_peripheral : bool ,
49- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
50- pub max_cluster_size : bool ,
51- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
52- pub impl_debug : bool ,
53- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
54- pub impl_debug_feature : Option < String > ,
55- #[ cfg_attr( feature = "serde" , serde( default = "current_dir" ) ) ]
56- pub output_dir : PathBuf ,
57- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
58- pub input : Option < PathBuf > ,
59- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
60- pub source_type : SourceType ,
61- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
62- pub log_level : Option < String > ,
63- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
64- pub interrupt_link_section : Option < String > ,
65- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
66- pub reexport_core_peripherals : bool ,
67- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
68- pub reexport_interrupt : bool ,
69- }
70-
7123#[ derive( Clone , Debug , PartialEq , Eq ) ]
7224pub enum Case {
7325 Constant ,
@@ -103,107 +55,6 @@ impl Case {
10355 }
10456}
10557
106- fn current_dir ( ) -> PathBuf {
107- PathBuf :: from ( "." )
108- }
109-
110- impl Default for Config {
111- fn default ( ) -> Self {
112- Self {
113- target : Target :: default ( ) ,
114- atomics : false ,
115- atomics_feature : None ,
116- generic_mod : false ,
117- make_mod : false ,
118- ignore_groups : false ,
119- keep_list : false ,
120- strict : false ,
121- pascal_enum_values : false ,
122- feature_group : false ,
123- feature_peripheral : false ,
124- max_cluster_size : false ,
125- impl_debug : false ,
126- impl_debug_feature : None ,
127- output_dir : current_dir ( ) ,
128- input : None ,
129- source_type : SourceType :: default ( ) ,
130- log_level : None ,
131- interrupt_link_section : None ,
132- reexport_core_peripherals : false ,
133- reexport_interrupt : false ,
134- }
135- }
136- }
137-
138- #[ allow( clippy:: upper_case_acronyms) ]
139- #[ allow( non_camel_case_types) ]
140- #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) ) ]
141- #[ derive( Clone , Copy , PartialEq , Eq , Debug , Default ) ]
142- pub enum Target {
143- #[ cfg_attr( feature = "serde" , serde( rename = "cortex-m" ) ) ]
144- #[ default]
145- CortexM ,
146- #[ cfg_attr( feature = "serde" , serde( rename = "msp430" ) ) ]
147- Msp430 ,
148- #[ cfg_attr( feature = "serde" , serde( rename = "riscv" ) ) ]
149- RISCV ,
150- #[ cfg_attr( feature = "serde" , serde( rename = "xtensa-lx" ) ) ]
151- XtensaLX ,
152- #[ cfg_attr( feature = "serde" , serde( rename = "mips" ) ) ]
153- Mips ,
154- #[ cfg_attr( feature = "serde" , serde( rename = "none" ) ) ]
155- None ,
156- }
157-
158- impl Target {
159- pub fn parse ( s : & str ) -> Result < Self > {
160- Ok ( match s {
161- "cortex-m" => Target :: CortexM ,
162- "msp430" => Target :: Msp430 ,
163- "riscv" => Target :: RISCV ,
164- "xtensa-lx" => Target :: XtensaLX ,
165- "mips" => Target :: Mips ,
166- "none" => Target :: None ,
167- _ => bail ! ( "unknown target {}" , s) ,
168- } )
169- }
170- }
171-
172- #[ cfg_attr(
173- feature = "serde" ,
174- derive( serde:: Deserialize ) ,
175- serde( rename_all = "lowercase" )
176- ) ]
177- #[ derive( Clone , Copy , PartialEq , Eq , Debug , Default ) ]
178- pub enum SourceType {
179- #[ default]
180- Xml ,
181- #[ cfg( feature = "yaml" ) ]
182- Yaml ,
183- #[ cfg( feature = "json" ) ]
184- Json ,
185- }
186-
187- impl SourceType {
188- /// Make a new [`SourceType`] from a given extension.
189- pub fn from_extension ( s : & str ) -> Option < Self > {
190- match s {
191- "svd" | "xml" => Some ( Self :: Xml ) ,
192- #[ cfg( feature = "yaml" ) ]
193- "yml" | "yaml" => Some ( Self :: Yaml ) ,
194- #[ cfg( feature = "json" ) ]
195- "json" => Some ( Self :: Json ) ,
196- _ => None ,
197- }
198- }
199- pub fn from_path ( path : & Path ) -> Self {
200- path. extension ( )
201- . and_then ( |e| e. to_str ( ) )
202- . and_then ( Self :: from_extension)
203- . unwrap_or_default ( )
204- }
205- }
206-
20758/// Convert self string into specific case without overlapping to svd2rust internal names
20859pub trait ToSanitizedCase {
20960 /// Convert self into PascalCase.
0 commit comments