@@ -60,6 +60,7 @@ pub struct Emitter {
6060 single_line : Vec < ( ) > ,
6161 multi_line : Vec < ( ) > ,
6262 adjust_line : bool ,
63+ keep_tail_newline : bool ,
6364 in_always_ff : bool ,
6465 in_direction_modport : bool ,
6566 in_direction_with_var : bool ,
@@ -108,6 +109,7 @@ impl Default for Emitter {
108109 single_line : Vec :: new ( ) ,
109110 multi_line : Vec :: new ( ) ,
110111 adjust_line : false ,
112+ keep_tail_newline : false ,
111113 in_always_ff : false ,
112114 in_direction_modport : false ,
113115 in_direction_with_var : false ,
@@ -328,7 +330,7 @@ impl Emitter {
328330 fn push_token ( & mut self , x : & Token ) {
329331 self . consume_adjust_line ( x) ;
330332 let text = resource_table:: get_str_value ( x. text ) . unwrap ( ) ;
331- let text = if text. ends_with ( '\n' ) {
333+ let text = if ! self . keep_tail_newline && text. ends_with ( '\n' ) {
332334 self . consumed_next_newline = true ;
333335 text. trim_end ( )
334336 } else {
@@ -1559,8 +1561,7 @@ impl Emitter {
15591561 }
15601562
15611563 let user_defined = r#type. unwrap ( ) . get_user_defined ( ) ?;
1562- let ( type_symbol, _) =
1563- resolve_generic_path ( & user_defined. path , & symbol. namespace , Some ( map) ) ;
1564+ let ( type_symbol, _) = user_defined. path . resolve_path ( & symbol. namespace , Some ( map) ) ;
15641565 type_symbol
15651566 . ok ( )
15661567 . map ( |x| ( x. found , x. full_path , x. generic_tables ) )
@@ -1796,10 +1797,10 @@ impl Emitter {
17961797 ) -> ( Result < ResolveResult , ResolveError > , GenericSymbolPath ) {
17971798 let generic_map = self . generic_map . last ( ) ;
17981799 if let Some ( namespace) = namespace {
1799- resolve_generic_path ( path, namespace, generic_map)
1800+ path. resolve_path ( namespace, generic_map)
18001801 } else {
18011802 let namespace = namespace_table:: get ( path. paths [ 0 ] . base . id ) . unwrap ( ) ;
1802- resolve_generic_path ( path, & namespace, generic_map)
1803+ path. resolve_path ( & namespace, generic_map)
18031804 }
18041805 }
18051806
@@ -2007,6 +2008,11 @@ impl VerylWalker for Emitter {
20072008 }
20082009 }
20092010
2011+ /// Semantic action for non-terminal 'EscapedBackslash'
2012+ fn escaped_backslash ( & mut self , arg : & EscapedBackslash ) {
2013+ self . token ( & arg. escaped_backslash_token . replace ( "\\ " ) ) ;
2014+ }
2015+
20102016 /// Semantic action for non-terminal 'Bool'
20112017 fn bool ( & mut self , arg : & Bool ) {
20122018 self . veryl_token ( & arg. bool_token . replace ( "logic" ) ) ;
@@ -5268,21 +5274,39 @@ impl VerylWalker for Emitter {
52685274 /// Semantic action for non-terminal 'EmbedDeclaration'
52695275 fn embed_declaration ( & mut self , arg : & EmbedDeclaration ) {
52705276 if arg. identifier . identifier_token . to_string ( ) == "inline" {
5271- let text = arg. embed_content . embed_content_token . to_string ( ) ;
5272- let text = if arg. identifier0 . identifier_token . to_string ( ) == "sv" {
5273- & text
5274- . replace ( "{{{" , "`ifndef SYNTHESIS" )
5275- . replace ( "}}}" , "`endif" )
5276- } else {
5277- text. strip_prefix ( "{{{" )
5278- . unwrap ( )
5279- . strip_prefix ( "}}}" )
5280- . unwrap ( )
5281- } ;
5282- self . veryl_token ( & arg. embed_content . embed_content_token . replace ( text) ) ;
5277+ let is_sv = arg. identifier0 . identifier_token . to_string ( ) == "sv" ;
5278+
5279+ if is_sv {
5280+ self . token (
5281+ & arg. embed_content
5282+ . embed_triple_l_brace
5283+ . embed_triple_l_brace_token
5284+ . replace ( "`ifndef SYNTHESIS" ) ,
5285+ ) ;
5286+ }
5287+
5288+ self . keep_tail_newline = true ;
5289+ for x in & arg. embed_content . embed_content_list {
5290+ self . embed_item ( & x. embed_item ) ;
5291+ }
5292+ self . keep_tail_newline = false ;
5293+
5294+ if is_sv {
5295+ self . token (
5296+ & arg. embed_content
5297+ . embed_triple_r_brace
5298+ . embed_triple_r_brace_token
5299+ . replace ( "`endif" ) ,
5300+ ) ;
5301+ }
52835302 }
52845303 }
52855304
5305+ /// Semantic action for non-terminal 'EmbedIdentifier'
5306+ fn embed_identifier ( & mut self , arg : & EmbedIdentifier ) {
5307+ self . scoped_identifier ( & arg. scoped_identifier ) ;
5308+ }
5309+
52865310 /// Semantic action for non-terminal 'IncludeDeclaration'
52875311 fn include_declaration ( & mut self , arg : & IncludeDeclaration ) {
52885312 if arg. identifier . identifier_token . to_string ( ) == "inline" {
@@ -5724,63 +5748,3 @@ pub fn emitting_identifier(arg: &Identifier) -> Identifier {
57245748 } ;
57255749 identifier_with_prefix_suffix ( arg, & prefix, & suffix)
57265750}
5727-
5728- pub fn resolve_generic_path (
5729- path : & GenericSymbolPath ,
5730- namespace : & Namespace ,
5731- generic_maps : Option < & Vec < GenericMap > > ,
5732- ) -> ( Result < ResolveResult , ResolveError > , GenericSymbolPath ) {
5733- let mut path = path. clone ( ) ;
5734- path. resolve_imported ( namespace, generic_maps) ;
5735-
5736- for i in 0 ..path. len ( ) {
5737- let base = path. base_path ( i) ;
5738- if let Ok ( symbol) = symbol_table:: resolve ( ( & base, namespace) ) {
5739- if !symbol. found . kind . is_generic ( ) {
5740- continue ;
5741- }
5742-
5743- let params = symbol. found . generic_parameters ( ) ;
5744- let n_args = path. paths [ i] . arguments . len ( ) ;
5745-
5746- for param in params. iter ( ) . skip ( n_args) {
5747- path. paths [ i]
5748- . arguments
5749- . push ( param. 1 . default_value . as_ref ( ) . unwrap ( ) . clone ( ) ) ;
5750- }
5751-
5752- for arg in & mut path. paths [ i] . arguments {
5753- if let Ok ( symbol) = symbol_table:: resolve ( ( & arg. mangled_path ( ) , namespace) ) {
5754- if let Some ( target) = symbol. found . alias_target ( ) {
5755- if let ( Ok ( _) , path) =
5756- resolve_generic_path ( & target, & symbol. found . namespace , generic_maps)
5757- {
5758- * arg = path;
5759- }
5760- }
5761- }
5762- }
5763- }
5764- }
5765-
5766- if let Some ( maps) = generic_maps {
5767- path. apply_map ( maps) ;
5768- }
5769-
5770- let result = symbol_table:: resolve ( ( & path. mangled_path ( ) , namespace) ) ;
5771- if let Ok ( symbol) = & result {
5772- if let Some ( target) = symbol. found . alias_target ( ) {
5773- if let Some ( parent) = symbol. found . get_parent ( ) {
5774- if matches ! ( parent. kind, SymbolKind :: GenericInstance ( _) ) {
5775- // Alias target may be a generic parameter if it is defined in a generic package.
5776- // Need to apply parent's generic map to resolve a generic parameter.
5777- let map = parent. generic_maps ( ) ;
5778- return resolve_generic_path ( & target, & symbol. found . namespace , Some ( & map) ) ;
5779- }
5780- }
5781- return resolve_generic_path ( & target, & symbol. found . namespace , generic_maps) ;
5782- }
5783- }
5784-
5785- ( result, path)
5786- }
0 commit comments