@@ -4885,6 +4885,8 @@ impl VerylWalker for Emitter {
48854885 } else {
48864886 unreachable ! ( )
48874887 } ;
4888+ let empty_header =
4889+ arg. module_declaration_opt1 . is_none ( ) && arg. module_declaration_opt2 . is_none ( ) ;
48884890
48894891 let maps = self . get_generic_maps ( & symbol. found ) ;
48904892 for ( i, map) in maps. iter ( ) . enumerate ( ) {
@@ -4922,7 +4924,7 @@ impl VerylWalker for Emitter {
49224924
49234925 let mut import_declarations = self . file_scope_import . clone ( ) ;
49244926 import_declarations. append ( & mut arg. collect_import_declarations ( ) ) ;
4925- if !import_declarations. is_empty ( ) {
4927+ if !import_declarations. is_empty ( ) && !empty_header {
49264928 self . newline_push ( ) ;
49274929 for ( i, x) in import_declarations. iter ( ) . enumerate ( ) {
49284930 if i != 0 {
@@ -4934,16 +4936,26 @@ impl VerylWalker for Emitter {
49344936 }
49354937
49364938 if let Some ( ref x) = arg. module_declaration_opt1 {
4937- self . space ( 1 ) ;
4939+ if import_declarations. is_empty ( ) {
4940+ self . space ( 1 ) ;
4941+ }
49384942 self . with_parameter ( & x. with_parameter ) ;
49394943 }
49404944 if let Some ( ref x) = arg. module_declaration_opt2 {
4941- self . space ( 1 ) ;
4945+ if import_declarations. is_empty ( ) || arg. module_declaration_opt1 . is_some ( ) {
4946+ self . space ( 1 ) ;
4947+ }
49424948 self . port_declaration ( & x. port_declaration ) ;
49434949 }
49444950 self . token_will_push ( & arg. l_brace . l_brace_token . replace ( ";" ) ) ;
49454951 for ( i, x) in arg. module_declaration_list . iter ( ) . enumerate ( ) {
49464952 self . newline_list ( i) ;
4953+ if i == 0 && !import_declarations. is_empty ( ) && empty_header {
4954+ for x in & import_declarations {
4955+ self . emit_import_declaration ( x) ;
4956+ self . newline ( ) ;
4957+ }
4958+ }
49474959 if i == 0 && self . modport_ports_table . is_some ( ) {
49484960 self . emit_expanded_modport_connections ( ) ;
49494961 self . modport_ports_table = None ;
@@ -4985,8 +4997,9 @@ impl VerylWalker for Emitter {
49854997 /// Semantic action for non-terminal 'InterfaceDeclaration'
49864998 fn interface_declaration ( & mut self , arg : & InterfaceDeclaration ) {
49874999 let symbol = symbol_table:: resolve ( arg. identifier . as_ref ( ) ) . unwrap ( ) ;
4988- let maps = self . get_generic_maps ( & symbol . found ) ;
5000+ let empty_header = arg . interface_declaration_opt1 . is_none ( ) ;
49895001
5002+ let maps = self . get_generic_maps ( & symbol. found ) ;
49905003 for ( i, map) in maps. iter ( ) . enumerate ( ) {
49915004 if i != 0 {
49925005 self . newline ( ) ;
@@ -5010,7 +5023,7 @@ impl VerylWalker for Emitter {
50105023
50115024 let mut import_declarations = self . file_scope_import . clone ( ) ;
50125025 import_declarations. append ( & mut arg. collect_import_declarations ( ) ) ;
5013- if !import_declarations. is_empty ( ) {
5026+ if !import_declarations. is_empty ( ) && !empty_header {
50145027 self . newline_push ( ) ;
50155028 for ( i, x) in import_declarations. iter ( ) . enumerate ( ) {
50165029 if i != 0 {
@@ -5022,12 +5035,20 @@ impl VerylWalker for Emitter {
50225035 }
50235036
50245037 if let Some ( ref x) = arg. interface_declaration_opt1 {
5025- self . space ( 1 ) ;
5038+ if import_declarations. is_empty ( ) {
5039+ self . space ( 1 ) ;
5040+ }
50265041 self . with_parameter ( & x. with_parameter ) ;
50275042 }
50285043 self . token_will_push ( & arg. l_brace . l_brace_token . replace ( ";" ) ) ;
50295044 for ( i, x) in arg. interface_declaration_list . iter ( ) . enumerate ( ) {
50305045 self . newline_list ( i) ;
5046+ if i == 0 && !import_declarations. is_empty ( ) && empty_header {
5047+ for x in & import_declarations {
5048+ self . emit_import_declaration ( x) ;
5049+ self . newline ( ) ;
5050+ }
5051+ }
50315052 self . interface_group ( & x. interface_group ) ;
50325053 }
50335054 self . newline_list_post ( arg. interface_declaration_list . is_empty ( ) ) ;
0 commit comments